Search in sources :

Example 1 with ASTNode

use of org.codice.ddf.endpoints.ASTNode in project ddf by codice.

the class OpenSearchQuery method addContextualFilter.

public void addContextualFilter(String searchTerm, String selectors) throws ParsingException {
    String methodName = "addContextualFilter";
    Filter filter = null;
    KeywordFilterGenerator keywordFilterGenerator = new KeywordFilterGenerator(filterBuilder);
    KeywordTextParser parser = Parboiled.createParser(KeywordTextParser.class);
    // translate the search terms into an abstract syntax tree
    ParsingResult<ASTNode> result = new RecoveringParseRunner(parser.inputPhrase()).run(searchTerm);
    // make sure it's a good result before using it
    if (result.matched && !result.hasErrors()) {
        filter = generateContextualFilter(selectors, keywordFilterGenerator, result);
    } else if (result.hasErrors()) {
        throw new ParsingException("Unable to parse keyword search phrase. " + generateParsingError(result));
    }
    if (filter != null) {
        filters.add(filter);
    }
}
Also used : KeywordFilterGenerator(org.codice.ddf.endpoints.KeywordFilterGenerator) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) ParsingException(org.parboiled.errors.ParsingException) ASTNode(org.codice.ddf.endpoints.ASTNode) RecoveringParseRunner(org.parboiled.parserunners.RecoveringParseRunner) KeywordTextParser(org.codice.ddf.endpoints.KeywordTextParser)

Example 2 with ASTNode

use of org.codice.ddf.endpoints.ASTNode in project ddf by codice.

the class TestKeywordTextParser method trace.

// We have been using this for debugging purposes, its not meant to be a test.
@Ignore
@Test
public void trace() {
    Map<String, String> inputToOutput = new LinkedHashMap<String, String>();
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    List<String> inputs = new ArrayList<String>();
    // inputs.add("A \"(test test2)\" OR test2");
    inputs.add("A B  C D");
    for (String input : inputs) {
        KeywordTextParser parser = Parboiled.createParser(KeywordTextParser.class);
        ParsingResult<ASTNode> result = new TracingParseRunner(parser.inputPhrase()).run(input);
        // ParsingResult<ASTNode> result = new
        // ReportingParseRunner(parser.inputPhrase()).run(input);
        KeywordFilterGenerator kfg = new KeywordFilterGenerator(filterBuilder);
        Filter filter = kfg.getFilterFromASTNode(result.resultValue);
        inputToOutput.put(input, filter.toString());
    // visualize(result);
    }
    for (Map.Entry<String, String> iteration : inputToOutput.entrySet()) {
        System.out.println(iteration.getKey() + " : " + iteration.getValue());
    }
}
Also used : KeywordFilterGenerator(org.codice.ddf.endpoints.KeywordFilterGenerator) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) TracingParseRunner(org.parboiled.parserunners.TracingParseRunner) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) ASTNode(org.codice.ddf.endpoints.ASTNode) KeywordTextParser(org.codice.ddf.endpoints.KeywordTextParser) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ASTNode (org.codice.ddf.endpoints.ASTNode)2 KeywordFilterGenerator (org.codice.ddf.endpoints.KeywordFilterGenerator)2 KeywordTextParser (org.codice.ddf.endpoints.KeywordTextParser)2 Filter (org.opengis.filter.Filter)2 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)1 SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)1 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)1 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)1 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 ParsingException (org.parboiled.errors.ParsingException)1 RecoveringParseRunner (org.parboiled.parserunners.RecoveringParseRunner)1 TracingParseRunner (org.parboiled.parserunners.TracingParseRunner)1