-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathname_similarity.py
More file actions
41 lines (32 loc) · 1.44 KB
/
name_similarity.py
File metadata and controls
41 lines (32 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""
Example code to call Analytics API to get match score (similarity) of two names.
"""
import argparse
import json
import os
from rosette.api import API, NameSimilarityParameters, RosetteException
def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'):
""" Run the example """
# Create an API instance
api = API(user_key=key, service_url=alt_url)
matched_name_data1 = "Michael Jackson"
matched_name_data2 = "迈克尔·杰克逊"
params = NameSimilarityParameters()
params["name1"] = {"text": matched_name_data1, "language": "eng", "entityType": "PERSON"}
params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"}
#params["parameters"] = {"conflictScore": "0.9", "deletionScore": "0.2"}
try:
return api.name_similarity(params)
except RosetteException as exception:
print(exception)
PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Calls the ' +
os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
PARSER.add_argument('-k', '--key', help='Analytics API Key', required=True)
PARSER.add_argument('-u', '--url', help="Alternative API URL",
default='https://analytics.babelstreet.com/rest/v1/')
if __name__ == '__main__':
ARGS = PARSER.parse_args()
RESULT = run(ARGS.key, ARGS.url)
print(RESULT)