Search in sources :

Example 21 with DataWriter

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

the class NlpEntityTest method getNextTupleTest9.

@Test
public void getNextTupleTest9() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getTest9Tuple();
    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.getTest9ResultTuples();
    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 22 with DataWriter

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

the class NlpEntityTest method getNextTupleTest8.

@Test
public void getNextTupleTest8() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getTest8Tuple();
    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.MONEY);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest8ResultTuples();
    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 23 with DataWriter

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

the class NlpEntityTest method getNextTupleTest6.

/**
     * Scenario 6:Test getNextTuple using two fields:
     * <p>
     * Sentence1: Microsoft, Google and Facebook are organizations. Sentence2:
     * Donald Trump and Barack Obama are persons.
     * <p>
     * Only search for Organization for all fields.
     */
@Test
public void getNextTupleTest6() 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.ORGANIZATION);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest6ResultTuples();
    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 24 with DataWriter

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

the class NlpEntityTest method getNextTupleTest11.

@Test
public void getNextTupleTest11() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getTwoSentenceTestTuple();
    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 = Arrays.asList(attribute1, attribute2);
    List<Tuple> returnedResults = getQueryResults(TWO_SENTENCE_TABLE, attributeNames, NlpEntityType.NE_ALL);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest11ResultTuple();
    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 25 with DataWriter

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

the class JoinTestHelper method insertToTable.

public static void insertToTable(String tableName, Tuple... tuples) throws StorageException {
    RelationManager relationManager = RelationManager.getRelationManager();
    DataWriter tableDataWriter = relationManager.getTableDataWriter(tableName);
    tableDataWriter.open();
    for (Tuple tuple : Arrays.asList(tuples)) {
        tableDataWriter.insertTuple(tuple);
    }
    tableDataWriter.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)

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