-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from RavirajBaraiya/MatchTypeEmail
Match type email
- Loading branch information
Showing
7 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
core/src/main/java/zingg/similarity/function/EmailMatchTypeFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package zingg.similarity.function; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.spark.ml.util.Identifiable$; | ||
|
||
|
||
public class EmailMatchTypeFunction extends StringSimilarityDistanceFunction { | ||
|
||
public static final Log LOG = LogFactory | ||
.getLog(EmailMatchTypeFunction.class); | ||
//private static final String String = null; | ||
|
||
|
||
public EmailMatchTypeFunction() { | ||
this("EmailMatchTypeFunction"); | ||
} | ||
|
||
public EmailMatchTypeFunction(String s) { | ||
super(s); | ||
//gap = new SAffineGap(); | ||
} | ||
|
||
@Override | ||
public Double call(String first, String second) { | ||
first = first.split("@",0)[0]; | ||
second = second.split("@",0)[0]; | ||
return super.call(first,second); | ||
/* | ||
double score1 = 0.0; | ||
double score2 = 0.0; | ||
double score = 0.0; | ||
try { | ||
if (first == null || first.equals("")) { | ||
score1 = 1.0d; | ||
} | ||
if (second == null || second.equals("")) { | ||
score2 = 1.0d; | ||
} | ||
if (score1 != 1.0d && score2 != 1.0d) { | ||
first = first.split("@",0)[0]; | ||
second = second.split("@",0)[0]; | ||
score = first.equalsIgnoreCase(second)? 1.0d : 0.0d; | ||
} | ||
else { | ||
score = 1.0d; | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
LOG.warn("Error processing differences for " + first + "," + second); | ||
} finally { | ||
if (Double.isNaN(score)) { | ||
score = 0.0; | ||
} | ||
return score; | ||
*/ | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
core/src/main/java/zingg/similarity/function/StringSimilarityDistanceFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
core/src/test/java/zingg/similarity/function/TestEmailMatchTypeFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package zingg.similarity.function; | ||
|
||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TestEmailMatchTypeFunction { | ||
|
||
|
||
@Test | ||
public void testFirstEntryNull() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = null; | ||
String second = "xyz321@pqr.co"; | ||
assertEquals(expected.call(first,second.split("@",0)[0]), emailMatchFn.call(first, second)); | ||
} | ||
|
||
@Test | ||
public void testFirstEntryEmpty() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = ""; | ||
String second = "xyz321@pqr.co"; | ||
assertEquals(expected.call(first.split("@",0)[0],second.split("@",0)[0]), emailMatchFn.call(first, second)); | ||
} | ||
|
||
@Test | ||
public void testSecondEntryNull() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = "xyz321@pqr.co"; | ||
String second = null; | ||
assertEquals(expected.call(first.split("@",0)[0],second), emailMatchFn.call(first,second)); | ||
} | ||
|
||
@Test | ||
public void testSecondEntryEmpty() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = "xyz321@pqr.co"; | ||
String second = ""; | ||
assertEquals(expected.call(first.split("@",0)[0],second.split("@",0)[0]), emailMatchFn.call(first,second)); | ||
} | ||
@Test | ||
public void testBothEmpty() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = ""; | ||
String second = ""; | ||
assertEquals(expected.call(first.split("@",0)[0],second.split("@",0)[0]), emailMatchFn.call(first,second)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
//AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = null; | ||
String second = null; | ||
assertEquals(1d, emailMatchFn.call(first,second)); | ||
} | ||
|
||
@Test | ||
public void testBothExact() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
//AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = "xyz321@pqr.co"; | ||
String second = "xyz321@pqr.co"; | ||
assertEquals(1d, emailMatchFn.call(first,second)); | ||
} | ||
|
||
@Test | ||
public void testbothDifferent() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = "xyz321@pqr.co"; | ||
String second = "pqr981@abc.in"; | ||
assertEquals(expected.call(first.split("@",0)[0],second.split("@",0)[0]), emailMatchFn.call(first,second)); | ||
} | ||
|
||
@Test | ||
public void testFirstPartMatch() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
//AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = "pqr981@abc.in"; | ||
String second = "pqr981@xyz.com"; | ||
assertEquals(1d, emailMatchFn.call(first,second)); | ||
} | ||
|
||
@Test | ||
public void testFirstPartDifferentSecondPartMatch() { | ||
EmailMatchTypeFunction emailMatchFn = new EmailMatchTypeFunction(); | ||
AffineGapSimilarityFunction expected = new AffineGapSimilarityFunction(); | ||
String first = "pqr981@xyz.com"; | ||
String second = "aqr981@xyz.com"; | ||
assertEquals(expected.call(first.split("@",0)[0],second.split("@",0)[0]), emailMatchFn.call(first,second)); | ||
} | ||
|
||
} |