org.apache.jena.riot.system.RiotLib Java Examples

The following examples show how to use org.apache.jena.riot.system.RiotLib. 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: StreamingRDFWriter.java    From tarql with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void writeTurtle(String baseIRI, PrefixMapping prefixes, boolean writeBase) {
	// Auto-register RDF prefix so that rdf:type is displayed well
	// All other prefixes come from the query and should be as author intended
	prefixes = ensureRDFPrefix(prefixes);

	if (writeBase) {
		// Jena's streaming Turtle writers don't output base even if it is provided,
		// so we write it directly.
		IndentedWriter w = new IndentedWriter(out);
		RiotLib.writeBase(w, baseIRI);
		w.flush();
	}
	
	StreamRDF writer = new WriterStreamRDFBlocks(out);
	if (dedupWindowSize > 0) {
		writer = new StreamRDFDedup(writer, dedupWindowSize);
	}
	writer.start();
	writer.base(baseIRI);
	for (Entry<String, String> e : prefixes.getNsPrefixMap().entrySet()) {
		writer.prefix(e.getKey(), e.getValue());
	}
	StreamOps.sendTriplesToStream(triples, writer);
	writer.finish();
}
 
Example #2
Source File: RDFStar2RDF.java    From RDFstarTools with Apache License 2.0 5 votes vote down vote up
public void execute()
{
    // print all prefixes and the base IRI to the output file
    try ( IndentedWriter writer = new IndentedWriter(outStream) ) {
        RiotLib.writePrefixes(writer, pmap);
        RiotLib.writeBase(writer, baseIRI);

        // second pass over the file to perform the conversion in a streaming manner
        final PipedRDFIterator<Triple> it = new PipedRDFIterator<>(BUFFER_SIZE);
        final PipedTriplesStream triplesStream = new PipedTriplesStream(it);

        // PipedRDFStream and PipedRDFIterator need to be on different threads
        final Runnable r = new Runnable() {
            @Override
            public void run() {
                RDFParser.create().labelToNode( LabelToNode.createUseLabelEncoded() )
                .source(inputFilename)
                .lang(LangTurtleStar.TURTLESTAR)
                .base(baseIRI)
                .build()
                .parse(triplesStream);
            }
        };
        final ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.submit(r);

        final NodeFormatter nFmt = new NodeFormatterTTL(baseIRI, pmap);

        while ( it.hasNext() ) {
            printTriples(it.next(), writer, nFmt, false);
        }

        it.close();
        executor.shutdown();

        writer.write(" .");
        writer.flush();
    }
}
 
Example #3
Source File: ParserProfileTurtleStarExtImplTest.java    From RDFstarTools with Apache License 2.0 5 votes vote down vote up
public ParserProfileTurtleStarExtImplTest() {
	super( new ParserProfileTurtleStarExtImpl(RiotLib.factoryRDF(),
			 ErrorHandlerFactory.errorHandlerStd,
                IRIResolver.create(),
                getPrefixMap(),
                RIOT.getContext().copy(),
                true,
                false) );
}
 
Example #4
Source File: ParserProfileTurtleStarWrapperImplTest.java    From RDFstarTools with Apache License 2.0 5 votes vote down vote up
static protected ParserProfileTurtleStar createParserProfileTurtleStar() {
	ParserProfileStd wrappedProfile = new ParserProfileStd(RiotLib.factoryRDF(), 
               ErrorHandlerFactory.errorHandlerStd,
               IRIResolver.create(),
               getPrefixMap(),
               RIOT.getContext().copy(),
               true,
               false);

	return new ParserProfileTurtleStarWrapperImpl(wrappedProfile);		
}
 
Example #5
Source File: RdflintParserTurtle.java    From rdflint with MIT License 5 votes vote down vote up
private String expandPrefixedName(String prefix, String localPart) {
  String expansion = getPrefixMap().expand(prefix, localPart);
  if (expansion == null) {
    if (ARQ.isTrue(ARQ.fixupUndefinedPrefixes)) {
      return RiotLib.fixupPrefixIRI(prefix, localPart);
    }
  }
  return expansion;
}
 
Example #6
Source File: RDFPatchReaderText.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
private static Node tokenToNode(Token token) {
    if ( token.isIRI() )
        // URI or <_:...>
        return RiotLib.createIRIorBNode(token.getImage());
    if ( token.isBNode() ) {
        // Blank node as _:...
        String label = token.getImage().substring(bNodeLabelStart.length());
        return NodeFactory.createBlankNode(label);
    }
    Node node = token.asNode();
    if ( node == null )
        throw exception(token, "Expect a Node, got %s",token);
    return node;
}
 
Example #7
Source File: SHACLCWriter.java    From shacl with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
       IndentedWriter iOut = RiotLib.create(out);
       iOut.setUnitIndent(1);
       iOut.setPadChar('\t');
	write(iOut, graph, prefixMap, baseURI, context);
}
 
Example #8
Source File: ExRIOT_out3.java    From xcurator with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI, Context context)
{
    // Writers are discouraged : just hope the charset is UTF-8.
    IndentedWriter x = RiotLib.create(out) ;
    SSE.write(x, graph) ;
}
 
Example #9
Source File: RDF2RDFStar.java    From RDFstarTools with Apache License 2.0 4 votes vote down vote up
public void convert( String inputFilename,
		             OutputStream outStream,
                        Lang inputLang,
		             String baseIRI,
		             ErrorHandler errHandler,
		             boolean enableChecking )
{
	final FirstPass fp = new FirstPass(inputFilename, inputLang, baseIRI, errHandler, enableChecking);
	fp.execute();

	// print all prefixes and the base IRI to the output file
	try( IndentedWriter writer = new IndentedWriter(outStream) ) {
	    RiotLib.writePrefixes(writer, fp.getPrefixMap());
	    RiotLib.writeBase(writer, fp.getBaseIRI());

	    // second pass over the file to perform the conversion in a streaming manner
	    // (PipedTriplesStream and PipedRDFIterator need to be on different threads!!)
	    final PipedRDFIterator<Triple> it = new PipedRDFIterator<>(BUFFER_SIZE);
	    final PipedTriplesStream triplesStream = new PipedTriplesStream(it);

	    final Parser p = new Parser(inputFilename, triplesStream, enableChecking);

	    if ( baseIRI != null )
	        p.setBaseIRI(baseIRI);

	    if ( inputLang != null )
	        p.setLang(inputLang);

	    if ( errHandler != null )
	        p.setErrorHandler(errHandler);

	    final ExecutorService executor = Executors.newSingleThreadExecutor();
	    executor.submit(p);

	    final NodeFormatter nFmt = new NodeFormatterTurtleStarExtImpl(fp.getBaseIRI(), fp.getPrefixMap());
	    printTriples(writer, nFmt, it, fp.getReifiedTriples());

	    it.close();
	    executor.shutdown();

	    writer.write(" .");
	    writer.flush();
	}
}