Skip to content

Commit

Permalink
Merge pull request #16 from openvenues/1.0
Browse files Browse the repository at this point in the history
upgrading to use libpostal 1.0 API
  • Loading branch information
albarrentine authored Apr 6, 2017
2 parents 7278c6e + a302d31 commit 0364c0d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: java
branches:
only:
- master
jdk:
- oraclejdk8
- oraclejdk7
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ Before building the Java bindings, you must install the libpostal C library. Mak

**On Ubuntu/Debian**
```
sudo apt-get install curl libsnappy-dev autoconf automake libtool pkg-config
sudo apt-get install curl autoconf automake libtool pkg-config
```

**On CentOS/RHEL**
```
sudo yum install snappy snappy-devel autoconf automake libtool pkgconfig
sudo yum install curl autoconf automake libtool pkgconfig
```

**On Mac OSX**
```
sudo brew install snappy autoconf automake libtool pkg-config
sudo brew install curl autoconf automake libtool pkg-config
```

**Installing libpostal**
Expand Down Expand Up @@ -92,6 +92,13 @@ This will implicitly run [build.sh](./build.sh) which automatically runs the Aut

On RHEL it might be necessary to set ```PKG_CONFIG_PATH=/usr/lib/pkgconfig``` before running the gradle build.

Usage in a Java project
-----------------------

The JNI portion of jpostal builds shared object files (.so on Linux, .jniLib on Mac) that need to be on java.library.path. After running ```gradle assemble``` the .so/.jniLib files can be found under ```src/main/jniLibs``` in the checkout dir. For running the tests, we set java.library.path explicitly [here](https://github.com/openvenues/jpostal/blob/master/build.gradle#L18).

For gradle users, there's a plugin called gradle-natives that may be helpful: https://github.com/cjstehno/coffeaelectronica/wiki/Going-Native-with-Gradle

Compatibility
-------------

Expand Down
8 changes: 4 additions & 4 deletions src/main/c/jpostal_AddressExpander.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_mapzen_jpostal_AddressExpander_libpostal
const char *address = (*env)->GetStringUTFChars(env, jAddress, 0);

size_t num_expansions = 0;
normalize_options_t options = get_libpostal_default_options();
libpostal_normalize_options_t options = libpostal_get_default_options();

jfieldID fid;

Expand Down Expand Up @@ -208,7 +208,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_mapzen_jpostal_AddressExpander_libpostal

options.roman_numerals = (*env)->GetBooleanField(env, jOptions, fid);

char **expansions = expand_address((char *)address, options, &num_expansions);
char **expansions = libpostal_expand_address((char *)address, options, &num_expansions);

(*env)->ReleaseStringUTFChars(env, jAddress, address);

Expand All @@ -225,7 +225,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_mapzen_jpostal_AddressExpander_libpostal
}

if (expansions != NULL) {
expansion_array_destroy(expansions, num_expansions);
libpostal_expansion_array_destroy(expansions, num_expansions);
}

if (languages != NULL) {
Expand All @@ -250,7 +250,7 @@ JNIEXPORT void JNICALL Java_com_mapzen_jpostal_ExpanderOptions_00024Builder_setD
jfieldID fid;
jclass cls = (*env)->GetObjectClass(env, builder);

normalize_options_t default_options = get_libpostal_default_options();
libpostal_normalize_options_t default_options = libpostal_get_default_options();

fid = (*env)->GetFieldID(env, cls, "languages", "[Ljava/lang/String;");
if (fid == 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/c/jpostal_AddressParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_mapzen_jpostal_AddressParser_libpostalPa

const char *address = (*env)->GetStringUTFChars(env, jAddress, 0);

address_parser_options_t options = get_libpostal_address_parser_default_options();
libpostal_address_parser_options_t options = libpostal_get_address_parser_default_options();

jfieldID fid;

Expand Down Expand Up @@ -56,7 +56,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_mapzen_jpostal_AddressParser_libpostalPa
options.country = (char *)(*env)->GetStringUTFChars(env, jCountry, 0);
}

address_parser_response_t *response = parse_address((char *)address, options);
libpostal_address_parser_response_t *response = libpostal_parse_address((char *)address, options);

(*env)->ReleaseStringUTFChars(env, jAddress, address);

Expand Down Expand Up @@ -92,7 +92,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_mapzen_jpostal_AddressParser_libpostalPa
}

if (response != NULL) {
address_parser_response_destroy(response);
libpostal_address_parser_response_destroy(response);
}

return ret;
Expand All @@ -112,7 +112,7 @@ JNIEXPORT void JNICALL Java_com_mapzen_jpostal_ParserOptions_00024Builder_setDef
jfieldID fid;
jclass cls = (*env)->GetObjectClass(env, builder);

address_parser_options_t default_options = get_libpostal_address_parser_default_options();
libpostal_address_parser_options_t default_options = libpostal_get_address_parser_default_options();

fid = (*env)->GetFieldID(env, cls, "language", "Ljava/lang/String;");
if (fid == 0) {
Expand Down
28 changes: 0 additions & 28 deletions src/test/java/com/mapzen/jpostal/TestAddressParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,5 @@ public void testParseUSAddress() {
new ParsedComponent("11216", "postcode"),
new ParsedComponent("usa", "country")
);

testParse("whole foods ny",
new ParsedComponent("whole foods", "house"),
new ParsedComponent("ny", "state")
);

testParse("1917/2 Pike Drive",
new ParsedComponent("1917 / 2", "house_number"),
new ParsedComponent("pike drive", "road")
);

testParse("3437 warwickshire rd,pa",
new ParsedComponent("3437", "house_number"),
new ParsedComponent("warwickshire rd", "road"),
new ParsedComponent("pa", "state")
);

testParse("3437 warwickshire rd, pa",
new ParsedComponent("3437", "house_number"),
new ParsedComponent("warwickshire rd", "road"),
new ParsedComponent("pa", "state")
);

testParse("3437 warwickshire rd pa",
new ParsedComponent("3437", "house_number"),
new ParsedComponent("warwickshire rd", "road"),
new ParsedComponent("pa", "state")
);
}
}

0 comments on commit 0364c0d

Please sign in to comment.