Search in sources :

Example 1 with TextIndexException

use of org.apache.jena.query.text.TextIndexException in project jena by apache.

the class DefineAnalyzersAssembler method open.

public static boolean open(Assembler a, Resource list) {
    Resource current = list;
    boolean isMultilingualSupport = false;
    while (current != null && !current.equals(RDF.nil)) {
        Statement firstStmt = current.getProperty(RDF.first);
        if (firstStmt == null) {
            throw new TextIndexException("parameter list not well formed: " + current);
        }
        RDFNode first = firstStmt.getObject();
        if (!first.isResource()) {
            throw new TextIndexException("parameter specification must be an anon resource : " + first);
        }
        // process the current list element to add an analyzer
        Resource adding = (Resource) first;
        if (adding.hasProperty(TextVocab.pAnalyzer)) {
            Statement analyzerStmt = adding.getProperty(TextVocab.pAnalyzer);
            RDFNode analyzerNode = analyzerStmt.getObject();
            if (!analyzerNode.isResource()) {
                throw new TextIndexException("addAnalyzers text:analyzer must be an analyzer spec resource: " + analyzerNode);
            }
            // calls GenericAnalyzerAssembler
            Analyzer analyzer = (Analyzer) a.open((Resource) analyzerNode);
            if (adding.hasProperty(TextVocab.pDefAnalyzer)) {
                Statement defStmt = adding.getProperty(TextVocab.pDefAnalyzer);
                Resource id = defStmt.getResource();
                if (id.getURI() != null) {
                    Util.defineAnalyzer(id, analyzer);
                } else {
                    throw new TextIndexException("addAnalyzers text:defineAnalyzer property must be a uri resource: " + adding);
                }
            }
            if (adding.hasProperty(TextVocab.pAddLang)) {
                Statement langStmt = adding.getProperty(TextVocab.pAddLang);
                String langCode = langStmt.getString();
                if (StringUtils.isNotBlank(langCode)) {
                    Util.addAnalyzer(langCode, analyzer);
                    isMultilingualSupport = true;
                    if (adding.hasProperty(TextVocab.pSearchFor)) {
                        Statement searchForStmt = adding.getProperty(TextVocab.pSearchFor);
                        List<String> tags = getStringList(searchForStmt, "text:searchFor");
                        Util.addSearchForTags(langCode, tags);
                    }
                    if (adding.hasProperty(TextVocab.pAuxIndex)) {
                        Statement auxIndexStmt = adding.getProperty(TextVocab.pAuxIndex);
                        List<String> tags = getStringList(auxIndexStmt, "text:auxIndex");
                        Util.addAuxIndexes(langCode, tags);
                        log.trace("addAuxIndexes for {} with tags: {}", langCode, tags);
                    }
                    if (adding.hasProperty(TextVocab.pIndexAnalyzer)) {
                        Statement indexStmt = adding.getProperty(TextVocab.pIndexAnalyzer);
                        Resource key = indexStmt.getResource();
                        Analyzer indexer = Util.getDefinedAnalyzer(key);
                        Util.addIndexAnalyzer(langCode, indexer);
                        log.trace("addIndexAnalyzer lang: {} with analyzer: {}", langCode, indexer);
                    }
                } else {
                    throw new TextIndexException("text:addLang property must be a non-blank string: " + adding);
                }
            }
        }
        Statement restStmt = current.getProperty(RDF.rest);
        if (restStmt == null) {
            throw new TextIndexException("parameter list not terminated by rdf:nil");
        }
        RDFNode rest = restStmt.getObject();
        if (!rest.isResource()) {
            throw new TextIndexException("parameter list node is not a resource : " + rest);
        }
        current = (Resource) rest;
    }
    Util.finishCaching();
    return isMultilingualSupport;
}
Also used : TextIndexException(org.apache.jena.query.text.TextIndexException) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) Analyzer(org.apache.lucene.analysis.Analyzer) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 2 with TextIndexException

use of org.apache.jena.query.text.TextIndexException in project jena by apache.

the class DefineAnalyzersAssembler method getStringList.

private static List<String> getStringList(Statement stmt, String p) {
    List<String> tags = new ArrayList<String>();
    RDFNode aNode = stmt.getObject();
    if (!aNode.isResource()) {
        throw new TextIndexException(p + " property is not a list : " + aNode);
    }
    Resource current = (Resource) aNode;
    while (current != null && !current.equals(RDF.nil)) {
        Statement firstStmt = current.getProperty(RDF.first);
        if (firstStmt == null) {
            throw new TextIndexException(p + " list not well formed: " + current);
        }
        RDFNode first = firstStmt.getObject();
        if (!first.isLiteral()) {
            throw new TextIndexException(p + " list not a String : " + first);
        }
        String tag = first.toString();
        tags.add(tag);
        Statement restStmt = current.getProperty(RDF.rest);
        if (restStmt == null) {
            throw new TextIndexException(p + " list not terminated by rdf:nil");
        }
        RDFNode rest = restStmt.getObject();
        if (!rest.isResource()) {
            throw new TextIndexException(p + " list rest node is not a resource : " + rest);
        }
        current = (Resource) rest;
    }
    return tags;
}
Also used : TextIndexException(org.apache.jena.query.text.TextIndexException) Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 3 with TextIndexException

