Search in sources :

Example 26 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.

the class NlpEntityTestConstants method getTest5ResultTuples.

public static List<Tuple> getTest5ResultTuples() {
    List<Tuple> resultList = new ArrayList<>();
    List<Span> spanList = new ArrayList<Span>();
    Span span1 = new Span("sentence_two", 0, 12, NlpEntityType.PERSON.toString(), "Donald Trump");
    Span span2 = new Span("sentence_two", 17, 29, NlpEntityType.PERSON.toString(), "Barack Obama");
    spanList.add(span1);
    spanList.add(span2);
    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);
    Schema returnSchema = Utils.addAttributeToSchema(tuple1.getSchema(), new Attribute(RESULTS, AttributeType.LIST));
    Tuple returnTuple = DataflowUtils.getSpanTuple(tuple1.getFields(), spanList, returnSchema);
    resultList.add(returnTuple);
    return resultList;
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) TextField(edu.uci.ics.textdb.api.field.TextField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span)

Example 27 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.

the class JsonSerializationTest method testSchema.

@Test
public void testSchema() {
    Schema schema = new Schema(Arrays.asList(new Attribute("_id", AttributeType._ID_TYPE), new Attribute("text", AttributeType.TEXT), new Attribute("payload", AttributeType.LIST)));
    TestUtils.testJsonSerialization(schema);
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) Test(org.junit.Test)

Example 28 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.

the class SchemaTest method testGetInvalidAttribute.

@Test
public void testGetInvalidAttribute() {
    Attribute retrievedAttribute1 = schema.getAttribute("invalid_attribute");
    Assert.assertNull(retrievedAttribute1);
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Test(org.junit.Test)

Example 29 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.

the class SchemaTest method testGetAttributes.

@Test
public void testGetAttributes() {
    List<Attribute> attributes = schema.getAttributes();
    Assert.assertEquals(this.attributes.length, attributes.size());
    for (Attribute attribute : this.attributes) {
        Assert.assertTrue(attributes.contains(attribute));
    }
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Test(org.junit.Test)

Example 30 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.

the class KeywordConjunctionTest method testSingleWordQueryInTextFieldChinese.

/**
     * Verifies GetNextTuple of Keyword Matcher and single word queries in Text
     * Field using Chinese.
     * 
     * @throws Exception
     */
@Test
public void testSingleWordQueryInTextFieldChinese() throws Exception {
    // Prepare the query
    String query = "北京大学";
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstantsChinese.FIRST_NAME);
    attributeNames.add(TestConstantsChinese.LAST_NAME);
    attributeNames.add(TestConstantsChinese.DESCRIPTION);
    // Prepare the expected result list
    List<Span> list = new ArrayList<>();
    Span span = new Span("description", 0, 4, "北京大学", "北京大学", 0);
    list.add(span);
    Attribute[] schemaAttributes = new Attribute[TestConstantsChinese.ATTRIBUTES_PEOPLE.length + 1];
    for (int count = 0; count < schemaAttributes.length - 1; count++) {
        schemaAttributes[count] = TestConstantsChinese.ATTRIBUTES_PEOPLE[count];
    }
    schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
    IField[] fields1 = { new StringField("无忌"), new StringField("长孙"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("北京大学电气工程学院"), new ListField<>(list) };
    IField[] fields2 = { new StringField("孔明"), new StringField("洛克贝尔"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("北京大学计算机学院"), new ListField<>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
    List<Tuple> expectedResultList = new ArrayList<>();
    expectedResultList.add(tuple1);
    expectedResultList.add(tuple2);
    // Perform the query
    List<Tuple> resultList = KeywordTestHelper.getQueryResults(CHINESE_TABLE, query, attributeNames, conjunction, Integer.MAX_VALUE, 0);
    // check the results
    boolean contains = TestUtils.equals(expectedResultList, resultList);
    Assert.assertTrue(contains);
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

Attribute (edu.uci.ics.textdb.api.schema.Attribute)118 ArrayList (java.util.ArrayList)94 Schema (edu.uci.ics.textdb.api.schema.Schema)93 Test (org.junit.Test)88 IField (edu.uci.ics.textdb.api.field.IField)87 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)85 TextField (edu.uci.ics.textdb.api.field.TextField)74 Span (edu.uci.ics.textdb.api.span.Span)69 StringField (edu.uci.ics.textdb.api.field.StringField)61 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)58 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)57 DateField (edu.uci.ics.textdb.api.field.DateField)54 SimpleDateFormat (java.text.SimpleDateFormat)53 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)23 ListField (edu.uci.ics.textdb.api.field.ListField)14 AttributeType (edu.uci.ics.textdb.api.schema.AttributeType)9 List (java.util.List)7 DataFlowException (edu.uci.ics.textdb.api.exception.DataFlowException)6 Collectors (java.util.stream.Collectors)6 SchemaConstants (edu.uci.ics.textdb.api.constants.SchemaConstants)5