class documentation

class LocalAPI(AbstractAPI):

View In Hierarchy

The local api

Method get_senses Get the senses of synsets searched by words or by ResourceIDs, satisfying the optional constraints.
Method get_senses_containing Get the senses of synsets containing the word with the given constraints.
Method get_senses_from Get the senses of synsets from the word with the given constraints.
Method get_synset Return the synset identified by the ResourceID in input.
Method get_synsets Get synsets by words or by ResourceIDs, satisfying the optional constraints.
Method iterator Create a new instance of BabelSynset iterator.
Method lexicon_iterator Create a new instance of a lexicon iterator.
Method offset_iterator Create a new instance of an offset iterator.
Method to_babelnet_synsets Get a BabelSytnset using the languages passed as input and an id_.
Method to_synsets Convert from ResourceID to the corresponding BabelSynset.
Method version Get the version of loaded BabelNet indices.
Method wordnet_iterator Create a new instance of a WordNet iterator.
Method _get_outgoing_edges Return the outgoing edges from a given BabelSynsetID
Method _get_senses Private version of get_senses().
Method _get_synsets Private version of get_synsets()
Method _mapping_from_ids Get the mapping from BabelSynsetID to _InternalBabelSynsetID.
Method _prepare_kwargs Prepare the input data by trasforming each iterable in an ordered set.
Method _to_wordnet_synsets 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_outgoing_edges Return the outgoing edges from a given BabelSynsetID
def get_senses(self, *args, **kwargs):

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.
**kwargskeyword arguemts.
containing:boolUsed if the senses are searched by words: if it is True, the words have to be contained in the sense (default False).
from_langs:Iterable[Language]An iterable collection of Languages used for searching the senses.
to_langs:Iterable[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:boolTrue if the search is insensitive to accents, etc. (default True).
sources:Iterable[BabelSenseSource]An iterable collection of BabelSenseSources used to restrict the search.
synset_filters:Iterable[Callable[[BabelSynset], bool]]An iterable collection of filters (functions accepting a BabelSynset and returning bool) to be applied to each synset retrieved.
sense_filters:Iterable[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
ValueErrorIf arg is not an homogeneous collection
def get_senses_containing(self, word, language=None, pos=None, to_langs=None):

Get the senses of synsets containing the word with the given constraints.

Parameters
word:strThe 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.
to_langs:Optional[Set[Language]]An iterable collection of Languages in which the senses are to be retrieved.
Returns
List[BabelSense]The senses of the word.
def get_senses_from(self, word, language=None, pos=None, to_langs=None):

Get the senses of synsets from the word with the given constraints.

Parameters
word:strThe 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.
to_langs:Optional[Set[Language]]An iterable collection of Languages in which the senses are to be retrieved.
Returns
List[BabelSense]The senses of the word.
def get_synset(self, resource_id, to_langs=None):

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
resource_id:ResourceIDThe resource identifier.
to_langs:Optional[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.
def get_synsets(self, *args, **kwargs):

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.
**kwargskeyword arguemts.
containing:boolUsed if the senses are searched by words: if it is True, the words have to be contained in the sense (default False).
from_langs:Iterable[Language]An iterable collection of Languages used for searching the senses.
to_langs:Iterable[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:boolTrue if the search is insensitive to accents, etc. (default True).
sources:Iterable[BabelSenseSource]An iterable collection of BabelSenseSources used to restrict the search.
synset_filters:Iterable[Callable[[BabelSynset], bool]]An iterable collection of filters (functions accepting a BabelSynset and returning bool) to be applied to each synset retrieved.
sense_filters:Iterable[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
ValueErrorIf arg is not an homogeneous collection
def iterator(self):

Create a new instance of BabelSynset iterator.

Returns
BabelSynsetIteratorAn instance of a BabelSynset iterator.
Raises
NotImplementedErrorRaised if the function is called using online APIs.
def lexicon_iterator(self):

Create a new instance of a lexicon iterator.

Returns
BabelLexiconIteratorAn instance of a lexicon iterator.
Raises
NotImplementedErrorRaised if the function is called using online APIs.
def offset_iterator(self):

Create a new instance of an offset iterator.

Returns
BabelOffsetIteratorAn instance of an offset iterator.
Raises
NotImplementedErrorRaised if the function is called using online APIs.
def to_babelnet_synsets(self, id_, languages):

Get a BabelSytnset using the languages passed as input and an id_.

Parameters
id_the id that needs to be converted
languagesthe languages to use.
Raises
NotImplementedErrorif not implemented
def to_synsets(self, resource_id, languages=None):

Convert from ResourceID to the corresponding BabelSynset.

Parameters
resource_id:ResourceIDThe input ID.
languages:Optional[Iterable[Language]]The target languages to populate synsets with (default None).
Returns
List[BabelSynset]The list of corresponding synsets.
Raises
NotImplementedErrorif not implemented
def version(self):

Get the version of loaded BabelNet indices.

Returns
BabelVersionThe BabelVersion of BabelNet indices.
Raises
NotImplementedErrorif not implemented
def wordnet_iterator(self):

Create a new instance of a WordNet iterator.

Returns
WordNetSynsetIteratorAn instance of a WordNetSynset iterator.
Raises
NotImplementedErrorRaised if the function is called using online APIs.
def _get_outgoing_edges(self, synset_id):

Return the outgoing edges from a given BabelSynsetID

Parameters
synset_id:BabelSynsetIDThe BabelSynsetID whose outgoing edges we want to retrieve.
Returns
List[BabelSynsetRelation]The list of relation edges.
Raises
NotImplementedErrorif not implemented
def _get_senses(self, words=None, resource_ids=None, containing=False, to_langs=None, sources=None, **kwargs):

Private version of get_senses().

Parameters
words:Optional[Set[str]]A set of words to look for
resource_ids:Optional[Set[ResourceID]]a set of resource ids to look for
containing:Optional[bool]Contaninig parameter.
to_langs:Optional[Set[Language]]If set, the results will be in these languages
sources:Optional[Set[BabelSenseSource]]filter on the sources
**kwargskeyword arguemts.s
Returns
List[BabelSense]the list of BabelSenses
Raises
NotImplementedErrorif not implemented
def _get_synsets(self, words=None, resource_ids=None, from_langs=None, to_langs=None, poses=None, normalized=True, sources=None, synset_filters=None, sense_filters=None):

Private version of get_synsets()

Parameters
words:Optional[Set[str]]A set of words to look for
resource_ids:Optional[Set[ResourceID]]a set of resource ids to look for
from_langs:Optional[Set[Language]]The language of the words passed as input
to_langs:Optional[Set[Language]]If set, the results will be in these languages
poses:Set[Set[POS]]Filter on poses
normalized:Optional[bool]if true, results will be normalized
sources:Optional[Set[BabelSenseSource]]filter on sources
synset_filters:Optional[Set[Callable[[BabelSynset], bool]]]filter on synsets
sense_filters:Optional[Set[Callable[[BabelSense], bool]]]filter on senses
Returns
List[BabelSynset]the list of BabelSynset.
Raises
NotImplementedErrorif not implemented
def _mapping_from_ids(self, *ids):

Get the mapping from BabelSynsetID to _InternalBabelSynsetID.

Parameters
*ids:BabelSynsetIDa tuple of BabelSynsetID to use.
Returns
Dict[BabelSynsetID, List["_InternalBabelSynsetID"]The mapping from BabelSynsetID to a list of _InternalBabelSynsetID
Raises
NotImplementedErrorif not implemented
def _prepare_kwargs(self, kwargs):

Prepare the input data by trasforming each iterable in an ordered set.

Parameters
kwargsthe keyword argumetns to unpack
def _to_wordnet_synsets(self, id_, languages):

Convert a WordNetSynsetID into a Synset.

Parameters
id_the WordnetSynsetID to convert
languagesthe languages that will be used for the results inside the Synset.
def examples(self, synset_id, filter_langs, *ids):

Get the examples (in the specified languages) of a BabelSynsetID.

Parameters
synset_id:BabelSynsetIDThe BabelSynsetID to use
filter_langs:Set[Language]The set of language to use
*ids:_InternalBabelSynsetIDthe ids
Returns
List[BabelExample]A list of BabelExamples
Raises
NotImplementedErrorRaised if not implemented.
def glosses(self, synset_id, filter_langs, *ids):

Get the glosses (in the specified languages) of a BabelSysetID.

Parameters
synset_id:BabelSynsetIDthe BabelSynsetID from where the glosses will be retreived
filter_langs:Set[Language]The set of language to use.
*ids:_InternalBabelSynsetIDthe _InternalBabelSynsetID
Returns
List[BabelGloss]A list of BabelGlosses
Raises
NotImplementedErrorRaised if not implemented.
def images(self, id):

Get the images of a BabelSynsetID.

Parameters
id:BabelSynsetIDthe BabelSynsetID to use
Returns
List[BabelImage]A list of BabelImages
Raises
NotImplementedErrorRaised if the function is called using online APIs.
_index =

An instance of the BabelNet indexes.