public void setDatasetContentType(String contentType) { // Check that this is a valid setting Lang lang = RDFLanguages.contentTypeToLang(contentType); if (lang == null) throw new IllegalArgumentException("Given Content Type '" + contentType + "' is not supported by RIOT"); if (!RDFLanguages.isQuads(lang)) throw new IllegalArgumentException("Given Content Type '" + contentType + "' is not a RDF Dataset format"); datasetContentType = contentType; }
@Override protected RecordReader<LongWritable, QuadWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isQuads(lang)) throw new IOException( lang.getLabel() + " is not a RDF quads format, perhaps you wanted TriplesInputFormat or TriplesOrQuadsInputFormat instead?"); // This will throw an appropriate error if the language does not support // triples return HadoopRdfIORegistry.createQuadReader(lang); }
@Override protected RecordReader<LongWritable, QuadWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isQuads(lang)) throw new IOException( lang.getLabel() + " is not a RDF quads format, perhaps you wanted TriplesInputFormat or TriplesOrQuadsInputFormat instead?"); // This will throw an appropriate error if the language does not support // triples return HadoopRdfIORegistry.createQuadReader(lang); }
@Override protected RecordWriter<TKey, QuadWritable> getRecordWriter(Writer writer, Configuration config, Path outputPath) throws IOException { Lang lang = RDFLanguages.filenameToLang(outputPath.getName()); if (lang == null) throw new IOException("There is no registered RDF language for the output file " + outputPath.toString()); if (!RDFLanguages.isQuads(lang)) throw new IOException( lang.getName() + " is not a RDF quads format, perhaps you wanted TriplesOutputFormat or TriplesOrQuadsOutputFormat instead?"); // This will throw an appropriate error if the language does not support // writing quads return HadoopRdfIORegistry.<TKey> createQuadWriter(lang, writer, config); }
@Override protected RecordWriter<TKey, QuadWritable> getRecordWriter(Writer writer, Configuration config, Path outputPath) throws IOException { Lang lang = RDFLanguages.filenameToLang(outputPath.getName()); if (lang == null) throw new IOException("There is no registered RDF language for the output file " + outputPath.toString()); if (!RDFLanguages.isQuads(lang)) throw new IOException( lang.getName() + " is not a RDF quads format, perhaps you wanted TriplesOutputFormat or TriplesOrQuadsOutputFormat instead?"); // This will throw an appropriate error if the language does not support // writing quads return HadoopRdfIORegistry.<TKey> createQuadWriter(lang, writer, config); }
/** Set the output format for sending RDF Datasets to the remote server. * This is used for HTTP PUT and POST to a dataset. * This must be a quads format. */ public RDFConnectionRemoteBuilder quadsFormat(RDFFormat fmtQuads) { if ( ! RDFLanguages.isQuads(fmtQuads.getLang()) ) throw new RiotException("Not a language for RDF Datasets: "+fmtQuads); this.outputQuads = fmtQuads; return this; }
/** Set the output format for sending RDF Datasets to the remote server. * This is used for HTTP PUT and POST to a dataset. * This must be a quads format. */ public RDFConnectionRemoteBuilder quadsFormat(RDFFormat fmtQuads) { if ( ! RDFLanguages.isQuads(fmtQuads.getLang()) ) throw new RiotException("Not a language for RDF Datasets: "+fmtQuads); this.outputQuads = fmtQuads; return this; }
public boolean isQuadsMediaType(MediaType mediaType) { MediaType formatType = new MediaType(mediaType.getType(), mediaType.getSubtype()); // discard charset param Lang lang = RDFLanguages.contentTypeToLang(formatType.toString()); return lang != null && RDFLanguages.isQuads(lang); }
/** Set the output format for sending RDF Datasets to the remote server. * This is used for HTTP PUT and POST to a dataset. * This must be a quads format. */ public RDFConnectionRemoteBuilder quadsFormat(Lang langQuads) { Objects.requireNonNull(langQuads); if ( ! RDFLanguages.isQuads(langQuads) ) throw new RiotException("Not a language for RDF Datasets: "+langQuads); RDFFormat fmt = RDFWriterRegistry.defaultSerialization(langQuads); if ( fmt == null ) throw new RiotException("Language name not recognized: "+langQuads); quadsFormat(fmt); return this; }
/** Set the output format for sending RDF Datasets to the remote server. * This is used for HTTP PUT and POST to a dataset. * This must be a quads format. */ public RDFConnectionRemoteBuilder quadsFormat(Lang langQuads) { Objects.requireNonNull(langQuads); if ( ! RDFLanguages.isQuads(langQuads) ) throw new RiotException("Not a language for RDF Datasets: "+langQuads); RDFFormat fmt = RDFWriterRegistry.defaultSerialization(langQuads); if ( fmt == null ) throw new RiotException("Language name not recognized: "+langQuads); quadsFormat(fmt); return this; }
@Override protected RecordWriter<TKey, QuadWritable> getRecordWriter(Writer writer, Configuration config, Path outputPath) throws IOException { Lang lang = RDFLanguages.filenameToLang(outputPath.getName()); if (lang == null) throw new IOException("There is no registered RDF language for the output file " + outputPath.toString()); if (!RDFLanguages.isQuads(lang) && !RDFLanguages.isTriples(lang)) throw new IOException(lang.getName() + " is not a RDF triples/quads format"); if (HadoopRdfIORegistry.hasQuadWriter(lang)) { // Supports quads directly return HadoopRdfIORegistry.<TKey> createQuadWriter(lang, writer, config); } else { // Try to create a triples writer and wrap downwards from quads // This will throw an error if a triple writer is not available return new QuadsToTriplesWriter<TKey>(HadoopRdfIORegistry.<TKey> createTripleWriter(lang, writer, config)); } }
@Override protected RecordReader<LongWritable, QuadWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isQuads(lang) && !RDFLanguages.isTriples(lang)) throw new IOException(lang.getLabel() + " is not a RDF triples/quads format"); if (HadoopRdfIORegistry.hasQuadReader(lang)) { // Supports quads directly return HadoopRdfIORegistry.createQuadReader(lang); } else { // Try to create a triples reader and wrap upwards into quads // This will throw an error if a triple reader is not available return new TriplesToQuadsReader(HadoopRdfIORegistry.createTripleReader(lang)); } }
@Override protected RecordReader<LongWritable, QuadWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isQuads(lang) && !RDFLanguages.isTriples(lang)) throw new IOException(lang.getLabel() + " is not a RDF triples/quads format"); if (HadoopRdfIORegistry.hasQuadReader(lang)) { // Supports quads directly return HadoopRdfIORegistry.createQuadReader(lang); } else { // Try to create a triples reader and wrap upwards into quads // This will throw an error if a triple reader is not available return new TriplesToQuadsReader(HadoopRdfIORegistry.createTripleReader(lang)); } }
/** Get a StreamRDF destination that will output in syntax {@code RDFFormat} * and is guaranteed to do so in a scaling, streaming fashion. * @param output OutputStream * @param format The syntax (as an {@link RDFFormat}) * @return StreamRDF, or null if format is not registered for streaming. * @see StreamOps#graphToStream * @see StreamOps#datasetToStream */ public static StreamRDF getWriterStream(OutputStream output, RDFFormat format) { StreamRDFWriterFactory x = registry.get(format) ; if ( x == null ) throw new RiotException("Failed to find a writer factory for "+format) ; StreamRDF stream = x.create(output, format) ; if ( ! RDFLanguages.isQuads(format.getLang()) ) // Only pass through triples. stream = new StreamTriplesOnly(stream) ; return stream ; }
/** Send a file to named graph (or "default" or null for the default graph). * <p> * The Content-Type is inferred from the file extension. * <p> * "Replace" means overwrite existing data, othewise the date is added to the target. */ protected void upload(String graph, String file, boolean replace) { // if triples Lang lang = RDFLanguages.filenameToLang(file); if ( RDFLanguages.isQuads(lang) ) throw new ARQException("Can't load quads into a graph"); if ( ! RDFLanguages.isTriples(lang) ) throw new ARQException("Not an RDF format: "+file+" (lang="+lang+")"); String url = LibRDFConn.urlForGraph(svcGraphStore, graph); doPutPost(url, file, lang, replace); }
/** Send a file to named graph (or "default" or null for the default graph). * <p> * The Content-Type is inferred from the file extension. * <p> * "Replace" means overwrite existing data, othewise the date is added to the target. */ protected void upload(String graph, String file, boolean replace) { // if triples Lang lang = RDFLanguages.filenameToLang(file); if ( RDFLanguages.isQuads(lang) ) throw new ARQException("Can't load quads into a graph"); if ( ! RDFLanguages.isTriples(lang) ) throw new ARQException("Not an RDF format: "+file+" (lang="+lang+")"); String url = LibRDFConn.urlForGraph(svcGraphStore, graph); doPutPost(url, file, lang, replace); }
@Override protected void exec() { DatasetGraph dsg = super.getDatasetGraphTDB() ; // Prefer stream over fully pretty output formats. RDFFormat fmt = modLangOutput.getOutputStreamFormat() ; // Stream writing happens naturally - no need to call StreamRDFWriter. //if ( fmt != null && StreamRDFWriter.registered(fmt) ) if ( fmt == null ) fmt = modLangOutput.getOutputFormatted() ; if ( fmt == null ) // Default. fmt = RDFFormat.NQUADS ; if ( ! RDFLanguages.isQuads(fmt.getLang() )) throw new CmdException("Databases can be dumped only in quad formats (e.g. Trig, N-Quads), not "+fmt.getLang()) ; RDFDataMgr.write(System.out, dsg, fmt) ; } }
@Override protected void exec() { DatasetGraph dsg = getDatasetGraph() ; // Prefer stream over fully pretty output formats. RDFFormat fmt = modLangOutput.getOutputStreamFormat() ; // Stream writing happens naturally - no need to call StreamRDFWriter. //if ( fmt != null && StreamRDFWriter.registered(fmt) ) if ( fmt == null ) fmt = modLangOutput.getOutputFormatted() ; if ( fmt == null ) // Default. fmt = RDFFormat.NQUADS ; if ( ! RDFLanguages.isQuads(fmt.getLang() )) throw new CmdException("Databases can be dumped only in quad formats (e.g. Trig, N-Quads), not "+fmt.getLang()) ; RDFFormat fmtFinal = fmt ; Txn.executeRead(dsg, ()->RDFDataMgr.write(System.out, dsg, fmtFinal)); } }
@Test public void jenaSystem_read_1() { assertTrue(RDFLanguages.isRegistered(JenaJSONLD.JSONLD)); assertTrue(RDFLanguages.isTriples(JenaJSONLD.JSONLD)); assertTrue(RDFLanguages.isQuads(JenaJSONLD.JSONLD)); }