Skip to content

Commit 87406c9

Browse files
authored
Merge pull request #62 from rosette-api/RCB-508_name-dedup-rct
Rcb 508 name dedup rct
2 parents 1207df6 + d2c030e commit 87406c9

13 files changed

+516
-278
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ docs/_build/
7272

7373
# PyBuilder
7474
target/
75+
76+
settings.json
77+
*.orig

examples/README.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,32 @@ You can now run your desired _endpoint_.py file to see it in action.
1212
For example, run `python/examples/categories.py` if you want to see the categories
1313
functionality demonstrated.
1414

15-
All files require you to input your Rosette API User Key after --key to run.
16-
For example: `python ping.py --key 1234567890`
17-
All also allow you to input your own service URL if desired.
18-
For example: `python ping.py --key 1234567890 --service_url http://www.myurl.com`
15+
All files require you to input your Rosette API User Key after --key to run.
16+
For example: `python ping.py --key 1234567890`
17+
All also allow you to input your own service URL if desired.
18+
For example: `python ping.py --key 1234567890 --service_url http://www.myurl.com`
1919
Some (specified below) allow an additional input of either a file (.html or .txt) or a URL with `--file` or `--url`
2020

2121
Each example, when run, prints its output to the console.
2222

23-
| File Name | What it does |
24-
| ------------- |------------- |
25-
| categories.py | Gets the category of a document at a URL |
26-
| entities.py | Gets the entities from a piece of text |
27-
| info.py | Gets information about Rosette API |
28-
| language.py | Gets the language of a piece of text |
29-
| matched-name.py | Gets the similarity score of two names |
30-
| morphology_complete.py | Gets the complete morphological analysis of a piece of text|
31-
| morphology_compound-components.py | Gets the de-compounded words from a piece of text |
32-
| morphology_han-readings.py | Gets the Chinese words from a piece of text |
33-
| morphology_lemmas.py | Gets the lemmas of words from a piece of text |
34-
| morphology_parts-of-speech.py | Gets the part-of-speech tags for words in a piece of text |
35-
| ping.py | Pings the Rosette API to check for reachability |
36-
| relationships.py | Gets the relationships between entities from a piece of text |
23+
| File Name | What it does |
24+
| ------------- |------------- |
25+
| categories.py | Gets the category of a document at a URL |
26+
| entities.py | Gets the entities from a piece of text |
27+
| info.py | Gets information about Rosette API |
28+
| language.py | Gets the language of a piece of text |
29+
| matched-name.py | Gets the similarity score of two names |
30+
| morphology_complete.py | Gets the complete morphological analysis of a piece of text|
31+
| morphology_compound-components.py | Gets the de-compounded words from a piece of text |
32+
| morphology_han-readings.py | Gets the Chinese words from a piece of text |
33+
| morphology_lemmas.py | Gets the lemmas of words from a piece of text |
34+
| morphology_parts-of-speech.py | Gets the part-of-speech tags for words in a piece of text |
35+
| name_deduplication.py | De-duplicates a list of names |
36+
| ping.py | Pings the Rosette API to check for reachability |
37+
| relationships.py | Gets the relationships between entities from a piece of text |
3738
| sentences.py | Gets the sentences from a piece of text |
38-
| sentiment.py | Gets the sentiment of a local file |
39-
| tokens.py | Gets the tokens (words) from a piece of text |
39+
| sentiment.py | Gets the sentiment of a local file |
40+
| tokens.py | Gets the tokens (words) from a piece of text |
4041
| translated-name.py | Translates a name from one language to another |
42+
| transliteration.py | Transliterates the given text |
4143

examples/language.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'):
1818
language_data = "Por favor Señorita, says the man."
1919
params = DocumentParameters()
2020
params["content"] = language_data
21-
api.setCustomHeaders("X-RosetteAPI-App", "python-app")
21+
api.setcustom_headers("X-RosetteAPI-App", "python-app")
2222
try:
2323
return api.language(params)
2424
except RosetteException as e:

examples/morphology_compound-components.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import json
99
import os
1010

11-
from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException
11+
from rosette.api import API, DocumentParameters, RosetteException
1212

1313

