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);
}
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();
}
}
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;
}
}
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;
}
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;
}
Aggregations