Skip to content

Commit 89074e7

Browse files
committed
Matcher and Genderizer tests working.
1 parent 5e7b9b9 commit 89074e7

File tree

8 files changed

+84
-35
lines changed

8 files changed

+84
-35
lines changed

.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_5_4.xml renamed to .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_4_0.xml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_5_4.xml renamed to .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_4_0.xml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_guava_2_4_0.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.nameapi.client.services.matcher.personmatcher;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
5+
import org.nameapi.ontology5.input.entities.person.InputPerson;
6+
import org.nameapi.ontology5.services.formatter.FormatterProperties;
7+
8+
/**
9+
*
10+
*/
11+
public class PersonMatcherArgument {
12+
13+
@NotNull
14+
private final InputPerson inputPerson1;
15+
@NotNull
16+
private final InputPerson inputPerson2;
17+
18+
public PersonMatcherArgument(@NotNull InputPerson inputPerson1, @NotNull InputPerson inputPerson2) {
19+
this.inputPerson1 = inputPerson1;
20+
this.inputPerson2 = inputPerson2;
21+
}
22+
23+
@NotNull
24+
public InputPerson getInputPerson1() {
25+
return inputPerson1;
26+
}
27+
28+
@NotNull
29+
public InputPerson getInputPerson2() {
30+
return inputPerson2;
31+
}
32+
}

src/main/java/org/nameapi/client/services/matcher/personmatcher/PersonMatcherCommand.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.optimaize.command4j.ExecutionContext;
55
import org.jetbrains.annotations.NotNull;
66
import org.nameapi.client.services.NameApiBaseCommand;
7-
import org.nameapi.ontology5.input.entities.person.InputPerson;
87
import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatcherResult;
98

