use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class DictionaryMatcherTest method testSingleWordQueryInStringFieldUsingScanChinese.
/**
* Scenario: verifies GetNextTuple of DictionaryMatcher and single word
* queries in String Field using SUBSTRING_SCANBASED
* Test in Chinese.
*/
@Test
public void testSingleWordQueryInStringFieldUsingScanChinese() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("孔明"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list = new ArrayList<Span>();
Span span = new Span("firstName", 0, 2, "孔明", "孔明");
list.add(span);
Schema resultSchema = Utils.addAttributeToSchema(TestConstantsChinese.SCHEMA_PEOPLE, RESULTS_ATTRIBUTE);
IField[] fields1 = { new StringField("孔明"), new StringField("洛克贝尔"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("北京大学计算机学院"), new ListField<Span>(list) };
Tuple tuple1 = new Tuple(resultSchema, fields1);
List<Tuple> expectedResults = new ArrayList<Tuple>();
expectedResults.add(tuple1);
List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstantsChinese.LAST_NAME, TestConstantsChinese.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(CHINESE_TABLE, dictionary, attributeNames, KeywordMatchingType.SUBSTRING_SCANBASED);
boolean contains = TestUtils.equals(expectedResults, returnedResults);
Assert.assertTrue(contains);
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class DictionaryMatcherTest method testSingleWordQueryInStringFieldUsingKeywordChinese.
/**
* Scenario: verifies GetNextTuple of DictionaryMatcher and multiple word
* queries in String Field using KEYWORDOPERATOR
* Test in Chinese.
*/
@Test
public void testSingleWordQueryInStringFieldUsingKeywordChinese() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("无忌", "长孙"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list1 = new ArrayList<Span>();
List<Span> list2 = new ArrayList<Span>();
Span span1 = new Span("lastName", 0, 2, "长孙", "长孙");
Span span2 = new Span("firstName", 0, 2, "无忌", "无忌");
list1.add(span1);
list2.add(span2);
Attribute[] schemaAttributes = new Attribute[TestConstantsChinese.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < schemaAttributes.length - 1; count++) {
schemaAttributes[count] = TestConstantsChinese.ATTRIBUTES_PEOPLE[count];
}
schemaAttributes[schemaAttributes.length - 1] = RESULTS_ATTRIBUTE;
IField[] fields1 = { new StringField("无忌"), new StringField("长孙"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("北京大学电气工程学院"), new ListField<Span>(list1) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
IField[] fields2 = { new StringField("无忌"), new StringField("长孙"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("北京大学电气工程学院"), new ListField<Span>(list2) };
Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
List<Tuple> expectedResults = new ArrayList<Tuple>();
expectedResults.add(tuple1);
expectedResults.add(tuple2);
List<String> attributeNames = Arrays.asList(TestConstantsChinese.FIRST_NAME, TestConstantsChinese.LAST_NAME, TestConstantsChinese.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(CHINESE_TABLE, dictionary, attributeNames, KeywordMatchingType.CONJUNCTION_INDEXBASED);
boolean contains = TestUtils.equals(expectedResults, returnedResults);
Assert.assertTrue(contains);
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class DictionaryMatcherTest method testSingleWordQueryInTextFieldUsingKeywordChinese.
/**
* Scenario: verifies GetNextTuple of DictionaryMatcher and single word
* queries in Text Field using KEYWORD OPERATOR in Chinese
*/
@Test
public void testSingleWordQueryInTextFieldUsingKeywordChinese() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("北京大学"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list = new ArrayList<Span>();
Span span = new Span("description", 0, 4, "北京大学", "北京大学", 0);
list.add(span);
Attribute[] schemaAttributes = new Attribute[TestConstantsChinese.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < schemaAttributes.length - 1; count++) {
schemaAttributes[count] = TestConstantsChinese.ATTRIBUTES_PEOPLE[count];
}
schemaAttributes[schemaAttributes.length - 1] = RESULTS_ATTRIBUTE;
IField[] fields1 = { new StringField("无忌"), new StringField("长孙"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("北京大学电气工程学院"), new ListField<Span>(list) };
IField[] fields2 = { new StringField("孔明"), new StringField("洛克贝尔"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("北京大学计算机学院"), new ListField<Span>(list) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
List<Tuple> expectedResults = new ArrayList<Tuple>();
expectedResults.add(tuple1);
expectedResults.add(tuple2);
List<String> attributeNames = Arrays.asList(TestConstantsChinese.FIRST_NAME, TestConstantsChinese.LAST_NAME, TestConstantsChinese.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(CHINESE_TABLE, dictionary, attributeNames, KeywordMatchingType.CONJUNCTION_INDEXBASED);
boolean contains = TestUtils.equals(expectedResults, returnedResults);
Assert.assertTrue(contains);
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class JoinDistanceTest method testWhenOpenOrCloseIsCalledTwiceAndTryToGetNextTupleWhenClosed.
// ------------------------<Test cases for cursor.>------------------------
/*
* This case tests for the scenario when open and/or close is called twice
* and also when getNextTuple() is called when operator is closed.
* Test result: Opening or closing the operator twice shouldn't result in
* any noticeable difference in operation. But, calling getNetTuple() when
* operator is closed should throw an exception.
*/
@Test(expected = DataFlowException.class)
public void testWhenOpenOrCloseIsCalledTwiceAndTryToGetNextTupleWhenClosed() throws Exception {
List<Tuple> tuples = JoinTestConstants.bookGroup1.subList(1, 5);
JoinTestHelper.insertToTable(BOOK_TABLE, tuples);
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "typical", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "actually", conjunction);
JoinDistancePredicate distancePredicate = new JoinDistancePredicate(JoinTestConstants.REVIEW, 90);
Join join = new Join(distancePredicate);
join.setOuterInputOperator(keywordSourceOuter);
join.setInnerInputOperator(keywordSourceInner);
Tuple tuple;
List<Tuple> resultList = new ArrayList<>();
join.open();
join.open();
while ((tuple = join.getNextTuple()) != null) {
resultList.add(tuple);
}
join.close();
join.close();
Assert.assertEquals(4, resultList.size());
// this line should throw an exception because operator is already closed
if ((tuple = join.getNextTuple()) != null) {
resultList.add(tuple);
}
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class JoinDistanceTest method testOneOfTheOperatorResultIsEmpty.
// This case tests for the scenario when either/both of the operators'
// result lists are empty (i.e. when one/both of the operators' are
// not able to find any suitable matches)
// Test result: Join should return an empty list.
@Test
public void testOneOfTheOperatorResultIsEmpty() throws Exception {
JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "special", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "book", conjunction);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 20), Integer.MAX_VALUE, 0);
Assert.assertEquals(0, resultList.size());
}
Aggregations