Search in sources :

Example 26 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class ProjectionOperatorTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    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();
}
Also used : Tuple(edu.uci.ics.textdb.api.tuple.Tuple) RelationManager(edu.uci.ics.textdb.storage.RelationManager) DataWriter(edu.uci.ics.textdb.storage.DataWriter) BeforeClass(org.junit.BeforeClass)

Example 27 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class RegexMatcherTestHelper 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.nGramAnalyzerString(3));
    DataWriter peopleDataWriter = relationManager.getTableDataWriter(PEOPLE_TABLE);
    peopleDataWriter.open();
    for (Tuple tuple : TestConstants.getSamplePeopleTuples()) {
        peopleDataWriter.insertTuple(tuple);
    }
    peopleDataWriter.close();
    // create the corporation table and write tuples
    relationManager.createTable(CORP_TABLE, "../index/test_tables/" + CORP_TABLE, RegexTestConstantsCorp.SCHEMA_CORP, LuceneAnalyzerConstants.nGramAnalyzerString(3));
    DataWriter corpDataWriter = relationManager.getTableDataWriter(CORP_TABLE);
    corpDataWriter.open();
    for (Tuple tuple : RegexTestConstantsCorp.getSampleCorpTuples()) {
        corpDataWriter.insertTuple(tuple);
    }
    corpDataWriter.close();
    // create the staff table
    relationManager.createTable(STAFF_TABLE, "../index/tests/" + STAFF_TABLE, RegexTestConstantStaff.SCHEMA_STAFF, LuceneAnalyzerConstants.nGramAnalyzerString(3));
    DataWriter staffDataWriter = relationManager.getTableDataWriter(STAFF_TABLE);
    staffDataWriter.open();
    for (Tuple tuple : RegexTestConstantStaff.getSampleStaffTuples()) {
        staffDataWriter.insertTuple(tuple);
    }
    staffDataWriter.close();
    // create the text table
    relationManager.createTable(TEXT_TABLE, "../index/tests/" + TEXT_TABLE, RegexTestConstantsText.SCHEMA_TEXT, LuceneAnalyzerConstants.nGramAnalyzerString(3));
    DataWriter textDataWriter = relationManager.getTableDataWriter(TEXT_TABLE);
    textDataWriter.open();
    for (Tuple tuple : RegexTestConstantsText.getSampleTextTuples()) {
        textDataWriter.insertTuple(tuple);
    }
    textDataWriter.close();
}
Also used : Tuple(edu.uci.ics.textdb.api.tuple.Tuple) RelationManager(edu.uci.ics.textdb.storage.RelationManager) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 28 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTest1.

/**
     * Scenario 1: Test getNextTuple with only one span in the return list Text
     * : Microsoft is a organization. Search for all NE_ALL entity types
     *
     * @throws Exception
     */
@Test
public void getNextTupleTest1() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getTest1Tuple();
    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.getTest1ResultTuples();
    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 29 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTest7.

/**
     * Scenario 7:Test getNextTuple using sentence: Sentence1: Feeling the warm
     * sun rays beaming steadily down, the girl decided there was no need to
     * wear a coat. Search for Adjective.
     */
@Test
public void getNextTupleTest7() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getTest7Tuple();
    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.ADJECTIVE);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest7ResultTuples();
    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 30 with DataWriter

use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.

the class NlpEntityTest method getNextTupleTest5.

/**
     * Scenario 5:Test getNextTuple using two fields:
     * <p>
     * Sentence1: Microsoft, Google and Facebook are organizations. Sentence2:
     * Donald Trump and Barack Obama are persons.
     * <p>
     * Only search the second field for all NE_ALL entity types
     */
@Test
public void getNextTupleTest5() 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 attribute = NlpEntityTestConstants.SENTENCE_TWO;
    List<String> attributeNames = new ArrayList<>();
    attributeNames.add(attribute);
    List<Tuple> returnedResults = getQueryResults(TWO_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest5ResultTuples();
    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

DataWriter (edu.uci.ics.textdb.storage.DataWriter)34 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)31 RelationManager (edu.uci.ics.textdb.storage.RelationManager)18 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 BeforeClass (org.junit.BeforeClass)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 StorageException (edu.uci.ics.textdb.api.exception.StorageException)3 IDField (edu.uci.ics.textdb.api.field.IDField)3 StringField (edu.uci.ics.textdb.api.field.StringField)3 IOException (java.io.IOException)3 File (java.io.File)2 TextDBException (edu.uci.ics.textdb.api.exception.TextDBException)1 IField (edu.uci.ics.textdb.api.field.IField)1 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)1 TextField (edu.uci.ics.textdb.api.field.TextField)1 BufferedReader (java.io.BufferedReader)1 ParseException (java.text.ParseException)1 Scanner (java.util.Scanner)1