Java Client for the NameAPI Web Services at https://www.nameapi.org.
There are functional tests that demonstrate how to use this library.
All you need to send requests is your own api key which you can get from nameapi.org.
This library requires at least Java 17 starting from version 6.0.0 (use a previous version for Java 8).
Using Maven:
<dependency>
<groupId>org.nameapi.client</groupId>
<artifactId>nameapi-client</artifactId>
<version>6.0.0</version>
</dependency>
Or Gradle:
implementation 'org.nameapi.client:nameapi-client:6.0.0'
Also you could download the jar, or check out the source code from this GitHub project.
At first, you need some includes, to the context information:
importorg.nameapi.ontology5.input.context.Context;
importorg.nameapi.ontology5.input.context.ContextBuilder;
importorg.nameapi.ontology5.input.context.Priority;You need a Context that explains a bit your working environment, something like:
Contextcontext = newContextBuilder()
.priority(Priority.REALTIME)
.build();Then you need an executor and a mode:
importcom.optimaize.anythingworks.common.host.Host;
importcom.optimaize.anythingworks.common.host.Protocol;
importcom.optimaize.command4j.CommandExecutor;
importcom.optimaize.command4j.Mode;
importorg.nameapi.client.lib.NameApiModeFactory;
importorg.nameapi.client.lib.NameApiPortUrlFactory;
importorg.nameapi.client.lib.NameApiRemoteExecutors;
CommandExecutorexecutor = NameApiRemoteExecutors.get();
Modemode = NameApiModeFactory.withContext(
"your-api-key",
context,
//the default and live server is "api.nameapi.org"newHost("api.nameapi.org", Protocol.HTTPS), NameApiPortUrlFactory.version5_3()
);Now you're ready to execute commands.
This code sends a simple ping to nameapi to test the connection:
importorg.nameapi.client.services.system.ping.PingCommand;
PingCommandcommand = newPingCommand();
executor.execute(command, mode, null).get(); //returns "pong"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.
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:
importorg.nameapi.ontology5.input.entities.person.InputPerson;
importorg.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder;
importorg.nameapi.ontology5.input.entities.person.name.InputPersonName;
importorg.nameapi.ontology5.input.entities.person.name.builder.NameBuilders;
InputPersonNamename = NameBuilders.western().fullname("John F. Kennedy").build();
InputPersoninputPerson = newNaturalInputPersonBuilder().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:
importorg.nameapi.client.services.parser.personnameparser.PersonNameParserCommand;
importorg.nameapi.ontology5.services.parser.personnameparser.PersonNameParserResult;
PersonNameParserCommandcommand = newPersonNameParserCommand();
PersonNameParserResultresult = 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:
importorg.nameapi.client.services.genderizer.persongenderizer.PersonGenderizerCommand;
importorg.nameapi.ontology5.services.genderizer.GenderizerResult;
PersonGenderizerCommandcommand = newPersonGenderizerCommand();
GenderizerResultresult = 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:
importorg.nameapi.client.services.matcher.personmatcher.PersonMatcherArgument;
importorg.nameapi.client.services.matcher.personmatcher.PersonMatcherCommand;
importorg.nameapi.ontology5.input.entities.person.NaturalInputPerson;
importorg.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder;
importorg.nameapi.ontology5.services.matcher.personmatcher.PersonMatcherResult;
PersonMatcherCommandcommand = newPersonMatcherCommand();
NaturalInputPersonperson1 = newNaturalInputPersonBuilder().name( NameBuilders.western().fullname("John F. Kennedy").build() ).build();
NaturalInputPersonperson2 = newNaturalInputPersonBuilder().name( NameBuilders.western().fullname("Jack Kennedy").build() ).build();
PersonMatcherArgumentargument = newPersonMatcherArgument(person1, person2);
PersonMatcherResultresult = 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.
importorg.nameapi.client.services.formatter.personnameformatter.PersonNameFormatterArgument;
importorg.nameapi.client.services.formatter.personnameformatter.PersonNameFormatterCommand;
importorg.nameapi.ontology5.input.entities.person.NaturalInputPerson;
importorg.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder;
importorg.nameapi.ontology5.services.formatter.FormatterProperties;
importorg.nameapi.ontology5.services.formatter.FormatterResult;
PersonNameFormatterCommandcommand = newPersonNameFormatterCommand();
NaturalInputPersonperson = newNaturalInputPersonBuilder().name( NameBuilders.western().fullname("john f. kennedy").build() ).build();
FormatterPropertiesproperties = newFormatterProperties(true);
PersonNameFormatterArgumentargument = newPersonNameFormatterArgument(person, properties);
FormatterResultformatterResult = executor.execute(command, mode, argument).get();Detects various types of possibly fake data in person records.
importorg.nameapi.ontology5.input.entities.address.StructuredAddressBuilder;
importorg.nameapi.ontology5.input.entities.address.StructuredPlaceInfoBuilder;
importorg.nameapi.ontology5.input.entities.address.StructuredStreetInfoBuilder;
importorg.nameapi.ontology5.input.entities.contact.EmailAddressFactory;
importorg.nameapi.ontology5.input.entities.contact.TelNumberFactory;
importorg.nameapi.ontology5.input.entities.person.InputPerson;
importorg.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder;
importorg.nameapi.ontology5.input.entities.person.name.builder.WesternInputPersonNameBuilder;
importorg.nameapi.ontology5.services.riskdetector.*;
PersonRiskDetectorCommandcommand = newPersonRiskDetectorCommand();
InputPersonperson = newNaturalInputPersonBuilder()
.name(newWesternInputPersonNameBuilder().givenName("John").surname("Doe").build())
.addEmail(EmailAddressFactory.forAddress("john.doe@example.com"))
.addTelNumber(TelNumberFactory.forNumber("999 999 999"))
.addAddressForAll(
newStructuredAddressBuilder()
.placeInfo(newStructuredPlaceInfoBuilder().locality("Atlantis").postalCode("55555").build())
.streetInfo(newStructuredStreetInfoBuilder().streetName("Hill road").houseNumber("72").build())
.build())
.build();
RiskDetectorResultresult = executor.execute(command, mode, person).get();The Email Name Parser extracts names out of email addresses.
importorg.nameapi.client.services.email.emailnameparser.EmailNameParserCommand;
importorg.nameapi.ontology5.services.email.emailnameparser.EmailNameParserResult;
EmailNameParserCommandcommand = newEmailNameParserCommand();
EmailNameParserResultresult = executor.execute(command, mode, "john.doe@example.com").get();The DEA-Detector checks email addresses against a list of known "trash domains" such as mailinator.com.
importorg.nameapi.client.services.email.disposableemailaddressdetector.DisposableEmailAddressDetectorCommand;
importorg.nameapi.ontology5.services.email.disposableemailaddressdetector.DisposableEmailAddressDetectorResult;
DisposableEmailAddressDetectorCommandcommand = newDisposableEmailAddressDetectorCommand();
DisposableEmailAddressDetectorResultresult = executor.execute(command, mode, "blahblah@10minutemail.com").get();