use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestConcurrentAccess method mrswGraph4.
@Test(expected = ConcurrentModificationException.class)
public void mrswGraph4() {
Model m = create().getDefaultModel();
Resource r = m.createResource("x");
ExtendedIterator<Statement> iter1 = m.listLiteralStatements(r, null, 1);
assertNotNull(iter1.next());
// and now the iterator has implicitly finished.
Triple t = SSE.parseTriple("(<y> <p> 99)");
m.getGraph().add(t);
// Bad - modification of the dataset occurred.
iter1.hasNext();
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestConcurrentAccess method mrswGraph2.
@Test(expected = ConcurrentModificationException.class)
public void mrswGraph2() {
Model m = create().getDefaultModel();
Resource r = m.createResource("x");
ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
assertNotNull(iter1.next());
Triple t = SSE.parseTriple("(<y> <p> 99)");
m.getGraph().add(t);
// Bad
iter1.hasNext();
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class RDFOutput method asRDF.
public Resource asRDF(Model model, boolean result) {
Resource results = model.createResource();
results.addProperty(RDF.type, ResultSetGraphVocab.ResultSet);
Literal lit = model.createTypedLiteral(result);
results.addProperty(ResultSetGraphVocab.p_boolean, lit);
return results;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestJsonLDWriter method testContextByUri.
/**
* Checks that one can pass a context defined by its URI
*
* -- well NO, this doesn't work
*/
@Test
public final void testContextByUri() {
Model m = ModelFactory.createDefaultModel();
String ns = "http://schema.org/";
Resource s = m.createResource();
m.add(s, m.createProperty(ns + "name"), "Jane Doe");
m.add(s, m.createProperty(ns + "url"), "http://www.janedoe.com");
m.add(s, RDF.type, "Person");
// we can pass an uri in the context, as a quoted string (it is a JSON string)
JsonLDWriteContext jenaContext = new JsonLDWriteContext();
try {
jenaContext.set(JsonLDWriter.JSONLD_CONTEXT, "{\"@context\" : \"http://schema.org/\"}");
String jsonld = toString(m, RDFFormat.JSONLD, jenaContext);
// check it parses ok
Model m2 = parse(jsonld);
// assertTrue(m2.isIsomorphicWith(m)); // It should be the case, but no.
} catch (Throwable e) {
// maybe test run in a setting wo external connectivity - not a real problem
String mess = e.getMessage();
if ((mess != null) && (mess.contains("loading remote context failed"))) {
Logger.getLogger(getClass()).info(mess);
e.printStackTrace();
} else {
throw e;
}
}
// But anyway, that's not what we want to do:
// there's no point in passing the uri of a context to have it dereferenced by jsonld-java
// (this is for a situation where one would want to parse a jsonld file containing a context defined by a uri)
// What we want is to pass a context to jsonld-java (in order for json-ld java to produce the correct jsonld output)
// and then we want to replace the @context in the output by "@context":"ourUri"
// How would we do that? see testSubstitutingContext()
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestJsonLDWriter method simpleModel.
private Model simpleModel(String ns) {
Model m = ModelFactory.createDefaultModel();
Resource s = m.createResource(ns + "s");
Property p = m.createProperty(ns + "p");
Resource o = m.createResource(ns + "o");
m.add(s, p, o);
return m;
}
Aggregations