use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class RelationManagerTest method test17.
/*
* Test on getMetaData() to see if it successfully get metadata from "relation_manager_test_table"
*/
@Test
public void test17() throws Exception {
String tableName = "relation_manager_test_table";
String tableDirectory = "./index/test_table";
Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING), new Attribute("number", AttributeType.STRING));
RelationManager relationManager = RelationManager.getRelationManager();
relationManager.deleteTable(tableName);
relationManager.createTable(tableName, tableDirectory, tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
List<TableMetadata> metaData = relationManager.getMetaData();
// result should contain metadata about test table "relation_manager_test_table"
List<TableMetadata> result = metaData.stream().filter(x -> x.getTableName().equals(tableName)).collect(Collectors.toList());
Assert.assertEquals(result.size(), 1);
TableMetadata testTable = result.get(0);
List<String> testTableSchema = testTable.getSchema().getAttributeNames();
Assert.assertEquals(tableName, testTable.getTableName());
Assert.assertEquals("_id", testTableSchema.get(0));
Assert.assertEquals("content", testTableSchema.get(1));
Assert.assertEquals("number", testTableSchema.get(2));
relationManager.deleteTable(tableName);
}
use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class RelationManagerTest method test16.
/*
* Test that table name with upper case in it is handled properly.
*/
@Test
public void test16() throws Exception {
String tableName1 = "Relation_Manager_Test_Table_15_1";
String indexDirectory = "./index/test_table/relation_manager_test_table_16";
Schema schema = new Schema(new Attribute("content", AttributeType.TEXT));
String luceneAnalyzerString = "standard";
relationManager.deleteTable(tableName1);
relationManager.createTable(tableName1, indexDirectory, schema, luceneAnalyzerString);
Assert.assertTrue(relationManager.checkTableExistence(tableName1));
relationManager.deleteTable(tableName1);
Assert.assertTrue(!relationManager.checkTableExistence(tableName1));
}
use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class RelationManagerTest method test3.
/*
* Create a table and test if table's information can be retrieved successfully.
*/
@Test
public void test3() throws Exception {
String tableName = "relation_manager_test_table_1";
String tableDirectory = "./index/test_table_1/";
Schema tableSchema = new Schema(new Attribute("city", AttributeType.STRING), new Attribute("description", AttributeType.TEXT), new Attribute("tax rate", AttributeType.DOUBLE), new Attribute("population", AttributeType.INTEGER), new Attribute("record time", AttributeType.DATE));
String tableLuceneAnalyzerString = LuceneAnalyzerConstants.standardAnalyzerString();
Analyzer tableLuceneAnalyzer = LuceneAnalyzerConstants.getLuceneAnalyzer(tableLuceneAnalyzerString);
RelationManager relationManager = RelationManager.getRelationManager();
relationManager.deleteTable(tableName);
relationManager.createTable(tableName, tableDirectory, tableSchema, tableLuceneAnalyzerString);
Assert.assertEquals(new File(tableDirectory).getCanonicalPath(), relationManager.getTableDirectory(tableName));
Assert.assertEquals(Utils.getSchemaWithID(tableSchema), relationManager.getTableSchema(tableName));
Assert.assertEquals(tableLuceneAnalyzer.getClass(), relationManager.getTableAnalyzer(tableName).getClass());
relationManager.deleteTable(tableName);
}
use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class DictionaryMatcherTest method testSingleWordQueryInStringFieldUsingScan.
/**
* Scenario: verifies GetNextTuple of DictionaryMatcher and single word
* queries in String Field using SCANOPERATOR
*/
@Test
public void testSingleWordQueryInStringFieldUsingScan() throws Exception {
ArrayList<String> names = new ArrayList<String>(Arrays.asList("bruce"));
Dictionary dictionary = new Dictionary(names);
// create a data tuple first
List<Span> list = new ArrayList<Span>();
Span span = new Span("firstName", 0, 5, "bruce", "bruce");
list.add(span);
Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < schemaAttributes.length - 1; count++) {
schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
schemaAttributes[schemaAttributes.length - 1] = RESULTS_ATTRIBUTE;
IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry"), new ListField<Span>(list) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
List<Tuple> expectedResults = new ArrayList<Tuple>();
expectedResults.add(tuple1);
List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_TABLE, dictionary, attributeNames, KeywordMatchingType.SUBSTRING_SCANBASED);
boolean contains = TestUtils.equals(expectedResults, returnedResults);
Assert.assertTrue(contains);
}
use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class KeywordConjunctionTest method testSingleWordQueryInTextField.
/**
* Verifies GetNextTuple of Keyword Matcher and single word queries in Text
* Field
*
* @throws Exception
*/
@Test
public void testSingleWordQueryInTextField() throws Exception {
// Prepare the query
String query = "TaLL";
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstants.FIRST_NAME);
attributeNames.add(TestConstants.LAST_NAME);
attributeNames.add(TestConstants.DESCRIPTION);
// Prepare the expected result list
List<Span> list = new ArrayList<>();
Span span = new Span("description", 0, 4, "tall", "Tall", 0);
list.add(span);
Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < schemaAttributes.length - 1; count++) {
schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry"), new ListField<>(list) };
IField[] fields2 = { new StringField("christian john wayne"), new StringField("rock bale"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Tall Fair"), 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(PEOPLE_TABLE, query, attributeNames, conjunction);
// check the results
boolean contains = TestUtils.equals(expectedResultList, resultList);
Assert.assertTrue(contains);
}
Aggregations