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