diff --git a/.travis.yml b/.travis.yml index c9a34d4..fce7d4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: python +branches: + only: + - master python: - "2.7" - "3.4" diff --git a/README.md b/README.md index 1c7a9f3..f084fa8 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,15 @@ Before using the Python bindings, you must install the libpostal C library. Make **On Ubuntu/Debian** ``` -sudo apt-get install libsnappy-dev autoconf automake libtool python-dev pkg-config +sudo apt-get install curl autoconf automake libtool python-dev pkg-config ``` **On CentOS/RHEL** ``` -sudo yum install snappy snappy-devel autoconf automake libtool python-devel pkgconfig +sudo yum install curl autoconf automake libtool python-devel pkgconfig ``` **On Mac OSX** ``` -sudo brew install snappy autoconf automake libtool pkg-config +sudo brew install curl autoconf automake libtool pkg-config ``` **Installing libpostal** diff --git a/postal/expand.py b/postal/expand.py index 9c5900b..bd16446 100644 --- a/postal/expand.py +++ b/postal/expand.py @@ -54,17 +54,18 @@ def expand_address(address, languages=None, **kw): return _expand.expand_address(address, languages=languages, **kw) # Constants for address components +ADDRESS_NONE = _expand.ADDRESS_NONE ADDRESS_ANY = _expand.ADDRESS_ANY ADDRESS_NAME = _expand.ADDRESS_NAME ADDRESS_HOUSE_NUMBER = _expand.ADDRESS_HOUSE_NUMBER ADDRESS_STREET = _expand.ADDRESS_STREET ADDRESS_UNIT = _expand.ADDRESS_UNIT -ADDRESS_LOCALITY = _expand.ADDRESS_LOCALITY -ADDRESS_ADMIN1 = _expand.ADDRESS_ADMIN1 -ADDRESS_ADMIN2 = _expand.ADDRESS_ADMIN2 -ADDRESS_ADMIN3 = _expand.ADDRESS_ADMIN3 -ADDRESS_ADMIN4 = _expand.ADDRESS_ADMIN4 -ADDRESS_ADMIN_OTHER = _expand.ADDRESS_ADMIN_OTHER -ADDRESS_COUNTRY = _expand.ADDRESS_COUNTRY -ADDRESS_NEIGHBORHOOD = _expand.ADDRESS_NEIGHBORHOOD +ADDRESS_LEVEL = _expand.ADDRESS_LEVEL +ADDRESS_STAIRCASE = _expand.ADDRESS_STAIRCASE +ADDRESS_ENTRANCE = _expand.ADDRESS_ENTRANCE +ADDRESS_CATEGORY = _expand.ADDRESS_CATEGORY +ADDRESS_NEAR = _expand.ADDRESS_NEAR +ADDRESS_TOPONYM = _expand.ADDRESS_TOPONYM +ADDRESS_POSTAL_CODE = _expand.ADDRESS_POSTAL_CODE +ADDRESS_PO_BOX = _expand.ADDRESS_PO_BOX ADDRESS_ALL = _expand.ADDRESS_ALL diff --git a/postal/pyexpand.c b/postal/pyexpand.c index dd82a19..4117caa 100644 --- a/postal/pyexpand.c +++ b/postal/pyexpand.c @@ -21,7 +21,7 @@ struct module_state { static PyObject *py_expand(PyObject *self, PyObject *args, PyObject *keywords) { PyObject *arg_input; PyObject *arg_languages; - normalize_options_t options = get_libpostal_default_options(); + libpostal_normalize_options_t options = libpostal_get_default_options(); PyObject *result = NULL; @@ -172,7 +172,7 @@ static PyObject *py_expand(PyObject *self, PyObject *args, PyObject *keywords) { #endif if (language != NULL && item != Py_None) { - if (strlen(language) >= MAX_LANGUAGE_LEN) { + if (strlen(language) >= LIBPOSTAL_MAX_LANGUAGE_LEN) { PyErr_SetString(PyExc_TypeError, "language was longer than a language code"); free(languages); Py_DECREF(seq); @@ -198,7 +198,7 @@ static PyObject *py_expand(PyObject *self, PyObject *args, PyObject *keywords) { } size_t num_expansions = 0; - char **expansions = expand_address(input, options, &num_expansions); + char **expansions = libpostal_expand_address(input, options, &num_expansions); if (languages != NULL) { for (int i = 0; i < num_languages; i++) { @@ -228,10 +228,7 @@ static PyObject *py_expand(PyObject *self, PyObject *args, PyObject *keywords) { } exit_free_expansions: - for (int i = 0; i < num_expansions; i++) { - free(expansions[i]); - } - free(expansions); + libpostal_expansion_array_destroy(expansions, num_expansions); exit_decref_str: #ifndef IS_PY3K Py_XDECREF(str_input); @@ -316,20 +313,23 @@ init_expand(void) { "Error loading libpostal"); } - PyModule_AddIntConstant(module, "ADDRESS_ANY", ADDRESS_ANY); - PyModule_AddIntConstant(module, "ADDRESS_NAME", ADDRESS_NAME); - PyModule_AddIntConstant(module, "ADDRESS_HOUSE_NUMBER", ADDRESS_HOUSE_NUMBER); - PyModule_AddIntConstant(module, "ADDRESS_STREET", ADDRESS_STREET); - PyModule_AddIntConstant(module, "ADDRESS_UNIT", ADDRESS_UNIT); - PyModule_AddIntConstant(module, "ADDRESS_LOCALITY", ADDRESS_LOCALITY); - PyModule_AddIntConstant(module, "ADDRESS_ADMIN1", ADDRESS_ADMIN1); - PyModule_AddIntConstant(module, "ADDRESS_ADMIN2", ADDRESS_ADMIN2); - PyModule_AddIntConstant(module, "ADDRESS_ADMIN3", ADDRESS_ADMIN3); - PyModule_AddIntConstant(module, "ADDRESS_ADMIN4", ADDRESS_ADMIN4); - PyModule_AddIntConstant(module, "ADDRESS_ADMIN_OTHER", ADDRESS_ADMIN_OTHER); - PyModule_AddIntConstant(module, "ADDRESS_COUNTRY", ADDRESS_COUNTRY); - PyModule_AddIntConstant(module, "ADDRESS_NEIGHBORHOOD", ADDRESS_NEIGHBORHOOD); - PyModule_AddIntConstant(module, "ADDRESS_ALL", ADDRESS_ALL); + PyModule_AddIntConstant(module, "ADDRESS_NONE", LIBPOSTAL_ADDRESS_NONE); + PyModule_AddIntConstant(module, "ADDRESS_ANY", LIBPOSTAL_ADDRESS_ANY); + PyModule_AddIntConstant(module, "ADDRESS_NAME", LIBPOSTAL_ADDRESS_NAME); + PyModule_AddIntConstant(module, "ADDRESS_HOUSE_NUMBER", LIBPOSTAL_ADDRESS_HOUSE_NUMBER); + PyModule_AddIntConstant(module, "ADDRESS_STREET", LIBPOSTAL_ADDRESS_STREET); + PyModule_AddIntConstant(module, "ADDRESS_UNIT", LIBPOSTAL_ADDRESS_UNIT); + PyModule_AddIntConstant(module, "ADDRESS_LEVEL", LIBPOSTAL_ADDRESS_LEVEL); + PyModule_AddIntConstant(module, "ADDRESS_STAIRCASE", LIBPOSTAL_ADDRESS_STAIRCASE); + PyModule_AddIntConstant(module, "ADDRESS_ENTRANCE", LIBPOSTAL_ADDRESS_ENTRANCE); + + PyModule_AddIntConstant(module, "ADDRESS_CATEGORY", LIBPOSTAL_ADDRESS_CATEGORY); + PyModule_AddIntConstant(module, "ADDRESS_NEAR", LIBPOSTAL_ADDRESS_NEAR); + + PyModule_AddIntConstant(module, "ADDRESS_TOPONYM", LIBPOSTAL_ADDRESS_TOPONYM); + PyModule_AddIntConstant(module, "ADDRESS_POSTAL_CODE", LIBPOSTAL_ADDRESS_POSTAL_CODE); + PyModule_AddIntConstant(module, "ADDRESS_PO_BOX", LIBPOSTAL_ADDRESS_PO_BOX); + PyModule_AddIntConstant(module, "ADDRESS_ALL", LIBPOSTAL_ADDRESS_ALL); #ifndef IS_PY3K Py_AtExit(&cleanup_libpostal); diff --git a/postal/pyparser.c b/postal/pyparser.c index 0ebd5e6..3e01cb9 100644 --- a/postal/pyparser.c +++ b/postal/pyparser.c @@ -140,11 +140,11 @@ static PyObject *py_parse_address(PyObject *self, PyObject *args, PyObject *keyw } } - address_parser_options_t options = get_libpostal_address_parser_default_options(); + libpostal_address_parser_options_t options = libpostal_get_address_parser_default_options(); options.language = language; options.country = country; - address_parser_response_t *parsed = parse_address(input, options); + libpostal_address_parser_response_t *parsed = libpostal_parse_address(input, options); if (parsed == NULL) { goto exit_decref_country_str; } @@ -184,7 +184,7 @@ static PyObject *py_parse_address(PyObject *self, PyObject *args, PyObject *keyw } exit_destroy_response: - address_parser_response_destroy(parsed); + libpostal_address_parser_response_destroy(parsed); exit_decref_country_str: #ifndef IS_PY3K if (str_country != Py_None) { diff --git a/postal/tests/test_expand.py b/postal/tests/test_expand.py index 3ebef02..1486560 100644 --- a/postal/tests/test_expand.py +++ b/postal/tests/test_expand.py @@ -31,7 +31,7 @@ def test_expansions(self): self.have_expansion_in_common('Thirty W 26th St Fl #7', '30 West Twenty-sixth Street Floor Number 7', languages=['en']) - self.contained_in_expansions('Friedrichstraße 128, Berlin, Germany', 'friedrich strasse 128 berlin germany') + self.contained_in_expansions('Friedrichstraße 128, Berlin, Germany', 'friedrich straße 128 berlin germany') self.contained_in_expansions('MAPLE ST.', 'maple street') self.contained_in_expansions('ST ISIDORE DR', 'saint isidore drive') diff --git a/postal/tests/test_parser.py b/postal/tests/test_parser.py index d81acd6..a9aa955 100644 --- a/postal/tests/test_parser.py +++ b/postal/tests/test_parser.py @@ -37,26 +37,6 @@ def test_parses(self): 'country': 'usa' }) - self.contains_components('whole foods ny', {'house': 'whole foods', 'state': 'ny'}) - self.contains_components('1917/2 Pike Drive', { - 'house_number': '1917 / 2', - 'road': 'pike drive' - }) - self.contains_components('3437 warwickshire rd,pa', { - 'house_number': '3437', - 'road': 'warwickshire rd', - 'state': 'pa' - }) - self.contains_components('3437 warwickshire rd, pa', { - 'house_number': '3437', - 'road': 'warwickshire rd', - 'state': 'pa' - }) - self.contains_components('3437 warwickshire rd pa', { - 'house_number': '3437', - 'road': 'warwickshire rd', - 'state': 'pa' - }) if __name__ == '__main__': unittest.main() diff --git a/setup.py b/setup.py index 63684b1..ffe0358 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def main(): setup( name='postal', - version='0.3', + version='1.0', install_requires=[ 'six', ],