Search in sources :

Example 16 with DataWriter

use of edu.uci.ics.texera.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.getInstance().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.texera.api.tuple.Tuple) DataWriter(edu.uci.ics.texera.storage.DataWriter) Test(org.junit.Test)

Example 17 with DataWriter

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

the class NlpEntityTest method getNextTupleTestWithLimitOffset.

public void getNextTupleTestWithLimitOffset() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getOneSentenceTestTuple();
    DataWriter oneSentenceDataWriter = RelationManager.getInstance().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, 2, 2);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest10ResultTuples();
    Assert.assertEquals(returnedResults.size(), 2);
    Assert.assertTrue(TestUtils.containsAll(expectedResults, returnedResults));
}
Also used : Tuple(edu.uci.ics.texera.api.tuple.Tuple) DataWriter(edu.uci.ics.texera.storage.DataWriter)

Example 18 with DataWriter

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

the class NlpEntityTest method getNextTupleTestWithLimit.

public void getNextTupleTestWithLimit() throws Exception {
    List<Tuple> data = NlpEntityTestConstants.getOneSentenceTestTuple();
    DataWriter oneSentenceDataWriter = RelationManager.getInstance().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, 3, 0);
    List<Tuple> expectedResults = NlpEntityTestConstants.getTest10ResultTuples();
    // ExpectedResults is the array containing all the matches.
    // Since the order of returning records in returnedResults is not deterministic, we use containsAll
    // to ensure that the records in returnedResults are included in the ExpectedResults.
    Assert.assertEquals(returnedResults.size(), 3);
    Assert.assertTrue(TestUtils.containsAll(expectedResults, returnedResults));
}
Also used : Tuple(edu.uci.ics.texera.api.tuple.Tuple) DataWriter(edu.uci.ics.texera.storage.DataWriter)

Example 19 with DataWriter

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

the class DictionaryManager method deleteDictionary.

public void deleteDictionary(String dictID) {
    DataWriter dataWriter = relationManager.getTableDataWriter(DictionaryManagerConstants.TABLE_NAME);
    dataWriter.open();
    // clean up the same dictionary metadata if it already exists in dictionary table
    dataWriter.deleteTuple(new TermQuery(new Term(DictionaryManagerConstants.NAME, dictID)));
    dataWriter.close();
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) DataWriter(edu.uci.ics.texera.storage.DataWriter)

Example 20 with DataWriter

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

the class DictionaryManager method addDictionary.

public void addDictionary(String dictID, String dictionaryContent, String dictionaryName, String dictionaryDescription) throws StorageException {
    // write metadata info
    DataWriter dataWriter = relationManager.getTableDataWriter(DictionaryManagerConstants.TABLE_NAME);
    dataWriter.open();
    // clean up the same dictionary metadata if it already exists in dictionary table
    dataWriter.deleteTuple(new TermQuery(new Term(DictionaryManagerConstants.NAME, dictID)));
    // insert new tuple
    dataWriter.insertTuple(new Tuple(DictionaryManagerConstants.SCHEMA, new StringField(dictID)));
    dataWriter.close();
    // write actual dictionary file
    writeContentToFile(dictID, dictionaryContent);
    writeNameToFile(dictID, dictionaryName);
    writeDescriptionToFile(dictID, dictionaryDescription);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) StringField(edu.uci.ics.texera.api.field.StringField) Term(org.apache.lucene.index.Term) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DataWriter(edu.uci.ics.texera.storage.DataWriter)

Aggregations

DataWriter (edu.uci.ics.texera.storage.DataWriter)37 Tuple (edu.uci.ics.texera.api.tuple.Tuple)33 RelationManager (edu.uci.ics.texera.storage.RelationManager)19 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 BeforeClass (org.junit.BeforeClass)8 StorageException (edu.uci.ics.texera.api.exception.StorageException)3 IDField (edu.uci.ics.texera.api.field.IDField)3 StringField (edu.uci.ics.texera.api.field.StringField)3 IOException (java.io.IOException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Term (org.apache.lucene.index.Term)2 TermQuery (org.apache.lucene.search.TermQuery)2 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)1 IField (edu.uci.ics.texera.api.field.IField)1 TupleSink (edu.uci.ics.texera.dataflow.sink.tuple.TupleSink)1 TupleSinkPredicate (edu.uci.ics.texera.dataflow.sink.tuple.TupleSinkPredicate)1 TwitterJsonConverter (edu.uci.ics.texera.dataflow.twitter.TwitterJsonConverter)1 TwitterJsonConverterPredicate (edu.uci.ics.texera.dataflow.twitter.TwitterJsonConverterPredicate)1