109
import java.util.concurrent.Callable;
@@ -13,7 +12,7 @@
1312
* Compares two people and tells if and how they match.
1413
*/
1514
public class PersonMatcherCommand
16-
extends NameApiBaseCommand<RestPort, InputPerson, PersonMatcherResult>
15+
extends NameApiBaseCommand<RestPort, PersonMatcherArgument, PersonMatcherResult>
1716
{
1817

1918
private static final String SERVICE_PATH = "/matcher/personmatcher";
@@ -23,8 +22,8 @@ public PersonMatcherCommand() {
2322
}
2423

2524
@Override
26-
public PersonMatcherResult call(@NotNull Optional<InputPerson> arg, @NotNull ExecutionContext ec) throws Exception {
27-
return getPort(ec).call(getApiKey(ec), getContext(ec), arg.get());
25+
public PersonMatcherResult call(@NotNull Optional<PersonMatcherArgument> arg, @NotNull ExecutionContext ec) throws Exception {
26+
return getPort(ec).call(getApiKey(ec), getContext(ec), arg.get().getInputPerson1(), arg.get().getInputPerson2());
2827
}
2928

3029
@NotNull @Override

src/main/java/org/nameapi/client/services/matcher/personmatcher/RestPort.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.nameapi.ontology5.input.context.Context;
1010
import org.nameapi.ontology5.input.entities.person.InputPerson;
1111
import org.nameapi.ontology5.services.InputWithPerson;
12+
import org.nameapi.ontology5.services.InputWithTwoPeople;
1213
import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatcherResult;
1314

1415
/**
@@ -22,14 +23,14 @@ public RestPort(RestHttpClient restApiClient, String servicePath) {
2223
super(restApiClient, servicePath);
2324
}
2425

25-
public PersonMatcherResult call(String apiKey, Context context, InputPerson inputPerson) {
26+
public PersonMatcherResult call(String apiKey, Context context, InputPerson inputPerson1, InputPerson inputPerson2) {
2627
QueryParams queryParams = QueryParams.create();
2728
queryParams.add("apiKey", apiKey);
2829

2930
RestHttpClientResponse<PersonMatcherResult> response = restApiClient.invokeBody(
3031
servicePath, "POST",
3132
queryParams, HeaderParams.none(),
32-
new InputWithPerson(context, inputPerson),
33+
new InputWithTwoPeople(context, inputPerson1, inputPerson2),
3334
returnType
3435
);
3536
return response.getResult().get();

src/test/functional/java/org/nameapi/client/services/genderizer/persongenderizer/PersonGenderizerCommandTest.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
import com.optimaize.command4j.CommandExecutor;
44
import com.optimaize.command4j.Mode;
5-
import org.nameapi.client.services.FunctionalTestsNameApiModeFactory;
65
import org.nameapi.client.lib.NameApiRemoteExecutors;
76
import org.nameapi.client.services.AbstractTest;
8-
import org.nameapi.ontology5.input.entities.address.SegregatedPlaceInfoBuilder;
9-
import org.nameapi.ontology5.input.entities.address.SegregatedStreetInfoBuilder;
10-
import org.nameapi.ontology5.input.entities.address.StandardAddressBuilder;
7+
import org.nameapi.client.services.FunctionalTestsNameApiModeFactory;
8+
import org.nameapi.ontology5.input.entities.address.StructuredAddressBuilder;
9+
import org.nameapi.ontology5.input.entities.address.StructuredPlaceInfoBuilder;
10+
import org.nameapi.ontology5.input.entities.address.StructuredStreetInfoBuilder;
1111
import org.nameapi.ontology5.input.entities.person.NaturalInputPerson;
1212
import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder;
1313
import org.nameapi.ontology5.input.entities.person.age.AgeInfoFactory;
1414
import org.nameapi.ontology5.input.entities.person.gender.ComputedPersonGender;
15-
import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender;
15+
import org.nameapi.ontology5.services.genderizer.GenderizerResult;
1616
import org.testng.annotations.Test;
1717

1818
import static org.testng.Assert.assertEquals;
@@ -28,7 +28,8 @@ public void testCall() throws Exception {
2828
PersonGenderizerCommand command = new PersonGenderizerCommand();
2929
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
3030
NaturalInputPerson person = new NaturalInputPersonBuilder().name(makeName("Petra Müller")).build();
31-
assertEquals(executor.execute(command, mode, person).get().getGender(), ComputedPersonGender.FEMALE);
31+
GenderizerResult genderizerResult = executor.execute(command, mode, person).get();
32+
assertEquals(genderizerResult.getGender(), ComputedPersonGender.FEMALE);
3233
}
3334

3435
@Test
@@ -41,24 +42,25 @@ public void testCall2() throws Exception {
4142
.addNationality("US")
4243
.addNativeLanguage("en")
4344
.correspondenceLanguage("en")
44-
.addAddressForAll(new StandardAddressBuilder()
45-
.setPlaceInfo(
46-
new SegregatedPlaceInfoBuilder()
45+
.addAddressForAll(new StructuredAddressBuilder()
46+
.placeInfo(
47+
new StructuredPlaceInfoBuilder()
4748
.postalCode("90210")
4849
.locality("Beverly Hills")
4950
.country("US")
5051
.build()
5152
)
52-
.setStreetInfo(
53-
new SegregatedStreetInfoBuilder()
54-
.streetName("Hill road")
55-
.streetNumber("512")
56-
.build()
53+
.streetInfo(
54+
new StructuredStreetInfoBuilder()
55+
.streetName("Hill road")
56+
.streetNumber("512")
57+
.build()
5758
)
5859
.build()
5960
)
6061
.build();
61-
assertEquals(executor.execute(command, mode, person).get().getGender(), ComputedPersonGender.MALE);
62+
GenderizerResult result = executor.execute(command, mode, person).get();
63+
assertEquals(result.getGender(), ComputedPersonGender.MALE);
6264
}
6365

6466
/**
@@ -69,7 +71,8 @@ public void testCall3() throws Exception {
6971
PersonGenderizerCommand command = new PersonGenderizerCommand();
7072
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
7173
NaturalInputPerson person = new NaturalInputPersonBuilder().name(makeName("John", "")).build();
72-
assertEquals(executor.execute(command, mode, person).get().getGender(), ComputedPersonGender.MALE);
74+
GenderizerResult result = executor.execute(command, mode, person).get();
75+
assertEquals(result.getGender(), ComputedPersonGender.MALE);
7376
}
7477

7578
// /**

src/test/functional/java/org/nameapi/client/services/matcher/personmatcher/PersonMatcherCommandTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import org.nameapi.client.services.AbstractTest;
88
import org.nameapi.ontology5.input.entities.person.NaturalInputPerson;
99
import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder;
10-
import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatcherArgument;
10+
import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatchType;
11+
import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatcherResult;
1112
import org.testng.annotations.Test;
1213

1314
import static org.testng.Assert.assertEquals;
@@ -25,8 +26,8 @@ public void test_equal() throws Exception {
2526
NaturalInputPerson person1 = new NaturalInputPersonBuilder().name(makeName("Petra Müller")).build();
2627
NaturalInputPerson person2 = new NaturalInputPersonBuilder().name(makeName("Petra Müller")).build();
2728
PersonMatcherArgument argument = new PersonMatcherArgument(person1, person2);
28-
// PersonMatcherResult result = executor.execute(command, mode, argument).get();
29-
// assertEquals(result.getMatchType(), PersonMatchType.EQUAL);
29+
PersonMatcherResult result = executor.execute(command, mode, argument).get();
30+
assertEquals(result.getMatchType(), PersonMatchType.EQUAL);
3031
}
3132

3233
@Test
@@ -36,8 +37,8 @@ public void test_matching() throws Exception {
3637
NaturalInputPerson person1 = new NaturalInputPersonBuilder().name(makeName("Petra Müller")).build();
3738
NaturalInputPerson person2 = new NaturalInputPersonBuilder().name(makeName("Petra Mueller")).build();
3839
PersonMatcherArgument argument = new PersonMatcherArgument(person1, person2);
39-
// PersonMatcherResult result = executor.execute(command, mode, argument).get();
40-
// assertEquals(result.getMatchType(), PersonMatchType.EQUAL);
40+
PersonMatcherResult result = executor.execute(command, mode, argument).get();
41+
assertEquals(result.getMatchType(), PersonMatchType.MATCHING);
4142
}
4243

4344
}

0 commit comments

Comments
 (0)