use of edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate in project textdb by TextDB.
the class TextQLParserTest method testExtractKeywordMatchPredicate.
/**
* Test the extractKeywordMatchPredicate method of the parser.
* It should parse an extract keyword predicate and return the expected KeywordExtractPredicate object.
* @throws ParseException if an unexpected ParseException is thrown
*/
@Test
public void testExtractKeywordMatchPredicate() throws ParseException {
String keywordMatchPredicate00 = " KEYWORDMATCH(g0, \"key1\") ";
ExtractPredicate keywordMatchParameters00 = new KeywordExtractPredicate(Arrays.asList("g0"), "key1", null);
Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate00))).extractKeywordMatchPredicate(), keywordMatchParameters00);
String keywordMatchPredicate01 = " KEYWORDMATCH(g1, \"key2\", conjunction) ";
ExtractPredicate keywordMatchParameters01 = new KeywordExtractPredicate(Arrays.asList("g1"), "key2", "conjunction");
Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate01))).extractKeywordMatchPredicate(), keywordMatchParameters01);
String keywordMatchPredicate02 = " KEYWORDMATCH(g2, \"key3\", phrase) ";
ExtractPredicate keywordMatchParameters02 = new KeywordExtractPredicate(Arrays.asList("g2"), "key3", "phrase");
Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate02))).extractKeywordMatchPredicate(), keywordMatchParameters02);
String keywordMatchPredicate03 = " KEYWORDMATCH(g3, \"key4\", substring) ";
ExtractPredicate keywordMatchParameters03 = new KeywordExtractPredicate(Arrays.asList("g3"), "key4", "substring");
Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate03))).extractKeywordMatchPredicate(), keywordMatchParameters03);
String keywordMatchPredicate04 = " KEYWORDMATCH([g4], \"key0\") ";
ExtractPredicate keywordMatchParameters04 = new KeywordExtractPredicate(Arrays.asList("g4"), "key0", null);
Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate04))).extractKeywordMatchPredicate(), keywordMatchParameters04);
String keywordMatchPredicate05 = " KEYWORDMATCH([g4,g5], \"key0\") ";
ExtractPredicate keywordMatchParameters05 = new KeywordExtractPredicate(Arrays.asList("g4", "g5"), "key0", null);
Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate05))).extractKeywordMatchPredicate(), keywordMatchParameters05);
String keywordMatchPredicate06 = " KEYWORDMATCH([g6,g7,h8,i9], \"key\") ";
ExtractPredicate keywordMatchParameters06 = new KeywordExtractPredicate(Arrays.asList("g6", "g7", "h8", "i9"), "key", null);
Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate06))).extractKeywordMatchPredicate(), keywordMatchParameters06);
String keywordMatchPredicate07 = " KEYWORDMATCH([g6,g7,h8,i9], \"key\", substring) ";
ExtractPredicate keywordMatchParameters07 = new KeywordExtractPredicate(Arrays.asList("g6", "g7", "h8", "i9"), "key", "substring");
Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate07))).extractKeywordMatchPredicate(), keywordMatchParameters07);
String keywordMatchPredicate08 = " KEYWORDMATCH ([i6,j7,l8,m9, \"key5\") ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate08))).extractKeywordMatchPredicate(), ParseException.class);
String keywordMatchPredicate09 = " KEYWORDMATCH (i6,j7,l8,m9, \"key5\") ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate09))).extractKeywordMatchPredicate(), ParseException.class);
String keywordMatchPredicate10 = " KEYWORDMATCH (i6,j7,l8,m9], \"key5\") ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate10))).extractKeywordMatchPredicate(), ParseException.class);
String keywordMatchPredicate11 = " KEYWORDMATCH ([i6,j7,l8,m9, \"key5\", conjunction) ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate11))).extractKeywordMatchPredicate(), ParseException.class);
String keywordMatchPredicate12 = " KEYWORDMATCH (i6,j7,l8,m9, \"key5\", substring) ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate12))).extractKeywordMatchPredicate(), ParseException.class);
String keywordMatchPredicate13 = " KEYWORDMATCH ([i6,j7,l8,m9, \"key5\", phrase) ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate13))).extractKeywordMatchPredicate(), ParseException.class);
String keywordMatchPredicate14 = " KEYWORDMATCH ([], key5) ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate14))).extractKeywordMatchPredicate(), ParseException.class);
String keywordMatchPredicate15 = " KEYWORDMATCH ([a], key5) ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate15))).extractKeywordMatchPredicate(), ParseException.class);
String keywordMatchPredicate16 = " KEYWORDMATCH ([a]) ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate16))).extractKeywordMatchPredicate(), ParseException.class);
String keywordMatchPredicate17 = " KEYWORDMATCH (\"key1\") ";
assertException(() -> (new TextQLParser(string2InputStream(keywordMatchPredicate17))).extractKeywordMatchPredicate(), ParseException.class);
}
use of edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate in project textdb by TextDB.
the class CreateViewStatementTest method testGettersAndGetters.
/**
* Test the setter methods and the getter methods.
* Call the setter of CreateViewStatement and test if the
* returned value by the getter is the same.
*/
@Test
public void testGettersAndGetters() {
Statement subStatement;
ProjectPredicate projectPredicate;
ExtractPredicate extractPredicate;
CreateViewStatement createViewStatement = new CreateViewStatement(null, null);
// Tests for the id attribute
createViewStatement.setId(null);
Assert.assertEquals(createViewStatement.getId(), null);
createViewStatement.setId("statementId4");
Assert.assertEquals(createViewStatement.getId(), "statementId4");
createViewStatement.setId("_sid0");
Assert.assertEquals(createViewStatement.getId(), "_sid0");
// Tests for the subStatement attribute
createViewStatement.setSubStatement(null);
Assert.assertEquals(createViewStatement.getSubStatement(), null);
projectPredicate = new ProjectAllFieldsPredicate();
subStatement = new SelectStatement("substatementId0", projectPredicate, null, "from", null, null);
createViewStatement = new CreateViewStatement("statementId", subStatement);
Assert.assertEquals(createViewStatement.getSubStatement(), subStatement);
projectPredicate = new ProjectAllFieldsPredicate();
subStatement = new SelectStatement("substatementId1", projectPredicate, null, "table", null, null);
createViewStatement = new CreateViewStatement("statementId", subStatement);
Assert.assertEquals(createViewStatement.getSubStatement(), subStatement);
projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("c", "d"));
extractPredicate = new KeywordExtractPredicate(Arrays.asList("f0", "f1"), "xxx", KeywordMatchingType.PHRASE_INDEXBASED.toString());
subStatement = new SelectStatement("id", projectPredicate, extractPredicate, "source", null, null);
createViewStatement.setSubStatement(subStatement);
Assert.assertEquals(createViewStatement.getSubStatement(), subStatement);
}
use of edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate in project textdb by TextDB.
the class SelectStatementTest method testSelectStatementBeansBuilder04.
/**
* Test the correctness of the generated beans by a SelectStatement with a
* ProjectAllFieldsPredicate and a KeywordExtractPredicate.
* Get a graph by calling getInternalPredicateBases() and getInternalLinkBeans()
* methods and check if the generated path form the node getInputNodeID() to
* the node getOutputNodeID() is correct. Also check whether getInputViews()
* is returning the correct dependencies.
*/
@Test
public void testSelectStatementBeansBuilder04() {
ProjectPredicate projectPredicate = new ProjectAllFieldsPredicate();
ExtractPredicate extractPredicate = new KeywordExtractPredicate(Arrays.asList("f1"), "keyword", KeywordMatchingType.CONJUNCTION_INDEXBASED.toString());
SelectStatement selectStatement = new SelectStatement("id", projectPredicate, extractPredicate, "source", null, null);
List<PredicateBase> expectedGeneratedBeans = Arrays.asList(new KeywordPredicate("keyword", Arrays.asList("f1"), null, KeywordMatchingType.CONJUNCTION_INDEXBASED, "id_e"));
List<String> dependencies = Arrays.asList("source");
Assert.assertEquals(selectStatement.getInputViews(), dependencies);
StatementTestUtils.assertGeneratedBeans(selectStatement, expectedGeneratedBeans);
}
use of edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate in project textdb by TextDB.
the class CreateViewStatementTest method testCreateViewStatementBeansBuilder01.
/**
* Test the correctness of the generated beans by a CreateViewStatement with
* a SelectExtractStatement as sub-statement with a
* SelectSomeFieldsPredicate and a KeywordExtractPredicate.
* Get a graph by calling getInternalOperatorBeans() and getInternalLinkBeans()
* methods and check if the generated path form the node getInputNodeID() to
* the node getOutputNodeID() is correct. Also check whether getInputViews()
* is returning the correct dependencies.
*/
@Test
public void testCreateViewStatementBeansBuilder01() {
ProjectPredicate projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("x", "y"));
ExtractPredicate extractPredicate = new KeywordExtractPredicate(Arrays.asList("a", "b"), "zzz", KeywordMatchingType.SUBSTRING_SCANBASED.toString());
Statement subStatement = new SelectStatement("id", projectPredicate, extractPredicate, "from", null, null);
CreateViewStatement createViewStatement = new CreateViewStatement("idx", subStatement);
List<PredicateBase> expectedGeneratedBeans = Collections.emptyList();
List<String> dependencies = Arrays.asList(subStatement.getId());
Assert.assertEquals(createViewStatement.getInputViews(), dependencies);
StatementTestUtils.assertGeneratedBeans(createViewStatement, expectedGeneratedBeans);
}
Aggregations