当前位置: 首页>>代码示例>>Java>>正文


Java DatasetGraph类代码示例

本文整理汇总了Java中org.apache.jena.sparql.core.DatasetGraph的典型用法代码示例。如果您正苦于以下问题:Java DatasetGraph类的具体用法?Java DatasetGraph怎么用?Java DatasetGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DatasetGraph类属于org.apache.jena.sparql.core包,在下文中一共展示了DatasetGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeJsonLd

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
private void writeJsonLd(final OutputStream output, final DatasetGraph graph, final IRI... profiles) {
    final String profile = getCustomJsonLdProfile(profiles);
    final RDFFormat format = nonNull(profile) && nonNull(cache) ? JSONLD_COMPACT_FLAT : getJsonLdProfile(profiles);
    final WriterDatasetRIOT writer = RDFDataMgr.createDatasetWriter(format);
    final PrefixMap pm = RiotLib.prefixMap(graph);
    final String base = null;
    final JsonLDWriteContext ctx = new JsonLDWriteContext();
    if (nonNull(profile) && nonNull(cache)) {
        LOGGER.debug("Setting JSON-LD context with profile: {}", profile);
        final String c = cache.get(profile, p -> {
            try (final TypedInputStream res = HttpOp.execHttpGet(profile)) {
                return IOUtils.toString(res.getInputStream(), UTF_8);
            } catch (final IOException | HttpException ex) {
                LOGGER.warn("Error fetching profile {}: {}", p, ex.getMessage());
                return null;
            }
        });
        if (nonNull(c)) {
            ctx.setJsonLDContext(c);
            ctx.setJsonLDContextSubstitution("\"" + profile + "\"");
        }
    }
    writer.write(output, graph, pm, base, ctx);
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:25,代码来源:JenaIOService.java

示例2: build

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
public static DatasetGraph build(String dirname) {
        FileOps.ensureDir(dirname);
        boolean empty = ! FileOps.existsAnyFiles(dirname);
        if ( empty )
            formatDatabase(dirname);
        RocksTDB rtdb = openDB(dirname);
//        if ( ! empty )
//            try {
//                rtdb.rdb.compactRange();
//            }
//            catch (RocksDBException e) {
//                throw RocksException.wrap(e);
//            }
        Location location = Location.create(dirname);
        return TDBBuilderR.build(rtdb);
    }
 
开发者ID:afs,项目名称:tdb3,代码行数:17,代码来源:BuildR.java

示例3: getDatasetGraph

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
private Optional<DatasetGraph> getDatasetGraph(final String url) {
    try (final FcrepoResponse head = headResource(url)) {

        final List<URI> types = head.getLinkHeaders("type");
        LOGGER.debug("Link headers: " + types);

        if (types.contains(URI.create(LDP + "NonRDFSource"))) {
            // Is this a NonRDFSource?
            LOGGER.debug("Get NonRdfSource Description for: {}", url);
            verifyNonRdfSourceDescription(head);
            return Optional.empty();

        } else {
            // This is a container
            LOGGER.debug("Get triples for: {}", url);
            try (final FcrepoResponse get = getResource(url)) {
                final Model model = createDefaultModel();
                final Dataset d = new DatasetImpl(model.read(get.getBody(), "", TEXT_TURTLE));
                return Optional.of(d.asDatasetGraph());
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:awoods,项目名称:fcrepo-java-client-etc,代码行数:26,代码来源:Walker.java

示例4: change_1

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
@Test
public void change_1() {
    String NAME = "change_1s";
    DeltaClient dClient = createRegister(NAME);
    
    try(DeltaConnection dConn = dClient.get(NAME)) {
        long verLocal0 = dConn.getLocalVersion();
        long verRemotel0 = dConn.getRemoteVersionLatest();
        
        DatasetGraph dsg = dConn.getDatasetGraph();
        Txn.executeWrite(dsg, ()->{
            dsg.add(SSE.parseQuad("(:gx :sx :px :ox)"));
        });
        
        long verLocal1 = dConn.getLocalVersion();
        long verRemotel1 = dConn.getRemoteVersionLatest();
        assertEquals(verLocal1, dConn.getLocalVersion());
        assertEquals(verRemotel1, dConn.getRemoteVersionLatest());
        
        assertFalse(dConn.getDatasetGraph().isEmpty());
        if ( dConn.getStorage() != null )
            assertFalse(dConn.getStorage().isEmpty());
    }
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:25,代码来源:AbstractTestDeltaConnection.java

示例5: change_2

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
@Test
public void change_2() {
    String NAME = "change_2";
    DeltaClient dClient = createRegister(NAME);
    try(DeltaConnection dConn = dClient.get(NAME)) {
        Id dsRef = dConn.getDataSourceId();
        long version = dConn.getRemoteVersionLatest();

        DatasetGraph dsg = dConn.getDatasetGraph();
        Txn.executeWrite(dsg, ()->{
            Quad q = SSE.parseQuad("(_ :s1 :p1 :o1)");
            dsg.add(q);
        });
        // Rebuild directly.
        DatasetGraph dsg2 = DatasetGraphFactory.createTxnMem();
        long ver = dConn.getRemoteVersionLatest();
        RDFPatch patch1 = dConn.getLink().fetch(dsRef, ver) ;
        RDFPatchOps.applyChange(dsg2, patch1);

        Set<Quad> set1 = Txn.calculateRead(dsg, ()->Iter.toSet(dsg.find()));
        Set<Quad> set2 = Txn.calculateRead(dsg2, ()->Iter.toSet(dsg2.find()));
        assertEquals(set1, set2);
    }
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:25,代码来源:AbstractTestDeltaConnection.java

示例6: change_read_new

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
private void change_read_new(Runnable betweenSections) {
    Quad quad = DeltaTestLib.freshQuad();
    
    String NAME = "DS-"+counter.incrementAndGet();
    DeltaClient dClient = createRegister(NAME);
    Id dsRef;
    
    try(DeltaConnection dConn = dClient.get(NAME)) {
        dConn.getPatchLogInfo().getDataSourceId();
        dsRef = dConn.getDataSourceId();
        long version = dConn.getRemoteVersionLatest();
        DatasetGraph dsg = dConn.getDatasetGraph();
        Txn.executeWrite(dsg, ()->dsg.add(quad) );
    }

    betweenSections.run();

    // New client.
    // Rebuild.
    dClient = resetDeltaClient(NAME);
    try(DeltaConnection dConn = dClient.get(NAME)) {
        boolean b = dConn.getDatasetGraph().contains(quad);
        assertTrue(b);
    }
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:26,代码来源:AbstractTestDeltaConnection.java

示例7: update_3

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
@Test
public void update_3() {
    // Create on the Delta link then setup DeltaClient
    DeltaLink dLink = getLink();
    String DS_NAME = "12345";
    
    Id dsRef = dLink.newDataSource(DS_NAME, "http://example/datasource_update_3");
    DeltaClient dClient = createDeltaClient();
    dClient.register(dsRef, LocalStorageType.MEM, TxnSyncPolicy.NONE);
    DeltaConnection dConn = dClient.get(DS_NAME);
    Quad quad = SSE.parseQuad("(_ :s :p :o)");
    DatasetGraph dsg = dConn.getDatasetGraph();

    long x0 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) );
    assertEquals(0, x0);
    
    dsg.begin(ReadWrite.WRITE);
    dsg.add(quad);
    dsg.abort();
    
    long x1 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) );
    assertEquals(0, x1);
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:24,代码来源:AbstractTestDeltaClient.java

示例8: main2

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
public static void main2(String ...args) {
        int PORT = 2020;
        DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem();
        RDFChanges changeLog = RDFPatchOps.textWriter(System.out);
        DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog);
        
        // Create a server with the changes-enables dataset.
        // Plain server. No other registration necessary.
        FusekiServer server = 
            FusekiServer.create()
                .setPort(PORT)
                .add("/ds", dsg)
                .build();
        server.start();

        RDFConnection conn = RDFConnectionFactory.connect("http://localhost:"+PORT+"/ds");
        UpdateRequest update = UpdateFactory.create("PREFIX : <http://example/> INSERT DATA { :s :p 123 }");
        // Note - no prefix in changes. The SPARQL Update prefix is not a chnage to the dataset prefixes.
        conn.update(update);
        
        server.stop(); 
//        // Server in the background so explicitly exit.
//        System.exit(0);
    }
 
开发者ID:afs,项目名称:rdf-delta,代码行数:25,代码来源:DeltaEx3_FusekiLogChanges.java

示例9: main

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
public static void main(String ...args) {
    // -- Base dataset 
    DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem();

    // -- Destination for changes.
    // Text form of output.  
    OutputStream out = System.out;
    // Create an RDFChanges that writes to "out".
    RDFChanges changeLog = RDFPatchOps.textWriter(out);

    // Combined datasetgraph and changes. 
    DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog);

    // Wrap in the Dataset API
    Dataset ds = DatasetFactory.wrap(dsg);

    // --------
    // Do something. Read in data.ttl inside a transaction.
    // (data.ttl is in src/main/resources/)
    Txn.executeWrite(ds,
        ()->RDFDataMgr.read(dsg, "data.ttl")
        );
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:24,代码来源:DeltaEx1_DatasetWithPatchLog.java

示例10: UNUSED_CURRENTLY_forkUpdateFetcher

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
private static void UNUSED_CURRENTLY_forkUpdateFetcher(String source, DatasetGraph dsg) {
        if ( true ) {
            Log.warn(DeltaAssembler.class, "forkUpdateFetcher not set up");
            if ( true ) return;
            throw new NotImplemented("NEED THE STATE AREA; NEED THE DATASOURCE ID; NEED THE CLIENT ID");
        }
        DeltaLink dc = DeltaLinkHTTP.connect(source) ;
        DeltaConnection client = null;
        Runnable r = ()->{
            try { client.sync(); }
            catch (Exception ex) { 
                Delta.DELTA_LOG.warn("Failed to sync with the change server: "+ex.getMessage()) ;
//                // Delay this task ; extra 3s + the time interval of 2s.
//                Dones not work as expected.
//                Lib.sleep(5*1000);
            }
        } ;
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(1) ;
        executor.scheduleWithFixedDelay(r, 2, 2, TimeUnit.SECONDS) ;
    }
 
开发者ID:afs,项目名称:rdf-delta,代码行数:21,代码来源:DeltaAssembler.java

示例11: testUpdateAction

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
@Test
public void testUpdateAction() {
    DatasetGraph gs = getMarkLogicDatasetGraph();
    UpdateRequest update = new UpdateRequest();
    update.add("INSERT DATA { <s2> <p1> <o1> }");
    update.add("DROP ALL")
            .add("CREATE GRAPH <http://example/update1>")
            .add("BASE <http://example.org/> INSERT DATA { GRAPH <http://example.org/update2> { <s1> <p1> <o1>  } }")
            .add("BASE <http://example.org/> INSERT DATA { GRAPH <http://example.org/update3> { <s1> <p1> <o1>  } }");

    UpdateAction.execute(update, gs);

    QueryExecution askQuery = QueryExecutionFactory
            .create("BASE <http://example.org/> ASK WHERE { GRAPH <update3> { <s1> <p1> <o1>  }}",
                    DatasetFactory.wrap(gs));
    assertTrue("update action must update database.", askQuery.execAsk());

}
 
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:19,代码来源:MarkLogicUpdatesTest.java

示例12: execQuery

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
public static void execQuery(String sparqlQueryString, DatasetGraph dsg)
{
    // Add a datset wrapper to conform with the query interface.
    // This should not be very expensive.
    Dataset dataset = DatasetFactory.create(dsg) ;
    
    Query query = QueryFactory.create(sparqlQueryString) ;
    QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
    try {
        ResultSet results = qexec.execSelect() ;
        for ( ; results.hasNext() ; )
        {
            QuerySolution soln = results.nextSolution() ;
            int count = soln.getLiteral("count").getInt() ;
            System.out.println("count = "+count) ;
        }
      } finally { qexec.close() ; }
}
 
开发者ID:xcurator,项目名称:xcurator,代码行数:19,代码来源:ExTDB_Txn3.java

示例13: assertIdentical

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
private void assertIdentical(final String uri, final String originalRdf) throws IOException {
    try (CloseableDataset roundtripped = getDataset(new HttpGet(uri))) {
        try (CloseableDataset original = parseTriples(new ByteArrayInputStream(originalRdf.getBytes()))) {
            final DatasetGraph originalGraph = original.asDatasetGraph();
            final DatasetGraph roundtrippedGraph = roundtripped.asDatasetGraph();
            final Iterator<Quad> originalQuadIt = originalGraph.find();
            while (originalQuadIt.hasNext()) {
                final Quad q = originalQuadIt.next();
                assertTrue(q + " should be preserved through a roundtrip! \nOriginal RDF: " + originalRdf
                        + "\nRoundtripped Graph:\n" + roundtrippedGraph, roundtrippedGraph.contains(q));
                roundtrippedGraph.delete(q);
            }
            assertTrue("Roundtripped graph had extra quads! " + roundtrippedGraph, roundtrippedGraph.isEmpty());
        }
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:17,代码来源:FedoraRelaxedLdpIT.java

示例14: testGetObjectVersionProfile

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
@Test
public void testGetObjectVersionProfile() throws IOException {
    final String id = getRandomUniqueId();
    final String label = "v0.0.1";

    createObjectAndClose(id);
    enableVersioning(id);
    postObjectVersion(id, label);
    logger.debug("Retrieved version profile:");
    try (final CloseableDataset dataset = getDataset(new HttpGet(serverAddress + id + "/fcr:versions"))) {
        final DatasetGraph graph = dataset.asDatasetGraph();
        assertEquals("Expected exactly 3 triples!", 3, countTriples(graph));
        final Resource subject = createResource(serverAddress + id);
        final Iterator<Quad> hasVersionTriple = graph.find(ANY, subject.asNode(), HAS_VERSION.asNode(), ANY);
        assertTrue("Didn't find a version triple!", hasVersionTriple.hasNext());
        final Node versionURI = hasVersionTriple.next().getObject();
        assertFalse("Found extra version triple!", hasVersionTriple.hasNext());
        assertTrue("Version label wasn't presented!",
                graph.contains(ANY, versionURI, HAS_VERSION_LABEL.asNode(), createLiteral(label)));
        assertTrue("Version creation date wasn't present!",
                graph.contains(ANY, versionURI, CREATED_DATE.asNode(), ANY));
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:24,代码来源:FedoraVersionsIT.java

示例15: testVersioningANodeWithAVersionableChild

import org.apache.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
@Test
public void testVersioningANodeWithAVersionableChild() throws IOException {
    final String id = getRandomUniqueId();
    createObjectAndClose(id);
    enableVersioning(id);
    logger.debug("Adding a child");
    createDatastream(id, "ds", "This DS will not be versioned");
    logger.debug("Posting version");
    postObjectVersion(id, "label");

    logger.debug("Retrieved version profile:");
    try (final CloseableDataset dataset = getDataset(new HttpGet(serverAddress + id + "/fcr:versions"))) {
        final DatasetGraph results = dataset.asDatasetGraph();
        final Node subject = createURI(serverAddress + id);
        assertTrue("Didn't find a version triple!", results.contains(ANY, subject, HAS_VERSION.asNode(), ANY));
        final Iterator<Quad> versionIt = results.find(ANY, subject, HAS_VERSION.asNode(), ANY);
        while (versionIt.hasNext()) {
            final String url = versionIt.next().getObject().getURI();
            assertEquals("Version " + url + " isn't accessible!", OK.getStatusCode(), getStatus(new HttpGet(url)));
        }
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:23,代码来源:FedoraVersionsIT.java


注:本文中的org.apache.jena.sparql.core.DatasetGraph类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。