Skip to content

Commit 24d5a30

Browse files
committed
Merge pull request #10 from rosette-api/0.7.1
Merge 0.7.1 to master
2 parents f50ab07 + 7f16616 commit 24d5a30

32 files changed

+1358
-259
lines changed

.travis.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Each example, when run, prints its output to the console.
3131
| morphology_lemmas.py | Gets the lemmas of words from a piece of text |
3232
| morphology_parts-of-speech.py | Gets the part-of-speech tags for words in a piece of text |
3333
| ping.py | Pings the Rosette API to check for reachability |
34+
| relationships.py | Gets the relationships between entities from a piece of text |
3435
| sentences.py | Gets the sentences from a piece of text |
3536
| sentiment.py | Gets the sentiment of a local file |
3637
| tokens.py | Gets the tokens (words) from a piece of text |

examples/categories.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,20 @@
44
Example code to call Rosette API to get the category of a document (at a given URL).
55
"""
66

7-
import argparse
87
import json
98

109
from rosette.api import API, DocumentParameters
1110

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

18-
# Create an API instance
19-
if args.service_url:
20-
api = API(service_url=args.service_url, user_key=args.key)
21-
else:
22-
api = API(user_key=args.key)
12+
def run(key):
13+
url = "https://en.wikipedia.org/wiki/Basis_Technology_Corp."
14+
# Create an API instance
15+
api = API(user_key=key)
16+
params = DocumentParameters()
2317

24-
params = DocumentParameters()
18+
# Use a URL to input data instead of a string
19+
params["contentUri"] = url
20+
result = api.categories(params)
2521

26-
# Use a URL to input data instead of a string
27-
params["contentUri"] = args.url
28-
29-
result = api.categories(params)
30-
31-
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
22+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
23+
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")

examples/entities.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,16 @@
44
Example code to call Rosette API to get entities from a piece of text.
55
"""
66

7-
import argparse
87
import json
98

109
from rosette.api import API, DocumentParameters
1110

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

17-
# Create an API instance
18-
if args.service_url:
19-
api = API(service_url=args.service_url, user_key=args.key)
20-
else:
21-
api = API(user_key=args.key)
22-
23-
params = DocumentParameters()
24-
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."
25-
result = api.entities(params) # entity linking is turned off
26-
27-
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
12+
def run(key):
13+
# Create an API instance
14+
api = API(user_key=key)
15+
params = DocumentParameters()
16+
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."
17+
result = api.entities(params) # entity linking is turned off
18+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
19+
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")

examples/entities_linked.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@
44
Example code to call Rosette API to get linked (against Wikipedia) entities from a piece of text.
55
"""
66

7-
import argparse
87
import json
98

109
from rosette.api import API, DocumentParameters
1110

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

17-
# Create an API instance
18-
if args.service_url:
19-
api = API(service_url=args.service_url, user_key=args.key)
20-
else:
21-
api = API(user_key=args.key)
12+
def run(key):
13+
# Create an API instance
14+
api = API(user_key=key)
2215

23-
params = DocumentParameters()
24-
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."
25-
result = api.entities(params, True) # entity linking is turned on
16+
params = DocumentParameters()
17+
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."
18+
result = api.entities(params, True) # entity linking is turned on
2619

27-
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
20+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
21+
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")

examples/info.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@
44
Example code to call Rosette API to get information such as version and build
55
"""
66

7-
import argparse
87
import json
98

10-
from rosette.api import API
9+
from rosette.api import API, DocumentParameters
1110

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

17-
# Create an API instance
18-
if args.service_url:
19-
api = API(service_url=args.service_url, user_key=args.key)
20-
else:
21-
api = API(user_key=args.key)
12+
def run(key):
13+
# Create an API instance
14+
api = API(user_key=key)
2215

23-
result = api.info()
16+
result = api.info()
2417

25-
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
18+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
19+
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")

examples/language.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@
44
Example code to call Rosette API to determine the language of a piece of text.
55
"""
66

7-
import argparse
87
import json
98

109
from rosette.api import API, DocumentParameters
1110

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

17-
# Create an API instance
18-
if args.service_url:
19-
api = API(service_url=args.service_url, user_key=args.key)
20-
else:
21-
api = API(user_key=args.key)
12+
def run(key):
13+
# Create an API instance
14+
api = API(user_key=key)
2215

23-
params = DocumentParameters()
16+
params = DocumentParameters()
2417

25-
params["content"] = u"Por favor Señorita, says the man."
26-
result = api.language(params)
18+
params["content"] = u"Por favor Señorita, says the man."
19+
result = api.language(params)
2720

28-
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
21+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
22+
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")

examples/matched-name.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@
44
Example code to call Rosette API to get match score (similarity) of two names.
55
"""
66

7-
import argparse
87
import json
98

109
from rosette.api import API, NameMatchingParameters
1110

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

17-
# Create an API instance
18-
if args.service_url:
19-
api = API(service_url=args.service_url, user_key=args.key)
20-
else:
21-
api = API(user_key=args.key)
12+
def run(key):
13+
# Create an API instance
14+
api = API(user_key=key)
2215

23-
params = NameMatchingParameters()
24-
params["name1"] = {"text": "Michael Jackson", "language": "eng", "entityType": "PERSON"}
25-
params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"}
26-
result = api.matched_name(params)
16+
params = NameMatchingParameters()
17+
params["name1"] = {"text": "Michael Jackson", "language": "eng", "entityType": "PERSON"}
18+
params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"}
19+
result = api.matched_name(params)
2720

28-
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
21+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
22+
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")

examples/morphology_complete.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@
44
Example code to call Rosette API to get the complete morphological analysis of a piece of text.
55
"""
66

7-
import argparse
87
import json
98

109
from rosette.api import API, DocumentParameters
1110

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

17-
# Create an API instance
18-
if args.service_url:
19-
api = API(service_url=args.service_url, user_key=args.key)
20-
else:
21-
api = API(user_key=args.key)
12+
def run(key):
13+
# Create an API instance
14+
api = API(user_key=key)
2215

23-
params = DocumentParameters()
24-
params["content"] = u"The quick brown fox jumped over the lazy dog. Yes he did."
25-
result = api.morphology(params)
16+
params = DocumentParameters()
17+
params["content"] = u"The quick brown fox jumped over the lazy dog. Yes he did."
18+
result = api.morphology(params)
2619

27-
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
20+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
21+
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")

examples/morphology_compound-components.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@
44
Example code to call Rosette API to get de-compounded words from a piece of text.
55
"""
66

7-
import argparse
87
import json
98

109
from rosette.api import API, DocumentParameters, MorphologyOutput
1110

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

17-
# Create an API instance
18-
if args.service_url:
19-
api = API(service_url=args.service_url, user_key=args.key)
20-
else:
21-
api = API(user_key=args.key)
12+
def run(key):
13+
# Create an API instance
14+
api = API(user_key=key)
2215

23-
params = DocumentParameters()
24-
params["content"] = u"Rechtsschutzversicherungsgesellschaften"
25-
result = api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS)
16+
params = DocumentParameters()
17+
params["content"] = u"Rechtsschutzversicherungsgesellschaften"
18+
result = api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS)
2619

27-
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
20+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))
21+
return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")

0 commit comments

Comments
 (0)