Search in sources :

Example 1 with Attribute

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

the class Utils method removeFields.

/**
    * Remove one or more fields from a tuple.
    * 
    * @param tuple
    * @param removeFields
    * @return
    */
public static Tuple removeFields(Tuple tuple, String... removeFields) {
    List<String> removeFieldList = Arrays.asList(removeFields);
    List<Integer> removedFeidsIndex = removeFieldList.stream().map(attributeName -> tuple.getSchema().getIndex(attributeName)).collect(Collectors.toList());
    Attribute[] newAttrs = tuple.getSchema().getAttributes().stream().filter(attr -> (!removeFieldList.contains(attr.getAttributeName()))).toArray(Attribute[]::new);
    Schema newSchema = new Schema(newAttrs);
    IField[] newFields = IntStream.range(0, tuple.getSchema().getAttributes().size()).filter(index -> (!removedFeidsIndex.contains(index))).mapToObj(index -> tuple.getField(index)).toArray(IField[]::new);
    return new Tuple(newSchema, newFields);
}
Also used : IntStream(java.util.stream.IntStream) SchemaConstants(edu.uci.ics.textdb.api.constants.SchemaConstants) DataConstants(edu.uci.ics.textdb.api.constants.DataConstants) Arrays(java.util.Arrays) Attribute(edu.uci.ics.textdb.api.schema.Attribute) TextdbProject(edu.uci.ics.textdb.api.constants.DataConstants.TextdbProject) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Schema(edu.uci.ics.textdb.api.schema.Schema) List(java.util.List) Paths(java.nio.file.Paths) IField(edu.uci.ics.textdb.api.field.IField) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) IField(edu.uci.ics.textdb.api.field.IField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Example 2 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 3 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 4 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 5 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