Search in sources :

Example 81 with RDFNode

use of org.apache.jena.rdf.model.RDFNode in project wikidata-query-rdf by wikimedia.

the class BigdataStatementToJenaStatementMapper method apply.

@Override
public Statement apply(final BigdataStatement blzgStmt) {
    final Resource s = convertToJenaResource(blzgStmt.getSubject());
    final Property p = convertToJenaProperty(blzgStmt.getPredicate());
    final RDFNode o = convertToJenaRDFNode(blzgStmt.getObject());
    return ResourceFactory.createStatement(s, p, o);
}
Also used : BigdataResource(com.bigdata.rdf.model.BigdataResource) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 82 with RDFNode

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

the class QueryExecUtils method getOne.

/**
     * Execute, expecting the result to be one row, one column. Return that one
     * RDFNode or null Throw excpetion if more than one.
     */
public static RDFNode getOne(QueryExecution qExec, String varname) {
    try {
        ResultSet rs = qExec.execSelect();
        if (!rs.hasNext())
            return null;
        QuerySolution qs = rs.nextSolution();
        RDFNode r = qs.get(varname);
        if (rs.hasNext()) {
            QuerySolution qs2 = rs.next();
            RDFNode r2 = qs2.get(varname);
            if (rs.hasNext())
                throw new ARQException("More than one: var ?" + varname + " -> " + r + ", " + r2 + ", ...");
            else
                throw new ARQException("Found two matches: var ?" + varname + " -> " + r + ", " + r2);
        }
        return r;
    } finally {
        qExec.close();
    }
}
Also used : ARQException(org.apache.jena.sparql.ARQException) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 83 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 84 with RDFNode

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

the class FusekiBuilder method buildDataAccessPoint.

/** Build a DataAccessPoint, including DataService at Resource svc */
public static DataAccessPoint buildDataAccessPoint(Resource svc, DatasetDescriptionRegistry dsDescMap) {
    RDFNode n = FusekiLib.getOne(svc, "fu:name");
    if (!n.isLiteral())
        throw new FusekiConfigException("Not a literal for access point name: " + FmtUtils.stringForRDFNode(n));
    Literal object = n.asLiteral();
    if (object.getDatatype() != null && !object.getDatatype().equals(XSDDatatype.XSDstring))
        Fuseki.configLog.error(format("Service name '%s' is not a string", FmtUtils.stringForRDFNode(object)));
    String name = object.getLexicalForm();
    name = DataAccessPoint.canonical(name);
    DataService dataService = FusekiBuilder.buildDataService(svc, dsDescMap);
    DataAccessPoint dataAccess = new DataAccessPoint(name, dataService);
    return dataAccess;
}
Also used : FusekiConfigException(org.apache.jena.fuseki.FusekiConfigException) Literal(org.apache.jena.rdf.model.Literal) DataAccessPoint(org.apache.jena.fuseki.server.DataAccessPoint) RDFNode(org.apache.jena.rdf.model.RDFNode) DataService(org.apache.jena.fuseki.server.DataService)

Example 85 with RDFNode

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

the class FusekiBuilder method getOne.

public static RDFNode getOne(Resource svc, String property) {
    String ln = property.substring(property.indexOf(':') + 1);
    ResultSet rs = FusekiLib.query("SELECT * { ?svc " + property + " ?x}", svc.getModel(), "svc", svc);
    if (!rs.hasNext())
        throw new FusekiConfigException("No " + ln + " for service " + FusekiLib.nodeLabel(svc));
    RDFNode x = rs.next().get("x");
    if (rs.hasNext())
        throw new FusekiConfigException("Multiple " + ln + " for service " + FusekiLib.nodeLabel(svc));
    return x;
}
Also used : FusekiConfigException(org.apache.jena.fuseki.FusekiConfigException) ResultSet(org.apache.jena.query.ResultSet) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

RDFNode (org.apache.jena.rdf.model.RDFNode)145 Resource (org.apache.jena.rdf.model.Resource)51 Model (org.apache.jena.rdf.model.Model)30 Statement (org.apache.jena.rdf.model.Statement)27 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)22 Node (org.apache.jena.graph.Node)20 QuerySolution (org.apache.jena.query.QuerySolution)20 TextIndexException (org.apache.jena.query.text.TextIndexException)17 Property (org.apache.jena.rdf.model.Property)17 Literal (org.apache.jena.rdf.model.Literal)15 SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)13 Dataset (org.apache.jena.query.Dataset)13 Triple (org.apache.jena.graph.Triple)12 QueryExecution (org.apache.jena.query.QueryExecution)10 StmtIterator (org.apache.jena.rdf.model.StmtIterator)9 Query (org.apache.jena.query.Query)8 NodeIterator (org.apache.jena.rdf.model.NodeIterator)8 RDFList (org.apache.jena.rdf.model.RDFList)8 AccessDeniedException (org.apache.jena.shared.AccessDeniedException)7