Search in sources :

Example 1 with ConfigurableAnalyzer

use of org.apache.jena.query.text.analyzer.ConfigurableAnalyzer in project jena by apache.

the class ConfigurableAnalyzerAssembler method open.

/*
    text:map (
         [ text:field "text" ; 
           text:predicate rdfs:label;
           text:analyzer [
               a  text:ConfigurableAnalyzer ;
               text:tokenizer text:LetterTokenizer ;
               text:filters (text:LowerCaseFilter)
           ]
         ]
        .
    */
@Override
public Analyzer open(Assembler a, Resource root, Mode mode) {
    if (root.hasProperty(TextVocab.pTokenizer)) {
        Resource tokenizerResource = root.getPropertyResourceValue(TextVocab.pTokenizer);
        String tokenizer = tokenizerResource.getLocalName();
        List<String> filters;
        if (root.hasProperty(TextVocab.pFilters)) {
            Resource filtersResource = root.getPropertyResourceValue(TextVocab.pFilters);
            filters = toFilterList(filtersResource);
        } else {
            filters = new ArrayList<>();
        }
        return new ConfigurableAnalyzer(tokenizer, filters);
    } else {
        throw new TextIndexException("text:tokenizer setting is required by ConfigurableAnalyzer");
    }
}
Also used : ConfigurableAnalyzer(org.apache.jena.query.text.analyzer.ConfigurableAnalyzer) TextIndexException(org.apache.jena.query.text.TextIndexException) Resource(org.apache.jena.rdf.model.Resource)

Aggregations

TextIndexException (org.apache.jena.query.text.TextIndexException)1 ConfigurableAnalyzer (org.apache.jena.query.text.analyzer.ConfigurableAnalyzer)1 Resource (org.apache.jena.rdf.model.Resource)1