Search in sources :

Example 41 with Property

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

the class TestAssembler method model_6.

@Test
public void model_6() {
    Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
    Resource xNamed = assem.getResource("http://example/test#graphNamed");
    Store store = create(assem);
    // Named graph: Check they are connected to the same place in the store 
    Model model2 = (Model) Assembler.general.open(xNamed);
    Model model3 = (Model) Assembler.general.open(xNamed);
    Resource s = model2.createResource();
    Property p = model2.createProperty("http://example/p");
    // Check two models connected to the same graph 
    Literal o2 = model2.createLiteral("xyz");
    model2.add(s, p, o2);
    assertTrue(model3.contains(s, p, o2));
}
Also used : Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Store(org.apache.jena.sdb.Store) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 42 with Property

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

the class ExTDB6 method main.

public static void main(String[] args) throws Exception {
    /// turn off the "No BGP optimizer warning"
    TDB.setOptimizerWarningFlag(false);
    final IRIFactory iriFactory = IRIFactory.semanticWebImplementation();
    final String DATASET_DIR_NAME = "data0";
    final Dataset data0 = TDBFactory.createDataset(DATASET_DIR_NAME);
    // show the currently registered names
    for (Iterator<String> it = data0.listNames(); it.hasNext(); ) {
        out.println("NAME=" + it.next());
    }
    out.println("getting named model...");
    /// this is the OWL portion
    final Model model = data0.getNamedModel(MY_NS);
    out.println("Model := " + model);
    out.println("getting graph...");
    /// this is the DATA in that MODEL
    final Graph graph = model.getGraph();
    out.println("Graph := " + graph);
    if (graph.isEmpty()) {
        final Resource product1 = model.createResource(iriFactory.construct(MY_NS + "product/1").toString());
        final Property hasName = model.createProperty(MY_NS, "#hasName");
        final Statement stmt = model.createStatement(product1, hasName, model.createLiteral("Beach Ball", "en"));
        out.println("Statement = " + stmt);
        model.add(stmt);
        // just for fun
        out.println("Triple := " + stmt.asTriple().toString());
    } else {
        out.println("Graph is not Empty; it has " + graph.size() + " Statements");
        long t0, t1;
        t0 = System.currentTimeMillis();
        final Query q = QueryFactory.create("PREFIX exns: <" + MY_NS + "#>\n" + "PREFIX exprod: <" + MY_NS + "product/>\n" + " SELECT * " + // +" WHERE { exprod:1 exns:hasName ?name }"
        " WHERE { ?res ?pred ?obj }");
        out.println("Query := " + q);
        t1 = System.currentTimeMillis();
        out.println("QueryFactory.TIME=" + (t1 - t0));
        t0 = System.currentTimeMillis();
        final QueryExecution qExec = QueryExecutionFactory.create(q, model);
        t1 = System.currentTimeMillis();
        out.println("QueryExecutionFactory.TIME=" + (t1 - t0));
        try {
            t0 = System.currentTimeMillis();
            ResultSet rs = qExec.execSelect();
            t1 = System.currentTimeMillis();
            out.println("executeSelect.TIME=" + (t1 - t0));
            while (rs.hasNext()) {
                QuerySolution sol = rs.next();
                out.println("Solution := " + sol);
                for (Iterator<String> names = sol.varNames(); names.hasNext(); ) {
                    final String name = names.next();
                    out.println("\t" + name + " := " + sol.get(name));
                }
            }
        } finally {
            qExec.close();
        }
    }
    out.println("closing graph");
    graph.close();
    out.println("closing model");
    model.close();
    //out.println("closing DataSetGraph");
    //dsg.close();
    out.println("closing DataSet");
    data0.close();
}
Also used : Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) Graph(org.apache.jena.graph.Graph) Model(org.apache.jena.rdf.model.Model) IRIFactory(org.apache.jena.iri.IRIFactory) Property(org.apache.jena.rdf.model.Property)

Example 43 with Property

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

the class AbstractWholeFileTripleInputFormatTests method generateTuples.

@Override
protected final void generateTuples(OutputStream output, int num) throws IOException {
    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 % 10 == 0) {
            currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
        }
        m.add(currSubj, predicate, m.createTypedLiteral(i));
    }
    this.writeTuples(m, output);
    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 44 with Property

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

the class AbstractCompressedWholeFileTripleInputFormatTests method generateTuples.

@Override
protected final void generateTuples(OutputStream output, int num) throws IOException {
    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 % 10 == 0) {
            currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
        }
        m.add(currSubj, predicate, m.createTypedLiteral(i));
    }
    this.writeTuples(m, output);
    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 Property

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

the class AbstractWholeFileTripleInputFormatTests 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)

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