Search in sources :

Example 36 with Property

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

the class QueryRewriteIndex method toModel.

/**
 * COnverts the index to a model of asserted spatial relation statements.
 *
 * @return Model containing all true assertions.
 */
public Model toModel() {
    Model model = ModelFactory.createDefaultModel();
    for (Entry<String, Boolean> entry : index.entrySet()) {
        Boolean value = entry.getValue();
        if (value) {
            String[] parts = entry.getKey().split(KEY_SEPARATOR);
            Resource subject = ResourceFactory.createResource(parts[0]);
            Property property = ResourceFactory.createProperty(parts[1]);
            Resource object = ResourceFactory.createResource(parts[2]);
            model.add(subject, property, object);
        }
    }
    return model;
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 37 with Property

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

the class SecurityExample method main.

/**
 * @param args
 */
public static void main(String[] args) {
    String[] names = { "alice", "bob", "chuck", "darla" };
    RDFNode msgType = ResourceFactory.createResource("http://example.com/msg");
    Property pTo = ResourceFactory.createProperty("http://example.com/to");
    Property pFrom = ResourceFactory.createProperty("http://example.com/from");
    Property pSubj = ResourceFactory.createProperty("http://example.com/subj");
    Model model = ModelFactory.createDefaultModel();
    URL url = SecurityExample.class.getClassLoader().getResource("org/apache/jena/security/example/example.ttl");
    model.read(url.toExternalForm());
    ResIterator ri = model.listSubjectsWithProperty(RDF.type, msgType);
    System.out.println("All the messages");
    while (ri.hasNext()) {
        Resource msg = ri.next();
        Statement to = msg.getProperty(pTo);
        Statement from = msg.getProperty(pFrom);
        Statement subj = msg.getProperty(pSubj);
        System.out.println(String.format("%s to: %s  from: %s  subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
    }
    System.out.println();
    ExampleEvaluator evaluator = new ExampleEvaluator(model);
    model = Factory.getInstance(evaluator, "http://example.com/SecuredModel", model);
    for (String userName : names) {
        evaluator.setPrincipal(userName);
        System.out.println("Messages " + userName + " can manipulate");
        ri = model.listSubjectsWithProperty(RDF.type, msgType);
        while (ri.hasNext()) {
            Resource msg = ri.next();
            Statement to = msg.getProperty(pTo);
            Statement from = msg.getProperty(pFrom);
            Statement subj = msg.getProperty(pSubj);
            System.out.println(String.format("%s to: %s  from: %s  subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
        }
        ri.close();
        for (String name : names) {
            System.out.println(String.format("%s messages to %s", model.listSubjectsWithProperty(pTo, name).toList().size(), name));
        }
        System.out.println();
    }
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode) URL(java.net.URL)

Example 38 with Property

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

the class SecuredModelTest method __testGetProperty_exists.

private void __testGetProperty_exists(Supplier<Property> supplier) {
    try {
        Property prop = supplier.get();
        assertEquals(p.getURI(), prop.getURI());
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : ReadDeniedException(org.apache.jena.shared.ReadDeniedException) Property(org.apache.jena.rdf.model.Property)

Example 39 with Property

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

the class TestDatasetTDB method load2.

private static void load2(Model model) {
    Resource r2 = model.createResource(base1 + "r2");
    Property p1 = model.createProperty(baseNS + "p1");
    model.add(r2, p1, "x1");
    model.add(r2, p1, "x2");
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 40 with Property

use of org.apache.jena.rdf.model.Property 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)

Aggregations

Property (org.apache.jena.rdf.model.Property)89 Resource (org.apache.jena.rdf.model.Resource)58 Model (org.apache.jena.rdf.model.Model)45 RDFNode (org.apache.jena.rdf.model.RDFNode)18 Test (org.junit.Test)18 Statement (org.apache.jena.rdf.model.Statement)17 StmtIterator (org.apache.jena.rdf.model.StmtIterator)14 ArrayList (java.util.ArrayList)13 Literal (org.apache.jena.rdf.model.Literal)11 Node (org.apache.jena.graph.Node)6 Triple (org.apache.jena.graph.Triple)6 Iterator (java.util.Iterator)5 OntModel (org.apache.jena.ontology.OntModel)5 Dataset (org.apache.jena.query.Dataset)5 QueryExecution (org.apache.jena.query.QueryExecution)5 InfModel (org.apache.jena.rdf.model.InfModel)4 Store (org.apache.jena.sdb.Store)4 HashSet (java.util.HashSet)3 LEGATO (legato.LEGATO)3 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)3