use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class JoinDistanceTest method testForLimitWhenLimitIsZero.
/*
* This case tests for the scenario when limit is 0 and offset is 0 and
* join is performed.
* Test result: An empty list.
*/
@Test
public void testForLimitWhenLimitIsZero() 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), 0, 0);
Assert.assertEquals(0, resultList.size());
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class JoinDistanceTest method testOneSpanEncompassesOtherAndDifferenceGreaterThanThreshold.
/*
* This case tests for the scenario when one of the spans to be joined encompasses the other span
* and |(span 1 spanStartIndex) - (span 2 spanStartIndex)|
* and/or |(span 1 spanEndIndex) - (span 2 spanEndIndex)| exceed threshold.
*
* e.g.
* [<11, 18>]
* [<3, 33>]
* threshold = 10 (beyond threshold)
* Test result: Join should return an empty list.
*/
@Test
public void testOneSpanEncompassesOtherAndDifferenceGreaterThanThreshold() throws Exception {
JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "special", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "takes a special kind of writer", phrase);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 10), Integer.MAX_VALUE, 0);
Assert.assertEquals(0, resultList.size());
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class JoinTestHelper method alterField.
/**
* Alter a field of a tuple. ( The schema will also be changed accordingly. )
* @param originalTuple
* @param fieldIndex
* @param newField
* @return
*/
public static Tuple alterField(Tuple originalTuple, int fieldIndex, IField newField) {
List<Attribute> originalAttributes = originalTuple.getSchema().getAttributes();
List<Attribute> newAttributes = new ArrayList<>();
List<IField> newFields = new ArrayList<>();
for (int i = 0; i < originalAttributes.size(); i++) {
if (i == fieldIndex) {
newAttributes.add(new Attribute(originalAttributes.get(i).getAttributeName(), DataflowUtils.getAttributeType(newField)));
newFields.add(newField);
} else {
newAttributes.add(originalAttributes.get(i));
newFields.add(originalTuple.getField(i));
}
}
return new Tuple(new Schema(newAttributes.stream().toArray(Attribute[]::new)), newFields.stream().toArray(IField[]::new));
}
use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.
the class DictionaryMatcherTest method testStopWordsInQueryUsingPhrase.
/**
* Scenario S-14:verifies: Query with Stop Words match corresponding phrases
* in the document using PHRASE OPERATOR.
*/
@Test
public void testStopWordsInQueryUsingPhrase() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("lin and is angry"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list = new ArrayList<>();
Span span = new Span("description", 25, 45, "lin and is angry", "lin clooney is Angry");
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.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 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);
}
Aggregations