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"] = u"Was ist so böse an der Europäischen Zentralbank?"
# 6. Make a call.
result = api.morphology(params)
# result is a Python dictionary that contains
{u'lemmas': [{u'text': u'Was', u'lemma': u'was'}, {u'text': u'ist', u'lemma': u'sein'}, {u'text': u'so', u'lemma': u'so'}, {u'text': u'böse', u'lemma': u'böse'}, {u'text': u'an', u'lemma': u'an'}, {u'text': u'der', u'lemma': u'der'}, {u'text': u'Europäischen', u'lemma': u'europäisch'}, {u'text': u'Zentralbank', u'lemma': u'Zentralbank'}, {u'text': u'?', u'lemma': u'?'}]}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.apipackages that your application needs. Therosette.apipackages includeAPIDocumentParametersNameMatchingParametersNameTranslationParametersMorphologyOutputDataFormatInputUnit
-
Create an
APIobject with theuser_keyparameter. -
Create a parameters object for your request input:
Parameter Endpoint NameMatchingParametersfor /matched-nameNameTranslationParametersfor /translated-nameDocumentParametersfor all other endpoints -
Set the parameters required for your operation: "
content" or "contentUri" forDocumentParameters; "name" and "targetLanguage" forNameTranslationParameters; "name1.text" and "name2.text" forNameMatchingParameters; Other parameters are optional. -
Create an
APImethod for the endpoint you are calling. The methods areentities(linked)wherelinkedisFalsefor entity extraction andTruefor 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()matched_name()translated_name()
-
The API will return a dictionary with the results.