Skip to content

Commit

Permalink
Merge pull request #17 from renaudjester/fix-bitwise-operator
Browse files Browse the repository at this point in the history
fix: wrong usage of bitwise operator
  • Loading branch information
JulesBelveze authored Jan 17, 2023
2 parents ab212bb + 439951f commit 461c9b3
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions concepcy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]):
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 461c9b3

Please sign in to comment.