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);
}
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));
}
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));
}
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();
}
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);
}
Aggregations