use of edu.uci.ics.textdb.api.field.IntegerField in project textdb by TextDB.
the class ComparableMatcherTest method testDoubleMatching2.
/**
* Verifies the behavior of ComparableMatcher<Double> with matching type LESS_THAN
*
* @throws Exception
*/
@Test
public void testDoubleMatching2() throws Exception {
// Prepare the query
double threshold = 5.75;
Attribute attribute = TestConstants.HEIGHT_ATTR;
String attributeName = attribute.getAttributeName();
ComparisonType matchingType = ComparisonType.LESS_THAN;
// Perform the query
List<Tuple> returnedResults = getDoubleQueryResults(attributeName, matchingType, threshold);
IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry") };
List<Tuple> expectedResults = new ArrayList<>();
expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields1));
// check the results
Assert.assertEquals(1, returnedResults.size());
Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
use of edu.uci.ics.textdb.api.field.IntegerField in project textdb by TextDB.
the class ComparableMatcherTest method testDoubleMatching3.
/**
* Verifies the behavior of ComparableMatcher<Double> with matching type LESS_THAN_OR_EQUAL_TO
*
* @throws Exception
*/
@Test
public void testDoubleMatching3() throws Exception {
// Prepare the query
double threshold = 5.95;
Attribute attribute = TestConstants.HEIGHT_ATTR;
String attributeName = attribute.getAttributeName();
ComparisonType matchingType = ComparisonType.LESS_THAN_OR_EQUAL_TO;
// Perform the query
List<Tuple> returnedResults = getDoubleQueryResults(attributeName, matchingType, threshold);
IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry") };
IField[] fields2 = { new StringField("tom hanks"), new StringField("cruise"), new IntegerField(45), new DoubleField(5.95), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1971")), new TextField("Short Brown") };
List<Tuple> expectedResults = new ArrayList<>();
expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields1));
expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields2));
// check the results
Assert.assertEquals(2, returnedResults.size());
Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
use of edu.uci.ics.textdb.api.field.IntegerField in project textdb by TextDB.
the class ComparableMatcherTest method testIntegerMatching5.
/**
* Verifies the behavior of ComparableMatcher<Integer> with matching type LESS_THAN
*
* @throws Exception
*/
@Test
public void testIntegerMatching5() throws Exception {
// Prepare the query
int threshold = 43;
Attribute attribute = TestConstants.AGE_ATTR;
String attributeName = attribute.getAttributeName();
ComparisonType matchingType = ComparisonType.LESS_THAN;
// Perform the query
List<Tuple> returnedResults = getIntegerQueryResults(attributeName, matchingType, threshold);
IField[] fields1 = { new StringField("christian john wayne"), new StringField("rock bale"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Tall Fair") };
IField[] fields2 = { new StringField("Mary brown"), new StringField("Lake Forest"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Short angry") };
List<Tuple> expectedResults = new ArrayList<>();
expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields1));
expectedResults.add(new Tuple(TestConstants.SCHEMA_PEOPLE, fields2));
// check the results
Assert.assertEquals(2, returnedResults.size());
Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
use of edu.uci.ics.textdb.api.field.IntegerField in project textdb by TextDB.
the class WordCountIndexSource method computeNextMatchingTuple.
private Tuple computeNextMatchingTuple() throws TextDBException {
if (sortedWordCountMap == null) {
computeWordCount();
}
if (wordCountIterator.hasNext()) {
Entry<String, Integer> entry = wordCountIterator.next();
List<IField> tupleFieldList = new ArrayList<>();
// Generate the new UUID.
tupleFieldList.add(IDField.newRandomID());
tupleFieldList.add(new StringField(entry.getKey()));
tupleFieldList.add(new IntegerField(entry.getValue()));
cursor++;
return new Tuple(SCHEMA_WORD_COUNT, tupleFieldList);
}
return null;
}
use of edu.uci.ics.textdb.api.field.IntegerField in project textdb by TextDB.
the class DictionaryMatcherTest method testMatchingWithLimitOffset.
@Test
public void testMatchingWithLimitOffset() throws Exception {
ArrayList<String> word = new ArrayList<String>(Arrays.asList("angry"));
Dictionary dictionary = new Dictionary(word);
Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < schemaAttributes.length - 1; count++) {
schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
schemaAttributes[schemaAttributes.length - 1] = RESULTS_ATTRIBUTE;
Span span1 = new Span("description", 5, 10, "angry", "Angry");
Span span2 = new Span("description", 6, 11, "angry", "Angry");
Span span3 = new Span("description", 40, 45, "angry", "Angry");
Span span4 = new Span("description", 6, 11, "angry", "angry");
List<Span> list1 = new ArrayList<>();
list1.add(span1);
IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry"), new ListField<>(list1) };
List<Span> list2 = new ArrayList<>();
list2.add(span2);
IField[] fields2 = { new StringField("brad lie angelina"), new StringField("pitt"), new IntegerField(44), new DoubleField(6.10), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-12-1972")), new TextField("White Angry"), new ListField<>(list2) };
List<Span> list3 = new ArrayList<>();
list3.add(span3);
IField[] fields3 = { new StringField("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is Angry"), new ListField<>(list3) };
List<Span> list4 = new ArrayList<>();
list4.add(span4);
IField[] fields4 = { new StringField("Mary brown"), new StringField("Lake Forest"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Short angry"), new ListField<>(list4) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
Tuple tuple3 = new Tuple(new Schema(schemaAttributes), fields3);
Tuple tuple4 = new Tuple(new Schema(schemaAttributes), fields4);
List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
List<Tuple> expectedList = new ArrayList<>();
List<Tuple> resultList = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_TABLE, dictionary, attributeNames, KeywordMatchingType.PHRASE_INDEXBASED, 1, 1);
expectedList.add(tuple1);
expectedList.add(tuple2);
expectedList.add(tuple3);
expectedList.add(tuple4);
Assert.assertEquals(expectedList.size(), 4);
Assert.assertEquals(resultList.size(), 1);
Assert.assertTrue(TestUtils.containsAll(expectedList, resultList));
}
Aggregations