The SupWSD Python API is a Python binding to an HTTP RESTful service that gives you programmatic access to SupWSD, a framework for supervised Word Sense Disambiguation (WSD). The SupWSD service is available only for English and enforces a default limit of 1000 free requests per 1 hour period.

The SupWSD Python API requires python 2.7 or above.

LICENSES: All the data of the external resources are released under the terms of the respective licenses.

Installation

To work with the Python API, install the package with:

Copied to clipboard click to copy
pip install supwsd

Usage examples

Here are some code samples to demonstrate using the SupWSD API.

Retrieve the SupSense for all words

Copied to clipboard click to copy
from supwsd.wsd import SupWSD
		
text = 'The human brain is quite proficient at word-sense disambiguation.'

for sense in SupWSD().senses(text):
	print('Word: {}\tLemma: {}\tPOS: {}\tSense: {}'.format(sense.word, sense.lemma, sense.pos, sense.key()))

Retrieve the SupSense for specific words (use SupWSD.SENSE_TAG to tag a word)

Copied to clipboard click to copy
from supwsd.wsd import SupWSD
		
text = 'The human ' + SupWSD.SENSE_TAG + 'brain' + SupWSD.SENSE_TAG + ' is quite proficient at word-sense disambiguation. The fact that natural language is formed '+ SupWSD.SENSE_TAG+'in a way'+ SupWSD.SENSE_TAG+' that requires so much of it is a ' + SupWSD.SENSE_TAG + 'reflection' + SupWSD.SENSE_TAG + ' of that neurologic reality.'

for sense in SupWSD().senses(text):
	print('Word: {}\tLemma: {}\tPOS: {}\tSense: {}'.format(sense.word, sense.lemma, sense.pos, sense.key()))

Retrieve all SupResult objects (with sense keys and probabilities)

Copied to clipboard click to copy
from supwsd.wsd import SupWSD

text = 'The human brain is quite proficient at word-sense disambiguation.'

for sense in SupWSD().senses(text,True):
	print('Word: {}\tLemma: {}\tPOS: {}\tSense: {}'.format(sense.word, sense.lemma, sense.pos, sense.key()))
	for result in sense.results:
		print('Sense {}\tProbability: {}'.format(result.key, result.prob))

Statistics

SemCor + OMSTI
Total number of senses: 33.958
Total number of lemmas: 22.435
Total number of nouns: 11.391
Total number of verbs: 4.664
Total number of adjectives: 4.879
Total number of adverbs: 1.501