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 #824 from zinggAI/issue821
added null or blank and exact match type to int, long and date issue#821
- Loading branch information
Showing
12 changed files
with
299 additions
and
3 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
26 changes: 26 additions & 0 deletions
26
common/core/src/main/java/zingg/common/core/similarity/function/CheckNullFunction.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,26 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class CheckNullFunction<T> extends SimFunction<T> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory | ||
.getLog(CheckNullFunction.class); | ||
|
||
public CheckNullFunction(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public Double call(T first, T second) { | ||
if (first != null && second != null) { | ||
return 1d; | ||
} | ||
return 0d; | ||
} | ||
|
||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
common/core/src/main/java/zingg/common/core/similarity/function/SimilarityFunctionExact.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,21 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class SimilarityFunctionExact<T> extends SimFunction<T> { | ||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory | ||
.getLog(SimilarityFunctionExact.class); | ||
|
||
public SimilarityFunctionExact(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public Double call(T first, T second) { | ||
if (first == null || second == null) return 1d; | ||
double score = first.equals(second) ? 1d : 0d; | ||
return score; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...n/core/src/test/java/zingg/common/core/similarity/function/TestCheckNullFunctionDate.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,34 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.jupiter.api.Test; | ||
public class TestCheckNullFunctionDate { | ||
|
||
@Test | ||
public void testFirstNull() { | ||
assertEquals(0d, simFunc().call(null, new Date(2))); | ||
} | ||
|
||
@Test | ||
public void testSecondNull() { | ||
assertEquals(0d, simFunc().call(new Date(1), null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
assertEquals(0d, simFunc().call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNotNull() { | ||
assertEquals(1d, simFunc().call(new Date(1), new Date(2))); | ||
} | ||
|
||
protected CheckNullFunction<Date> simFunc() { | ||
return new CheckNullFunction<Date>("CheckNullFunctionDate"); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...on/core/src/test/java/zingg/common/core/similarity/function/TestCheckNullFunctionInt.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,34 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestCheckNullFunctionInt { | ||
|
||
|
||
@Test | ||
public void testFirstNull() { | ||
assertEquals(0d, simFunc().call(null, 2)); | ||
} | ||
|
||
@Test | ||
public void testSecondNull() { | ||
assertEquals(0d, simFunc().call(1, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
assertEquals(0d, simFunc().call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNotNull() { | ||
assertEquals(1d, simFunc().call(1, 2)); | ||
} | ||
|
||
protected CheckNullFunction<Integer> simFunc() { | ||
return new CheckNullFunction<Integer>("CheckNullFunctionInt"); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...n/core/src/test/java/zingg/common/core/similarity/function/TestCheckNullFunctionLong.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,34 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestCheckNullFunctionLong { | ||
|
||
|
||
@Test | ||
public void testFirstNull() { | ||
assertEquals(0d, simFunc().call(null, 2l)); | ||
} | ||
|
||
@Test | ||
public void testSecondNull() { | ||
assertEquals(0d, simFunc().call(1l, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
assertEquals(0d, simFunc().call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNotNull() { | ||
assertEquals(1d, simFunc().call(1l, 2l)); | ||
} | ||
|
||
protected CheckNullFunction<Long> simFunc() { | ||
return new CheckNullFunction<Long>("CheckNullFunctionLong"); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
.../src/test/java/zingg/common/core/similarity/function/TestDateSimilarityFunctionExact.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,42 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestDateSimilarityFunctionExact { | ||
|
||
|
||
@Test | ||
public void testFirstNull() { | ||
assertEquals(1d, simFunc().call(null, new Date(2))); | ||
} | ||
|
||
|
||
@Test | ||
public void testSecondNull() { | ||
assertEquals(1d, simFunc().call(new Date(1), null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
assertEquals(1d, simFunc().call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testNotEqual() { | ||
assertEquals(0d, simFunc().call(new Date(101), new Date(102))); | ||
} | ||
|
||
@Test | ||
public void testEqual() { | ||
assertEquals(1d, simFunc().call(new Date(101), new Date(101))); | ||
} | ||
|
||
protected SimilarityFunctionExact<Date> simFunc() { | ||
return new SimilarityFunctionExact<Date>("DateSimilarityFunctionExact"); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...c/test/java/zingg/common/core/similarity/function/TestIntegerSimilarityFunctionExact.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,38 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestIntegerSimilarityFunctionExact { | ||
|
||
@Test | ||
public void testFirstNull() { | ||
assertEquals(1d, simFunc().call(null, 2)); | ||
} | ||
|
||
@Test | ||
public void testSecondNull() { | ||
assertEquals(1d, simFunc().call(1, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
assertEquals(1d, simFunc().call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testNotEqual() { | ||
assertEquals(0d, simFunc().call(101, 102)); | ||
} | ||
|
||
@Test | ||
public void testEqual() { | ||
assertEquals(1d, simFunc().call(101, 101)); | ||
} | ||
|
||
protected SimilarityFunctionExact<Integer> simFunc() { | ||
return new SimilarityFunctionExact<Integer>("IntegerSimilarityFunctionExact"); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
.../src/test/java/zingg/common/core/similarity/function/TestLongSimilarityFunctionExact.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,39 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestLongSimilarityFunctionExact { | ||
|
||
|
||
@Test | ||
public void testFirstNull() { | ||
assertEquals(1d, simFunc().call(null, 2l)); | ||
} | ||
|
||
@Test | ||
public void testSecondNull() { | ||
assertEquals(1d, simFunc().call(1l, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
assertEquals(1d, simFunc().call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testNotEqual() { | ||
assertEquals(0d, simFunc().call(101l, 102l)); | ||
} | ||
|
||
@Test | ||
public void testEqual() { | ||
assertEquals(1d, simFunc().call(101l, 101l)); | ||
} | ||
|
||
protected SimilarityFunctionExact<Long> simFunc() { | ||
return new SimilarityFunctionExact<Long>("LongSimilarityFunctionExact"); | ||
} | ||
|
||
} |
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