Search in sources :

Example 76 with Resource

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();
}
Also used : Triple(org.apache.jena.graph.Triple) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 77 with Resource

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();
}
Also used : Triple(org.apache.jena.graph.Triple) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 78 with Resource

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

Example 79 with Resource

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()
}
Also used : JsonLDWriteContext(org.apache.jena.riot.JsonLDWriteContext) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) JsonString(org.apache.jena.atlas.json.JsonString) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 80 with Resource

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

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