Search in sources :

Example 26 with RDFNode

use of org.apache.jena.rdf.model.RDFNode in project jena by apache.

the class SecuredRDFNodeImpl method as.

@SuppressWarnings("unchecked")
@Override
public <T extends RDFNode> T as(final Class<T> view) throws ReadDeniedException, AuthenticationRequiredException, SecuredUnsupportedPolymorphismException {
    checkRead();
    // see if the base Item can as
    T baseAs = holder.getBaseItem().as(view);
    if (view.equals(SecuredRDFNodeImpl.class) || view.equals(RDFNode.class)) {
        return (T) this;
    }
    final Method m = getConstructor(view);
    if (m == null) {
        throw new SecuredUnsupportedPolymorphismException(this, view);
    }
    try {
        return (T) m.invoke(null, securedModel, baseAs);
    } catch (final UnsupportedPolymorphismException e) {
        throw new SecuredUnsupportedPolymorphismException(this, view);
    } catch (final IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (final IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
Also used : SecuredUnsupportedPolymorphismException(org.apache.jena.permissions.model.SecuredUnsupportedPolymorphismException) UnsupportedPolymorphismException(org.apache.jena.enhanced.UnsupportedPolymorphismException) SecuredUnsupportedPolymorphismException(org.apache.jena.permissions.model.SecuredUnsupportedPolymorphismException) Method(java.lang.reflect.Method) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode) RDFNode(org.apache.jena.rdf.model.RDFNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 27 with RDFNode

use of org.apache.jena.rdf.model.RDFNode in project jena by apache.

the class SpatialIndexLuceneAssembler method open.

/*
    <#index> a :SpatialIndexLucene ;
        #spatial:directory "mem" ;
        spatial:directory <file:DIR> ;
        spatial:definition <#definition> ;
        .
    */
@SuppressWarnings("resource")
@Override
public SpatialIndex open(Assembler a, Resource root, Mode mode) {
    try {
        if (!GraphUtils.exactlyOneProperty(root, pDirectory))
            throw new SpatialIndexException("No 'spatial:directory' property on " + root);
        Directory directory;
        RDFNode n = root.getProperty(pDirectory).getObject();
        if (n.isLiteral()) {
            if (!"mem".equals(n.asLiteral().getLexicalForm()))
                throw new SpatialIndexException("No 'spatial:directory' property on " + root + " is a literal and not \"mem\"");
            directory = new RAMDirectory();
        } else {
            Resource x = n.asResource();
            String path = IRILib.IRIToFilename(x.getURI());
            File dir = new File(path);
            directory = FSDirectory.open(dir.toPath());
        }
        Resource r = GraphUtils.getResourceValue(root, pDefinition);
        EntityDefinition docDef = (EntityDefinition) a.open(r);
        return SpatialDatasetFactory.createLuceneIndex(directory, docDef);
    } catch (IOException e) {
        IO.exception(e);
        return null;
    }
}
Also used : EntityDefinition(org.apache.jena.query.spatial.EntityDefinition) Resource(org.apache.jena.rdf.model.Resource) SpatialIndexException(org.apache.jena.query.spatial.SpatialIndexException) IOException(java.io.IOException) File(java.io.File) RDFNode(org.apache.jena.rdf.model.RDFNode) RAMDirectory(org.apache.lucene.store.RAMDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) SpatialVocab.pDirectory(org.apache.jena.query.spatial.assembler.SpatialVocab.pDirectory)

Example 28 with RDFNode

use of org.apache.jena.rdf.model.RDFNode in project jena by apache.

the class LocalizedAnalyzerAssembler method open.

/*
    text:map (
         [ text:field "text" ; 
           text:predicate rdfs:label;
           text:analyzer [
               a  lucene:LocalizedAnalyzer ;
               text:language "en" ;
         ]
        .
     */
@Override
public Analyzer open(Assembler a, Resource root, Mode mode) {
    if (root.hasProperty(TextVocab.pLanguage)) {
        RDFNode node = root.getProperty(TextVocab.pLanguage).getObject();
        if (!node.isLiteral()) {
            throw new TextIndexException("text:language property must be a string : " + node);
        }
        String lang = node.toString();
        return Util.getLocalizedAnalyzer(lang);
    } else {
        return new StandardAnalyzer();
    }
}
Also used : TextIndexException(org.apache.jena.query.text.TextIndexException) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 29 with RDFNode

use of org.apache.jena.rdf.model.RDFNode 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 30 with RDFNode

use of org.apache.jena.rdf.model.RDFNode 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

RDFNode (org.apache.jena.rdf.model.RDFNode)49 Resource (org.apache.jena.rdf.model.Resource)21 Model (org.apache.jena.rdf.model.Model)10 QuerySolution (org.apache.jena.query.QuerySolution)9 Node (org.apache.jena.graph.Node)8 Literal (org.apache.jena.rdf.model.Literal)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Property (org.apache.jena.rdf.model.Property)6 Dataset (org.apache.jena.query.Dataset)5 Statement (org.apache.jena.rdf.model.Statement)5 Date (java.sql.Date)4 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)4 TextIndexException (org.apache.jena.query.text.TextIndexException)4 Extractor (infoeval.main.WikiData.Extractor)3 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)3 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)3 ARQException (org.apache.jena.sparql.ARQException)3 UpdateRequest (org.apache.jena.update.UpdateRequest)3 File (java.io.File)2