Search in sources :

Example 26 with Dictionary

use of edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary in project textdb by TextDB.

the class DictionaryMatcherTest method testMultipleWordQueryInTextFieldUsingScan1.

/**
 * Testcases for scan-based DictionaryMatcher, use getScanSourceResults method only.
 * @throws Exception
 */
@Test
public void testMultipleWordQueryInTextFieldUsingScan1() throws Exception {
    ArrayList<String> names = new ArrayList<String>(Arrays.asList("tall", "fair"));
    Dictionary dictionary = new Dictionary(names);
    // create a data tuple first
    List<Span> list = new ArrayList<Span>();
    List<Span> list1 = new ArrayList<Span>();
    Span span = new Span("description", 0, 4, "tall", "Tall");
    Span span1 = new Span("description", 5, 9, "fair", "Fair");
    list.add(span);
    list1.add(span);
    list1.add(span1);
    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>(list1) };
    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.SUBSTRING_SCANBASED);
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : Dictionary(edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 27 with Dictionary

use of edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary in project textdb by TextDB.

the class DictionaryMatcherPerformanceTest method match.

/**
 * This function does match for a dictionary
 */
public static void match(ArrayList<String> queryList, KeywordMatchingType opType, String luceneAnalyzerStr, String tableName) throws Exception {
    List<String> attributeNames = Arrays.asList(MedlineIndexWriter.ABSTRACT);
    Dictionary dictionary = new Dictionary(queryList);
    DictionarySourcePredicate dictionarySourcePredicate = new DictionarySourcePredicate(dictionary, attributeNames, luceneAnalyzerStr, opType, tableName, SchemaConstants.SPAN_LIST);
    DictionaryMatcherSourceOperator dictionaryMatcher = new DictionaryMatcherSourceOperator(dictionarySourcePredicate);
    long startMatchTime = System.currentTimeMillis();
    dictionaryMatcher.open();
    Tuple nextTuple = null;
    int counter = 0;
    while ((nextTuple = dictionaryMatcher.getNextTuple()) != null) {
        ListField<Span> spanListField = nextTuple.getField(SchemaConstants.SPAN_LIST);
        List<Span> spanList = spanListField.getValue();
        counter += spanList.size();
    }
    dictionaryMatcher.close();
    long endMatchTime = System.currentTimeMillis();
    matchTime = (endMatchTime - startMatchTime) / 1000.0;
    resultCount = counter;
}
Also used : Dictionary(edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary) Span(edu.uci.ics.texera.api.span.Span) DictionaryMatcherSourceOperator(edu.uci.ics.texera.dataflow.dictionarymatcher.DictionaryMatcherSourceOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DictionarySourcePredicate(edu.uci.ics.texera.dataflow.dictionarymatcher.DictionarySourcePredicate)

Example 28 with Dictionary

use of edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary in project textdb by TextDB.

the class DictionaryMatcherTest method testSingleWordQueryInStringFieldUsingScan.

/**
 * Scenario: verifies GetNextTuple of DictionaryMatcher and single word
 * queries in String Field using SCANOPERATOR
 */
@Test
public void testSingleWordQueryInStringFieldUsingScan() throws Exception {
    ArrayList<String> names = new ArrayList<String>(Arrays.asList("bruce"));
    Dictionary dictionary = new Dictionary(names);
    // create a data tuple first
    List<Span> list = new ArrayList<Span>();
    Span span = new Span("firstName", 0, 5, "bruce", "bruce");
    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) };
    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.texera.dataflow.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 29 with Dictionary

use of edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary in project textdb by TextDB.

the class DictionaryMatcherTest method testSingleWordQueryInTextFieldUsingScanChinese.

/**
 * Scenario: verifies GetNextTuple of DictionaryMatcher and single word
 * queries in Text Field using SCANOPERATOR in Chinese.
 */
@Test
public void testSingleWordQueryInTextFieldUsingScanChinese() 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>();
    Span span1 = new Span("description", 8, 10, "学院", "学院");
    list1.add(span1);
    List<Span> list2 = new ArrayList<Span>();
    Span span2 = new Span("description", 7, 9, "学院", "学院");
    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) };
    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>(list2) };
    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.SUBSTRING_SCANBASED);
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : Dictionary(edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 30 with Dictionary

use of edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary 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>();
    Span span1 = new Span("lastName", 0, 2, "长孙", "长孙");
    Span span2 = new Span("firstName", 0, 2, "无忌", "无忌");
    list1.add(span1);
    list1.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);
    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.CONJUNCTION_INDEXBASED);
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : Dictionary(edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

Dictionary (edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary)33 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)31 Span (edu.uci.ics.texera.api.span.Span)30 Tuple (edu.uci.ics.texera.api.tuple.Tuple)30 DateField (edu.uci.ics.texera.api.field.DateField)29 DoubleField (edu.uci.ics.texera.api.field.DoubleField)29 IField (edu.uci.ics.texera.api.field.IField)29 IntegerField (edu.uci.ics.texera.api.field.IntegerField)29 StringField (edu.uci.ics.texera.api.field.StringField)29 TextField (edu.uci.ics.texera.api.field.TextField)29 Schema (edu.uci.ics.texera.api.schema.Schema)29 SimpleDateFormat (java.text.SimpleDateFormat)29 Attribute (edu.uci.ics.texera.api.schema.Attribute)28 DictionarySourcePredicate (edu.uci.ics.texera.dataflow.dictionarymatcher.DictionarySourcePredicate)2 DictionaryMatcherSourceOperator (edu.uci.ics.texera.dataflow.dictionarymatcher.DictionaryMatcherSourceOperator)1 DictionaryPredicate (edu.uci.ics.texera.dataflow.dictionarymatcher.DictionaryPredicate)1