use of edu.uci.ics.texera.api.span.Span 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);
}
use of edu.uci.ics.texera.api.span.Span 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 = 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, exactResultsWithLimitOffset));
Assert.assertEquals(expectedResults.size(), 3);
Assert.assertEquals(exactResultsWithLimitOffset.size(), 2);
}
use of edu.uci.ics.texera.api.span.Span in project textdb by TextDB.
the class RegexMatcherTest method testRegexText1.
@Test
public void testRegexText1() throws Exception {
String query = "test(er|ing|ed|s)?";
List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(TEXT_TABLE, query, Arrays.asList(RegexTestConstantsText.CONTENT));
List<Tuple> expectedResults = new ArrayList<Tuple>();
// expected to match "test" & testing"
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, 5, 9, query, "test"));
spans.add(new Span(RegexTestConstantsText.CONTENT, 21, 28, query, "testing"));
IField spanField = new ListField<Span>(new ArrayList<Span>(spans));
List<IField> fields = new ArrayList<IField>(data.get(0).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
// expected to match "tests"
spans.clear();
spans.add(new Span(RegexTestConstantsText.CONTENT, 87, 92, query, "tests"));
spanField = new ListField<Span>(new ArrayList<Span>(spans));
fields = new ArrayList<IField>(data.get(2).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
// expected to match "tested"
spans.clear();
spans.add(new Span(RegexTestConstantsText.CONTENT, 43, 49, query, "tested"));
spanField = new ListField<Span>(new ArrayList<Span>(spans));
fields = new ArrayList<IField>(data.get(3).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.span.Span 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 = new Schema.Builder().add(RegexTestConstantsText.SCHEMA_TEXT).add(RESULTS, AttributeType.LIST).build();
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.texera.api.span.Span in project textdb by TextDB.
the class RegexMatcherTest method testGetNextTuplePeopleFirstName.
@Test
public void testGetNextTuplePeopleFirstName() throws Exception {
String query = "g[^\\s]*";
List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(PEOPLE_TABLE, query, Arrays.asList(TestConstants.FIRST_NAME));
List<Tuple> expectedResults = new ArrayList<Tuple>();
// expected to match "brad lie angelina"
List<Tuple> data = TestConstants.getSamplePeopleTuples();
Schema spanSchema = new Schema.Builder().add(TestConstants.SCHEMA_PEOPLE).add(RESULTS, AttributeType.LIST).build();
List<Span> spans = new ArrayList<Span>();
spans.add(new Span(TestConstants.FIRST_NAME, 11, 17, query, "gelina"));
IField spanField = new ListField<Span>(new ArrayList<Span>(spans));
List<IField> fields = new ArrayList<IField>(data.get(2).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
// expected to match "george lin lin"
spans.clear();
spans.add(new Span(TestConstants.FIRST_NAME, 0, 6, query, "george"));
spanField = new ListField<Span>(new ArrayList<Span>(spans));
fields = new ArrayList<IField>(data.get(3).getFields());
fields.add(spanField);
expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
Assert.assertTrue(TestUtils.equals(expectedResults, exactResults));
}
Aggregations