Search in sources :

Example 41 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.

the class RegexMatcherTest method testRegexText4.

@Test
public void testRegexText4() throws Exception {
    String query = "\\[(.)?\\]";
    List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(TEXT_TABLE, query, Arrays.asList(RegexTestConstantsText.CONTENT));
    List<Tuple> expectedResults = new ArrayList<Tuple>();
    // expected to match [a] & [!]
    List<Tuple> data = RegexTestConstantsText.getSampleTextTuples();
    Schema spanSchema = Utils.addAttributeToSchema(RegexTestConstantsText.SCHEMA_TEXT, new Attribute(RESULTS, AttributeType.LIST));
    List<Span> spans = new ArrayList<Span>();
    spans.add(new Span(RegexTestConstantsText.CONTENT, 110, 113, query, "[a]"));
    spans.add(new Span(RegexTestConstantsText.CONTENT, 120, 123, query, "[!]"));
    IField spanField = new ListField<Span>(new ArrayList<Span>(spans));
    List<IField> fields = new ArrayList<IField>(data.get(10).getFields());
    fields.add(spanField);
    expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
    Assert.assertTrue(TestUtils.equals(expectedResults, exactResults));
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) ListField(edu.uci.ics.textdb.api.field.ListField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 42 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTest10.

@Test
public void getNextTupleTest10() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getOneSentenceTestTuple();
    DataWriter oneSentenceDataWriter = RelationManager.getRelationManager().getTableDataWriter(ONE_SENTENCE_TABLE);
    oneSentenceDataWriter.open();
    for (Tuple tuple : data) {
        oneSentenceDataWriter.insertTuple(tuple);
    }
    oneSentenceDataWriter.close();
    String attribute1 = NlpEntityTestConstants.SENTENCE_ONE;
    List<String> attributeNames = Arrays.asList(attribute1);
    List<Tuple> returnedResults = getQueryResults(ONE_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest10ResultTuples();
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DataWriter(edu.uci.ics.textdb.storage.DataWriter) Test(org.junit.Test)

Example 43 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTest4.

/**
     * Scenario 4:Test getNextTuple with more than one span in the return list
     * and with different recognized classes and more than one fields in the
     * source tuple.
     * <p>
     * Sentence1: Microsoft, Google and Facebook are organizations. Sentence2:
     * Donald Trump and Barack Obama are persons. Search for all NE_ALL entity
     * types
     */
@Test
public void getNextTupleTest4() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getTest4Tuple();
    DataWriter twoSentenceDataWriter = RelationManager.getRelationManager().getTableDataWriter(TWO_SENTENCE_TABLE);
    twoSentenceDataWriter.open();
    for (Tuple tuple : data) {
        twoSentenceDataWriter.insertTuple(tuple);
    }
    twoSentenceDataWriter.close();
    String attribute1 = NlpEntityTestConstants.SENTENCE_ONE;
    String attribute2 = NlpEntityTestConstants.SENTENCE_TWO;
    List<String> attributeNames = new ArrayList<>();
    attributeNames.add(attribute1);
    attributeNames.add(attribute2);
    List<Tuple> returnedResults = getQueryResults(TWO_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest4ResultTuples();
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : ArrayList(java.util.ArrayList) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DataWriter(edu.uci.ics.textdb.storage.DataWriter) Test(org.junit.Test)

Example 44 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTest3.

/**
     * Scenario 3: Test getNextTuple with more than one span in the return list
     * and with different recognized classes. Text: Microsoft, Google and
     * Facebook are organizations and Donald Trump and Barack Obama are persons.
     * Search for all NE_ALL entity types
     */
@Test
public void getNextTupleTest3() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getTest3Tuple();
    DataWriter oneSentenceDataWriter = RelationManager.getRelationManager().getTableDataWriter(ONE_SENTENCE_TABLE);
    oneSentenceDataWriter.open();
    for (Tuple tuple : data) {
        oneSentenceDataWriter.insertTuple(tuple);
    }
    oneSentenceDataWriter.close();
    String attribute1 = NlpEntityTestConstants.SENTENCE_ONE;
    List<String> attributeNames = new ArrayList<>();
    attributeNames.add(attribute1);
    List<Tuple> returnedResults = getQueryResults(ONE_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest3ResultTuples();
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : ArrayList(java.util.ArrayList) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DataWriter(edu.uci.ics.textdb.storage.DataWriter) Test(org.junit.Test)

Example 45 with Tuple

use of edu.uci.ics.textdb.api.tuple.Tuple in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTest2.

/**
     * Scenario 2: Test getNextTuple with more than one span in the return list
     * Text: Microsoft, Google and Facebook are organizations Search for all
     * NE_ALL entity types
     */
@Test
public void getNextTupleTest2() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getTest2Tuple();
    DataWriter oneSentenceDataWriter = RelationManager.getRelationManager().getTableDataWriter(ONE_SENTENCE_TABLE);
    oneSentenceDataWriter.open();
    for (Tuple tuple : data) {
        oneSentenceDataWriter.insertTuple(tuple);
    }
    oneSentenceDataWriter.close();
    String attribute1 = NlpEntityTestConstants.SENTENCE_ONE;
    List<String> attributeNames = new ArrayList<>();
    attributeNames.add(attribute1);
    List<Tuple> returnedResults = getQueryResults(ONE_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest2ResultTuples();
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : ArrayList(java.util.ArrayList) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DataWriter(edu.uci.ics.textdb.storage.DataWriter) Test(org.junit.Test)

Aggregations

Tuple (edu.uci.ics.textdb.api.tuple.Tuple)234 ArrayList (java.util.ArrayList)144 Test (org.junit.Test)135 IField (edu.uci.ics.textdb.api.field.IField)102 Schema (edu.uci.ics.textdb.api.schema.Schema)95 TextField (edu.uci.ics.textdb.api.field.TextField)92 StringField (edu.uci.ics.textdb.api.field.StringField)85 Attribute (edu.uci.ics.textdb.api.schema.Attribute)84 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)80 Span (edu.uci.ics.textdb.api.span.Span)80 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 DateField (edu.uci.ics.textdb.api.field.DateField)61 SimpleDateFormat (java.text.SimpleDateFormat)60 DataWriter (edu.uci.ics.textdb.storage.DataWriter)31 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)25 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)20 RelationManager (edu.uci.ics.textdb.storage.RelationManager)19 JoinDistancePredicate (edu.uci.ics.textdb.exp.join.JoinDistancePredicate)18 ScanBasedSourceOperator (edu.uci.ics.textdb.exp.source.scan.ScanBasedSourceOperator)17 ScanSourcePredicate (edu.uci.ics.textdb.exp.source.scan.ScanSourcePredicate)17