use of edu.uci.ics.texera.api.span.Span in project textdb by TextDB.
the class SpanTupleTest method createSpanListField.
private IField createSpanListField() {
List<Span> list = new ArrayList<Span>();
// The key value will be:
// For RegexMatcher : "n.*k"
// For NamedEntityMatcher : LOCATION
// For DictionaryMatcher: "new york" - For DictionaryMatcher the key and
// value are same
// For KeyWordMatcher: "new york" - the value can be "new" or "york"
Span span1 = new Span("description", 18, 26, "LOCATION", "new york");
Span span2 = new Span("description", 52, 63, "LOCATION", "los angeles");
list.add(span1);
list.add(span2);
IField spanListField = new ListField<Span>(list);
return spanListField;
}
use of edu.uci.ics.texera.api.span.Span in project textdb by TextDB.
the class LabeledRegexMatcherTest method testMultipleLabeledRegex.
@Test
public void testMultipleLabeledRegex() throws Exception {
String query = "<lab1>.*<lab2>";
List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(PEOPLE_TABLE, query, "short", Arrays.asList(TestConstants.DESCRIPTION), "lab1", false, Integer.MAX_VALUE, 0, "angry", "lab2");
List<Tuple> expectedResults = new ArrayList<>();
// expected to match "Short angry" and "Short and lin clooney is Angry"
List<Tuple> data = TestConstants.getSamplePeopleTuples();
Schema spanSchema = new Schema.Builder().add(TestConstants.SCHEMA_PEOPLE).add(RESULTS, AttributeType.LIST).build();
List<Span> spans = new ArrayList<>();
spans.add(new Span(TestConstants.DESCRIPTION, 0, 11, query, "Short angry"));
IField spanField = new ListField<>(new ArrayList<>(spans));
List<IField> fields = new ArrayList<>(data.get(5).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
spans.clear();
spans.add(new Span(TestConstants.DESCRIPTION, 15, 45, query, "Short and lin clooney is Angry"));
spanField = new ListField<>(new ArrayList<>(spans));
fields = new ArrayList<>(data.get(3).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
List<String> attributeNames = new ArrayList<>();
attributeNames.add(RESULTS);
Assert.assertTrue(TestUtils.attributeEquals(expectedResults, exactResults, attributeNames));
}
use of edu.uci.ics.texera.api.span.Span in project textdb by TextDB.
the class LabeledRegexMatcherTest method testGetNextTupleLabeledRegex.
@Test
public void testGetNextTupleLabeledRegex() throws Exception {
String query = "<name>";
String keywordQuery = "george lin lin";
List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(PEOPLE_TABLE, query, keywordQuery, Arrays.asList(TestConstants.FIRST_NAME), "name", false, Integer.MAX_VALUE, 0);
List<Tuple> expectedResults = new ArrayList<>();
// expected to match "george lin lin"
List<Tuple> data = TestConstants.getSamplePeopleTuples();
Schema spanSchema = new Schema.Builder().add(TestConstants.SCHEMA_PEOPLE).add(RESULTS, AttributeType.LIST).build();
List<Span> spans = new ArrayList<>();
spans.add(new Span(TestConstants.FIRST_NAME, 0, 14, query, "george lin lin"));
IField spanField = new ListField<>(new ArrayList<>(spans));
List<IField> fields = new ArrayList<>(data.get(3).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
List<String> attributeNames = new ArrayList<>();
attributeNames.add(RESULTS);
Assert.assertTrue(TestUtils.attributeEquals(expectedResults, exactResults, attributeNames));
}
use of edu.uci.ics.texera.api.span.Span in project textdb by TextDB.
the class LabeledRegexMatcherTest method testIgnoreCaseLabeledRegex.
@Test
public void testIgnoreCaseLabeledRegex() throws Exception {
String query = "<NAME>";
String keywordQuery = "george lin lin";
List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(PEOPLE_TABLE, query, keywordQuery, Arrays.asList(TestConstants.FIRST_NAME), "name", false, Integer.MAX_VALUE, 0);
List<Tuple> expectedResults = new ArrayList<>();
// expected to match "george lin lin"
List<Tuple> data = TestConstants.getSamplePeopleTuples();
Schema spanSchema = new Schema.Builder().add(TestConstants.SCHEMA_PEOPLE).add(RESULTS, AttributeType.LIST).build();
List<Span> spans = new ArrayList<>();
spans.add(new Span(TestConstants.FIRST_NAME, 0, 14, query, "george lin lin"));
IField spanField = new ListField<>(new ArrayList<>(spans));
List<IField> fields = new ArrayList<>(data.get(3).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
List<String> attributeNames = new ArrayList<>();
attributeNames.add(RESULTS);
Assert.assertTrue(TestUtils.attributeEquals(expectedResults, exactResults, attributeNames));
}
use of edu.uci.ics.texera.api.span.Span in project textdb by TextDB.
the class LabeledRegexMatcherTest method testDisjunctionLabeledRegex.
@Test
public void testDisjunctionLabeledRegex() throws Exception {
String query = "<lab1>|<lab2>";
List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(PEOPLE_TABLE, query, "short", Arrays.asList(TestConstants.DESCRIPTION), "lab1", false, Integer.MAX_VALUE, 0, "angry", "lab2");
List<Tuple> expectedResults = new ArrayList<>();
// expected to match "Short" and "angry"
List<Tuple> data = TestConstants.getSamplePeopleTuples();
Schema spanSchema = new Schema.Builder().add(TestConstants.SCHEMA_PEOPLE).add(RESULTS, AttributeType.LIST).build();
List<Span> spans = new ArrayList<>();
spans.add(new Span(TestConstants.DESCRIPTION, 0, 5, query, "Short"));
spans.add(new Span(TestConstants.DESCRIPTION, 6, 11, query, "angry"));
IField spanField = new ListField<>(new ArrayList<>(spans));
List<IField> fields = new ArrayList<>(data.get(3).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
// expected to match "Short" and "Angry"
spans.clear();
spans.add(new Span(TestConstants.DESCRIPTION, 15, 20, query, "Short"));
spans.add(new Span(TestConstants.DESCRIPTION, 40, 45, query, "Angry"));
spanField = new ListField<>(new ArrayList<>(spans));
fields = new ArrayList<>(data.get(5).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
List<String> attributeNames = new ArrayList<>();
attributeNames.add(RESULTS);
Assert.assertTrue(TestUtils.attributeEquals(expectedResults, exactResults, attributeNames));
}
Aggregations