Search in sources :

Example 21 with TextIndexException

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

the class Params method getParamSpecs.

protected static List<ParamSpec> getParamSpecs(Resource list) {
    List<ParamSpec> result = new ArrayList<>();
    Resource current = list;
    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);
        }
        result.add(getParamSpec((Resource) first));
        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;
    }
    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 22 with TextIndexException

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

the class Params method getType.

private static String getType(Resource node) {
    Statement typeStmt = node.getProperty(TextVocab.pParamType);
    Statement valueStmt = node.getProperty(TextVocab.pParamValue);
    String type = null;
    if (typeStmt == null) {
        if (valueStmt == null) {
            throw new TextIndexException("Parameter specification must have a text:paramValue: " + node);
        }
        RDFNode obj = valueStmt != null ? valueStmt.getObject() : null;
        Literal lit = obj.asLiteral();
        RDFDatatype rdfType = lit.getDatatype();
        Class<?> clazz = rdfType.getJavaClass();
        if (clazz == java.lang.Boolean.class) {
            type = TYPE_BOOL;
        } else if (clazz == java.math.BigInteger.class) {
            type = TYPE_INT;
        } else if (clazz == java.lang.String.class) {
            type = TYPE_STRING;
        }
    } else {
        Resource typeRes = typeStmt.getResource();
        type = typeRes.getLocalName();
    }
    return type;
}
Also used : TextIndexException(org.apache.jena.query.text.TextIndexException) Statement(org.apache.jena.rdf.model.Statement) Literal(org.apache.jena.rdf.model.Literal) Resource(org.apache.jena.rdf.model.Resource) RDFDatatype(org.apache.jena.datatypes.RDFDatatype) RDFNode(org.apache.jena.rdf.model.RDFNode)

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