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);
}
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);
}
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);
}
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));
}
}
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);
}
Aggregations