-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* telemetry fix * comment fixes * comments fix * junits * comment fixes * comment fixes * comment fixes * comment fixes * comment fixes and refactor code * comment fixes and refactor code * pmd comments * adding asserts * Update TestStopWordUtility.java * updating asserts
- Loading branch information
Showing
7 changed files
with
143 additions
and
11 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
common/client/src/main/java/zingg/common/client/HasStopWords.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,11 @@ | ||
package zingg.common.client; | ||
|
||
import scala.Serializable; | ||
|
||
public class HasStopWords implements Serializable { | ||
|
||
public static boolean isStopwordField(FieldDefinition f){ | ||
return (!(f.getStopWords() == null || f.getStopWords() == "")); | ||
} | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
common/client/src/main/java/zingg/common/client/util/StopWordUtility.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,29 @@ | ||
package zingg.common.client.util; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import zingg.common.client.FieldDefinition; | ||
import zingg.common.client.HasStopWords; | ||
import zingg.common.client.IArguments; | ||
|
||
public class StopWordUtility implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public List<? extends FieldDefinition> getFieldDefinitionWithStopwords(List<? extends FieldDefinition> fieldDefinition) { | ||
|
||
return fieldDefinition.stream() | ||
.filter(f -> HasStopWords.isStopwordField(f)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public String getFieldDefinitionNamesWithStopwords(IArguments args) { | ||
|
||
return getFieldDefinitionWithStopwords(args.getFieldDefinition()).stream() | ||
.map(FieldDefinition::getName) | ||
.collect(Collectors.joining(", ")); | ||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
common/client/src/test/java/zingg/common/client/util/TestStopWordUtility.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,96 @@ | ||
package zingg.common.client.util; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import zingg.common.client.Arguments; | ||
import zingg.common.client.FieldDefinition; | ||
import zingg.common.client.IArguments; | ||
import zingg.common.client.MatchType; | ||
import zingg.common.client.ZinggClientException; | ||
|
||
public class TestStopWordUtility { | ||
|
||
@Test | ||
public void testGetFieldDefinitionWithStopwords(){ | ||
try { | ||
FieldDefinition def1 = new FieldDefinition(); | ||
def1.setFieldName("field1"); | ||
def1.setDataType("string"); | ||
def1.setMatchTypeInternal(MatchType.FUZZY); | ||
def1.setFields("field1"); | ||
|
||
FieldDefinition def2 = new FieldDefinition(); | ||
def2.setFieldName("field2"); | ||
def2.setDataType("string"); | ||
def2.setMatchTypeInternal(MatchType.EXACT); | ||
def2.setStopWords("stopWordsFileName2"); | ||
def2.setFields("field2"); | ||
|
||
FieldDefinition def3 = new FieldDefinition(); | ||
def3.setFieldName("field3"); | ||
def3.setDataType("string"); | ||
def3.setMatchTypeInternal(MatchType.FUZZY); | ||
def3.setStopWords(null); | ||
def3.setFields("field3"); | ||
|
||
List<FieldDefinition> fieldDef = new ArrayList<FieldDefinition>(); | ||
fieldDef.add(def1); | ||
fieldDef.add(def2); | ||
fieldDef.add(def3); | ||
|
||
List<? extends FieldDefinition> stopWordList = new StopWordUtility().getFieldDefinitionWithStopwords(fieldDef); | ||
assertEquals(1,stopWordList.size()); | ||
assertEquals("field2", stopWordList.get(0).getName()); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
|
||
} | ||
|
||
} | ||
|
||
@Test | ||
public void testGetFieldDefinitionNamesWithStopwords() throws ZinggClientException{ | ||
FieldDefinition def1 = new FieldDefinition(); | ||
def1.setFieldName("field1"); | ||
def1.setDataType("string"); | ||
def1.setMatchTypeInternal(MatchType.FUZZY); | ||
def1.setFields("field1"); | ||
|
||
FieldDefinition def2 = new FieldDefinition(); | ||
def2.setFieldName("field2"); | ||
def2.setDataType("string"); | ||
def2.setMatchTypeInternal(MatchType.EXACT); | ||
def2.setStopWords("stopWordsFileName2"); | ||
def2.setFields("field2"); | ||
|
||
FieldDefinition def3 = new FieldDefinition(); | ||
def3.setFieldName("field3"); | ||
def3.setDataType("string"); | ||
def3.setMatchTypeInternal(MatchType.FUZZY); | ||
def3.setStopWords("stopWordsFileName3"); | ||
def3.setFields("field3"); | ||
|
||
List<FieldDefinition> fieldDef = new ArrayList<FieldDefinition>(); | ||
fieldDef.add(def1); | ||
fieldDef.add(def2); | ||
fieldDef.add(def3); | ||
IArguments args = null; | ||
try { | ||
args = new Arguments(); | ||
args.setFieldDefinition(fieldDef); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
String result = new StopWordUtility().getFieldDefinitionNamesWithStopwords(args); | ||
assertEquals("field2, field3", result); | ||
|
||
} | ||
|
||
} |
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