Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Each example, when run, prints its output to the console.
| morphology_lemmas.py | Gets the lemmas of words from a piece of text |
| morphology_parts-of-speech.py | Gets the part-of-speech tags for words in a piece of text |
| ping.py | Pings the Rosette API to check for reachability |
| relationships.py | Gets the relationships between entities from a piece of text |
| sentences.py | Gets the sentences from a piece of text |
| sentiment.py | Gets the sentiment of a local file |
| tokens.py | Gets the tokens (words) from a piece of text |
Expand Down
28 changes: 10 additions & 18 deletions examples/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,20 @@
Example code to call Rosette API to get the category of a document (at a given URL).
"""

import argparse
import json

from rosette.api import API, DocumentParameters

parser = argparse.ArgumentParser(description="Get the category of a piece of a document at a URL")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
parser.add_argument("--url", nargs="?", default="https://en.wikipedia.org/wiki/Basis_Technology_Corp.", help="Optional URL for data")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
url = "https://en.wikipedia.org/wiki/Basis_Technology_Corp."
# Create an API instance
api = API(user_key=key)
params = DocumentParameters()

params = DocumentParameters()
# Use a URL to input data instead of a string
params["contentUri"] = url
result = api.categories(params)

# Use a URL to input data instead of a string
params["contentUri"] = args.url

result = api.categories(params)

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
24 changes: 8 additions & 16 deletions examples/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@
Example code to call Rosette API to get entities from a piece of text.
"""

import argparse
import json

from rosette.api import API, DocumentParameters

parser = argparse.ArgumentParser(description="Get the entities from a piece of text")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)

params = DocumentParameters()
params["content"] = u"President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill based on Christian faith by July 1st or Washington will become totally dysfunctional, a terrible outcome for American people."
result = api.entities(params) # entity linking is turned off

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
def run(key):
# Create an API instance
api = API(user_key=key)
params = DocumentParameters()
params["content"] = u"President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill based on Christian faith by July 1st or Washington will become totally dysfunctional, a terrible outcome for American people."
result = api.entities(params) # entity linking is turned off
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
22 changes: 8 additions & 14 deletions examples/entities_linked.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
Example code to call Rosette API to get linked (against Wikipedia) entities from a piece of text.
"""

import argparse
import json

from rosette.api import API, DocumentParameters

parser = argparse.ArgumentParser(description="Get linked entities from a piece of text")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
# Create an API instance
api = API(user_key=key)

params = DocumentParameters()
params["content"] = u"President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill based on Christian faith by July 1st or Washington will become totally dysfunctional, a terrible outcome for American people."
result = api.entities(params, True) # entity linking is turned on
params = DocumentParameters()
params["content"] = u"President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill based on Christian faith by July 1st or Washington will become totally dysfunctional, a terrible outcome for American people."
result = api.entities(params, True) # entity linking is turned on

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
20 changes: 7 additions & 13 deletions examples/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@
Example code to call Rosette API to get information such as version and build
"""

import argparse
import json

from rosette.api import API
from rosette.api import API, DocumentParameters

parser = argparse.ArgumentParser(description="Get information about Rosette API")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
# Create an API instance
api = API(user_key=key)

result = api.info()
result = api.info()

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
22 changes: 8 additions & 14 deletions examples/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,19 @@
Example code to call Rosette API to determine the language of a piece of text.
"""

import argparse
import json

from rosette.api import API, DocumentParameters

parser = argparse.ArgumentParser(description="Determine the language of a piece of text")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
# Create an API instance
api = API(user_key=key)

params = DocumentParameters()
params = DocumentParameters()

params["content"] = u"Por favor Señorita, says the man."
result = api.language(params)
params["content"] = u"Por favor Señorita, says the man."
result = api.language(params)

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
24 changes: 9 additions & 15 deletions examples/matched-name.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,19 @@
Example code to call Rosette API to get match score (similarity) of two names.
"""

import argparse
import json

from rosette.api import API, NameMatchingParameters

parser = argparse.ArgumentParser(description="Get the similarity score of two names")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
# Create an API instance
api = API(user_key=key)

