-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Andrea Sterbini <[email protected]> Co-authored-by: Andrea Sterbini <[email protected]>
- Loading branch information
1 parent
806cda8
commit 4bc9fe0
Showing
6 changed files
with
122 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
from spacy.tokens.doc import Doc | ||
from spacy.tokens.token import Token | ||
from spacy.parts_of_speech import * | ||
from spacy.language import Language | ||
|
||
from spacy_wordnet.wordnet_domains import Wordnet, load_wordnet_domains | ||
|
||
try: | ||
|
||
@Language.factory("spacy_wordnet", default_config={"lang": "en"}) | ||
def wordnet_annotator(nlp, name, lang: str): | ||
return WordnetAnnotator(lang=lang) | ||
|
||
@Language.factory("spacy_wordnet", default_config={}) | ||
def wordnet_annotator(nlp, name): | ||
return WordnetAnnotator(nlp=nlp, name=name) | ||
|
||
except AttributeError: | ||
|
||
pass # spacy 2.x | ||
|
||
|
||
class WordnetAnnotator(object): | ||
__FIELD = "wordnet" | ||
|
||
def __init__(self, lang: str = "es"): | ||
def __init__(self, nlp: Language, name: str): | ||
Token.set_extension(WordnetAnnotator.__FIELD, default=None, force=True) | ||
load_wordnet_domains() | ||
self.__lang = lang | ||
self.__lang = nlp.lang | ||
|
||
def __call__(self, doc: Doc): | ||
for token in doc: | ||
wordnet = Wordnet(token=token, lang=self.__lang) | ||
token._.set(WordnetAnnotator.__FIELD, wordnet) | ||
|
||
return doc | ||
|
||
|
||
if hasattr(Language, "factory"): | ||
# SpaCy 3.x | ||
Language.factory("wordnet")(WordnetAnnotator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters