use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestReasoners method doTestTransitiveReduction.
/**
* Test that a transitive reduction is complete.
* Assumes test graph has no cycles (other than the trivial
* identity ones).
*/
public void doTestTransitiveReduction(Model model, Property dp) {
InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner(), model);
for (ResIterator i = im.listSubjects(); i.hasNext(); ) {
Resource base = i.nextResource();
List<RDFNode> directLinks = new ArrayList<>();
for (NodeIterator j = im.listObjectsOfProperty(base, dp); j.hasNext(); ) {
directLinks.add(j.next());
}
for (int n = 0; n < directLinks.size(); n++) {
Resource d1 = (Resource) directLinks.get(n);
for (int m = n + 1; m < directLinks.size(); m++) {
Resource d2 = (Resource) directLinks.get(m);
if (im.contains(d1, dp, d2) && !base.equals(d1) && !base.equals(d2)) {
assertTrue("Triangle discovered in transitive reduction", false);
}
}
}
}
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestReasoners method testModelFactoryRDFS.
/**
* Test the ModelFactory interface
*/
public void testModelFactoryRDFS() {
Model data = ModelFactory.createDefaultModel();
Property p = data.createProperty("urn:x-hp:ex/p");
Resource a = data.createResource("urn:x-hp:ex/a");
Resource b = data.createResource("urn:x-hp:ex/b");
Resource C = data.createResource("urn:x-hp:ex/c");
data.add(p, RDFS.range, C).add(a, p, b);
Model result = ModelFactory.createRDFSModel(data);
StmtIterator i = result.listStatements(b, RDF.type, (RDFNode) null);
TestUtil.assertIteratorValues(this, i, new Object[] { data.createStatement(b, RDF.type, RDFS.Resource), data.createStatement(b, RDF.type, C) });
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestCurrentRDFWG method suite.
/**
* Boilerplate for junit.
* This is its own test suite
*/
public static TestSuite suite() {
TestSuite suite = new TestSuite();
try {
Resource config = newResource().addProperty(ReasonerVocabulary.PROPsetRDFSLevel, "full");
constructRDFWGtests(suite, RDFSRuleReasonerFactory.theInstance(), config);
} catch (IOException e) {
// failed to even built the test harness
logger.error("Failed to construct RDF WG test harness", e);
}
return suite;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class DatasetAssembler method createDataset.
public Dataset createDataset(Assembler a, Resource root, Mode mode) {
// -------- Default graph
// Can use ja:graph or ja:defaultGraph
Resource dftGraph = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pDefaultGraph);
if (dftGraph == null)
dftGraph = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pGraph);
Model dftModel = null;
if (dftGraph != null)
dftModel = a.openModel(dftGraph);
else
// Assembler description did not define one.
dftModel = GraphFactory.makeDefaultModel();
Dataset ds = DatasetFactory.create(dftModel);
// -------- Named graphs
List<RDFNode> nodes = GraphUtils.multiValue(root, DatasetAssemblerVocab.pNamedGraph);
for (RDFNode n : nodes) {
if (!(n instanceof Resource))
throw new DatasetAssemblerException(root, "Not a resource: " + FmtUtils.stringForRDFNode(n));
Resource r = (Resource) n;
String gName = GraphUtils.getAsStringValue(r, DatasetAssemblerVocab.pGraphName);
Resource g = GraphUtils.getResourceValue(r, DatasetAssemblerVocab.pGraph);
if (g == null) {
g = GraphUtils.getResourceValue(r, DatasetAssemblerVocab.pGraphAlt);
if (g != null) {
Log.warn(this, "Use of old vocabulary: use :graph not :graphData");
} else {
throw new DatasetAssemblerException(root, "no graph for: " + gName);
}
}
Model m = a.openModel(g);
ds.addNamedModel(gName, m);
}
AssemblerUtils.setContext(root, ds.getContext());
return ds;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class AssemblerUtils method build.
public static Object build(String assemblerFile, Resource type) {
if (assemblerFile == null)
throw new ARQException("No assembler file");
Model spec = readAssemblerFile(assemblerFile);
Resource root = null;
try {
root = GraphUtils.findRootByType(spec, type);
if (root == null)
return null;
} catch (TypeNotUniqueException ex) {
throw new ARQException("Multiple types for: " + DatasetAssemblerVocab.tDataset);
}
return Assembler.general.open(root);
}
Aggregations