The Python binding requires Python 2.6 or greater and is available through pip:
pip install rosette_api
# 1. Set utf-8 encoding.
# -*- coding: utf-8 -*-
# 2. Imports from rosette.api.
from rosette.api import API, DocumentParameters, MorphologyOutput
# 3. Create API object.
api = API("[your_api-key]")
# 4. Create parameters object
params = DocumentParameters()
# 5. Set parameters.
params["content"] = "The quick brown fox jumped over the lazy dog. Yes he did."
# 6. Make a call.
result = api.morphology(params)
# result is a Python dictionary that contains
{u'tokens': [u'The', u'quick', u'brown', u'fox', u'jumped', u'over', u'the', u'lazy', u'dog', u'.', u'Yes', u'he', u'did', u'.'], u'posTags': [u'DET', u'ADJ', u'ADJ', u'NOUN', u'VERB', u'ADP', u'DET', u'ADJ', u'NOUN', u'PUNCT', u'VERB', u'PRON', u'VERB', u'PUNCT'], u'compoundComponents': [None, None, None, None, None, None, None, None, None, None, None, None, None, None], u'lemmas': [u'the', u'quick', u'brown', u'fox', u'jump', u'over', u'the', u'lazy', u'dog', u'.', u'yes', u'he', u'do', u'.'], u'hanReadings': [None, None, None, None, None, None, None, None, None, None, None, None, None, None]}
The samples use the following procedure:
-
If the application reads text in, set encoding to utf-8 in the first line of the script.
-
Import the
rosette.api
packages that your application needs. Therosette.api
packages includeAPI
DocumentParameters
NameSimilarityParameters
NameTranslationParameters
MorphologyOutput
DataFormat
-
Create an
API
object with theuser_key
parameter. -
Create a parameters object for your request input:
Parameter Endpoint NameSimilarityParameters
for /name-similarity
NameTranslationParameters
for /translated-name
DocumentParameters
for all other endpoints -
Set the parameters required for your operation: "
content
" or "contentUri
" forDocumentParameters
; "name
" and "targetLanguage
" forNameTranslationParameters
; "name1.text
" and "name2.text
" forNameSimilarityParameters
; Other parameters are optional. -
Invoke the
API
method for the endpoint you are calling. The methods areentities(linked)
wherelinked
isFalse
for entity extraction andTrue
for entity linking.categories()
sentiment()
language()
morphology(tag)
where tag is a member ofMorphologyOutput
:LEMMAS
,PARTS_OF_SPEECH
,COMPOUND_COMPONENTS
,HAN_READINGS
, orCOMPLETE
. An empty tag is equivalent toCOMPLETE
.sentences()
tokens()
relationships()
name_translation()
name_similarity()
matched_name()
*deprecatedtranslated_name()
*deprecated
-
The API will return a dictionary with the results.
See examples for more request samples.
See documentation
Visit Rosette API site