Skip to content

Commit 02899c0

Browse files
committed
RCB-620: Name and Address match parameter overrides.
1 parent fa48b56 commit 02899c0

File tree

4 files changed

+99
-9
lines changed

4 files changed

+99
-9
lines changed

examples/address_similarity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'):
1818
params = AddressSimilarityParameters()
1919
params["address1"] = {"houseNumber": "1600", "road": "Pennsylvania Ave NW", "city": "Washington", "state": "DC", "postCode": "20500"}
2020
params["address2"] = "160 Pennsilvana Avenue, Washington, D.C., 20500"
21+
#params["parameters"] = {"houseNumberAddressFieldWeight": "0.9"}
2122

2223
try:
2324
return api.address_similarity(params)

examples/name_similarity.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'):
2020
params = NameSimilarityParameters()
2121
params["name1"] = {"text": matched_name_data1, "language": "eng", "entityType": "PERSON"}
2222
params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"}
23+
#params["parameters"] = {"conflictScore": "0.9", "deletionScore": "0.2"}
24+
2325
try:
2426
return api.name_similarity(params)
2527
except RosetteException as exception:

rosette/api.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,28 @@ def validate(self):
250250

251251
class AddressSimilarityParameters(_DocumentParamSetBase):
252252
"""Parameter object for C{address-similarity} endpoint.
253-
All are required.
253+
254+
C{address1} and C{address2} are required.
255+
256+
`parameters` is optional.
254257
255258
C{address1} The address to be matched, a C{address} object or address string.
256259
257260
C{address2} The address to be matched, a C{address} object or address string.
258261
259262
The C{address} object contains these optional fields:
260263
city, island, district, stateDistrict, state, countryRegion, country, worldRegion, postCode, poBox
264+
265+
`parameters` is a dictionary listing any parameter overrides to include. For example, `postCodeAddressFieldWeight`.
266+
Setting `parameters` is not cumulative. Define all overrides at once. If defined multiple times, only the
267+
final declaration is used.
268+
269+
See `examples/address_similarity.py`
261270
"""
262271

263272
def __init__(self):
264273
self.use_multipart = False
265-
_DocumentParamSetBase.__init__(self, ("address1", "address2"))
274+
_DocumentParamSetBase.__init__(self, ("address1", "address2", "parameters"))
266275

267276
def validate(self):
268277
"""Internal. Do not use."""
@@ -276,26 +285,35 @@ def validate(self):
276285

277286
class NameSimilarityParameters(_DocumentParamSetBase):
278287
"""Parameter object for C{name-similarity} endpoint.
279-
All are required.
288+
289+
C{name1} and C{name2} are required.
290+
291+
`parameters` is optional.
280292
281293
C{name1} The name to be matched, a C{name} object.
282294
283295
C{name2} The name to be matched, a C{name} object.
284296
285297
The C{name} object contains these fields:
286298
287-
C{text} Text of the name, required.
299+
C{text} Text of the name, required.
300+
301+
C{language} Language of the name in ISO639 three-letter code, optional.
302+
303+
C{script} The ISO15924 code of the name, optional.
288304
289-
C{language} Language of the name in ISO639 three-letter code, optional.
305+
C{entityType} The entity type, can be "PERSON", "LOCATION" or "ORGANIZATION", optional.
290306
291-
C{script} The ISO15924 code of the name, optional.
307+
`parameters` is a dictionary listing any parameter overrides to include. For example, `deletionScore`.
308+
Setting `parameters` is not cumulative. Define all overrides at once. If defined multiple times, only the
309+
final declaration is used.
292310
293-
C{entityType} The entity type, can be "PERSON", "LOCATION" or "ORGANIZATION", optional.
311+
See `examples/name_similarity.py`
294312
"""
295313

296314
def __init__(self):
297315
self.use_multipart = False
298-
_DocumentParamSetBase.__init__(self, ("name1", "name2"))
316+
_DocumentParamSetBase.__init__(self, ("name1", "name2", "parameters"))
299317

300318
def validate(self):
301319
"""Internal. Do not use."""

tests/test_rosette_api.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,48 @@ def test_the_name_translation_endpoint(api, json_response):
427427
# Test the name similarity endpoint
428428

429429

430+
def test_the_name_similarity_single_parameters(api, json_response):
431+
"""Test the name similarity parameters"""
432+
httpretty.enable()
433+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
434+
body=json_response, status=200, content_type="application/json")
435+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-similarity",
436+
body=json_response, status=200, content_type="application/json")
437+
438+
matched_name_data1 = "John Mike Smith"
439+
matched_name_data2 = "John Joe Smith"
440+
params = NameSimilarityParameters()
441+
params["name1"] = {"text": matched_name_data1}
442+
params["name2"] = {"text": matched_name_data2}
443+
params["parameters"] = {"conflictScore": "0.9"}
444+
445+
result = api.name_similarity(params)
446+
assert result["name"] == "Rosette"
447+
httpretty.disable()
448+
httpretty.reset()
449+
450+
451+
def test_the_name_similarity_multiple_parameters(api, json_response):
452+
"""Test the name similarity parameters"""
453+
httpretty.enable()
454+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
455+
body=json_response, status=200, content_type="application/json")
456+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-similarity",
457+
body=json_response, status=200, content_type="application/json")
458+
459+
matched_name_data1 = "John Mike Smith"
460+
matched_name_data2 = "John Joe Smith"
461+
params = NameSimilarityParameters()
462+
params["name1"] = {"text": matched_name_data1}
463+
params["name2"] = {"text": matched_name_data2}
464+
params["parameters"] = {"conflictScore": "0.9", "deletionScore": "0.5"}
465+
466+
result = api.name_similarity(params)
467+
assert result["name"] == "Rosette"
468+
httpretty.disable()
469+
httpretty.reset()
470+
471+
430472
def test_the_name_similarity_endpoint(api, json_response):
431473
"""Test the name similarity endpoint"""
432474
httpretty.enable()
@@ -449,10 +491,11 @@ def test_the_name_similarity_endpoint(api, json_response):
449491
httpretty.disable()
450492
httpretty.reset()
451493

494+
452495
# Test the name deduplication endpoint
453496

454497

455-
def test_name_deduplicatation_parameters(api, json_response):
498+
def test_name_deduplication_parameters(api, json_response):
456499
"""Test the Name Deduplication Parameters"""
457500
httpretty.enable()
458501
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
@@ -612,6 +655,32 @@ def test_for_address_similarity_required_parameters(api, json_response):
612655
httpretty.reset()
613656

614657

658+
def test_for_address_similarity_optional_parameters(api, json_response):
659+
"""Test address similarity parameters"""
660+
httpretty.enable()
661+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
662+
body=json_response, status=200, content_type="application/json")
663+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/address-similarity",
664+
body=json_response, status=200, content_type="application/json")
665+
666+
params = AddressSimilarityParameters()
667+
668+
params["address1"] = {"houseNumber": "1600",
669+
"road": "Pennsylvania Ave NW",
670+
"city": "Washington",
671+
"state": "DC",
672+
"postCode": "20500"}
673+
674+
params["address2"] = {"text": "160 Pennsilvana Avenue, Washington, D.C., 20500"}
675+
676+
params["parameters"] = {"houseNumberAddressFieldWeight": "0.9"}
677+
678+
result = api.address_similarity(params)
679+
assert result["name"] == "Rosette"
680+
httpretty.disable()
681+
httpretty.reset()
682+
683+
615684
# Test for required Name Similarity parameters
616685

617686

0 commit comments

Comments
 (0)