use of org.apache.jena.riot.Lang in project jena by apache.
the class ResultSetFactory method load.
/**
* Load a result set from input stream into a result set (memory backed).
*
* @param input
* @param format
* @return ResultSet
*/
public static ResultSet load(InputStream input, ResultsFormat format) {
if (format == null) {
Log.warn(ResultSet.class, "Null format - defaulting to XML");
format = ResultsFormat.FMT_RS_XML;
}
// Old World - new world
Lang lang = ResultsFormat.convert(format);
if (lang != null)
return ResultSetMgr.read(input, lang);
if (format.equals(ResultsFormat.FMT_RS_JSON))
return JSONInput.fromJSON(input);
if (format.equals(ResultsFormat.FMT_RS_TSV))
return TSVInput.fromTSV(input);
if (format.equals(ResultsFormat.FMT_RS_CSV))
return CSVInput.fromCSV(input);
if (format.equals(ResultsFormat.FMT_RS_BIO))
return BIOInput.fromBIO(input);
if (format.equals(ResultsFormat.FMT_RS_XML))
return ResultSetFactory.fromXML(input);
if (format.equals(ResultsFormat.FMT_TEXT)) {
Log.warn(ResultSet.class, "Can't read a text result set");
throw new ResultSetException("Can't read a text result set");
}
if (format.equals(ResultsFormat.FMT_RDF_XML)) {
Model m = ModelFactory.createDefaultModel();
m.read(input, null);
return RDFInput.fromRDF(m);
}
if (format.equals(ResultsFormat.FMT_RDF_TTL)) {
Model m = ModelFactory.createDefaultModel();
m.read(input, null, "TURTLE");
return RDFInput.fromRDF(m);
}
if (format.equals(ResultsFormat.FMT_RDF_N3)) {
Model m = ModelFactory.createDefaultModel();
m.read(input, null, "N3");
return RDFInput.fromRDF(m);
}
if (format.equals(ResultsFormat.FMT_RDF_NT)) {
Model m = ModelFactory.createDefaultModel();
m.read(input, null, "N-TRIPLES");
return RDFInput.fromRDF(m);
}
Log.warn(ResultSet.class, "Unknown result set syntax: " + format);
return null;
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class UpdateEngineWorker method visit.
@Override
public void visit(UpdateLoad update) {
// LOAD SILENT? iri ( INTO GraphRef )?
String source = update.getSource();
Node dest = update.getDest();
try {
// Read into temporary storage to protect against parse errors.
if (dest != null) {
Lang lang = RDFLanguages.filenameToLang(source);
// load-to-graph - must be triples.
if (!RDFLanguages.isTriples(lang))
throw new UpdateException("Attempt to load quads into a graph");
// LOAD-INTO graph ... must be triples.
Graph g = GraphFactory.createGraphMem();
RDFParser.source(source).parse(g);
Graph g2 = graph(datasetGraph, dest);
GraphUtil.addInto(g2, g);
} else {
// LOAD <iri> -- allow quads.
DatasetGraph dsg = DatasetGraphFactory.create();
RDFParser.source(source).parse(dsg);
Iterator<Quad> iter = dsg.find();
for (; iter.hasNext(); ) {
Quad q = iter.next();
datasetGraph.add(q);
}
}
} catch (RuntimeException ex) {
if (!update.getSilent()) {
if (ex instanceof UpdateException)
throw ex;
throw new UpdateException("Failed to LOAD '" + source + "'", ex);
}
}
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class TestResultSetIO method data.
@Parameters(name = "{index}: {0}")
public static Collection<Object[]> data() {
Lang[] langs = { SPARQLResultSetXML, SPARQLResultSetJSON, SPARQLResultSetCSV, SPARQLResultSetTSV };
List<Object[]> x = new ArrayList<>();
for (Lang lang : langs) {
x.add(new Object[] { "test:" + lang.getName(), lang });
}
return x;
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class UnitTestEval method run4.
private void run4() {
DatasetGraph dsg = DatasetGraphFactory.create();
try {
if (baseIRI != null)
RDFDataMgr.read(dsg, input, baseIRI, lang);
else
RDFDataMgr.read(dsg, input, lang);
Lang outLang = RDFLanguages.filenameToLang(output, Lang.NQUADS);
DatasetGraph results = DatasetGraphFactory.create();
try {
RDFDataMgr.read(results, output, outLang);
} catch (RiotException ex) {
fail("Failed to read results: " + ex.getMessage());
}
boolean b = isomorphic(dsg, results);
if (!b) {
System.out.println("**** Test: " + getName());
System.out.println("---- Parsed");
RDFDataMgr.write(System.out, dsg, Lang.TRIG);
System.out.println("---- Expected");
RDFDataMgr.write(System.out, results, Lang.TRIG);
System.out.println("--------");
}
assertTrue("Datasets not isomorphic", b);
} catch (RiotException ex) {
// Catch and rethrow - debugging.
throw ex;
} catch (RuntimeException ex) {
ex.printStackTrace(System.err);
throw ex;
}
}
use of org.apache.jena.riot.Lang in project jena by apache.
the class UnitTestEval method run3.
// Triples test.
private void run3() {
Model model = ModelFactory.createDefaultModel();
try {
if (baseIRI != null)
RDFDataMgr.read(model, input, baseIRI, lang);
else
RDFDataMgr.read(model, input, lang);
Lang outLang = RDFLanguages.filenameToLang(output, Lang.NQUADS);
Model results = ModelFactory.createDefaultModel();
try {
RDFDataMgr.read(results, output, outLang);
} catch (RiotException ex) {
fail("Failed to read results: " + ex.getMessage());
}
boolean b = model.isIsomorphicWith(results);
if (!b) {
//model.isIsomorphicWith(results) ;
System.out.println("---- Parsed");
model.write(System.out, "TTL");
System.out.println("---- Expected");
results.write(System.out, "TTL");
System.out.println("--------");
}
assertTrue("Models not isomorphic", b);
} catch (RiotException ex) {
// Catch and rethrow - debugging.
throw ex;
} catch (RuntimeException ex) {
ex.printStackTrace(System.err);
throw ex;
}
}
Aggregations