Search in sources :

Example 91 with Resource

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);
                }
            }
        }
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) ResIterator(org.apache.jena.rdf.model.ResIterator) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) InfModel(org.apache.jena.rdf.model.InfModel) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 92 with Resource

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) });
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) OntModel(org.apache.jena.ontology.OntModel) InfModel(org.apache.jena.rdf.model.InfModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 93 with Resource

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;
}
Also used : TestSuite(junit.framework.TestSuite) Resource(org.apache.jena.rdf.model.Resource) IOException(java.io.IOException)

Example 94 with Resource

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;
}
Also used : Dataset(org.apache.jena.query.Dataset) Resource(org.apache.jena.rdf.model.Resource) Model(org.apache.jena.rdf.model.Model) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 95 with Resource

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);
}
Also used : TypeNotUniqueException(org.apache.jena.sparql.util.TypeNotUniqueException) ARQException(org.apache.jena.sparql.ARQException) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)178 Model (org.apache.jena.rdf.model.Model)86 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)34 RDFNode (org.apache.jena.rdf.model.RDFNode)24 Dataset (org.apache.jena.query.Dataset)20 Literal (org.apache.jena.rdf.model.Literal)17 BaseTest (org.apache.jena.atlas.junit.BaseTest)16 Node (org.apache.jena.graph.Node)16 Statement (org.apache.jena.rdf.model.Statement)14 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)9 InfModel (org.apache.jena.rdf.model.InfModel)9 Reader (java.io.Reader)8 ArrayList (java.util.ArrayList)8 JsonString (org.apache.jena.atlas.json.JsonString)8 Triple (org.apache.jena.graph.Triple)8 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5