use of org.apache.jena.riot.RiotException in project jena by apache.
the class JenaRDF2JSONLD method parse.
@Override
public RDFDataset parse(Object object) throws JsonLdError {
RDFDataset result = new RDFDataset();
if (object instanceof DatasetGraph) {
DatasetGraph dsg = (DatasetGraph) object;
Iterator<Quad> iter = dsg.find();
for (; iter.hasNext(); ) {
Quad q = iter.next();
Node s = q.getSubject();
Node p = q.getPredicate();
Node o = q.getObject();
Node g = q.getGraph();
String gq = null;
if (g != null && !Quad.isDefaultGraph(g)) {
gq = blankNodeOrIRIString(g);
if (gq == null)
throw new RiotException("Graph node is not a URI or a blank node");
}
String sq = blankNodeOrIRIString(s);
if (sq == null)
throw new RiotException("Subject node is not a URI or a blank node");
String pq = p.getURI();
if (o.isLiteral()) {
String lex = o.getLiteralLexicalForm();
String lang = o.getLiteralLanguage();
String dt = o.getLiteralDatatypeURI();
if (lang != null && lang.length() == 0) {
lang = null;
//dt = RDF.getURI()+"langString" ;
}
if (dt == null)
dt = XSDDatatype.XSDstring.getURI();
result.addQuad(sq, pq, lex, dt, lang, gq);
} else {
String oq = blankNodeOrIRIString(o);
result.addQuad(sq, pq, oq, gq);
}
}
} else
Log.warn(JenaRDF2JSONLD.class, "unknown");
return result;
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class RDFJSONWriter method send.
private static void send(JSWriter out, Pair<Node, Map<Node, Set<Node>>> item) {
Node s = item.getLeft();
if (s.isBlank()) {
out.key("_:" + s.getBlankNodeLabel());
} else if (s.isURI()) {
out.key(s.getURI());
} else {
throw new RiotException("Only URIs or blank nodes are legal subjects.");
}
out.startObject();
// out.pair(key, value) ;
Map<Node, Set<Node>> predicates = item.getRight();
for (Node p : predicates.keySet()) {
out.key(p.getURI());
out.startArray();
Set<Node> objects = predicates.get(p);
int i = 0;
for (Node o : objects) {
out.startObject();
if (o.isBlank()) {
out.pair("type", "bnode");
out.pair("value", "_:" + o.getBlankNodeLabel());
} else if (o.isURI()) {
out.pair("type", "uri");
out.pair("value", o.getURI());
} else if (o.isLiteral()) {
String lex = o.getLiteralLexicalForm();
out.pair("type", "literal");
out.pair("value", lex);
if (NodeUtils.isSimpleString(o)) {
// No-op.
} else if (NodeUtils.isLangString(o)) {
String lang = o.getLiteralLanguage();
out.pair("lang", lang);
} else {
// Datatype, nothing special.
String dt = o.getLiteralDatatypeURI();
out.pair("datatype", dt);
}
}
out.finishObject();
if (i < objects.size() - 1) {
out.arraySep();
}
i++;
}
out.finishArray();
}
out.finishObject();
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class Token method create.
static Token create(String s) {
PeekReader pr = PeekReader.readString(s);
TokenizerText tt = new TokenizerText(pr);
if (!tt.hasNext())
throw new RiotException("No token");
Token t = tt.next();
if (tt.hasNext())
throw new RiotException("Extraneous charcaters");
return t;
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class FactoryTestRiot method makeTest.
@Override
public Test makeTest(Resource manifest, Resource item, String testName, Resource action, Resource result) {
try {
Resource r = TestUtils.getResource(item, RDF.type);
if (r == null)
r = dftTestType;
if (r == null)
throw new RiotException("Can't determine the test type");
if (labelPrefix != null)
testName = labelPrefix + testName;
// In Turtle tests, the action directly names the file to process.
Resource input = action;
Resource output = result;
if (r.equals(VocabLangRDF.TestPositiveSyntaxTTL))
return new UnitTestSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.TURTLE, report);
if (r.equals(VocabLangRDF.TestNegativeSyntaxTTL))
return new UnitTestBadSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.TURTLE, report);
if (r.equals(VocabLangRDF.TestPositiveSyntaxTriG))
return new UnitTestSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.TRIG, report);
if (r.equals(VocabLangRDF.TestNegativeSyntaxTriG))
return new UnitTestBadSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.TRIG, report);
if (r.equals(VocabLangRDF.TestPositiveSyntaxNT))
return new UnitTestSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.NTRIPLES, report);
if (r.equals(VocabLangRDF.TestNegativeSyntaxNT))
return new UnitTestBadSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.NTRIPLES, report);
if (r.equals(VocabLangRDF.TestPositiveSyntaxNQ))
return new UnitTestSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.NQUADS, report);
if (r.equals(VocabLangRDF.TestNegativeSyntaxNQ))
return new UnitTestBadSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.NQUADS, report);
if (r.equals(VocabLangRDF.TestPositiveSyntaxRJ))
return new UnitTestSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.RDFJSON, report);
if (r.equals(VocabLangRDF.TestNegativeSyntaxRJ))
return new UnitTestBadSyntax(testName, item.getURI(), input.getURI(), RDFLanguages.RDFJSON, report);
if (r.equals(VocabLangRDF.TestSurpressed))
return new UnitTestSurpressed(testName, item.getURI(), report);
if (r.equals(VocabLangRDF.TestEvalTTL)) {
String base = rebase(input, assumedRootURITurtle);
return new UnitTestEval(testName, item.getURI(), input.getURI(), result.getURI(), base, RDFLanguages.TURTLE, report);
}
if (r.equals(VocabLangRDF.TestEvalTriG)) {
String base = rebase(input, assumedRootURITriG);
return new UnitTestEval(testName, item.getURI(), input.getURI(), result.getURI(), base, RDFLanguages.TRIG, report);
}
if (r.equals(VocabLangRDF.TestNegativeEvalTTL))
return new UnitTestBadEval(testName, item.getURI(), input.getURI(), RDFLanguages.TURTLE, report);
if (r.equals(VocabLangRDF.TestNegativeEvalTriG))
return new UnitTestBadEval(testName, item.getURI(), input.getURI(), RDFLanguages.TRIG, report);
if (r.equals(VocabLangRDF.TestEvalNT))
return new UnitTestEval(testName, item.getURI(), input.getURI(), result.getURI(), null, RDFLanguages.NTRIPLES, report);
if (r.equals(VocabLangRDF.TestNegativeEvalNT))
return new UnitTestBadEval(testName, item.getURI(), input.getURI(), RDFLanguages.NTRIPLES, report);
if (r.equals(VocabLangRDF.TestEvalRJ)) {
String base = rebase(input, assumedRootURIex);
return new UnitTestEval(testName, item.getURI(), input.getURI(), result.getURI(), base, RDFLanguages.RDFJSON, report);
}
if (r.equals(VocabLangRDF.TestNegativeEvalRJ))
return new UnitTestBadEval(testName, item.getURI(), input.getURI(), RDFLanguages.RDFJSON, report);
System.err.println("Unrecognized turtle test : (" + r + ")" + testName);
return null;
} catch (Exception ex) {
ex.printStackTrace(System.err);
System.err.println("Failed to grok test : " + testName);
return null;
}
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class UnitTestBadSyntax method run3.
private void run3() {
Model model = ModelFactory.createDefaultModel();
try {
RDFDataMgr.read(model, uri, uri, lang);
} catch (RiotException ex) {
return;
} catch (RuntimeException ex) {
ex.printStackTrace(System.err);
fail("Unexpected exception");
}
fail("Bad syntax test succeed in parsing the file");
}
Aggregations