use of org.apache.jena.irix.IRIException in project jena by apache.
the class shacl_parse method processModulesAndArgs.
@Override
protected void processModulesAndArgs() {
super.processModulesAndArgs();
if (super.hasArg(argOutput)) {
printCompact = false;
printRDF = false;
printText = false;
// Split values.
Function<String, Stream<String>> f = (x) -> {
String[] a = x.split(",");
return Arrays.stream(a);
};
List<String> values = StreamOps.toList(getValues(argOutput).stream().flatMap(f).map(s -> s.toLowerCase()));
printText = values.remove("text") || values.remove("t");
printCompact = values.remove("compact") || values.remove("c");
printRDF = values.remove("rdf") || values.remove("r");
if (values.remove("all") || values.remove("a")) {
printCompact = true;
printRDF = true;
printText = true;
}
if (!values.isEmpty())
throw new CmdException("Formats not recognized: " + values + " : Formats are 'text', 'compact', 'rdf' and 'all'");
} else {
printCompact = false;
printRDF = false;
printText = true;
}
if (super.contains(argSyntax)) {
String syntax = super.getValue(argSyntax);
Lang lang$ = RDFLanguages.nameToLang(syntax);
if (lang$ == null)
throw new CmdException("Can not detemine the syntax from '" + syntax + "'");
this.lang = lang$;
}
if (super.contains(argBase)) {
baseIRI = super.getValue(argBase);
try {
IRIx iri = IRIs.reference(baseIRI);
if (!iri.isAbsolute())
throw new CmdException("Base IRI not suitable for use as a base for RDF: " + baseIRI);
} catch (IRIException ex) {
throw new CmdException("Bad base IRI: " + baseIRI);
}
}
if (positionals.isEmpty())
// stdin
positionals.add("-");
}
use of org.apache.jena.irix.IRIException in project jena by apache.
the class CmdLangParse method parseRIOT.
protected ParseRecord parseRIOT(RDFParserBuilder builder, String filename) {
boolean checking = true;
if (modLangParse.explicitChecking())
checking = true;
if (modLangParse.explicitNoChecking())
checking = false;
builder.checking(checking);
if (checking)
builder.strict(true);
// Should use ErrorHandlerRecorder
ErrorHandlerTracking errHandler = ErrorHandlerFactory.errorHandlerTracking(ErrorHandlerFactory.stdLogger, true, modLangParse.stopOnWarnings());
builder.errorHandler(errHandler);
// Make into a cmd flag. (input and output subflags?)
// If input is "label, then output using NodeToLabel.createBNodeByLabelRaw() ;
// else use NodeToLabel.createBNodeByLabel() ;
// Also, as URI.
final boolean labelsAsGiven = false;
// labels = NodeToLabel.createBNodeByLabelEncoded() ;
if (labelsAsGiven)
builder.labelToNode(LabelToNode.createUseLabelAsGiven());
StreamRDF s = outputStream;
if (setup != null)
s = RDFSFactory.streamRDFS(s, setup);
StreamRDFCounting sink = StreamRDFLib.count(s);
s = null;
boolean successful = true;
modTime.startTimer();
RDFParser parser = builder.build();
try {
sink.start();
parser.parse(sink);
successful = true;
} catch (RiotNotFoundException ex) {
errHandler.error(ex.getMessage(), -1, -1);
successful = false;
} catch (RiotException ex) {
successful = false;
} catch (IRIException ex) {
successful = false;
}
sink.finish();
long x = modTime.endTimer();
ParseRecord outcome = new ParseRecord(filename, successful, x, sink.countTriples(), sink.countQuads(), errHandler);
return outcome;
}
use of org.apache.jena.irix.IRIException in project jena by apache.
the class ModLangParse method processArgs.
@Override
public void processArgs(CmdArgModule cmdLine) {
if (cmdLine.contains(argValidate)) {
validate = true;
strict = true;
explicitCheck = true;
bitbucket = true;
}
if (cmdLine.contains(argSyntax)) {
String syntax = cmdLine.getValue(argSyntax);
Lang lang$ = RDFLanguages.nameToLang(syntax);
if (lang$ == null)
throw new CmdException("Can not detemine the syntax from '" + syntax + "'");
this.lang = lang$;
}
if (cmdLine.contains(argCheck))
explicitCheck = true;
if (cmdLine.contains(argNoCheck))
explicitNoCheck = true;
if (cmdLine.contains(argStrict))
strict = true;
if (cmdLine.contains(argBase)) {
baseIRI = cmdLine.getValue(argBase);
try {
IRIx iri = IRIs.reference(baseIRI);
if (!iri.isAbsolute())
throw new CmdException("Base IRI not suitable for use as a base for RDF: " + baseIRI);
} catch (IRIException ex) {
throw new CmdException("Bad base IRI: " + baseIRI);
}
}
if (cmdLine.contains(argStop))
stopOnError = true;
if (cmdLine.contains(argStopWarn))
stopOnWarnings = true;
if (cmdLine.contains(argSink))
bitbucket = true;
if (cmdLine.contains(argCount)) {
bitbucket = true;
outputCount = true;
}
if (cmdLine.contains(argRDFS)) {
try {
rdfsVocabFilename = cmdLine.getArg(argRDFS).getValue();
rdfsVocab = RDFDataMgr.loadModel(rdfsVocabFilename);
} catch (RiotException ex) {
throw new CmdException("Error in RDFS vocabulary: " + rdfsVocabFilename);
} catch (Exception ex) {
throw new CmdException("Error: " + ex.getMessage());
}
}
}
use of org.apache.jena.irix.IRIException in project jena by apache.
the class NodeFunctions method resolveCheckIRI.
//
private static String resolveCheckIRI(String baseIRI, String iriStr) {
try {
IRIx iri = IRIx.create(iriStr);
IRIx base = (baseIRI != null) ? IRIx.create(baseIRI) : IRIs.getSystemBase();
IRIx result = base.resolve(iri);
if (!result.isReference())
throw new IRIException("Not suitable: " + result.str());
return result.str();
} catch (IRIException ex) {
throw new ExprEvalException("Bad IRI: " + iriStr);
}
}
use of org.apache.jena.irix.IRIException in project jena by apache.
the class FmtUtils method abbrevByBase.
public static String abbrevByBase(String uriStr, String base) {
try {
IRIx baseIRI = IRIx.create(base);
if (baseIRI == null)
return null;
IRIx relInput = IRIx.create(uriStr);
IRIx relativized = baseIRI.relativize(relInput);
return (relativized == null) ? null : relativized.toString();
} catch (IRIException ex) {
return null;
}
}
Aggregations