Search in sources :

Example 1 with Property

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

the class TestConnection method connection_1.

@Test
public void connection_1() {
    SDBConnection conn1 = SDBFactory.createConnection(conn);
    Store store1 = StoreFactory.create(storeDesc, conn1);
    // Reset
    store1.getTableFormatter().format();
    SDBConnection conn2 = SDBFactory.createConnection(conn);
    Store store2 = StoreFactory.create(storeDesc, conn2);
    Model model1 = SDBFactory.connectDefaultModel(store1);
    Model model2 = SDBFactory.connectDefaultModel(store2);
    Resource s = model1.createResource();
    Property p = model1.createProperty("http://example/p");
    // These are autocommit so two stores should be OK (but not a good design paradigm)
    model1.add(s, p, "model1");
    model2.add(s, p, "model2");
    assertEquals(2, model1.size());
    assertEquals(2, model2.size());
    assertTrue(model1.isIsomorphicWith(model2));
}
Also used : SDBConnection(org.apache.jena.sdb.sql.SDBConnection) 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 2 with Property

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

the class TestAssembler method model_5.

@Test
public void model_5() {
    Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
    Resource xDft = assem.getResource("http://example/test#graphDft");
    Store store = create(assem);
    // Default graph: Check they are connected to the same place in the store 
    Model model2 = (Model) Assembler.general.open(xDft);
    Model model3 = (Model) Assembler.general.open(xDft);
    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 3 with Property

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

the class TestAssembler method model_4.

@Test
public void model_4() {
    Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
    Resource xDft = assem.getResource("http://example/test#graphDft");
    Resource xNamed = assem.getResource("http://example/test#graphNamed");
    Store store = create(assem);
    Model model1 = (Model) Assembler.general.open(xDft);
    Model model2 = (Model) Assembler.general.open(xNamed);
    // Check they are not connected to the same place in the store 
    Resource s = model1.createResource();
    Property p = model1.createProperty("http://example/p");
    Literal o = model1.createLiteral("foo");
    model1.add(s, p, o);
    assertTrue(model1.contains(s, p, o));
    assertTrue(model1.size() == 1);
    assertTrue(model2.size() == 0);
    assertFalse(model1.isIsomorphicWith(model2));
}
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 4 with Property

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

the class T_TDBWriteTransaction method run.

public static void run(String location) {
    if (false) {
        Journal journal = Journal.create(Location.create(location));
        JournalControl.print(journal);
        journal.close();
    }
    //String location = args[0]; // + "/" + UUID.randomUUID().toString();
    //String baseGraphName = "com.ibm.test.graphNamePrefix.";   
    long totalExecTime = 0L;
    long size = 0;
    Dataset dataset = TDBFactory.createDataset(location);
    Dataset dataset1 = TDBFactory.createDataset(location);
    if (bracketWithReader)
        dataset1.begin(ReadWrite.READ);
    for (int i = 0; i < TOTAL; i++) {
        List<String> lastProcessedUris = new ArrayList<>();
        for (int j = 0; j < 10 * i; j++) {
            String lastProcessedUri = "http://test.net/xmlns/test/1.0/someUri" + j;
            lastProcessedUris.add(lastProcessedUri);
        }
        //Dataset dataset = TDBFactory.createDataset(location);
        //String graphName = baseGraphName + i;
        long t = System.currentTimeMillis();
        try {
            dataset.begin(ReadWrite.WRITE);
            Model m = dataset.getDefaultModel();
            m.removeAll();
            Resource subject = m.createResource(INDEX_INFO_SUBJECT);
            Property predicate = m.createProperty(TIMESTAMP_PREDICATE);
            m.addLiteral(subject, predicate, System.currentTimeMillis());
            predicate = m.createProperty(URI_PREDICATE);
            for (String uri : lastProcessedUris) {
                m.add(subject, predicate, m.createResource(uri));
            }
            predicate = m.createProperty(VERSION_PREDICATE);
            m.addLiteral(subject, predicate, 1.0);
            size += m.size() + 1;
            predicate = m.createProperty(INDEX_SIZE_PREDICATE);
            m.addLiteral(subject, predicate, size);
            dataset.commit();
        } catch (Throwable e) {
            dataset.abort();
            throw new RuntimeException(e);
        } finally {
            dataset.end();
            long writeOperationDuration = System.currentTimeMillis() - t;
            totalExecTime += writeOperationDuration;
            System.out.println("Write operation " + i + " took " + writeOperationDuration + "ms");
        }
    }
    if (bracketWithReader)
        dataset1.end();
    System.out.println("All " + TOTAL + " write operations wrote " + size + " triples and took " + totalExecTime + "ms");
}
Also used : Dataset(org.apache.jena.query.Dataset) ArrayList(java.util.ArrayList) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Journal(org.apache.jena.tdb.transaction.Journal) Property(org.apache.jena.rdf.model.Property)

Example 5 with Property

use of org.apache.jena.rdf.model.Property 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)

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