use of org.apache.jena.query.text.TextIndexException in project jena by apache.

the class PropListsAssembler method open.

public static void open(Assembler assembler, Resource list) {
    Resource current = list;
    while (current != null && !current.equals(RDF.nil)) {
        Statement firstStmt = current.getProperty(RDF.first);
        if (firstStmt == null) {
            throw new TextIndexException("text:propLists list not well formed: " + current);
        }
        RDFNode first = firstStmt.getObject();
        if (!first.isResource()) {
            throw new TextIndexException("text:propLists element must be an anon resource : " + first);
        }
        // process the current list element to add a property list
        Resource adding = (Resource) first;
        if (adding.hasProperty(TextVocab.pPropListProp)) {
            Statement propListPropStmt = adding.getProperty(TextVocab.pPropListProp);
            RDFNode propListPropNode = propListPropStmt.getObject();
            if (!propListPropNode.isResource()) {
                throw new TextIndexException("text:propLists text:propListProp must be a resource: " + propListPropNode);
            }
            if (adding.hasProperty(TextVocab.pProps)) {
                Statement propsStmt = adding.getProperty(TextVocab.pProps);
                List<Resource> props = getPropsList(propsStmt);
                Util.addPropsList((Resource) propListPropNode, props);
            }
        } else {
            throw new TextIndexException("text:propLists text:propListProp must be a resource: " + adding.getProperty(TextVocab.pPropListProp));
        }
        Statement restStmt = current.getProperty(RDF.rest);
        if (restStmt == null) {
            throw new TextIndexException("text:propLists  list not terminated by rdf:nil");
        }
        RDFNode rest = restStmt.getObject();
        if (!rest.isResource()) {
            throw new TextIndexException("text:propLists list rest is not a resource : " + rest);
        }
        current = (Resource) rest;
    }
}
Also used : TextIndexException(org.apache.jena.query.text.TextIndexException) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 4 with TextIndexException

use of org.apache.jena.query.text.TextIndexException in project jena by apache.

the class ConfigurableAnalyzer method getTokenizer.

private Tokenizer getTokenizer(String tokenizerName) {
    TokenizerSpec spec = tokenizerSpecs.get(tokenizerName);
    if (spec == null) {
        throw new TextIndexException("Unknown tokenizer : " + tokenizerName);
    }
    Class<?> clazz = spec.clazz;
    Class<?>[] paramClasses = spec.paramClasses;
    Object[] paramValues = spec.paramValues;
    return newTokenizer(clazz, paramClasses, paramValues);
}
Also used : TextIndexException(org.apache.jena.query.text.TextIndexException) TokenizerSpec(org.apache.jena.query.text.assembler.GenericTokenizerAssembler.TokenizerSpec)

Example 5 with TextIndexException

use of org.apache.jena.query.text.TextIndexException in project jena by apache.

the class ConfigurableAnalyzer method getTokenFilter.

private TokenFilter getTokenFilter(String filterName, TokenStream source) {
    FilterSpec spec = filterSpecs.get(filterName);
    if (spec == null) {
        throw new TextIndexException("Unknown filter : " + filterName);
    }
    Class<?> clazz = spec.clazz;
    Class<?>[] paramClasses = spec.paramClasses;
    Object[] paramValues = spec.paramValues;
    // the source should always be the first parameter
    paramValues[0] = source;
    return newFilter(clazz, paramClasses, paramValues);
}
Also used : TextIndexException(org.apache.jena.query.text.TextIndexException) FilterSpec(org.apache.jena.query.text.assembler.GenericFilterAssembler.FilterSpec)

Aggregations

TextIndexException (org.apache.jena.query.text.TextIndexException)22 RDFNode (org.apache.jena.rdf.model.RDFNode)17 Resource (org.apache.jena.rdf.model.Resource)14 Statement (org.apache.jena.rdf.model.Statement)12 ArrayList (java.util.ArrayList)7 Analyzer (org.apache.lucene.analysis.Analyzer)4 HashMap (java.util.HashMap)2 EntityDefinition (org.apache.jena.query.text.EntityDefinition)2 FilterSpec (org.apache.jena.query.text.assembler.GenericFilterAssembler.FilterSpec)2 TokenizerSpec (org.apache.jena.query.text.assembler.GenericTokenizerAssembler.TokenizerSpec)2 ParamSpec (org.apache.jena.query.text.assembler.Params.ParamSpec)2 Literal (org.apache.jena.rdf.model.Literal)2 CharArraySet (org.apache.lucene.analysis.CharArraySet)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 Reader (java.io.Reader)1 List (java.util.List)1 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)1 Node (org.apache.jena.graph.Node)1 TextIndexConfig (org.apache.jena.query.text.TextIndexConfig)1 ConfigurableAnalyzer (org.apache.jena.query.text.analyzer.ConfigurableAnalyzer)1