use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class NlpEntityTestConstants method getTest8ResultTuples.
public static List<Tuple> getTest8ResultTuples() {
List<Tuple> resultList = new ArrayList<>();
List<Span> spanList = new ArrayList<Span>();
Span span1 = new Span("sentence_one", 23, 34, NlpEntityType.MONEY.toString(), "300 dollars");
spanList.add(span1);
IField[] fields1 = { new TextField("This backpack costs me 300 dollars.") };
Tuple tuple1 = new Tuple(SCHEMA_ONE_SENTENCE, fields1);
Schema returnSchema = Utils.addAttributeToSchema(tuple1.getSchema(), new Attribute(RESULTS, AttributeType.LIST));
Tuple returnTuple = DataflowUtils.getSpanTuple(tuple1.getFields(), spanList, returnSchema);
resultList.add(returnTuple);
return resultList;
}
use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class ProjectionOperatorTest method testProjection1.
@Test
public void testProjection1() throws Exception {
List<String> projectionFields = Arrays.asList(TestConstants.DESCRIPTION);
Schema projectionSchema = new Schema(TestConstants.DESCRIPTION_ATTR);
IField[] fields1 = { new TextField("Tall Angry") };
IField[] fields2 = { new TextField("Short Brown") };
IField[] fields3 = { new TextField("White Angry") };
IField[] fields4 = { new TextField("Lin Clooney is Short and lin clooney is Angry") };
IField[] fields5 = { new TextField("Tall Fair") };
IField[] fields6 = { new TextField("Short angry") };
Tuple tuple1 = new Tuple(projectionSchema, fields1);
Tuple tuple2 = new Tuple(projectionSchema, fields2);
Tuple tuple3 = new Tuple(projectionSchema, fields3);
Tuple tuple4 = new Tuple(projectionSchema, fields4);
Tuple tuple5 = new Tuple(projectionSchema, fields5);
Tuple tuple6 = new Tuple(projectionSchema, fields6);
List<Tuple> expectedResults = Arrays.asList(tuple1, tuple2, tuple3, tuple4, tuple5, tuple6);
List<Tuple> returnedResults = getProjectionResults(new ScanBasedSourceOperator(new ScanSourcePredicate(PEOPLE_TABLE)), projectionFields);
Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class RegexMatcherTest method testRegexWithLimitOffset.
@Test
public void testRegexWithLimitOffset() throws Exception {
String query = "patient";
List<Tuple> exactResultsWithLimitOffset = RegexMatcherTestHelper.getQueryResults(TEXT_TABLE, query, Arrays.asList(RegexTestConstantsText.CONTENT), true, 2, 1);
List<Tuple> expectedResults = new ArrayList<Tuple>();
List<Tuple> data = RegexTestConstantsText.getSampleTextTuples();
Schema spanSchema = Utils.addAttributeToSchema(RegexTestConstantsText.SCHEMA_TEXT, new Attribute(RESULTS, AttributeType.LIST));
List<Span> spans = new ArrayList<Span>();
spans.add(new Span(RegexTestConstantsText.CONTENT, 4, 11, query, "patient"));
IField spanField = new ListField<Span>(new ArrayList<Span>(spans));
List<IField> fields = new ArrayList<IField>(data.get(4).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
spans.clear();
fields.clear();
spans.add(new Span(RegexTestConstantsText.CONTENT, 4, 11, query, "patient"));
spans.add(new Span(RegexTestConstantsText.CONTENT, 65, 72, query, "patient"));
spanField = new ListField<Span>(new ArrayList<Span>(spans));
fields = new ArrayList<IField>(data.get(5).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
spans.clear();
fields.clear();
spans.add(new Span(RegexTestConstantsText.CONTENT, 4, 11, query, "patient"));
spanField = new ListField<Span>(new ArrayList<Span>(spans));
fields = new ArrayList<IField>(data.get(6).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
Assert.assertTrue(TestUtils.containsAll(expectedResults, exactResultsWithLimitOffset));
Assert.assertEquals(expectedResults.size(), 3);
Assert.assertEquals(exactResultsWithLimitOffset.size(), 2);
}
use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class RegexMatcherTest method testRegexText4.
@Test
public void testRegexText4() throws Exception {
String query = "\\[(.)?\\]";
List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(TEXT_TABLE, query, Arrays.asList(RegexTestConstantsText.CONTENT));
List<Tuple> expectedResults = new ArrayList<Tuple>();
// expected to match [a] & [!]
List<Tuple> data = RegexTestConstantsText.getSampleTextTuples();
Schema spanSchema = Utils.addAttributeToSchema(RegexTestConstantsText.SCHEMA_TEXT, new Attribute(RESULTS, AttributeType.LIST));
List<Span> spans = new ArrayList<Span>();
spans.add(new Span(RegexTestConstantsText.CONTENT, 110, 113, query, "[a]"));
spans.add(new Span(RegexTestConstantsText.CONTENT, 120, 123, query, "[!]"));
IField spanField = new ListField<Span>(new ArrayList<Span>(spans));
List<IField> fields = new ArrayList<IField>(data.get(10).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
Assert.assertTrue(TestUtils.equals(expectedResults, exactResults));
}
use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class NlpEntityTestConstants method getTest11ResultTuple.
public static List<Tuple> getTest11ResultTuple() {
List<Tuple> resultList = new ArrayList<>();
List<Span> spanList = new ArrayList<Span>();
Span span1 = new Span("sentence_one", 0, 9, NlpEntityType.ORGANIZATION.toString(), "Microsoft");
Span span2 = new Span("sentence_one", 11, 17, NlpEntityType.ORGANIZATION.toString(), "Google");
Span span3 = new Span("sentence_one", 22, 30, NlpEntityType.ORGANIZATION.toString(), "Facebook");
Span span4 = new Span("sentence_two", 0, 12, NlpEntityType.PERSON.toString(), "Donald Trump");
Span span5 = new Span("sentence_two", 17, 29, NlpEntityType.PERSON.toString(), "Barack Obama");
Span span6 = new Span("sentence_one", 25, 29, NlpEntityType.TIME.toString(), "8 am");
Span span7 = new Span("sentence_two", 0, 12, NlpEntityType.DATE.toString(), "Aug 16 , 2016");
Span span8 = new Span("sentence_one", 14, 28, NlpEntityType.PERSON.toString(), "Kelly Clarkson");
Span span9 = new Span("sentence_two", 0, 14, NlpEntityType.PERSON.toString(), "Shirley Temple");
IField[] fields1 = { new TextField("Microsoft, Google and Facebook are organizations."), new TextField("Donald Trump and Barack Obama are persons") };
IField[] fields2 = { new TextField("I made an appointment at 8 am."), new TextField("Aug 16, 2016 is a really important date.") };
IField[] fields3 = { new TextField("I really love Kelly Clarkson's Because of You."), new TextField("Shirley Temple is a very famous actress.") };
Tuple tuple1 = new Tuple(SCHEMA_TWO_SENTENCE, fields1);
Tuple tuple2 = new Tuple(SCHEMA_TWO_SENTENCE, fields2);
Tuple tuple3 = new Tuple(SCHEMA_TWO_SENTENCE, fields3);
Schema returnSchema = Utils.addAttributeToSchema(tuple1.getSchema(), new Attribute(RESULTS, AttributeType.LIST));
spanList.add(span1);
spanList.add(span2);
spanList.add(span3);
spanList.add(span4);
spanList.add(span5);
resultList.add(DataflowUtils.getSpanTuple(tuple1.getFields(), spanList, returnSchema));
spanList.clear();
spanList.add(span6);
spanList.add(span7);
resultList.add(DataflowUtils.getSpanTuple(tuple2.getFields(), spanList, returnSchema));
spanList.clear();
spanList.add(span8);
spanList.add(span9);
resultList.add(DataflowUtils.getSpanTuple(tuple3.getFields(), spanList, returnSchema));
return resultList;
}
Aggregations