use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class JoinDistanceTest method testForLimitWhenLimitIsLesserThanActualNumberOfResultsAndHasOffset.
/*
* This case tests for the scenario when limit is some integer greater than
* 0 and less than the actual number of results and offset is some integer
* greater than 0 and less than actual number of results and join is
* performed.
* Test result: A list of tuples with number of tuples equal to limit
* starting from the set offset.
*/
@Test
public void testForLimitWhenLimitIsLesserThanActualNumberOfResultsAndHasOffset() 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);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 90), 1, 2);
Schema resultSchema = Utils.createSpanSchema(JoinTestConstants.BOOK_SCHEMA);
List<Span> spanList = new ArrayList<>();
Span span1 = new Span(JoinTestConstants.REVIEW, 28, 119, "typical_actually", "typical review. " + "This is a test. A book review test. " + "A test to test queries without actually");
spanList.add(span1);
Span span2 = new Span(JoinTestConstants.REVIEW, 186, 234, "typical_actually", "actually a review " + "even if it is not your typical");
spanList.add(span2);
IField[] book1 = { new IntegerField(54), new StringField("Andria Williams"), new StringField("The Longest Night: A Novel"), new IntegerField(400), new TextField("Review of a Book. This is a typical " + "review. This is a test. A book review " + "test. A test to test queries without " + "actually using actual review. From " + "here onwards, we can pretend this to " + "be actually a review even if it is not " + "your typical book review."), new ListField<>(spanList) };
Tuple expectedTuple1 = new Tuple(resultSchema, book1);
List<Tuple> expectedResult = new ArrayList<>(1);
expectedResult.add(expectedTuple1);
Assert.assertEquals(1, resultList.size());
Assert.assertTrue(TestUtils.equals(expectedResult, resultList));
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class JoinTestHelper method insertToTable.
public static void insertToTable(String tableName, List<Tuple> tuples) throws StorageException {
RelationManager relationManager = RelationManager.getRelationManager();
DataWriter outerDataWriter = relationManager.getTableDataWriter(tableName);
outerDataWriter.open();
for (Tuple tuple : tuples) {
outerDataWriter.insertTuple(tuple);
}
outerDataWriter.close();
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class DictionaryMatcherTest method testSingleWordQueryInStringFieldUsingKeyword.
/**
* Scenario: verifies GetNextTuple of DictionaryMatcher and multiple word
* queries in String Field using KEYWORDOPERATOR
*/
@Test
public void testSingleWordQueryInStringFieldUsingKeyword() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("john Lee", "bruce"));
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, 8, "john Lee", "john Lee");
Span span2 = new Span("firstName", 0, 5, "bruce", "bruce");
list1.add(span1);
list2.add(span2);
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>(list1) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
IField[] fields2 = { 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>(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(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_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 DictionaryMatcherTestHelper method writeTestTables.
public static void writeTestTables() throws TextDBException {
RelationManager relationManager = RelationManager.getRelationManager();
// create the people table and write tuples
relationManager.createTable(PEOPLE_TABLE, "../index/test_tables/" + PEOPLE_TABLE, TestConstants.SCHEMA_PEOPLE, LuceneAnalyzerConstants.standardAnalyzerString());
DataWriter peopleDataWriter = relationManager.getTableDataWriter(PEOPLE_TABLE);
peopleDataWriter.open();
for (Tuple tuple : TestConstants.getSamplePeopleTuples()) {
peopleDataWriter.insertTuple(tuple);
}
peopleDataWriter.close();
// create the people table and write tuples in Chinese
relationManager.createTable(CHINESE_TABLE, "../index/test_tables/" + CHINESE_TABLE, TestConstantsChinese.SCHEMA_PEOPLE, LuceneAnalyzerConstants.chineseAnalyzerString());
DataWriter chineseDataWriter = relationManager.getTableDataWriter(CHINESE_TABLE);
chineseDataWriter.open();
for (Tuple tuple : TestConstantsChinese.getSamplePeopleTuples()) {
chineseDataWriter.insertTuple(tuple);
}
chineseDataWriter.close();
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class DictionaryMatcherTestHelper method getDictionarySourceResults.
/**
* Get the results from the DictionarySourceOperator
* (which performs a index-based lookup for each keyword in the dictionary)
*
* @param tableName
* @param dictionary
* @param attributeNames
* @param matchingType
* @param limit
* @param offset
* @return
* @throws TextDBException
*/
public static List<Tuple> getDictionarySourceResults(String tableName, Dictionary dictionary, List<String> attributeNames, KeywordMatchingType matchingType, int limit, int offset) throws TextDBException {
RelationManager relationManager = RelationManager.getRelationManager();
String luceneAnalyzerStr = relationManager.getTableAnalyzerString(tableName);
DictionarySourcePredicate dictiaonrySourcePredicate = new DictionarySourcePredicate(dictionary, attributeNames, luceneAnalyzerStr, matchingType, tableName, RESULTS);
DictionaryMatcherSourceOperator dictionarySource = new DictionaryMatcherSourceOperator(dictiaonrySourcePredicate);
dictionarySource.setLimit(limit);
dictionarySource.setOffset(offset);
Tuple tuple;
List<Tuple> results = new ArrayList<>();
dictionarySource.open();
while ((tuple = dictionarySource.getNextTuple()) != null) {
results.add(tuple);
}
dictionarySource.close();
return results;
}
Aggregations