1414
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
@@ -19,7 +19,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'):
1919
params = DocumentParameters()
2020
params["content"] = morphology_compound_components_data
2121
try:
22-
return api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS)
22+
return api.morphology(params, api.morphology_output['COMPOUND_COMPONENTS'])
2323
except RosetteException as e:
2424
print(e)
2525

examples/morphology_han-readings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import json
99
import os
1010

11-
from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException
11+
from rosette.api import API, DocumentParameters, RosetteException
1212

1313

1414
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
@@ -19,7 +19,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'):
1919
params = DocumentParameters()
2020
params["content"] = morphology_han_readings_data
2121
try:
22-
return api.morphology(params, MorphologyOutput.HAN_READINGS)
22+
return api.morphology(params, api.morphology_output['HAN_READINGS'])
2323
except RosetteException as e:
2424
print(e)
2525

examples/morphology_lemmas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import json
99
import os
1010

11-
from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException
11+
from rosette.api import API, DocumentParameters, RosetteException
1212

1313

1414
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
@@ -19,7 +19,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'):
1919
params = DocumentParameters()
2020
params["content"] = morphology_lemmas_data
2121
try:
22-
return api.morphology(params, MorphologyOutput.LEMMAS)
22+
return api.morphology(params, api.morphology_output['LEMMAS'])
2323
except RosetteException as e:
2424
print(e)
2525

examples/morphology_parts-of-speech.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import json
99
import os
1010

11-
from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException
11+
from rosette.api import API, DocumentParameters, RosetteException
1212

1313

1414
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
@@ -19,7 +19,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'):
1919
params = DocumentParameters()
2020
params["content"] = morphology_parts_of_speech_data
2121
try:
22-
return api.morphology(params, MorphologyOutput.PARTS_OF_SPEECH)
22+
return api.morphology(params, api.morphology_output['PARTS_OF_SPEECH'])
2323
except RosetteException as e:
2424
print(e)
2525

examples/name_deduplication.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Example code to call Rosette API to deduplicate a list of names.
5+
"""
6+
7+
import argparse
8+
import json
9+
import os
10+
11+
from rosette.api import API, NameDeduplicationParameters, RosetteException
12+
13+
14+
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
15+
# Create an API instance
16+
api = API(user_key=key, service_url=altUrl)
17+
18+
dedup_list = ["John Smith", "Johnathon Smith", "Fred Jones"]
19+
threshold = 0.75
20+
params = NameDeduplicationParameters()
21+
params["names"] = dedup_list
22+
params["threshold"] = threshold
23+
try:
24+
return api.name_deduplication(params)
25+
except RosetteException as e:
26+
print(e)
27+
28+
29+
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
30+
parser.add_argument('-k', '--key', help='Rosette API Key', required=True)
31+
parser.add_argument('-u', '--url', help="Alternative API URL", default='https://api.rosette.com/rest/v1/')
32+
33+
if __name__ == '__main__':
34+
args = parser.parse_args()
35+
result = run(args.key, args.url)
36+
print(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8"))

examples/relationships.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'):
1717
relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist."
1818
params = DocumentParameters()
1919
params["content"] = relationships_text_data
20-
api.setOption('accuracyMode', 'PRECISION')
20+
api.set_option('accuracyMode', 'PRECISION')
2121
try:
2222
return api.relationships(params)
2323
except RosetteException as e:

examples/transliteration.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Example code to call Rosette API to transliterate a piece of text.
5+
"""
6+
7+
import argparse
8+
import json
9+
import os
10+
11+
from rosette.api import API, DocumentParameters, RosetteException
12+
13+
14+
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
15+
# Create an API instance
16+
api = API(user_key=key, service_url=altUrl)
17+
18+
transliteration_data = "Some random text"
19+
params = DocumentParameters()
20+
params["content"] = transliteration_data
21+
22+
try:
23+
return api.transliteration(params)
24+
except RosetteException as e:
25+
print(e)
26+
27+
28+
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
29+
parser.add_argument('-k', '--key', help='Rosette API Key', required=True)
30+
parser.add_argument('-u', '--url', help="Alternative API URL", default='https://api.rosette.com/rest/v1/')
31+
32+
if __name__ == '__main__':
33+
args = parser.parse_args()
34+
result = run(args.key, args.url)
35+
print(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8"))

0 commit comments

Comments
 (0)