From 439951f73e80f0c89ff00bb0baf5680c11d6ffdb Mon Sep 17 00:00:00 2001 From: renaudjester Date: Tue, 17 Jan 2023 22:33:35 +0100 Subject: [PATCH] fix: wrong usage of bitwise operator --- concepcy/__init__.py | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/concepcy/__init__.py b/concepcy/__init__.py index 6f705ea..52e0bfc 100644 --- a/concepcy/__init__.py +++ b/concepcy/__init__.py @@ -12,28 +12,23 @@ "concepcy", default_config={ "url": "https://api.conceptnet.io/query?node=/c/{lang}/{word}&other=/c/{lang}", - "relations_of_interest": [ - "RelatedTo", - "SimilarTo", - "InstanceOf" - ], + "relations_of_interest": ["RelatedTo", "SimilarTo", "InstanceOf"], "filter_edge_weight": 2, "filter_missing_text": False, - "as_dict": True - } + "as_dict": True, + }, ) class ConcepCyComponent: """ConceptNet component for spaCy pipeline""" def __init__( - self, - nlp: Language, - name: str, - url: str, - relations_of_interest: List[str], - as_dict: bool, - filter_edge_weight: Optional[int] = None, - filter_missing_text: Optional[bool] = None + self, + nlp: Language, + url: str, + relations_of_interest: List[str], + as_dict: bool, + filter_edge_weight: Optional[int] = None, + filter_missing_text: Optional[bool] = None, ): """ Notes: @@ -43,8 +38,6 @@ def __init__( Args: nlp (Language): spaCy language object - name (str): - name of the component url (str): base url to use to query the ConceptNet API relations_of_interest (List[str]): @@ -62,8 +55,10 @@ def __init__( self.lang = nlp.lang filter_weight = -1 if filter_edge_weight is None else filter_edge_weight - text_filter = True if filter_missing_text is None else ~filter_missing_text - filter_edge_fct = lambda x: (x.text is None or text_filter) and x.weight < filter_weight + text_filter = True if filter_missing_text is None else not filter_missing_text + filter_edge_fct = ( + lambda x: (x.text is None or text_filter) and x.weight < filter_weight + ) self.parser = ConceptnetParser(relations_of_interest, as_dict, filter_edge_fct) for relation in relations_of_interest: @@ -81,8 +76,15 @@ def make_requests(self, words: List[str]) -> List[Dict]: List[Dict]: responses from the ConceptNet API """ urls = [self.url.format(word=word, lang=self.lang) for word in words] - responses = boosted_requests(urls=urls, no_workers=32, max_tries=5, timeout=5, headers=None, parse_json=True, - verbose=False) + responses = boosted_requests( + urls=urls, + no_workers=32, + max_tries=5, + timeout=5, + headers=None, + parse_json=True, + verbose=False, + ) return responses def __call__(self, doc: Doc) -> Doc: