Skip to content

Commit c4173d4

Browse files
committed
Merge pull request #2 from rosette-api/0.5.4
Merge 0.5.4 to master
2 parents ddf3c41 + d1c9497 commit c4173d4

27 files changed

+268
-91
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# General
22
*~
3-
**/.DS_Store
3+
.DS_Store
4+
.DS_Store?
5+
.Spotlight-V100
6+
.Trashes
7+
ehthumbs.db
8+
Thumbs.db
49

510
# Jetbrains
611
**/.idea/*
712
!**/.idea/runConfigurations/
813
*.iml
14+
target/
915

1016
# Byte-compiled / optimized / DLL files
1117
__pycache__/

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This is the Python client binding for Rosette API.
2+
3+
The Python binding requires Python 2.6 or greater and is available through pip:
4+
5+
`pip install rosette_api`
6+
7+
```python
8+
# 1. Set utf-8 encoding.
9+
# -*- coding: utf-8 -*-
10+
11+
# 2. Imports from rosette.api.
12+
from rosette.api import API, DocumentParameters, MorphologyOutput
13+
14+
# 3. Create API object.
15+
api = API("[your_api-key]")
16+
17+
# 4. Create parameters object
18+
params = DocumentParameters()
19+
20+
# 5. Set parameters.
21+
params["content"] = u"Was ist so böse an der Europäischen Zentralbank?"
22+
23+
# 6. Make a call.
24+
result = api.morphology(params)
25+
26+
# result is a Python dictionary that contains
27+
28+
{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'?'}]}
29+
```
30+
31+
The samples use the following procedure:
32+
33+
1. If the application reads text in, set encoding to utf-8 in the first line of the script.
34+
35+
2. Import the `rosette.api` packages that your application needs. The `rosette.api` packages include
36+
* `API`
37+
* `DocumentParameters`
38+
* `NameMatchingParameters`
39+
* `NameTranslationParameters`
40+
* `MorphologyOutput`
41+
* `DataFormat`
42+
* `InputUnit`
43+
44+
3. Create an `API` object with the `user_key` parameter.
45+
46+
4. Create a parameters object for your request input:
47+
48+
| Parameter | Endpoint |
49+
| ----|----|
50+
| `NameMatchingParameters` | for `/matched-name` |
51+
| `NameTranslationParameters` | for `/translated-name` |
52+
| `DocumentParameters` | for all other endpoints |
53+
54+
55+
5. Set the parameters required for your operation: "`content`" or "`contentUri`" for `DocumentParameters`;
56+
"`name`" and "`targetLanguage`" for `NameTranslationParameters`; "`name1.text`" and "`name2.text`" for
57+
`NameMatchingParameters`; Other parameters are optional.
58+
59+
6. Create an `API` method for the endpoint you are calling. The methods are
60+
* `entities(linked)` where `linked` is `False` for entity extraction and `True` for entity linking.
61+
* `categories()`
62+
* `sentiment()`
63+
* `language()`
64+
* `morphology(tag)` where tag is a member of `MorphologyOutput`: `LEMMAS`, `PARTS_OF_SPEECH`, `COMPOUND_COMPONENTS`, `HAN_READINGS`, or `COMPLETE`. An empty tag is equivalent to `COMPLETE`.
65+
* `sentences()`
66+
* `tokens()`
67+
* `matched_name()`
68+
* `translated_name()`
69+
70+
7. The API will return a dictionary with the results.

README.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__author__ = 'rhausmann'

examples/categories.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"""
66

77
import argparse
8-
import pprint
8+
import json
99

1010
from rosette.api import API, DocumentParameters
1111

1212
parser = argparse.ArgumentParser(description="Get the category of a piece of a document at a URL")
1313
parser.add_argument("--key", required=True, help="Rosette API key")
1414
parser.add_argument("--service_url", nargs="?", help="Optional user service URL")
15-
parser.add_argument("--url", nargs="?", default="http://www.basistech.com/about/", help="Optional URL for data")
15+
parser.add_argument("--url", nargs="?", default="https://en.wikipedia.org/wiki/Basis_Technology_Corp.", help="Optional URL for data")
1616
args = parser.parse_args()
1717

1818
# Create an API instance
@@ -28,4 +28,4 @@
2828

2929
result = api.categories(params)
3030

31-
pprint.pprint(result)
31+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))

examples/entities.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import argparse
8-
import pprint
8+
import json
99

1010
from rosette.api import API, DocumentParameters
1111

@@ -21,9 +21,7 @@
2121
api = API(user_key=args.key)
2222

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

29-
pprint.pprint(result)
27+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))

examples/entities_linked.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import argparse
8-
import pprint
8+
import json
99

1010
from rosette.api import API, DocumentParameters
1111

@@ -21,9 +21,7 @@
2121
api = API(user_key=args.key)
2222

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

29-
pprint.pprint(result)
27+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))

examples/info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import argparse
8-
import pprint
8+
import json
99

1010
from rosette.api import API
1111

@@ -22,4 +22,4 @@
2222

2323
result = api.info()
2424

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

examples/language.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import argparse
8-
import pprint
8+
import json
99

1010
from rosette.api import API, DocumentParameters
1111

@@ -22,8 +22,7 @@
2222

2323
params = DocumentParameters()
2424

25-
# Use an HTML file to load data instead of a string
2625
params["content"] = u"Por favor Señorita, says the man."
2726
result = api.language(params)
2827

29-
pprint.pprint(result)
28+
print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8"))

examples/matched-name.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import argparse
8-
import pprint
8+
import json
99

1010
from rosette.api import API, NameMatchingParameters
1111

@@ -25,4 +25,4 @@
2525
params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"}
2626
result = api.matched_name(params)
2727

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

0 commit comments

Comments
 (0)