Java Code Examples for org.apache.jena.riot.system.StreamRDFLib#graph()

The following examples show how to use org.apache.jena.riot.system.StreamRDFLib#graph() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RDFStar2RDFTest.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
protected Graph convertAndLoadIntoGraph( String filename )
{
    final String fullFilename = getClass().getResource("/TurtleStar/"+filename).getFile();
    String result;
    try( ByteArrayOutputStream os = new ByteArrayOutputStream() ) {
        new RDFStar2RDF().convert(fullFilename, os);
        result = os.toString();
    }
    catch ( IOException e ) {
        fail( "Closing the output stream failed: " + e.getMessage() );
        return null;
    }

	final StringReader reader = new StringReader(result);
       final Graph g = ModelFactory.createDefaultModel().getGraph();
       final StreamRDF dest = StreamRDFLib.graph(g);

       RDFParser.create()
                .source(reader)
                .lang(Lang.TURTLE)
                .parse(dest);

	return g;
}
 
Example 2
Source File: DatasetDeclarationPlan.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
private void addNamedGraph(Binding binding, Context context, DatasetGraph dsg, Expr sourceExpr) {
	String sourceURI = evalSourceURI(binding, context, sourceExpr);
	final String absURI = baseURI(sourceURI, baseURI);
	Dataset dataset = ContextUtils.getDataset(context);
	Node n = NodeFactory.createURI(absURI);
	Graph g = dsg.getGraph(n);
	if (g == null) {
		g = GraphFactory.createJenaDefaultGraph();
		dsg.addGraph(n, g);
	}
	// default: check the dataset
	if (dataset.containsNamedModel(absURI)) {
		Graph dg = dataset.getNamedModel(absURI).getGraph();
		GraphUtil.addInto(g, dg);
		return;
	}
	// fallback: load as RDF graph
	StreamRDF dest = StreamRDFLib.graph(g);
	ContextUtils.loadGraph(context, sourceURI, absURI, dest);
}
 
Example 3
Source File: RDFStarUtils.java    From RDFstarTools with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the RDF* data from the given Turtle* serialization
 * to the given {@link Graph}. 
 */
static public void populateGraphFromTurtleStarSnippet( Graph graph, String snippet )
{
	final StringReader reader = new StringReader(snippet);
    final StreamRDF dest = StreamRDFLib.graph(graph);

    RDFParser.create()
             .source(reader)
             .lang(LangTurtleStar.TURTLESTAR)
             .parse(dest);
}
 
Example 4
Source File: DatasetDeclarationPlan.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
private void addDefaultGraph(Binding binding, Context context, DatasetGraph dsg, Expr sourceExpr) {
		String sourceURI = evalSourceURI(binding, context, sourceExpr);
		final String absURI = baseURI(sourceURI, baseURI);
		// default: check the dataset
		Dataset dataset = ContextUtils.getDataset(context);
		if (dataset.containsNamedModel(absURI)) {
//			Node n = NodeFactory.createURI(absURI);
			Graph g = dataset.getNamedModel(absURI).getGraph();
			GraphUtil.addInto(dsg.getDefaultGraph(), g);
			return;
		}
		// fallback: load as RDF graph
		StreamRDF dest = StreamRDFLib.graph(dsg.getDefaultGraph());
		ContextUtils.loadGraph(context, sourceURI, absURI, dest);
	}
 
Example 5
Source File: DatasetDeclarationPlan.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
private void loadGraph(Binding binding, Context context, SPARQLExtQuery generate, Graph graph) {
	QueryExecutor queryExecutor = ContextUtils.getQueryExecutor(context);
	StreamRDF dest = StreamRDFLib.graph(graph);
	Context newContext = ContextUtils.fork(context).setGenerateOutput(dest).fork();
	queryExecutor.execGenerateFromQuery(generate, binding, newContext);
}
 
Example 6
Source File: LangTurtleStarTest.java    From RDFstarTools with Apache License 2.0 3 votes vote down vote up
protected Graph loadGraphFromTurtleStarFile( String filename ) {

		final String fullFilename = getClass().getResource("/TurtleStar/"+filename).getFile();

        final Graph g = ModelFactory.createDefaultModel().getGraph();
        final StreamRDF dest = StreamRDFLib.graph(g);

		assertEquals( LangTurtleStar.TURTLESTAR, RDFLanguages.filenameToLang(fullFilename) );

        RDFParser.create()
                 .source( "file://" + fullFilename )
                 .parse(dest);

		return g;
	}