Search in sources :

Example 41 with Resource

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

the class TestAssemblerGroupTracing method testFail.

public void testFail() {
    Resource root = resourceInModel("x rdf:type A");
    AssemblerGroup g = AssemblerGroup.create();
    g.implementWith(resource("A"), new ShantAssemble());
    try {
        g.open(root);
        fail("shouldn't get past exception");
    } catch (AssemblerException e) {
        AssemblerGroup.Frame frame = new AssemblerGroup.Frame(resource("x"), resource("A"), ShantAssemble.class);
        assertEquals(listOfOne(frame), e.getDoing());
    }
}
Also used : AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Resource(org.apache.jena.rdf.model.Resource)

Example 42 with Resource

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

the class AbstractWholeFileQuadInputFormatTests method writeGoodTuples.

private void writeGoodTuples(OutputStream output, int num) {
    Dataset ds = DatasetFactory.createGeneral();
    Model m = ModelFactory.createDefaultModel();
    Resource currSubj = m.createResource("http://example.org/subjects/0");
    Property predicate = m.createProperty("http://example.org/predicate");
    for (int i = 0; i < num; i++) {
        if (i % 100 == 0) {
            ds.addNamedModel("http://example.org/graphs/" + (i / 100), m);
            m = ModelFactory.createDefaultModel();
        }
        if (i % 10 == 0) {
            currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
        }
        m.add(currSubj, predicate, m.createTypedLiteral(i));
    }
    if (!m.isEmpty()) {
        ds.addNamedModel("http://example.org/graphs/extra", m);
    }
    this.writeTuples(ds, output);
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 43 with Resource

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

the class AbstractCompressedWholeFileQuadInputFormatTests method writeGoodTuples.

private void writeGoodTuples(OutputStream output, int num) {
    Dataset ds = DatasetFactory.createGeneral();
    Model m = ModelFactory.createDefaultModel();
    Resource currSubj = m.createResource("http://example.org/subjects/0");
    Property predicate = m.createProperty("http://example.org/predicate");
    for (int i = 0; i < num; i++) {
        if (i % 100 == 0) {
            ds.addNamedModel("http://example.org/graphs/" + (i / 100), m);
            m = ModelFactory.createDefaultModel();
        }
        if (i % 10 == 0) {
            currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
        }
        m.add(currSubj, predicate, m.createTypedLiteral(i));
    }
    if (!m.isEmpty()) {
        ds.addNamedModel("http://example.org/graphs/extra", m);
    }
    this.writeTuples(ds, output);
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 44 with Resource

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

the class AbstractCompressedWholeFileTripleInputFormatTests method generateMixedTuples.

@Override
protected final void generateMixedTuples(OutputStream output, int num) throws IOException {
    // Write good data
    Model m = ModelFactory.createDefaultModel();
    Resource currSubj = m.createResource("http://example.org/subjects/0");
    Property predicate = m.createProperty("http://example.org/predicate");
    for (int i = 0; i < num / 2; i++) {
        if (i % 10 == 0) {
            currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
        }
        m.add(currSubj, predicate, m.createTypedLiteral(i));
    }
    this.writeTuples(m, output);
    // Write junk data
    byte[] junk = "junk data\n".getBytes(utf8);
    for (int i = 0; i < num / 2; i++) {
        output.write(junk);
    }
    output.flush();
    output.close();
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 45 with Resource

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

the class TestContainers method testCanAsContainer.

public void testCanAsContainer() {
    final String seqUri = "http://example.com/#seq";
    model.createSeq(seqUri);
    final Resource res = model.createResource(seqUri);
    Assert.assertTrue(res.canAs(Seq.class));
    Assert.assertTrue(res.canAs(Container.class));
}
Also used : Container(org.apache.jena.rdf.model.Container) Resource(org.apache.jena.rdf.model.Resource) Seq(org.apache.jena.rdf.model.Seq)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)179 Model (org.apache.jena.rdf.model.Model)87 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)35 RDFNode (org.apache.jena.rdf.model.RDFNode)25 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)15 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)9 Triple (org.apache.jena.graph.Triple)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 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5