Java Client for the NameAPI Web Service at http://www.nameapi.org/
There are functional tests (in test/functional) that demonstrate how to use this library.
All you need to send requests is your own api key, get it from nameapi.org.
This library requires at least Java 7.
<dependency> <groupId>org.nameapi.client</groupId> <artifactId>nameapi-client</artifactId> <version>5.0.1</version> </dependency>
Or you can download the jar, or check out the source code from this GitHub project.
At first you need one single include, the one to the nameapi service factory:
You need a Context that explains a bit your working environment, something like:
Context context = new ContextBuilder() .priority(Priority.REALTIME) .build();
Then you need an executor and a mode:
CommandExecutor executor = NameApiRemoteExecutors.get(); Mode mode = NameApiModeFactory.withContext( "your-api-key", context, //the default and live server is "api.nameapi.org" //we're using the latest release candidate with latest features here: new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable() );
Now you're ready to execute commands.
Send a ping
This code sends a simple ping to nameapi to test the connection:
PingCommand command = new PingCommand(); executor.execute(command, mode, null).get(); //returns "pong"
Input / Output
All input objects come with builders or nicely documented setters. The result objects returned by the services all have fully documented getters. Many input arguments are optional - that means you can start simple, and add more as you need. The vocabulary for the communication, with input/output classes, is in the separate "Ontology" software. It is included as a Maven dependency. For the project page see https://github.com/optimaize/nameapi-ontology-java
Behind the scenes this service api uses REST (previous versions used SOAP). But luckily you don't need to worry about any of the interface detail, you can just use the provided classes.
Person input object
Most services accept a 'Person' as input. This person contains a name, and optionally more data such as gender, birth date etc. The name can be just a single "full name" string, or it can be composed of multiple fields like given name, middle name, surname. This standardized api makes it simple to use different services in a consistent way, and is very convenient in accepting the data however you have it at hands.
Creating a simple person looks something like this:
InputPersonName name = NameBuilders.western().fullname("John F. Kennedy").build(); InputPerson inputPerson = new NaturalInputPersonBuilder().name(name).build();
The web service methods are implemented as commands. This brings the advantage that the command can be passed around and wrapped with other useful goodies such as logging in a unified way, without the need to put a wrapper around every service. For more specialized concerns such as auto-retry on failure this concept becomes a real advantage.
Name parsing is the process of splitting a full name into its components.
Using the objects created earlier:
PersonNameParserCommand command = new PersonNameParserCommand(); PersonNameParserResult result = executor.execute(command, mode, inputPerson).get();
Name genderizing is the process of identifying the gender based on a person's name.
Using the objects created earlier:
PersonGenderizerCommand command = new PersonGenderizerCommand(); GenderizerResult result = executor.execute(command, mode, inputPerson).get();
The Name Matcher compares names and name pairs to discover whether the people could possibly be one and the same person.
This service takes 2 people as input:
PersonMatcherCommand command = new PersonMatcherCommand(); NaturalInputPerson person1 = new NaturalInputPersonBuilder().name( NameBuilders.western().fullname("John F. Kennedy").build() ).build(); NaturalInputPerson person2 = new NaturalInputPersonBuilder().name( NameBuilders.western().fullname("Jack Kennedy").build() ).build(); PersonMatcherArgument argument = new PersonMatcherArgument(person1, person2); PersonMatcherResult result = executor.execute(command, mode, argument).get();
The Name Formatter displays personal names in the desired form. This includes the order as well as upper and lower case writing.
PersonNameFormatterCommand command = new PersonNameFormatterCommand(); NaturalInputPerson person = new NaturalInputPersonBuilder().name( NameBuilders.western().fullname("john f. kennedy").build() ).build(); FormatterProperties properties = new FormatterProperties(true); PersonNameFormatterArgument argument = new PersonNameFormatterArgument(person, properties); FormatterResult formatterResult = executor.execute(command, mode, argument).get();
Email Name Parser
The Email Name Parser extracts names out of email addresses.
EmailNameParserCommand command = new EmailNameParserCommand(); EmailNameParserResult result = executor.execute(command, mode, "firstname.lastname@example.org").get();
Disposable Email Address Detector
The DEA-Detector checks email addresses against a list of known "trash domains" such as mailinator.com.
DisposableEmailAddressDetectorCommand command = new DisposableEmailAddressDetectorCommand(); DisposableEmailAddressDetectorResult result = executor.execute(command, mode, "email@example.com").get();