use of edu.uci.ics.texera.api.field.ListField in project textdb by TextDB.
the class LabeledRegexMatcherTest method testQueryWithoutQualifiersLabeledRegex2.
@Test
public void testQueryWithoutQualifiersLabeledRegex2() throws Exception {
String query = "<lab2> is <lab1>";
List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(PEOPLE_TABLE, query, "short", Arrays.asList(TestConstants.DESCRIPTION), "lab1", false, Integer.MAX_VALUE, 0, "Clooney", "lab2");
List<Tuple> expectedResults = new ArrayList<>();
// expected to match "Short 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, 4, 20, query, "Clooney is Short"));
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.field.ListField 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.field.ListField 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.field.ListField in project textdb by TextDB.
the class RegexMatcherTest method testRegexText2.
@Test
public void testRegexText2() throws Exception {
String query = "follow(-| )?up";
List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(TEXT_TABLE, query, Arrays.asList(RegexTestConstantsText.CONTENT));
List<Tuple> expectedResults = new ArrayList<Tuple>();
// expected to match "followup"
List<Tuple> data = RegexTestConstantsText.getSampleTextTuples();
Schema spanSchema = new Schema.Builder().add(RegexTestConstantsText.SCHEMA_TEXT).add(RESULTS, AttributeType.LIST).build();
List<Span> spans = new ArrayList<Span>();
spans.add(new Span(RegexTestConstantsText.CONTENT, 28, 36, query, "followup"));
spans.add(new Span(RegexTestConstantsText.CONTENT, 54, 62, query, "followup"));
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()])));
// expected to match "follow up"
spans.clear();
spans.add(new Span(RegexTestConstantsText.CONTENT, 18, 27, query, "follow up"));
spans.add(new Span(RegexTestConstantsText.CONTENT, 51, 60, query, "follow up"));
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()])));
// expected to match "follow-up" & "followup"
spans.clear();
spans.add(new Span(RegexTestConstantsText.CONTENT, 24, 33, query, "follow-up"));
spans.add(new Span(RegexTestConstantsText.CONTENT, 38, 46, query, "followup"));
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.equals(expectedResults, exactResults));
}
use of edu.uci.ics.texera.api.field.ListField in project textdb by TextDB.
the class RegexMatcherTest method testRegexWithLimit.
@Test
public void testRegexWithLimit() throws Exception {
String query = "patient";
List<Tuple> exactResultsWithLimit = RegexMatcherTestHelper.getQueryResults(TEXT_TABLE, query, Arrays.asList(RegexTestConstantsText.CONTENT), true, 2, 0);
List<Tuple> expectedResults = new ArrayList<Tuple>();
List<Tuple> data = RegexTestConstantsText.getSampleTextTuples();
Schema spanSchema = new Schema.Builder().add(RegexTestConstantsText.SCHEMA_TEXT).add(RESULTS, AttributeType.LIST).build();
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, exactResultsWithLimit));
Assert.assertEquals(expectedResults.size(), 3);
Assert.assertEquals(exactResultsWithLimit.size(), 2);
}
Aggregations