Skip to content

Commit

Permalink
added null or blank and exact type to int, long and date
Browse files Browse the repository at this point in the history
  • Loading branch information
vikasgupta78 committed Apr 23, 2024
1 parent bb109e1 commit 4c928d0
Show file tree
Hide file tree
Showing 16 changed files with 417 additions and 3 deletions.
Expand Up @@ -4,10 +4,14 @@

import zingg.common.client.FieldDefinition;
import zingg.common.client.MatchType;
import zingg.common.core.similarity.function.CheckNullFunctionDate;
import zingg.common.core.similarity.function.DateSimilarityFunction;
import zingg.common.core.similarity.function.DateSimilarityFunctionExact;

public class DateFeature extends BaseFeature<Date> {

private static final long serialVersionUID = 1L;

public DateFeature() {

}
Expand All @@ -28,6 +32,12 @@ public void init(FieldDefinition f) {
if (f.getMatchType().contains(MatchType.FUZZY)) {
addSimFunction(new DateSimilarityFunction());
}
if (f.getMatchType().contains(MatchType.EXACT)) {
addSimFunction(new DateSimilarityFunctionExact());
}
if (f.getMatchType().contains(MatchType.NULL_OR_BLANK)) {
addSimFunction(new CheckNullFunctionDate());
}
}

}
Expand Up @@ -2,9 +2,13 @@

import zingg.common.client.FieldDefinition;
import zingg.common.client.MatchType;
import zingg.common.core.similarity.function.CheckNullFunctionInt;
import zingg.common.core.similarity.function.IntegerSimilarityFunction;
import zingg.common.core.similarity.function.IntegerSimilarityFunctionExact;
public class IntFeature extends BaseFeature<Integer> {

private static final long serialVersionUID = 1L;

public IntFeature() {

}
Expand All @@ -14,6 +18,12 @@ public void init(FieldDefinition newParam) {
if (newParam.getMatchType().contains(MatchType.FUZZY)) {
addSimFunction(new IntegerSimilarityFunction());
}
if (newParam.getMatchType().contains(MatchType.EXACT)) {
addSimFunction(new IntegerSimilarityFunctionExact());
}
if (newParam.getMatchType().contains(MatchType.NULL_OR_BLANK)) {
addSimFunction(new CheckNullFunctionInt());
}
}

}
Expand Up @@ -2,7 +2,9 @@

import zingg.common.client.FieldDefinition;
import zingg.common.client.MatchType;
import zingg.common.core.similarity.function.CheckNullFunctionLong;
import zingg.common.core.similarity.function.LongSimilarityFunction;
import zingg.common.core.similarity.function.LongSimilarityFunctionExact;
public class LongFeature extends BaseFeature<Long> {

private static final long serialVersionUID = 1L;
Expand All @@ -16,6 +18,12 @@ public void init(FieldDefinition newParam) {
if (newParam.getMatchType().contains(MatchType.FUZZY)) {
addSimFunction(new LongSimilarityFunction());
}
if (newParam.getMatchType().contains(MatchType.EXACT)) {
addSimFunction(new LongSimilarityFunctionExact());
}
if (newParam.getMatchType().contains(MatchType.NULL_OR_BLANK)) {
addSimFunction(new CheckNullFunctionLong());
}
}

}
@@ -0,0 +1,30 @@
package zingg.common.core.similarity.function;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CheckNullFunctionDate extends SimFunction<Date> {

private static final long serialVersionUID = 1L;
public static final Log LOG = LogFactory
.getLog(CheckNullFunctionDate.class);

public CheckNullFunctionDate() {
super("CheckNullFunctionDate");
}

public CheckNullFunctionDate(String name) {
super(name);
}

@Override
public Double call(Date first, Date second) {
if (first != null && second != null) {
return 1d;
}
return 0d;
}

}
@@ -0,0 +1,30 @@
package zingg.common.core.similarity.function;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CheckNullFunctionInt extends SimFunction<Integer> {

private static final long serialVersionUID = 1L;
public static final Log LOG = LogFactory
.getLog(CheckNullFunctionInt.class);

public CheckNullFunctionInt() {
super("CheckNullFunctionInt");
}

public CheckNullFunctionInt(String name) {
super(name);
}

@Override
public Double call(Integer first, Integer second) {
if (first != null && second != null) {
return 1d;
}
return 0d;
}



}
@@ -0,0 +1,30 @@
package zingg.common.core.similarity.function;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CheckNullFunctionLong extends SimFunction<Long> {

private static final long serialVersionUID = 1L;
public static final Log LOG = LogFactory
.getLog(CheckNullFunctionLong.class);

public CheckNullFunctionLong() {
super("CheckNullFunctionLong");
}

public CheckNullFunctionLong(String name) {
super(name);
}

@Override
public Double call(Long first, Long second) {
if (first != null && second != null) {
return 1d;
}
return 0d;
}



}
@@ -0,0 +1,23 @@
package zingg.common.core.similarity.function;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DateSimilarityFunctionExact extends SimFunction<Date> {
private static final long serialVersionUID = 1L;
public static final Log LOG = LogFactory
.getLog(DateSimilarityFunctionExact.class);

public DateSimilarityFunctionExact() {
super("DateSimilarityFunctionExact");
}

@Override
public Double call(Date first, Date second) {
if (first == null || second == null) return 1d;
double score = first.equals(second) ? 1d : 0d;
return score;
}
}
@@ -0,0 +1,21 @@
package zingg.common.core.similarity.function;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class IntegerSimilarityFunctionExact extends SimFunction<Integer> {
private static final long serialVersionUID = 1L;
public static final Log LOG = LogFactory
.getLog(IntegerSimilarityFunctionExact.class);

public IntegerSimilarityFunctionExact() {
super("IntegerSimilarityFunctionExact");
}

@Override
public Double call(Integer first, Integer second) {
if (first == null || second == null) return 1d;
double score = first==second ? 1d : 0d;
return score;
}
}
@@ -0,0 +1,21 @@
package zingg.common.core.similarity.function;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LongSimilarityFunctionExact extends SimFunction<Long> {
private static final long serialVersionUID = 1L;
public static final Log LOG = LogFactory
.getLog(LongSimilarityFunctionExact.class);

public LongSimilarityFunctionExact() {
super("LongSimilarityFunctionExact");
}

@Override
public Double call(Long first, Long second) {
if (first == null || second == null) return 1d;
double score = first==second ? 1d : 0d;
return score;
}
}
@@ -0,0 +1,36 @@
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() {
CheckNullFunctionDate isNull = new CheckNullFunctionDate();
assertEquals(0d, isNull.call(null, new Date(2)));
}


