Search in sources :

Example 51 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class RDFDataMgr method loadGraph.

/** Create a memory Graph and read in some data
     * @see #read(Graph,String,Lang) 
     */
public static Graph loadGraph(String uri, Lang lang) {
    Graph g = createGraph();
    read(g, uri, lang);
    return g;
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph)

Example 52 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class RDFDataMgr method read.

/** Read triples into a model with chars from a StringReader.
     * @param model     Destination for the RDF read.
     * @param in        InputStream
     * @param base      Base URI 
     * @param lang      Language syntax
     */
public static void read(Model model, StringReader in, String base, Lang lang) {
    Graph g = model.getGraph();
    StreamRDF dest = StreamRDFLib.graph(g);
    parseFromReader(dest, in, base, lang, (Context) null);
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph)

Example 53 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class DatasetGraphCollection method delete.

@Override
public void delete(Quad quad) {
    Graph g = fetchGraph(quad.getGraph());
    if (g == null)
        throw new JenaException("No such graph: " + quad.getGraph());
    g.delete(quad.asTriple());
}
Also used : JenaException(org.apache.jena.shared.JenaException) GraphUtils.triples2quadsDftGraph(org.apache.jena.sparql.util.graph.GraphUtils.triples2quadsDftGraph) Graph(org.apache.jena.graph.Graph)

Example 54 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class DynamicDatasets method dynamicDataset.

/** Given a DatasetGraph and a query, form a DatasetGraph that 
     * is the dynamic dataset from the collection of graphs from the dataset
     * that go to make up the default graph (union) and named graphs.  
     */
public static DatasetGraph dynamicDataset(Collection<Node> defaultGraphs, Collection<Node> namedGraphs, DatasetGraph dsg, boolean defaultUnionGraph) {
    Graph dft = new GraphUnionRead(dsg, defaultGraphs);
    DatasetGraph dsg2 = new DatasetGraphMapLink(dft);
    // The named graphs.
    for (Node gn : namedGraphs) {
        Graph g = GraphOps.getGraph(dsg, gn);
        if (g != null)
            dsg2.addGraph(gn, g);
    }
    if (dsg.getContext() != null)
        dsg2.getContext().putAll(dsg.getContext());
    if (defaultUnionGraph && defaultGraphs.size() == 0) {
        // Create a union graph - there were no defaultGraphs explicitly named.
        Graph unionGraph = new GraphUnionRead(dsg, namedGraphs);
        dsg2.setDefaultGraph(unionGraph);
    }
    // read-only, <urn:x-arq:DefaultGraph> and <urn:x-arq:UnionGraph> processing.
    dsg2 = new DynamicDatasetGraph(dsg2);
    // Record what we've done.
    // c.f. "ARQConstants.sysDatasetDescription" which is used to pass in a  DatasetDescription
    dsg2.getContext().set(ARQConstants.symDatasetDefaultGraphs, defaultGraphs);
    dsg2.getContext().set(ARQConstants.symDatasetNamedGraphs, namedGraphs);
    return dsg2;
}
Also used : GraphUnionRead(org.apache.jena.sparql.graph.GraphUnionRead) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node)

Example 55 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestAPI method testARQConstructQuad_bnodes.

@Test
public void testARQConstructQuad_bnodes() {
    String queryString = "PREFIX : <http://example/> CONSTRUCT { :s :p :o GRAPH _:a { :s :p :o1 } } WHERE { }";
    Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
    QueryExecution qExec = QueryExecutionFactory.create(q, d);
    Dataset ds = qExec.execConstructDataset();
    assertEquals(1, Iter.count(ds.asDatasetGraph().listGraphNodes()));
    Node n = ds.asDatasetGraph().listGraphNodes().next();
    assertTrue(n.isBlank());
    Graph g = ds.asDatasetGraph().getGraph(n);
    assertNotNull(g);
    assertFalse(g.isEmpty());
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

Graph (org.apache.jena.graph.Graph)247 Test (org.junit.Test)90 BaseTest (org.apache.jena.atlas.junit.BaseTest)56 Triple (org.apache.jena.graph.Triple)56 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)54 Node (org.apache.jena.graph.Node)46 AbstractTestGraph (org.apache.jena.graph.test.AbstractTestGraph)16 InfGraph (org.apache.jena.reasoner.InfGraph)16 ContractTest (org.xenei.junit.contract.ContractTest)16 Model (org.apache.jena.rdf.model.Model)14 MultiUnion (org.apache.jena.graph.compose.MultiUnion)9 Delta (org.apache.jena.graph.compose.Delta)8 BuilderGraph (org.apache.jena.sparql.sse.builders.BuilderGraph)8 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 PrefixMapping (org.apache.jena.shared.PrefixMapping)7 GraphUnionRead (org.apache.jena.sparql.graph.GraphUnionRead)7 IOException (java.io.IOException)6 Dataset (org.apache.jena.query.Dataset)6 Rule (org.apache.jena.reasoner.rulesys.Rule)6 ConfigTest (org.apache.jena.tdb.ConfigTest)6