Search in sources :

Example 6 with TextIndexException

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

the class StandardAnalyzerAssembler method toList.

private List<String> toList(Resource list) {
    List<String> result = new ArrayList<>();
    Resource current = list;
    while (current != null && !current.equals(RDF.nil)) {
        Statement stmt = current.getProperty(RDF.first);
        if (stmt == null) {
            throw new TextIndexException("stop word list not well formed");
        }
        RDFNode node = stmt.getObject();
        if (!node.isLiteral()) {
            throw new TextIndexException("stop word is not a literal : " + node);
        }
        result.add(((Literal) node).getLexicalForm());
        stmt = current.getProperty(RDF.rest);
        if (stmt == null) {
            throw new TextIndexException("stop word list not terminated by rdf:nil");
        }
        node = stmt.getObject();
        if (!node.isResource()) {
            throw new TextIndexException("stop word list node is not a resource : " + node);
        }
        current = (Resource) node;
    }
    return result;
}
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 7 with TextIndexException

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

the class StandardAnalyzerAssembler method analyzerWithStopWords.

private Analyzer analyzerWithStopWords(Resource root) {
    RDFNode node = root.getProperty(TextVocab.pStopWords).getObject();
    if (!node.isResource()) {
        throw new TextIndexException("text:stopWords property takes a list as a value : " + node);
    }
    CharArraySet stopWords = toCharArraySet((Resource) node);
    return new StandardAnalyzer(stopWords);
}
Also used : CharArraySet(org.apache.lucene.analysis.CharArraySet) TextIndexException(org.apache.jena.query.text.TextIndexException) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

TextIndexException (org.apache.jena.query.text.TextIndexException)7 RDFNode (org.apache.jena.rdf.model.RDFNode)4 Resource (org.apache.jena.rdf.model.Resource)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 EntityDefinition (org.apache.jena.query.text.EntityDefinition)2 Statement (org.apache.jena.rdf.model.Statement)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 Node (org.apache.jena.graph.Node)1 TextIndexConfig (org.apache.jena.query.text.TextIndexConfig)1 ConfigurableAnalyzer (org.apache.jena.query.text.analyzer.ConfigurableAnalyzer)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 CharArraySet (org.apache.lucene.analysis.CharArraySet)1