use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class RDFOutput method asRDF.
public Resource asRDF(Model model, ResultSet resultSet, boolean includeRowIndex) {
Resource results = model.createResource();
// This always goes in.
results.addProperty(RDF.type, ResultSetGraphVocab.ResultSet);
for (String vName : resultSet.getResultVars()) results.addProperty(ResultSetGraphVocab.resultVariable, vName);
int count = 0;
for (; resultSet.hasNext(); ) {
count++;
QuerySolution rBind = resultSet.nextSolution();
Resource thisSolution = model.createResource();
if (includeTypeProperties)
thisSolution.addProperty(RDF.type, ResultSetGraphVocab.ResultSolution);
results.addProperty(ResultSetGraphVocab.solution, thisSolution);
if (includeRowIndex) {
// This can lead to equivalent result sets having different graphs
// Best used if and only if query was completely sorted.
Literal x = model.createTypedLiteral(count + "", XSDDatatype.XSDinteger);
thisSolution.addLiteral(ResultSetGraphVocab.index, x);
}
Iterator<String> iter = getAllVars() ? rBind.varNames() : resultSet.getResultVars().iterator();
for (; iter.hasNext(); ) {
Resource thisBinding = model.createResource();
String rVar = iter.next();
RDFNode n = rBind.get(rVar);
if (n == null)
continue;
// }
if (includeTypeProperties)
thisBinding.addProperty(RDF.type, ResultSetGraphVocab.ResultBinding);
thisBinding.addProperty(ResultSetGraphVocab.variable, rVar);
thisBinding.addProperty(ResultSetGraphVocab.value, n);
thisSolution.addProperty(ResultSetGraphVocab.binding, thisBinding);
}
}
results.addProperty(ResultSetGraphVocab.size, model.createTypedLiteral(count));
addPrefixes(model);
return results;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class AllAccept method testWithContent.
public void testWithContent() throws IOException {
File f = FileUtils.tempFileName("assembler-acceptance-", ".n3");
Model data = model("a P b; b Q c");
try (FileOutputStream fs = new FileOutputStream(f)) {
data.write(fs, "N3");
}
Resource root = resourceInModel("x rdf:type ja:MemoryModel; x ja:content y; y ja:externalContent file:" + f.getAbsolutePath());
Model m = Assembler.general.openModel(root);
assertIsoModels(data, m);
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class AllAccept method testUnadornedInferenceModel.
public void testUnadornedInferenceModel() {
Resource root = resourceInModel("x ja:reasoner R; R rdf:type ja:ReasonerFactory");
Model m = Assembler.general.openModel(root);
assertInstanceOf(InfModel.class, m);
InfModel inf = (InfModel) m;
assertIsoModels(empty, inf.getRawModel());
assertInstanceOf(GenericRuleReasoner.class, inf.getReasoner());
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestAssemblerGroup method testClassesLoadedBeforeAddingTypes.
public void testClassesLoadedBeforeAddingTypes() {
String className = ImplementsSPOO.class.getName();
Resource root = resourceInModel("_root rdf:type ja:MemoryModel; _x ja:loadClass '" + className + "'");
ExpandingAssemblerGroup g = new AssemblerGroup.ExpandingAssemblerGroup();
g.implementWith(resource("ja:MemoryModel"), mockAssembler);
g.open(root);
assertEquals(resourceSet("SPOO ja:MemoryModel"), g.implementsTypes());
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestAssemblerGroup method testLoadsClasses.
public void testLoadsClasses() {
AssemblerGroup a = AssemblerGroup.create();
a.implementWith(resource("T"), new MockAssembler());
Resource root = resourceInModel("x rdf:type T; _c ja:loadClass '" + TestAssemblerGroup.class.getName() + "$Trivial'");
// In case already loaded.
loaded = false;
assertFalse("something has pre-loaded Trivial, so we can't test if it gets loaded", loaded);
assertEquals("mockmockmock", a.open(root));
assertTrue("the assembler group did not obey the ja:loadClass directive", loaded);
}
Aggregations