use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class PlanStore method deletePlan.
/**
* Removess a plan by given name from plan store.
*
* @param planName, the name of the plan.
* @throws TextDBException
*/
public void deletePlan(String planName) throws TextDBException {
Tuple plan = getPlan(planName);
if (plan == null) {
return;
}
IDField idField = (IDField) plan.getField(SchemaConstants._ID);
DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
dataWriter.open();
dataWriter.deleteTupleByID(idField);
dataWriter.close();
}
use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class NlpSplitTest method test2.
@Test
public void test2() throws TextDBException, ParseException {
TupleSourceOperator tupleSource = new TupleSourceOperator(NlpSplitTestConstants.getOneToManyTestTuple(), NlpSplitTestConstants.SPLIT_SCHEMA);
NlpSplitOperator sentence_list = new NlpSplitOperator(new NlpSplitPredicate(NLPOutputType.ONE_TO_MANY, NlpSplitTestConstants.TEXT, PropertyNameConstants.NLP_OUTPUT_TYPE));
TupleSink tupleSink = new TupleSink();
sentence_list.setInputOperator(tupleSource);
tupleSink.setInputOperator(sentence_list);
tupleSink.open();
List<Tuple> results = tupleSink.collectAllTuples();
tupleSink.close();
Assert.assertTrue(TestUtils.equals(NlpSplitTestConstants.getOneToManyResultTuple(), results));
Set<IDField> compset = new HashSet<IDField>();
for (Tuple result : results) {
Assert.assertFalse(compset.contains(result.getField(SchemaConstants._ID)));
compset.add(result.getField(SchemaConstants._ID));
}
}
use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class SimilarityJoinTest method test3.
/*
* Tests the Similarity Join Predicate on two similar words:
* Galaxy S8
* Galaxy Note 7
* Under the condition of similarity (NormalizedLevenshtein) > 0.5, these two words should match.
*
*/
@Test
public void test3() throws TextDBException {
JoinTestHelper.insertToTable(NEWS_TABLE_OUTER, JoinTestConstants.getNewsTuples().get(2));
JoinTestHelper.insertToTable(NEWS_TABLE_INNER, JoinTestConstants.getNewsTuples().get(3));
String phoneRegex = "[Gg]alaxy.{1,6}\\d";
RegexMatcher regexMatcherInner = JoinTestHelper.getRegexMatcher(JoinTestHelper.NEWS_TABLE_INNER, phoneRegex, JoinTestConstants.NEWS_BODY);
RegexMatcher regexMatcherOuter = JoinTestHelper.getRegexMatcher(JoinTestHelper.NEWS_TABLE_OUTER, phoneRegex, JoinTestConstants.NEWS_BODY);
SimilarityJoinPredicate similarityJoinPredicate = new SimilarityJoinPredicate(JoinTestConstants.NEWS_BODY, 0.5);
List<Tuple> results = JoinTestHelper.getJoinDistanceResults(regexMatcherInner, regexMatcherOuter, similarityJoinPredicate, Integer.MAX_VALUE, 0);
Schema joinInputSchema = Utils.addAttributeToSchema(JoinTestConstants.NEWS_SCHEMA, SchemaConstants.SPAN_LIST_ATTRIBUTE);
Schema resultSchema = similarityJoinPredicate.generateOutputSchema(joinInputSchema, joinInputSchema);
List<Span> resultSpanList = Arrays.asList(new Span("inner_" + JoinTestConstants.NEWS_BODY, 327, 336, phoneRegex, "Galaxy S8", -1), new Span("outer_" + JoinTestConstants.NEWS_BODY, 21, 34, phoneRegex, "Galaxy Note 7", -1));
Tuple resultTuple = new Tuple(resultSchema, new IDField(UUID.randomUUID().toString()), new IntegerField(4), new TextField("This is how Samsung plans to prevent future phones from catching fire"), new TextField("Samsung said that it has implemented a new eight-step testing process for " + "its lithium ion batteries, and that it’s forming a battery advisory board as well, " + "comprised of academics from Cambridge, Berkeley, and Stanford. " + "Note, this is for all lithium ion batteries in Samsung products, " + "not just Note phablets or the anticipated Galaxy S8 phone."), new IntegerField(3), new TextField("Samsung Explains Note 7 Battery Explosions, And Turns Crisis Into Opportunity"), new TextField("Samsung launched the Galaxy Note 7 to record preorders and sales in August, " + "but the rosy start soon turned sour. Samsung had to initiate a recall in September of " + "the first version of the Note 7 due to faulty batteries that overheated and exploded. " + "By October it had to recall over 2 million devices and discontinue the product. " + "It’s estimated that the recall will cost Samsung $5.3 billion."), new ListField<>(resultSpanList));
Assert.assertTrue(TestUtils.equals(Arrays.asList(resultTuple), results));
}
use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class SimilarityJoinPredicate method mergeTuples.
private Tuple mergeTuples(Tuple innerTuple, Tuple outerTuple, Schema outputSchema, List<Span> mergeSpanList) {
List<IField> resultFields = new ArrayList<>();
for (String attrName : outputSchema.getAttributeNames()) {
// generate a new _ID field for this tuple
if (attrName.equals(SchemaConstants._ID)) {
IDField newID = new IDField(UUID.randomUUID().toString());
resultFields.add(newID);
// use the generated spanList
} else if (attrName.equals(SchemaConstants.SPAN_LIST)) {
resultFields.add(new ListField<Span>(mergeSpanList));
// put the payload of two tuples together
} else if (attrName.equals(SchemaConstants.PAYLOAD)) {
ListField<Span> innerPayloadField = innerTuple.getField(SchemaConstants.PAYLOAD);
List<Span> innerPayload = innerPayloadField.getValue();
ListField<Span> outerPayloadField = outerTuple.getField(SchemaConstants.PAYLOAD);
List<Span> outerPayload = outerPayloadField.getValue();
List<Span> resultPayload = new ArrayList<>();
resultPayload.addAll(innerPayload.stream().map(span -> addFieldPrefix(span, INNER_PREFIX)).collect(Collectors.toList()));
resultPayload.addAll(outerPayload.stream().map(span -> addFieldPrefix(span, "outer_")).collect(Collectors.toList()));
// add other fields from inner/outer tuples
} else {
if (attrName.startsWith(INNER_PREFIX)) {
resultFields.add(innerTuple.getField(attrName.substring(INNER_PREFIX.length())));
} else if (attrName.startsWith(OUTER_PREFIX)) {
resultFields.add(outerTuple.getField(attrName.substring(OUTER_PREFIX.length())));
}
}
}
return new Tuple(outputSchema, resultFields.stream().toArray(IField[]::new));
}
use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class RelationManagerTest method test8.
/*
* Test inserting a tuple to a table and then delete it
*/
@Test
public void test8() throws Exception {
String tableName = "relation_manager_test_table";
String tableDirectory = "./index/test_table";
Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING));
RelationManager relationManager = RelationManager.getRelationManager();
relationManager.deleteTable(tableName);
relationManager.createTable(tableName, tableDirectory, tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
dataWriter.open();
Tuple insertedTuple = new Tuple(tableSchema, new StringField("test"));
IDField idField = dataWriter.insertTuple(insertedTuple);
dataWriter.close();
Tuple returnedTuple = relationManager.getTupleByID(tableName, idField);
Assert.assertEquals(insertedTuple.getField("content").getValue().toString(), returnedTuple.getField("content").getValue().toString());
dataWriter.open();
dataWriter.deleteTupleByID(idField);
dataWriter.close();
Tuple deletedTuple = relationManager.getTupleByID(tableName, idField);
Assert.assertNull(deletedTuple);
relationManager.deleteTable(tableName);
}
Aggregations