Skip to content

Commit 48f8d80

Browse files
committed
Added name_translation and name_similarity functions. Changed examples accordingly.
1 parent c0a4485 commit 48f8d80

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'):
2020
params = NameMatchingParameters()
2121
params["name1"] = {"text": matched_name_data1, "language": "eng", "entityType": "PERSON"}
2222
params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"}
23-
return api.matched_name(params)
23+
return api.name_similarity(params)
2424

2525

2626
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'):
2020
params["name"] = translated_name_data
2121
params["entityType"] = "PERSON"
2222
params["targetLanguage"] = "eng"
23-
return api.translated_name(params)
23+
params["targetScript"] = "Latn"
24+
params["targetScheme"] = "IC"
25+
return api.name_translation(params)
2426

2527

2628
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')

rosette/api.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def __init__(self):
400400

401401

402402
class NameTranslationParameters(_DocumentParamSetBase):
403-
"""Parameter object for C{translated_name} endpoint.
403+
"""Parameter object for C{name-translation} endpoint.
404404
The following values may be set by the indexing (i.e.,C{ parms["name"]}) operator. The values are all
405405
strings (when not C{None}).
406406
All are optional except C{name} and C{targetLanguage}. Scripts are in
@@ -436,7 +436,7 @@ def validate(self):
436436

437437

438438
class NameMatchingParameters(_DocumentParamSetBase):
439-
"""Parameter object for C{matched_name} endpoint.
439+
"""Parameter object for C{name-similarity} endpoint.
440440
All are required.
441441
442442
C{name1} The name to be matched, a C{name} object.
@@ -567,9 +567,9 @@ def call(self, parameters):
567567
"""Invokes the endpoint to which this L{EndpointCaller} is bound.
568568
Passes data and metadata specified by C{parameters} to the server
569569
endpoint to which this L{EndpointCaller} object is bound. For all
570-
endpoints except C{translated_name} and C{matched_name}, it must be a L{DocumentParameters}
571-
object or a string; for C{translated_name}, it must be an L{NameTranslationParameters} object;
572-
for C{matched_name}, it must be an L{NameMatchingParameters} object. For relationships,
570+
endpoints except C{name-translation} and C{name-similarity}, it must be a L{DocumentParameters}
571+
object or a string; for C{name-translation}, it must be an L{NameTranslationParameters} object;
572+
for C{name-similarity}, it must be an L{NameMatchingParameters} object. For relationships,
573573
it may be an L(DocumentParameters) or an L(RelationshipsParameters).
574574
575575
In all cases, the result is returned as a python dictionary
@@ -579,12 +579,12 @@ def call(self, parameters):
579579
@param parameters: An object specifying the data,
580580
and possible metadata, to be processed by the endpoint. See the
581581
details for those object types.
582-
@type parameters: For C{translated_name}, L{NameTranslationParameters}, otherwise L{DocumentParameters} or L{str}
582+
@type parameters: For C{name-translation}, L{NameTranslationParameters}, otherwise L{DocumentParameters} or L{str}
583583
@return: A python dictionary expressing the result of the invocation.
584584
"""
585585

586586
if not isinstance(parameters, _DocumentParamSetBase):
587-
if self.suburl != "matched-name" and self.suburl != "translated-name":
587+
if self.suburl != "name-similarity" and self.suburl != "name-translation":
588588
text = parameters
589589
parameters = DocumentParameters()
590590
parameters['content'] = text
@@ -766,21 +766,40 @@ def relationships(self, parameters):
766766
@return: A python dictionary containing the results of relationship extraction."""
767767
return EndpointCaller(self, "relationships").call(parameters)
768768

769-
def translated_name(self, parameters):
769+
def name_translation(self, parameters):
770770
"""
771771
Create an L{EndpointCaller} to perform name analysis and translation
772772
upon the name to which it is applied and call it.
773773
@param parameters: An object specifying the data,
774774
and possible metadata, to be processed by the name translator.
775775
@type parameters: L{NameTranslationParameters}
776776
@return: A python dictionary containing the results of name translation."""
777-
return EndpointCaller(self, "translated-name").call(parameters)
777+
return EndpointCaller(self, "name-translation").call(parameters)
778778

779-
def matched_name(self, parameters):
779+
def translated_name(self, parameters):
780+
""" deprecated
781+
Call name_translation to perform name analysis and translation
782+
upon the name to which it is applied.
783+
@param parameters: An object specifying the data,
784+
and possible metadata, to be processed by the name translator.
785+
@type parameters: L{NameTranslationParameters}
786+
@return: A python dictionary containing the results of name translation."""
787+
return self.name_translation(parameters)
788+
789+
def name_similarity(self, parameters):
780790
"""
781791
Create an L{EndpointCaller} to perform name matching and call it.
782792
@param parameters: An object specifying the data,
783793
and possible metadata, to be processed by the name matcher.
784794
@type parameters: L{NameMatchingParameters}
785795
@return: A python dictionary containing the results of name matching."""
786-
return EndpointCaller(self, "matched-name").call(parameters)
796+
return EndpointCaller(self, "name-similarity").call(parameters)
797+
798+
def matched_name(self, parameters):
799+
""" deprecated
800+
Call name_similarity to perform name matching.
801+
@param parameters: An object specifying the data,
802+
and possible metadata, to be processed by the name matcher.
803+
@type parameters: L{NameMatchingParameters}
804+
@return: A python dictionary containing the results of name matching."""
805+
return self.name_similarity(parameters)

0 commit comments

Comments
 (0)