public static List<Tuple> getSamplePeopleTuples() { try { 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("北京大学电气工程学院") }; 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("北京大学计算机学院") }; IField[] fields3 = { new StringField("宋江"), new StringField("建筑"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("伟大的建筑是历史的坐标,具有传承的价值。") }; Tuple tuple1 = new Tuple(SCHEMA_PEOPLE, fields1); Tuple tuple2 = new Tuple(SCHEMA_PEOPLE, fields2); Tuple tuple3 = new Tuple(SCHEMA_PEOPLE, fields3); return Arrays.asList(tuple1, tuple2, tuple3); } catch (ParseException e) { // exception should not happen because we know the data is correct e.printStackTrace(); return Arrays.asList(); } } }
public static List<Tuple> constructSamplePeopleTuples() { IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateTimeField(LocalDateTime.parse("1970-01-01T11:11:11")), new TextField("banana") }; IField[] fields2 = { new StringField("tom hanks"), new StringField("cruise"), new IntegerField(45), new DoubleField(5.95), new DateTimeField(LocalDateTime.parse("1980-01-02T13:14:15")), new TextField("mississippi") }; Tuple tuple1 = new Tuple(SCHEMA_PEOPLE, fields1); Tuple tuple2 = new Tuple(SCHEMA_PEOPLE, fields2); return Arrays.asList(tuple1, tuple2); } }
@Test public void testDoubleField() { DoubleField doubleField = new DoubleField(11.11); JsonNode jsonNode = TestUtils.testJsonSerialization(doubleField); Assert.assertTrue(jsonNode.get(JsonConstants.FIELD_VALUE).isFloatingPointNumber()); }
@Test public void testMinHeightAggregation() throws Exception { Attribute attribute = TestConstants.HEIGHT_ATTR; String attributeName = attribute.getName(); AggregationType aggType = AggregationType.MIN; String resultAttributeName = AggregatorTestConstants.MIN_HEIGHT_RESULT_ATTR_NAME; AggregationAttributeAndResult aggEntity = new AggregationAttributeAndResult(attributeName, aggType, resultAttributeName); List<AggregationAttributeAndResult> aggEntitiesList = new ArrayList<>(); aggEntitiesList.add(aggEntity); IField[] row1 = {new DoubleField(5.50)}; Schema schema = new Schema(new Attribute(resultAttributeName, AttributeType.DOUBLE)); List<Tuple> expectedResults = new ArrayList<>(); expectedResults.add(new Tuple(schema, row1)); List<Tuple> returnedResults = getQueryResults(aggEntitiesList); Assert.assertEquals(1, returnedResults.size()); Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults)); }
@Test public void testAvgHeightAggregation() throws Exception { Attribute attribute = TestConstants.HEIGHT_ATTR; String attributeName = attribute.getName(); AggregationType aggType = AggregationType.AVERAGE; String resultAttributeName = AggregatorTestConstants.AVG_HEIGHT_RESULT_ATTR_NAME; AggregationAttributeAndResult aggEntity = new AggregationAttributeAndResult(attributeName, aggType, resultAttributeName); List<AggregationAttributeAndResult> aggEntitiesList = new ArrayList<>(); aggEntitiesList.add(aggEntity); IField[] row1 = {new DoubleField((5.50 + 5.95 + 6.10 + 6.06 + 5.99 + 5.99) / 6.0)}; Schema schema = new Schema(new Attribute(resultAttributeName, AttributeType.DOUBLE)); List<Tuple> expectedResults = new ArrayList<>(); expectedResults.add(new Tuple(schema, row1)); List<Tuple> returnedResults = getQueryResults(aggEntitiesList); Assert.assertEquals(1, returnedResults.size()); Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults)); }
@Test public void testMaxHeightAggregation() throws Exception { Attribute attribute = TestConstants.HEIGHT_ATTR; String attributeName = attribute.getName(); AggregationType aggType = AggregationType.MAX; String resultAttributeName = AggregatorTestConstants.MAX_HEIGHT_RESULT_ATTR_NAME; AggregationAttributeAndResult aggEntity = new AggregationAttributeAndResult(attributeName, aggType, resultAttributeName); List<AggregationAttributeAndResult> aggEntitiesList = new ArrayList<>(); aggEntitiesList.add(aggEntity); IField[] row1 = {new DoubleField(6.10)}; Schema schema = new Schema(new Attribute(resultAttributeName, AttributeType.DOUBLE)); List<Tuple> expectedResults = new ArrayList<>(); expectedResults.add(new Tuple(schema, row1)); List<Tuple> returnedResults = getQueryResults(aggEntitiesList); Assert.assertEquals(1, returnedResults.size()); Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults)); }
@Test public void testSumHeightAggregation() throws Exception { Attribute attribute = TestConstants.HEIGHT_ATTR; String attributeName = attribute.getName(); AggregationType aggType = AggregationType.SUM; String resultAttributeName = AggregatorTestConstants.SUM_HEIGHT_RESULT_ATTR_NAME; AggregationAttributeAndResult aggEntity = new AggregationAttributeAndResult(attributeName, aggType, resultAttributeName); List<AggregationAttributeAndResult> aggEntitiesList = new ArrayList<>(); aggEntitiesList.add(aggEntity); IField[] row1 = {new DoubleField((5.50 + 5.95 + 6.10 + 6.06 + 5.99 + 5.99))}; Schema schema = new Schema(new Attribute(resultAttributeName, AttributeType.DOUBLE)); List<Tuple> expectedResults = new ArrayList<>(); expectedResults.add(new Tuple(schema, row1)); List<Tuple> returnedResults = getQueryResults(aggEntitiesList); Assert.assertEquals(1, returnedResults.size()); Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults)); }
@Test public void testMinHeightMaxHeightAggregation() throws Exception { Attribute attribute1 = TestConstants.HEIGHT_ATTR; String attributeName1 = attribute1.getName(); AggregationType aggType1 = AggregationType.MIN; Attribute attribute2 = TestConstants.HEIGHT_ATTR; String attributeName2 = attribute2.getName(); AggregationType aggType2 = AggregationType.MAX; String resultAttributeName1 = AggregatorTestConstants.MIN_HEIGHT_RESULT_ATTR_NAME; String resultAttributeName2 = AggregatorTestConstants.MAX_HEIGHT_RESULT_ATTR_NAME; AggregationAttributeAndResult aggEntity1 = new AggregationAttributeAndResult(attributeName1, aggType1, resultAttributeName1); AggregationAttributeAndResult aggEntity2 = new AggregationAttributeAndResult(attributeName2, aggType2, resultAttributeName2); List<AggregationAttributeAndResult> aggEntitiesList = new ArrayList<>(); aggEntitiesList.add(aggEntity1); aggEntitiesList.add(aggEntity2); IField[] row1 = {new DoubleField(5.50), new DoubleField(6.10)}; Schema schema = new Schema(new Attribute(resultAttributeName1, AttributeType.DOUBLE), new Attribute(resultAttributeName2, AttributeType.DOUBLE)); List<Tuple> expectedResults = new ArrayList<>(); expectedResults.add(new Tuple(schema, row1)); List<Tuple> returnedResults = getQueryResults(aggEntitiesList); Assert.assertEquals(1, returnedResults.size()); Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults)); }
@Test public void testGetters() throws ParseException { // create data tuple first Attribute[] attributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1]; for (int count = 0; count < attributes.length - 1; count++) { attributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count]; } attributes[attributes.length - 1] = SchemaConstants.SPAN_LIST_ATTRIBUTE; List<IField> fields = new ArrayList<IField>( Arrays.asList(new IField[] { new StringField("bruce"), new StringField("lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("bruce was born in new york city and was grown up in los angeles") })); IField spanField = createSpanListField(); fields.add(spanField); spanTuple = new Tuple(new Schema(attributes), fields.toArray(new IField[fields.size()])); IField spanFieldRetrieved = spanTuple.getField(SchemaConstants.SPAN_LIST); Assert.assertTrue(spanFieldRetrieved instanceof ListField); Assert.assertSame(spanField, spanFieldRetrieved); }
@Test public void testMultipleWordQueryInTextFieldUsingScan2() throws Exception { ArrayList<String> names = new ArrayList<String>(Arrays.asList("tall fair")); Dictionary dictionary = new Dictionary(names); // create a data tuple first List<Span> list1 = new ArrayList<Span>(); Span span1 = new Span("description", 0, 9, "tall fair","Tall Fair"); list1.add(span1); 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[] 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<Span>(list1) }; Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2); List<Tuple> expectedResults = new ArrayList<Tuple>(); expectedResults.add(tuple2); 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); }
@Test public void testMultipleWordQueryInStringFieldUsingScan() throws Exception { ArrayList<String> names = new ArrayList<String>(Arrays.asList("christian john wayne", "rock bale")); Dictionary dictionary = new Dictionary(names); // create a data tuple first List<Span> list1 = new ArrayList<Span>(); Span span1 = new Span("firstName", 0, 20, "christian john wayne","christian john wayne"); Span span2 = new Span("lastName", 0, 9, "rock bale", "rock bale"); list1.add(span1); list1.add(span2); 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("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<Span>(list1) }; 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); List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_TABLE, dictionary, attributeNames, KeywordMatchingType.SUBSTRING_SCANBASED); boolean contains = TestUtils.equals(expectedResults, returnedResults); Assert.assertTrue(contains); } @Test
@Test public void testMinHeightMaxAgeAggregation() throws Exception { Attribute attribute1 = TestConstants.HEIGHT_ATTR; String attributeName1 = attribute1.getName(); AggregationType aggType1 = AggregationType.MIN; Attribute attribute2 = TestConstants.AGE_ATTR; String attributeName2 = attribute2.getName(); AggregationType aggType2 = AggregationType.MAX; String resultAttributeName1 = AggregatorTestConstants.MIN_HEIGHT_RESULT_ATTR_NAME; String resultAttributeName2 = AggregatorTestConstants.MAX_AGE_RESULT_ATTR_NAME; AggregationAttributeAndResult aggEntity1 = new AggregationAttributeAndResult(attributeName1, aggType1, resultAttributeName1); AggregationAttributeAndResult aggEntity2 = new AggregationAttributeAndResult(attributeName2, aggType2, resultAttributeName2); List<AggregationAttributeAndResult> aggEntitiesList = new ArrayList<>(); aggEntitiesList.add(aggEntity1); aggEntitiesList.add(aggEntity2); IField[] row1 = {new DoubleField(5.50), new IntegerField(46)}; Schema schema = new Schema(new Attribute(resultAttributeName1, AttributeType.DOUBLE), new Attribute(resultAttributeName2, AttributeType.INTEGER)); List<Tuple> expectedResults = new ArrayList<>(); expectedResults.add(new Tuple(schema, row1)); List<Tuple> returnedResults = getQueryResults(aggEntitiesList); Assert.assertEquals(1, returnedResults.size()); Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults)); }
@Test public void testMultipleWordQueryInStringandTestFieldUsingScan() throws Exception { ArrayList<String> names = new ArrayList<String>(Arrays.asList("christian john wayne", "rock bale", "fair")); Dictionary dictionary = new Dictionary(names); // create a data tuple first List<Span> list1 = new ArrayList<Span>(); Span span1 = new Span("firstName", 0, 20, "christian john wayne","christian john wayne"); Span span2 = new Span("lastName", 0, 9, "rock bale", "rock bale"); Span span3 = new Span("description", 5, 9, "fair","Fair"); list1.add(span1); list1.add(span2); list1.add(span3); 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("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<Span>(list1) }; 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); }
/** * Scenario S-8:verifies ITuple returned by DictionaryMatcher and multiple * word queries using SCAN OPERATOR */ @Test public void testMultipleWordsQueryUsingScan() throws Exception { ArrayList<String> names = new ArrayList<String>(Arrays.asList("george lin lin")); Dictionary dictionary = new Dictionary(names); // create a data tuple first List<Span> list = new ArrayList<Span>(); Span span = new Span("firstName", 0, 14, "george lin lin", "george lin lin"); 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("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is 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); }
/** * Scenario S-10:verifies ITuple returned by DictionaryMatcher and multiple * word queries using PHRASE OPERATOR */ @Test public void testMultipleWordsQueryUsingPhrase() throws Exception { ArrayList<String> names = new ArrayList<String>(Arrays.asList("george lin lin")); Dictionary dictionary = new Dictionary(names); // create a data tuple first List<Span> list = new ArrayList<Span>(); Span span = new Span("firstName", 0, 14, "george lin lin", "george lin lin"); 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("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is 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.PHRASE_INDEXBASED); boolean contains = TestUtils.equals(expectedResults, returnedResults); Assert.assertTrue(contains); }
/** * 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); }
/** * Scenario S-14:verifies: Query with Stop Words match corresponding phrases * in the document using PHRASE OPERATOR. */ @Test public void testStopWordsInQueryUsingPhrase() throws Exception { ArrayList<String> names = new ArrayList<String>(Arrays.asList("lin and is angry")); Dictionary dictionary = new Dictionary(names); // create a data tuple first List<Span> list = new ArrayList<>(); Span span = new Span("description", 25, 45, "lin and is angry", "lin clooney is Angry"); 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("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is 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.PHRASE_INDEXBASED); boolean contains = TestUtils.equals(expectedResults, returnedResults); Assert.assertTrue(contains); }
/** * Scenario S-9:verifies ITuple returned by DictionaryMatcher and multiple * word queries using KEYWORD OPERATOR */ @Test public void testMultipleWordsQueryUsingKeyword() throws Exception { ArrayList<String> names = new ArrayList<String>(Arrays.asList("george lin lin")); Dictionary dictionary = new Dictionary(names); // create a data tuple first List<Span> list = new ArrayList<Span>(); Span span = new Span("firstName", 0, 14, "george lin lin", "george lin lin"); 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("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is 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.CONJUNCTION_INDEXBASED); boolean contains = TestUtils.equals(expectedResults, returnedResults); Assert.assertTrue(contains); }
/** * Scenario: verifies ITuple returned by DictionaryMatcher and multiple * word queries using SCAN OPERATOR in Chinese */ @Test public void testMultipleWordsQueryUsingScanChinese() throws Exception { ArrayList<String> names = new ArrayList<String>(Arrays.asList("洛克贝尔")); Dictionary dictionary = new Dictionary(names); // create a data tuple first List<Span> list = new ArrayList<Span>(); Span span = new Span("lastName", 0, 4, "洛克贝尔", "洛克贝尔"); 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] = RESULTS_ATTRIBUTE; IField[] fields1 = { 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<Span>(list) }; Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1); List<Tuple> expectedResults = new ArrayList<Tuple>(); expectedResults.add(tuple1); List<String> attributeNames = Arrays.asList(TestConstantsChinese.FIRST_NAME, TestConstantsChinese.LAST_NAME, TestConstantsChinese.DESCRIPTION); List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(CHINESE_TABLE, dictionary, attributeNames, KeywordMatchingType.SUBSTRING_SCANBASED); boolean contains = TestUtils.equals(expectedResults, returnedResults); Assert.assertTrue(contains); }
/** * Scenario: verifies GetNextTuple of DictionaryMatcher and single word * queries in String Field using SUBSTRING_SCANBASED * Test in Chinese. */ @Test public void testSingleWordQueryInStringFieldUsingScanChinese() throws Exception { ArrayList<String> names = new ArrayList<String>(Arrays.asList("孔明")); Dictionary dictionary = new Dictionary(names); // create a data tuple first List<Span> list = new ArrayList<Span>(); Span span = new Span("firstName", 0, 2, "孔明", "孔明"); list.add(span); Schema resultSchema = new Schema.Builder().add(TestConstantsChinese.SCHEMA_PEOPLE).add(RESULTS_ATTRIBUTE).build(); IField[] fields1 = { 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<Span>(list) }; Tuple tuple1 = new Tuple(resultSchema, fields1); List<Tuple> expectedResults = new ArrayList<Tuple>(); expectedResults.add(tuple1); List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstantsChinese.LAST_NAME, TestConstantsChinese.DESCRIPTION); List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(CHINESE_TABLE, dictionary, attributeNames, KeywordMatchingType.SUBSTRING_SCANBASED); boolean contains = TestUtils.equals(expectedResults, returnedResults); Assert.assertTrue(contains); }