use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class DictionaryMatcherTest method testSingleWordQueryInTextFieldUsingPhrase.
/**
* Scenario S-7:verifies GetNextTuple of DictionaryMatcher and single word
* queries in Text Field using PHRASE OPERATOR
*/
@Test
public void testSingleWordQueryInTextFieldUsingPhrase() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("tall"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list = new ArrayList<Span>();
Span span = new Span("description", 0, 4, "tall", "Tall");
list.add(span);
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;
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<Span>(list) };
IField[] fields2 = { 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"), 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(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_TABLE, dictionary, attributeNames, KeywordMatchingType.PHRASE_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 testMultipleWordsQueryUsingScan.
/**
* Scenario S-8:verifies ITuple returned by DictionaryMatcher and multiple
* word queries using SCAN OPERATOR
*/
@Test
public void testMultipleWordsQueryUsingScan() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("george lin lin"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list = new ArrayList<Span>();
Span span = new Span("firstName", 0, 14, "george lin lin", "george lin lin");
list.add(span);
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;
IField[] fields1 = { 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<Span>(list) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
List<Tuple> expectedResults = new ArrayList<Tuple>();
expectedResults.add(tuple1);
List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_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 testMultipleWordsQueryUsingPhraseChinese.
/**
* Scenario S-10C:verifies ITuple returned by DictionaryMatcher and multiple
* word queries using PHRASE OPERATOR in Chinese
*/
@Test
public void testMultipleWordsQueryUsingPhraseChinese() 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("lastName", 0, 4, "洛克贝尔", "洛克贝尔");
;
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(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);
List<Tuple> expectedResults = new ArrayList<Tuple>();
expectedResults.add(tuple1);
List<String> attributeNames = Arrays.asList(TestConstantsChinese.FIRST_NAME, TestConstantsChinese.LAST_NAME, TestConstantsChinese.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(CHINESE_TABLE, dictionary, attributeNames, KeywordMatchingType.PHRASE_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 TupleSink method getNextTuple.
@Override
public Tuple getNextTuple() throws TextDBException {
if (cursor == CLOSED) {
return null;
}
if (cursor >= predicate.getLimit() + predicate.getOffset()) {
return null;
}
Tuple resultTuple = null;
while (true) {
resultTuple = inputOperator.getNextTuple();
if (resultTuple == null) {
return null;
}
cursor++;
if (cursor > predicate.getOffset()) {
break;
}
}
return Utils.removeFields(resultTuple, SchemaConstants.PAYLOAD);
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class FileSourceOperator method getNextTuple.
@Override
public Tuple getNextTuple() throws TextDBException {
if (cursor == CLOSED || cursor >= pathList.size()) {
return null;
}
// 2) the cursor reaches the end
while (cursor < pathList.size()) {
try {
String content = new String(Files.readAllBytes(pathList.get(cursor)));
// create a tuple according to the string
// and assign a random ID to it
Tuple tuple = new Tuple(outputSchema, IDField.newRandomID(), new TextField(content));
cursor++;
return tuple;
} catch (IOException e) {
// if reading the current path fails, increment the cursor and continue
cursor++;
continue;
}
}
return null;
}
Aggregations