Skip to content

Commit c6c59f9

Browse files
committed
Added person matcher test.
1 parent c8e4f9c commit c6c59f9

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

src/org/nameapi/client/services/matcher/personmatcher/PersonMatcherService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ public function __construct(Context $context) {
4444
public function match(NaturalInputPerson $person1, NaturalInputPerson $person2) {
4545
$parameters = new wsdl\MatchArguments($this->context, $person1, $person2);
4646
$result = $this->soapPersonMatcher->match($parameters);
47+
48+
$genderWarnings = isSet($result->genderMatch->warnings) ? $result->genderMatch->warnings : null;
49+
4750
return new PersonMatchResult(
4851
new PersonMatchType($result->personMatchType),
4952
new PersonMatchComposition($result->personMatchComposition),
5053
$result->points, $result->confidence,
5154
new PersonNameMatch(new PersonNameMatchType($result->personNameMatch->type)),
52-
new GenderMatch(new GenderMatchType($result->genderMatch->type), $result->genderMatch->confidence, $result->genderMatch->warnings),
55+
new GenderMatch(new GenderMatchType($result->genderMatch->type), $result->genderMatch->confidence, $genderWarnings),
5356
new AgeMatch($result->ageMatch)
5457
);
5558
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace org\nameapi\client\services\matcher\personmatcher;
4+
5+
require_once(__DIR__.'/../../BaseServiceTest.php');
6+
7+
use org\nameapi\client\services\BaseServiceTest;
8+
use org\nameapi\ontology\input\entities\person\NaturalInputPerson;
9+
use org\nameapi\ontology\input\entities\person\name\InputPersonName;
10+
use org\nameapi\ontology\input\entities\person\age\AgeInfoFactory;
11+
12+
class PersonMatcherServiceTest extends BaseServiceTest {
13+
14+
public function testMatch_matching() {
15+
$personMatcher = $this->makeServiceFactory()->matcherServices()->personMatcher();
16+
$inputPerson1 = NaturalInputPerson::builder()
17+
->name(InputPersonName::westernBuilder()
18+
->fullname( "John F. Kennedy" )
19+
->build())
20+
->build();
21+
$inputPerson2 = NaturalInputPerson::builder()
22+
->name(InputPersonName::westernBuilder()
23+
->fullname( "Jack Kennedy" )
24+
->build())
25+
->build();
26+
$personMatchResult = $personMatcher->match($inputPerson1, $inputPerson2);
27+
$this->assertEquals('MATCHING', $personMatchResult->getPersonMatchType()->toString());
28+
}
29+
30+
public function testMatch_similar() {
31+
$personMatcher = $this->makeServiceFactory()->matcherServices()->personMatcher();
32+
$inputPerson1 = NaturalInputPerson::builder()
33+
->name(InputPersonName::westernBuilder()
34+
->fullname( "John F. Kennedy" )
35+
->build())
36+
->ageInfo( AgeInfoFactory::forDate(1917,5,29) )
37+
->build();
38+
$inputPerson2 = NaturalInputPerson::builder()
39+
->name(InputPersonName::westernBuilder()
40+
->fullname( "Jack Kennedy" )
41+
->build())
42+
->ageInfo( AgeInfoFactory::forDate(1990,12,31) )
43+
->build();
44+
$personMatchResult = $personMatcher->match($inputPerson1, $inputPerson2);
45+
$this->assertEquals('SIMILAR', $personMatchResult->getPersonMatchType()->toString());
46+
}
47+
48+
public function testMatch_different() {
49+
$personMatcher = $this->makeServiceFactory()->matcherServices()->personMatcher();
50+
$inputPerson1 = NaturalInputPerson::builder()
51+
->name(InputPersonName::westernBuilder()
52+
->fullname( "John F. Kennedy" )
53+
->build())
54+
->ageInfo( AgeInfoFactory::forDate(1917,5,29) )
55+
->build();
56+
$inputPerson2 = NaturalInputPerson::builder()
57+
->name(InputPersonName::westernBuilder()
58+
->fullname( "John Doe" )
59+
->build())
60+
->ageInfo( AgeInfoFactory::forDate(1990,12,31) )
61+
->build();
62+
$personMatchResult = $personMatcher->match($inputPerson1, $inputPerson2);
63+
$this->assertEquals('DIFFERENT', $personMatchResult->getPersonMatchType()->toString());
64+
}
65+
66+
}

0 commit comments

Comments
 (0)