Search in sources :

Example 16 with ListField

use of edu.uci.ics.texera.api.field.ListField in project textdb by TextDB.

the class RegexMatcherTest method testGetNextTupleStaffEmail.

@Test
public void testGetNextTupleStaffEmail() throws Exception {
    String query = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$";
    List<Tuple> exactResults = RegexMatcherTestHelper.getQueryResults(STAFF_TABLE, query, Arrays.asList(RegexTestConstantStaff.EMAIL));
    List<Tuple> expectedResults = new ArrayList<Tuple>();
    // expected to match "k.bocanegra@uci.edu"
    List<Tuple> data = RegexTestConstantStaff.getSampleStaffTuples();
    Schema spanSchema = new Schema.Builder().add(RegexTestConstantStaff.SCHEMA_STAFF).add(RESULTS, AttributeType.LIST).build();
    List<Span> spans = new ArrayList<Span>();
    spans.add(new Span(RegexTestConstantStaff.EMAIL, 0, 19, query, "m.bocanegra@164.com"));
    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 "hwangl@ics.uci.edu"
    spans.clear();
    spans.add(new Span(RegexTestConstantStaff.EMAIL, 0, 18, query, "hwangk@ske.akb.edu"));
    spanField = new ListField<Span>(new ArrayList<Span>(spans));
    fields = new ArrayList<IField>(data.get(1).getFields());
    fields.add(spanField);
    expectedResults.add(new Tuple(spanSchema, fields.toArray(new IField[fields.size()])));
    Assert.assertTrue(TestUtils.equals(expectedResults, exactResults));
}
Also used : Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) ListField(edu.uci.ics.texera.api.field.ListField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 17 with ListField

use of edu.uci.ics.texera.api.field.ListField in project textdb by TextDB.

the class NlpEntityTestConstants method getTest6ResultTuples.

public static List<Tuple> getTest6ResultTuples() {
    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");
    spanList.add(span1);
    spanList.add(span2);
    spanList.add(span3);
    IField[] fields1 = { new TextField("Microsoft, Google and Facebook are organizations."), new TextField("Donald Trump and Barack Obama are persons") };
    Tuple tuple1 = new Tuple(SCHEMA_TWO_SENTENCE, fields1);
    Tuple returnTuple = new Tuple.Builder(tuple1).add(REULST_ATTRIBUTE, new ListField<Span>(spanList)).build();
    return Arrays.asList(returnTuple);
}
Also used : ArrayList(java.util.ArrayList) TextField(edu.uci.ics.texera.api.field.TextField) ListField(edu.uci.ics.texera.api.field.ListField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span)

Example 18 with ListField

use of edu.uci.ics.texera.api.field.ListField in project textdb by TextDB.

the class NlpEntityTestConstants method getTest9ResultTuples.

public static List<Tuple> getTest9ResultTuples() {
    List<Span> spanList = new ArrayList<Span>();
    Span span1 = new Span("sentence_one", 25, 29, NlpEntityType.TIME.toString(), "8 am");
    Span span2 = new Span("sentence_two", 0, 12, NlpEntityType.DATE.toString(), "Aug 16 , 2016");
    spanList.add(span1);
    spanList.add(span2);
    IField[] fields1 = { new TextField("I made an appointment at 8 am."), new TextField("Aug 16, 2016 is a really important date.") };
    Tuple tuple1 = new Tuple(SCHEMA_TWO_SENTENCE, fields1);
    Tuple returnTuple = new Tuple.Builder(tuple1).add(REULST_ATTRIBUTE, new ListField<Span>(spanList)).build();
    return Arrays.asList(returnTuple);
}
Also used : ArrayList(java.util.ArrayList) TextField(edu.uci.ics.texera.api.field.TextField) ListField(edu.uci.ics.texera.api.field.ListField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span)

Example 19 with ListField

use of edu.uci.ics.texera.api.field.ListField in project textdb by TextDB.

the class NlpEntityTestConstants method getTest8ResultTuples.

public static List<Tuple> getTest8ResultTuples() {
    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);
    Tuple returnTuple = new Tuple.Builder(tuple1).add(REULST_ATTRIBUTE, new ListField<Span>(spanList)).build();
    return Arrays.asList(returnTuple);
}
Also used : ArrayList(java.util.ArrayList) TextField(edu.uci.ics.texera.api.field.TextField) ListField(edu.uci.ics.texera.api.field.ListField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span)

Example 20 with ListField

use of edu.uci.ics.texera.api.field.ListField in project textdb by TextDB.

the class NlpEntityTestConstants method getTest2ResultTuples.

public static List<Tuple> getTest2ResultTuples() {
    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");
    spanList.add(span1);
    spanList.add(span2);
    spanList.add(span3);
    IField[] fields1 = { new TextField("Microsoft, Google and Facebook are organizations.") };
    Tuple tuple1 = new Tuple(SCHEMA_ONE_SENTENCE, fields1);
    Tuple returnTuple = new Tuple.Builder(tuple1).add(REULST_ATTRIBUTE, new ListField<Span>(spanList)).build();
    return Arrays.asList(returnTuple);
}
Also used : ArrayList(java.util.ArrayList) TextField(edu.uci.ics.texera.api.field.TextField) ListField(edu.uci.ics.texera.api.field.ListField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span)

Aggregations

ListField (edu.uci.ics.texera.api.field.ListField)42 Span (edu.uci.ics.texera.api.span.Span)40 IField (edu.uci.ics.texera.api.field.IField)33 ArrayList (java.util.ArrayList)32 Tuple (edu.uci.ics.texera.api.tuple.Tuple)27 Schema (edu.uci.ics.texera.api.schema.Schema)26 Test (org.junit.Test)19 TextField (edu.uci.ics.texera.api.field.TextField)11 SchemaConstants (edu.uci.ics.texera.api.constants.SchemaConstants)8 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)8 AttributeType (edu.uci.ics.texera.api.schema.AttributeType)8 Collectors (java.util.stream.Collectors)8 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)7 ErrorMessages (edu.uci.ics.texera.api.constants.ErrorMessages)6 DataflowUtils (edu.uci.ics.texera.dataflow.utils.DataflowUtils)6 java.util (java.util)6 AbstractSingleInputOperator (edu.uci.ics.texera.dataflow.common.AbstractSingleInputOperator)5 Attribute (edu.uci.ics.texera.api.schema.Attribute)4 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2