Search in sources :

Example 31 with StringField

use of edu.uci.ics.textdb.api.field.StringField in project textdb by TextDB.

the class JoinDistanceTest method testForLimitWhenLimitIsGreaterThanActualNumberOfResults.

/*
     * This case tests for the scenario when limit is some integer greater than
     * 0 and greater than the actual number of results and offset is 0 and join
     * is performed.
     * Test result: A list of tuples with number of tuples equal to the maximum
     * number of tuples operator can generate (which is lesser than limit.)
     */
@Test
public void testForLimitWhenLimitIsGreaterThanActualNumberOfResults() 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), 10, 0);
    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(51), new StringField("author unknown"), new StringField("typical"), new IntegerField(300), 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) };
    IField[] book2 = { new IntegerField(53), new StringField("Noah Hawley"), new StringField("Before the Fall"), 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) };
    IField[] book3 = { 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) };
    IField[] book4 = { new IntegerField(55), new StringField("Matti Friedman"), new StringField("Pumpkinflowers: A Soldier's " + "Story"), new IntegerField(256), 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);
    Tuple expectedTuple2 = new Tuple(resultSchema, book2);
    Tuple expectedTuple3 = new Tuple(resultSchema, book3);
    Tuple expectedTuple4 = new Tuple(resultSchema, book4);
    List<Tuple> expectedResult = new ArrayList<>(5);
    expectedResult.add(expectedTuple1);
    expectedResult.add(expectedTuple2);
    expectedResult.add(expectedTuple3);
    expectedResult.add(expectedTuple4);
    Assert.assertEquals(4, resultList.size());
    Assert.assertTrue(TestUtils.equals(expectedResult, resultList));
}
Also used : Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) JoinDistancePredicate(edu.uci.ics.textdb.exp.join.JoinDistancePredicate) Span(edu.uci.ics.textdb.api.span.Span) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 32 with StringField

use of edu.uci.ics.textdb.api.field.StringField 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);
}
Also used : Dictionary(edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 33 with StringField

use of edu.uci.ics.textdb.api.field.StringField 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);
}
Also used : Dictionary(edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 34 with StringField

use of edu.uci.ics.textdb.api.field.StringField 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);
}
Also used : Dictionary(edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 35 with StringField

use of edu.uci.ics.textdb.api.field.StringField 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);
}
Also used : Dictionary(edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

StringField (edu.uci.ics.textdb.api.field.StringField)91 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)85 IField (edu.uci.ics.textdb.api.field.IField)84 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)81 TextField (edu.uci.ics.textdb.api.field.TextField)81 ArrayList (java.util.ArrayList)76 Test (org.junit.Test)75 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)68 DateField (edu.uci.ics.textdb.api.field.DateField)64 Schema (edu.uci.ics.textdb.api.schema.Schema)64 SimpleDateFormat (java.text.SimpleDateFormat)63 Attribute (edu.uci.ics.textdb.api.schema.Attribute)60 Span (edu.uci.ics.textdb.api.span.Span)58 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)24 JoinDistancePredicate (edu.uci.ics.textdb.exp.join.JoinDistancePredicate)9 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)9 IDField (edu.uci.ics.textdb.api.field.IDField)5 ParseException (java.text.ParseException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3