params = NameMatchingParameters()
params["name1"] = {"text": "Michael Jackson", "language": "eng", "entityType": "PERSON"}
params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"}
result = api.matched_name(params)
params = NameMatchingParameters()
params["name1"] = {"text": "Michael Jackson", "language": "eng", "entityType": "PERSON"}
params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"}
result = api.matched_name(params)

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
22 changes: 8 additions & 14 deletions examples/morphology_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
Example code to call Rosette API to get the complete morphological analysis of a piece of text.
"""

import argparse
import json

from rosette.api import API, DocumentParameters

parser = argparse.ArgumentParser(description="Get the complete morphological analysis of a piece of text")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
# Create an API instance
api = API(user_key=key)

params = DocumentParameters()
params["content"] = u"The quick brown fox jumped over the lazy dog. Yes he did."
result = api.morphology(params)
params = DocumentParameters()
params["content"] = u"The quick brown fox jumped over the lazy dog. Yes he did."
result = api.morphology(params)

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
22 changes: 8 additions & 14 deletions examples/morphology_compound-components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
Example code to call Rosette API to get de-compounded words from a piece of text.
"""

import argparse
import json

from rosette.api import API, DocumentParameters, MorphologyOutput

parser = argparse.ArgumentParser(description="Get de-compounded words from a piece of text")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
# Create an API instance
api = API(user_key=key)

params = DocumentParameters()
params["content"] = u"Rechtsschutzversicherungsgesellschaften"
result = api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS)
params = DocumentParameters()
params["content"] = u"Rechtsschutzversicherungsgesellschaften"
result = api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS)

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
22 changes: 8 additions & 14 deletions examples/morphology_han-readings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
Example code to call Rosette API to get Chinese readings of words in a piece of text.
"""

import argparse
import json

from rosette.api import API, DocumentParameters, MorphologyOutput

parser = argparse.ArgumentParser(description="Get Chinese readings of words in a piece of text")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
# Create an API instance
api = API(user_key=key)

params = DocumentParameters()
params["content"] = u"北京大学生物系主任办公室内部会议"
result = api.morphology(params, MorphologyOutput.HAN_READINGS)
params = DocumentParameters()
params["content"] = u"北京大学生物系主任办公室内部会议"
result = api.morphology(params, MorphologyOutput.HAN_READINGS)

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
22 changes: 8 additions & 14 deletions examples/morphology_lemmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
Example code to call Rosette API to get lemmas for words in a piece of text.
"""

import argparse
import json

from rosette.api import API, DocumentParameters, MorphologyOutput

parser = argparse.ArgumentParser(description="Get lemmas for words in a piece of text")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
# Create an API instance
api = API(user_key=key)

params = DocumentParameters()
params["content"] = u"The fact is that the geese just went back to get a rest and I'm not banking on their return soon"
result = api.morphology(params, MorphologyOutput.LEMMAS)
params = DocumentParameters()
params["content"] = u"The fact is that the geese just went back to get a rest and I'm not banking on their return soon"
result = api.morphology(params, MorphologyOutput.LEMMAS)

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
22 changes: 8 additions & 14 deletions examples/morphology_parts-of-speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
Example code to call Rosette API to get part-of-speech tags for words in a piece of text.
"""

import argparse
import json

from rosette.api import API, DocumentParameters, MorphologyOutput

parser = argparse.ArgumentParser(description="Get part-of-speech tags for words in text")
parser.add_argument("--key", required=True, help="Rosette API key")
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
args = parser.parse_args()

# Create an API instance
if args.service_url:
api = API(service_url=args.service_url, user_key=args.key)
else:
api = API(user_key=args.key)
def run(key):
# Create an API instance
api = API(user_key=key)

params = DocumentParameters()
params["content"] = u"The fact is that the geese just went back to get a rest and I'm not banking on their return soon"
result = api.morphology(params, MorphologyOutput.PARTS_OF_SPEECH)
params = DocumentParameters()
params["content"] = u"The fact is that the geese just went back to get a rest and I'm not banking on their return soon"
result = api.morphology(params, MorphologyOutput.PARTS_OF_SPEECH)

print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")
Loading