Skip to content

Commit b483749

Browse files
DEVOPS-247: add address-similarity
1 parent a60b186 commit b483749

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
# built documents.
5656
#
5757
# The short X.Y version.
58-
version = '1.12.1'
58+
version = '1.14.3'
5959
# The full version, including alpha/beta/rc tags.
60-
release = '1.12.1'
60+
release = '1.14.3'
6161

6262
# The language for content autogenerated by Sphinx. Refer to documentation
6363
# for a list of supported languages.

examples/address_similarity.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Example code to call Rosette API to get match score (similarity) of two addresses.
4+
"""
5+
from __future__ import print_function
6+
7+
import argparse
8+
import json
9+
import os
10+
11+
from rosette.api import API, AddressSimilarityParameters, RosetteException
12+
13+
14+
def run(key, alt_url='https://api.rosette.com/rest/v1/'):
15+
""" Run the example """
16+
# Create an API instance
17+
api = API(user_key=key, service_url=alt_url)
18+
19+
params = AddressSimilarityParameters()
20+
params["address1"] = {"city": "Cambridge", "state": "MA"}
21+
params["address2"] = {"city": "cambridge", "state": "massachusetts"}
22+
try:
23+
return api.address_similarity(params)
24+
except RosetteException as exception:
25+
print(exception)
26+
27+
28+
PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
29+
description='Calls the ' +
30+
os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
31+
PARSER.add_argument('-k', '--key', help='Rosette API Key', required=True)
32+
PARSER.add_argument('-u', '--url', help="Alternative API URL",
33+
default='https://api.rosette.com/rest/v1/')
34+
35+
if __name__ == '__main__':
36+
ARGS = PARSER.parse_args()
37+
RESULT = run(ARGS.key, ARGS.url)
38+
print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8"))

rosette/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
limitations under the License.
1313
"""
1414

15-
__version__ = '1.12.1'
15+
__version__ = '1.14.3'

rosette/api.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import requests
2929
import platform
3030

31-
_BINDING_VERSION = '1.12.1'
31+
_BINDING_VERSION = '1.14.3'
3232
_GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08])
3333

3434
_ISPY3 = sys.version_info[0] == 3
@@ -246,6 +246,32 @@ def validate(self):
246246
repr(option))
247247

248248

249+
class AddressSimilarityParameters(_DocumentParamSetBase):
250+
"""Parameter object for C{address-similarity} endpoint.
251+
All are required.
252+
253+
C{address1} The address to be matched, a C{address} object.
254+
255+
C{address2} The address to be matched, a C{address} object.
256+
257+
The C{address} object contains these optional fields:
258+
city, island, district, stateDistrict, state, countryRegion, country, worldRegion, postCode, poBox
259+
"""
260+
261+
def __init__(self):
262+
self.use_multipart = False
263+
_DocumentParamSetBase.__init__(self, ("address1", "address2"))
264+
265+
def validate(self):
266+
"""Internal. Do not use."""
267+
for option in ("address1", "address2"): # required
268+
if self[option] is None:
269+
raise RosetteException(
270+
"missingParameter",
271+
"Required Address Similarity parameter, " + option + ", not supplied",
272+
repr(option))
273+
274+
249275
class NameSimilarityParameters(_DocumentParamSetBase):
250276
"""Parameter object for C{name-similarity} endpoint.
251277
All are required.
@@ -550,6 +576,7 @@ def __init__(
550576
}
551577

552578
self.endpoints = {
579+
'ADDRESS_SIMILARITY': 'address-similarity',
553580
'CATEGORIES': 'categories',
554581
'ENTITIES': 'entities',
555582
'INFO': 'info',
@@ -879,6 +906,15 @@ def relationships(self, parameters):
879906
@return: A python dictionary containing the results of relationship extraction."""
880907
return EndpointCaller(self, self.endpoints['RELATIONSHIPS']).call(parameters)
881908

909+
def address_similarity(self, parameters):
910+
"""
911+
Create an L{EndpointCaller} to perform address similarity scoring and call it.
912+
@param parameters: An object specifying the data,
913+
and possible metadata, to be processed by the name matcher.
914+
@type parameters: L{AddressSimilarityParameters}
915+
@return: A python dictionary containing the results of name matching."""
916+
return EndpointCaller(self, self.endpoints['ADDRESS_SIMILARITY']).call(parameters)
917+
882918
def name_translation(self, parameters):
883919
"""
884920
Create an L{EndpointCaller} to perform name analysis and translation

0 commit comments

Comments
 (0)