class LocalAPI(AbstractAPI):
The local api
Method | get |
Get the senses of synsets searched by words or by ResourceIDs, satisfying the optional constraints. |
Method | get |
Get the senses of synsets containing the word with the given constraints. |
Method | get |
Get the senses of synsets from the word with the given constraints. |
Method | get |
Return the synset identified by the ResourceID in input. |
Method | get |
Get synsets by words or by ResourceIDs, satisfying the optional constraints. |
Method | iterator |
Create a new instance of BabelSynset iterator. |
Method | lexicon |
Create a new instance of a lexicon iterator. |
Method | offset |
Create a new instance of an offset iterator. |
Method | to |
Get a BabelSytnset using the languages passed as input and an id_. |
Method | to |
Convert from ResourceID to the corresponding BabelSynset. |
Method | version |
Get the version of loaded BabelNet indices. |
Method | wordnet |
Create a new instance of a WordNet iterator. |
Method | _get |
Return the outgoing edges from a given BabelSynsetID |
Method | _get |
Private version of get_senses(). |
Method | _get |
Private version of get_synsets() |
Method | _mapping |
Get the mapping from BabelSynsetID to _InternalBabelSynsetID. |
Method | _prepare |
Prepare the input data by trasforming each iterable in an ordered set. |
Method | _to |
Convert a WordNetSynsetID into a Synset. |
Method | examples |
Get the examples (in the specified languages) of a BabelSynsetID. |
Method | glosses |
Get the glosses (in the specified languages) of a BabelSysetID. |
Method | images |
Get the images of a BabelSynsetID. |
Class Variable | _index |
An instance of the BabelNet indexes. |
Inherited from AbstractAPI
:
Method | get |
Return the outgoing edges from a given BabelSynsetID |
Get the senses of synsets searched by words or by ResourceIDs, satisfying the optional constraints.
Parameters | |
*args:Union[str , ResourceID] | A homogeneous collection of words (str) or ResourceIDs used to search for senses in synsets. |
**kwargs | keyword arguemts. |
containing:bool | Used if the senses are searched by words: if it is True, the words have to be contained in the sense (default False). |
fromIterable[Language] | An iterable collection of Languages used for searching the senses. |
toIterable[Language] | An iterable collection of Languages in which the senses are to be retrieved. |
poses:Iterable[POS] | An iterable collection of Parts of Speech of the senses. |
normalized:bool | True if the search is insensitive to accents, etc. (default True). |
sources:Iterable[BabelSenseSource] | An iterable collection of BabelSenseSources used to restrict the search. |
synsetIterable[Callable[[BabelSynset] , bool]] | An iterable collection of filters (functions accepting a BabelSynset and returning bool) to be applied to each synset retrieved. |
senseIterable[Callable[[BabelSynset] , bool]] | An iterable collection of filters (functions accepting a BabelSense and returning bool) to be applied to each sense retrieved. |
Returns | |
List[BabelSense] | The resulting senses. |
Raises | |
ValueError | If arg is not an homogeneous collection |
Get the senses of synsets containing the word with the given constraints.
Parameters | |
word:str | The word whose senses are to be retrieved. |
language:Optional[Language] | The language of the input word. |
pos:Optional[POS] | The Part of Speech of the word. |
toOptional[Set[Language]] | An iterable collection of Languages in which the senses are to be retrieved. |
Returns | |
List[BabelSense] | The senses of the word. |
Get the senses of synsets from the word with the given constraints.
Parameters | |
word:str | The word whose senses are to be retrieved. |
language:Optional[Language] | The language of the input word. |
pos:Optional[POS] | The Part of Speech of the word. |
toOptional[Set[Language]] | An iterable collection of Languages in which the senses are to be retrieved. |
Returns | |
List[BabelSense] | The senses of the word. |
Return the synset identified by the ResourceID in input.
Some examples that can be used follow:
import babelnet as bn # Retrieving BabelSynset from a Wikipedia page title: synset = bn.get_synset(WikipediaID('BabelNet', Language.EN, POS.NOUN)) # Retrieving BabelSynset from a WordNet id: synset = bn.get_synset(WordNetSynsetID('wn:03544360n')) # Retrieving BabelSynset from a Wikidata page id: synset = bn.get_synset(WikidataID('Q4837690')) # Retrieving BabelSynset from a OmegaWiki page id: synset = bn.get_synset(OmegaWikiID('1499705'))
Parameters | |
resourceResourceID | The resource identifier. |
toOptional[Set[Language]] | A set of languages to use. If passed as input, the results in those languages will be returned. |
Returns | |
Optional[BabelSynset] | The synset identified by the ResourceID. |
Get synsets by words or by ResourceIDs, satisfying the optional constraints.
Parameters | |
*args:Union[str , ResourceID] | A homogeneous collection of words (str) or ResourceIDs used to search for synsets or senses in synsets. |
**kwargs | keyword arguemts. |
containing:bool | Used if the senses are searched by words: if it is True, the words have to be contained in the sense (default False). |
fromIterable[Language] | An iterable collection of Languages used for searching the senses. |
toIterable[Language] | An iterable collection of Languages in which the senses are to be retrieved. |
poses:Iterable[POS] | An iterable collection of Parts of Speech of the senses. |
normalized:bool | True if the search is insensitive to accents, etc. (default True). |
sources:Iterable[BabelSenseSource] | An iterable collection of BabelSenseSources used to restrict the search. |
synsetIterable[Callable[[BabelSynset] , bool]] | An iterable collection of filters (functions accepting a BabelSynset and returning bool) to be applied to each synset retrieved. |
senseIterable[Callable[[BabelSynset] , bool]] | An iterable collection of filters (functions accepting a BabelSense and returning bool) to be applied to each sense retrieved. |
Returns | |
List[BabelSynset] | The resulting synsets. |
Raises | |
ValueError | If arg is not an homogeneous collection |
Create a new instance of BabelSynset iterator.
Returns | |
BabelSynsetIterator | An instance of a BabelSynset iterator. |
Raises | |
NotImplementedError | Raised if the function is called using online APIs. |
Create a new instance of a lexicon iterator.
Returns | |
BabelLexiconIterator | An instance of a lexicon iterator. |
Raises | |
NotImplementedError | Raised if the function is called using online APIs. |
Create a new instance of an offset iterator.
Returns | |
BabelOffsetIterator | An instance of an offset iterator. |
Raises | |
NotImplementedError | Raised if the function is called using online APIs. |
Get a BabelSytnset using the languages passed as input and an id_.
Parameters | |
id_ | the id that needs to be converted |
languages | the languages to use. |
Raises | |
NotImplementedError | if not implemented |
Convert from ResourceID to the corresponding BabelSynset.
Parameters | |
resourceResourceID | The input ID. |
languages:Optional[Iterable[Language]] | The target languages to populate synsets with (default None). |
Returns | |
List[BabelSynset] | The list of corresponding synsets. |
Raises | |
NotImplementedError | if not implemented |
Get the version of loaded BabelNet indices.
Returns | |
BabelVersion | The BabelVersion of BabelNet indices. |
Raises | |
NotImplementedError | if not implemented |
Create a new instance of a WordNet iterator.
Returns | |
WordNetSynsetIterator | An instance of a WordNetSynset iterator. |
Raises | |
NotImplementedError | Raised if the function is called using online APIs. |
Return the outgoing edges from a given BabelSynsetID
Parameters | |
synsetBabelSynsetID | The BabelSynsetID whose outgoing edges we want to retrieve. |
Returns | |
List[BabelSynsetRelation] | The list of relation edges. |
Raises | |
NotImplementedError | if not implemented |
Private version of get_senses().
Parameters | |
words:Optional[ | A set of words to look for |
resourceOptional[ | a set of resource ids to look for |
containing:Optional[ | Contaninig parameter. |
toOptional[ | If set, the results will be in these languages |
sources:Optional[ | filter on the sources |
**kwargs | keyword arguemts.s |
Returns | |
List[BabelSense] | the list of BabelSenses |
Raises | |
NotImplementedError | if not implemented |
Private version of get_synsets()
Parameters | |
words:Optional[ | A set of words to look for |
resourceOptional[ | a set of resource ids to look for |
fromOptional[ | The language of the words passed as input |
toOptional[ | If set, the results will be in these languages |
poses:Set[ | Filter on poses |
normalized:Optional[ | if true, results will be normalized |
sources:Optional[ | filter on sources |
synsetOptional[ | filter on synsets |
senseOptional[ | filter on senses |
Returns | |
List[BabelSynset] | the list of BabelSynset. |
Raises | |
NotImplementedError | if not implemented |
Get the mapping from BabelSynsetID to _InternalBabelSynsetID.
Parameters | |
*ids:BabelSynsetID | a tuple of BabelSynsetID to use. |
Returns | |
Dict[BabelSynsetID , List[ "_InternalBabelSynsetID"] | The mapping from BabelSynsetID to a list of _InternalBabelSynsetID |
Raises | |
NotImplementedError | if not implemented |
Prepare the input data by trasforming each iterable in an ordered set.
Parameters | |
kwargs | the keyword argumetns to unpack |
Convert a WordNetSynsetID into a Synset.
Parameters | |
id_ | the WordnetSynsetID to convert |
languages | the languages that will be used for the results inside the Synset. |
Get the examples (in the specified languages) of a BabelSynsetID.
Parameters | |
synsetBabelSynsetID | The BabelSynsetID to use |
filterSet[Language] | The set of language to use |
*ids:_InternalBabelSynsetID | the ids |
Returns | |
List[BabelExample] | A list of BabelExamples |
Raises | |
NotImplementedError | Raised if not implemented. |
Get the glosses (in the specified languages) of a BabelSysetID.
Parameters | |
synsetBabelSynsetID | the BabelSynsetID from where the glosses will be retreived |
filterSet[Language] | The set of language to use. |
*ids:_InternalBabelSynsetID | the _InternalBabelSynsetID |
Returns | |
List[BabelGloss] | A list of BabelGlosses |
Raises | |
NotImplementedError | Raised if not implemented. |
Get the images of a BabelSynsetID.
Parameters | |
id:BabelSynsetID | the BabelSynsetID to use |
Returns | |
List[BabelImage] | A list of BabelImages |
Raises | |
NotImplementedError | Raised if the function is called using online APIs. |