@Test
public void testSecondNull() {
CheckNullFunctionDate isNull = new CheckNullFunctionDate();
assertEquals(0d, isNull.call(new Date(1), null));
}

@Test
public void testBothNull() {
CheckNullFunctionDate isNull = new CheckNullFunctionDate();
assertEquals(0d, isNull.call(null, null));
}

@Test
public void testBothNotNull() {
CheckNullFunctionDate isNull = new CheckNullFunctionDate();
assertEquals(1d, isNull.call(new Date(1), new Date(2)));
}

}
@@ -0,0 +1,35 @@
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() {
CheckNullFunctionInt isNull = new CheckNullFunctionInt();
assertEquals(0d, isNull.call(null, 2));
}


@Test
public void testSecondNull() {
CheckNullFunctionInt isNull = new CheckNullFunctionInt();
assertEquals(0d, isNull.call(1, null));
}

@Test
public void testBothNull() {
CheckNullFunctionInt isNull = new CheckNullFunctionInt();
assertEquals(0d, isNull.call(null, null));
}

@Test
public void testBothNotNull() {
CheckNullFunctionInt isNull = new CheckNullFunctionInt();
assertEquals(1d, isNull.call(1, 2));
}

}
@@ -0,0 +1,35 @@
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() {
CheckNullFunctionLong isNull = new CheckNullFunctionLong();
assertEquals(0d, isNull.call(null, 2l));
}


@Test
public void testSecondNull() {
CheckNullFunctionLong isNull = new CheckNullFunctionLong();
assertEquals(0d, isNull.call(1l, null));
}

@Test
public void testBothNull() {
CheckNullFunctionLong isNull = new CheckNullFunctionLong();
assertEquals(0d, isNull.call(null, null));
}

@Test
public void testBothNotNull() {
CheckNullFunctionLong isNull = new CheckNullFunctionLong();
assertEquals(1d, isNull.call(1l, 2l));
}

}
@@ -0,0 +1,43 @@
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() {
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact();
assertEquals(1d, exact.call(null, new Date(2)));
}


@Test
public void testSecondNull() {
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact();
assertEquals(1d, exact.call(new Date(1), null));
}

@Test
public void testBothNull() {
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact();
assertEquals(1d, exact.call(null, null));
}

@Test
public void testNotEqual() {
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact();
assertEquals(0d, exact.call(new Date(101), new Date(102)));
}

@Test
public void testEqual() {
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact();
assertEquals(1d, exact.call(new Date(101), new Date(101)));
}

}

0 comments on commit 4c928d0

Please sign in to comment.