use of org.apache.jena.riot.Lang in project jena by apache.
the class QueryExecUtils method outputResultSet.
@SuppressWarnings("deprecation")
public static void outputResultSet(ResultSet results, Prologue prologue, ResultsFormat outputFormat) {
// Proper ResultSet formats.
Lang lang = ResultsFormat.convert(outputFormat);
if (lang != null) {
ResultSetMgr.write(System.out, results, lang);
System.out.flush();
return;
}
// Old way.
boolean done = false;
if (prologue == null)
prologue = new Prologue(globalPrefixMap);
if (outputFormat.equals(ResultsFormat.FMT_UNKNOWN))
outputFormat = ResultsFormat.FMT_TEXT;
if (outputFormat.equals(ResultsFormat.FMT_NONE) || outputFormat.equals(ResultsFormat.FMT_COUNT)) {
int count = ResultSetFormatter.consume(results);
if (outputFormat.equals(ResultsFormat.FMT_COUNT)) {
System.out.println("Count = " + count);
}
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RDF_XML) || outputFormat.equals(ResultsFormat.FMT_RDF_N3) || outputFormat.equals(ResultsFormat.FMT_RDF_TTL)) {
Model m = RDFOutput.encodeAsModel(results);
m.setNsPrefixes(prologue.getPrefixMapping());
m.setNsPrefix("rs", ResultSetGraphVocab.getURI());
RDFDataMgr.write(System.out, m, Lang.TURTLE);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_XML)) {
ResultSetFormatter.outputAsXML(System.out, results);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_JSON)) {
ResultSetFormatter.outputAsJSON(System.out, results);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_SSE)) {
ResultSetFormatter.outputAsSSE(System.out, results, prologue);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_TEXT)) {
ResultSetFormatter.out(System.out, results, prologue);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_TUPLES)) {
PlainFormat pFmt = new PlainFormat(System.out, prologue);
ResultSetApply a = new ResultSetApply(results, pFmt);
a.apply();
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_CSV)) {
ResultSetFormatter.outputAsCSV(System.out, results);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_TSV)) {
ResultSetFormatter.outputAsTSV(System.out, results);
done = true;
}
if (outputFormat.equals(ResultsFormat.FMT_RS_BIO)) {
ResultSetFormatter.outputAsBIO(System.out, results);
done = true;
}
if (!done)
System.err.println("Unknown format request: " + outputFormat);
results = null;
System.out.flush();
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class ModLangOutput method processArgs.
@Override
public void processArgs(CmdArgModule cmdLine) {
if (cmdLine.contains(argPretty)) {
String langName = cmdLine.getValue(argPretty);
Lang lang = RDFLanguages.nameToLang(langName);
if (lang == null)
throw new CmdException("Not recognized as an RDF language : '" + langName + "'");
formattedOutput = RDFWriterRegistry.defaultSerialization(lang);
if (formattedOutput == null) {
System.err.println("Language '" + lang.getLabel() + "' not registered.");
printRegistered(System.err);
throw new CmdException("No output set: '" + langName + "'");
}
}
if (cmdLine.contains(argStream)) {
String langName = cmdLine.getValue(argStream);
Lang lang = RDFLanguages.nameToLang(langName);
if (lang == null)
throw new CmdException("Not recognized as an RDF language : '" + langName + "'");
streamOutput = StreamRDFWriter.defaultSerialization(lang);
if (streamOutput == null) {
System.err.println("Language '" + lang.getLabel() + "' not registered for streaming.");
printRegistered(System.err);
throw new CmdException("No output set: '" + langName + "'");
}
}
if (cmdLine.contains(argOutput)) {
String langName = cmdLine.getValue(argOutput);
Lang lang = RDFLanguages.nameToLang(langName);
if (lang == null)
throw new CmdException("Not recognized as an RDF language : '" + langName + "'");
if (StreamRDFWriter.registered(lang)) {
streamOutput = StreamRDFWriter.defaultSerialization(lang);
} else {
formattedOutput = RDFWriterRegistry.defaultSerialization(lang);
if (formattedOutput == null) {
System.err.println("Language '" + lang.getLabel() + "' not recognized.");
printRegistered(System.err);
throw new CmdException("No output set: '" + langName + "'");
}
}
}
if (cmdLine.contains(argCompress))
compressedOutput = true;
if (streamOutput == null && formattedOutput == null)
streamOutput = RDFFormat.NQUADS;
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class BulkLoader method loadTriples$.
/** Load into a graph */
private static void loadTriples$(BulkStreamRDF dest, List<String> urls) {
dest.startBulk();
for (String url : urls) {
loadLogger.info("Load: " + url + " -- " + DateTimeUtils.nowAsString());
Lang lang = RDFLanguages.filenameToLang(url, Lang.NTRIPLES);
RDFDataMgr.parse(dest, url, lang);
}
dest.finishBulk();
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class BulkLoader method loadQuads$.
/** Load quads into a dataset */
private static void loadQuads$(BulkStreamRDF dest, List<String> urls) {
dest.startBulk();
for (String url : urls) {
loadLogger.info("Load: " + url + " -- " + DateTimeUtils.nowAsString());
Lang lang = RDFLanguages.filenameToLang(url, Lang.NQUADS);
RDFDataMgr.parse(dest, url, lang);
}
dest.finishBulk();
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class CmdNodeTableBuilder method processModulesAndArgs.
@Override
protected void processModulesAndArgs() {
if (!super.contains(argLocation))
throw new CmdException("Required: --loc DIR");
// if ( !super.contains(argTriplesOut) ) throw new CmdException("Required: --triples FILE") ;
// if ( !super.contains(argQuadsOut) ) throw new CmdException("Required: --quads FILE") ;
locationString = super.getValue(argLocation);
location = Location.create(locationString);
dataFileTriples = super.getValue(argTriplesOut);
if (dataFileTriples == null)
dataFileTriples = location.getPath("triples", "tmp");
dataFileQuads = super.getValue(argQuadsOut);
if (dataFileQuads == null)
dataFileQuads = location.getPath("quads", "tmp");
if (Objects.equals(dataFileTriples, dataFileQuads))
cmdError("Triples and Quads work files are the same");
if (super.contains(argNoStats))
collectStats = false;
//datafiles = getPositionalOrStdin() ;
datafiles = getPositional();
if (datafiles.isEmpty())
datafiles = Arrays.asList("-");
// ---- Checking.
for (String filename : datafiles) {
Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS);
if (lang == null)
// Does not happen due to default above.
cmdError("File suffix not recognized: " + filename);
if (!filename.equals("-") && !FileOps.exists(filename))
cmdError("File does not exist: " + filename);
}
}
Aggregations