use of org.apache.jena.irix.IRIx 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.IRIx in project jena by apache.
the class NodeFormatterTTL method abbrevByBase.
private String abbrevByBase(String uriStr) {
if (baseIRI == null)
return null;
IRIx relInput = IRIx.create(uriStr);
IRIx relativized = baseIRI.relativize(relInput);
return (relativized == null) ? null : relativized.toString();
}
use of org.apache.jena.irix.IRIx in project jena by apache.
the class JenaPreparedStatement method setObject.
@Override
public void setObject(int parameterIndex, Object value) throws SQLException {
if (value == null)
throw new SQLException("Setting a null value is not permitted");
if (value instanceof Node) {
this.setParameter(parameterIndex, (Node) value);
} else if (value instanceof RDFNode) {
this.setParameter(parameterIndex, ((RDFNode) value).asNode());
} else if (value instanceof String) {
this.setParameter(parameterIndex, NodeFactory.createLiteral((String) value));
} else if (value instanceof Boolean) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(Boolean.toString((Boolean) value), XSDDatatype.XSDboolean));
} else if (value instanceof Long) {
this.setParameter(parameterIndex, NodeFactoryExtra.intToNode((Long) value));
} else if (value instanceof Integer) {
this.setParameter(parameterIndex, NodeFactoryExtra.intToNode((Integer) value));
} else if (value instanceof Short) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(Short.toString((Short) value), XSDDatatype.XSDshort));
} else if (value instanceof Byte) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(Byte.toString((Byte) value), XSDDatatype.XSDbyte));
} else if (value instanceof BigDecimal) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(((BigDecimal) value).toPlainString(), XSDDatatype.XSDdecimal));
} else if (value instanceof Float) {
this.setParameter(parameterIndex, NodeFactoryExtra.floatToNode((Float) value));
} else if (value instanceof Double) {
this.setParameter(parameterIndex, NodeFactoryExtra.doubleToNode((Double) value));
} else if (value instanceof Date) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(((Date) value).getTime());
this.setParameter(parameterIndex, NodeFactoryExtra.dateTimeToNode(c));
} else if (value instanceof Time) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(((Time) value).getTime());
this.setParameter(parameterIndex, NodeFactoryExtra.timeToNode(c));
} else if (value instanceof Calendar) {
this.setParameter(parameterIndex, NodeFactoryExtra.dateTimeToNode((Calendar) value));
} else if (value instanceof URL) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else if (value instanceof URI) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else if (value instanceof IRI) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else if (value instanceof IRIx) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else {
throw new SQLException("setObject() received a value that could not be converted to a RDF node for use in a SPARQL query");
}
}
use of org.apache.jena.irix.IRIx in project jena by apache.
the class RiotLib method profile.
/**
* Create a parser profile for the given setup
*/
private static ParserProfile profile(String baseIRI, boolean resolveIRIs, boolean checking, ErrorHandler handler) {
LabelToNode labelToNode = SyntaxLabels.createLabelToNode();
IRIx base = resolveIRIs ? IRIs.resolveIRI(baseIRI) : IRIx.create(baseIRI);
IRIxResolver resolver = IRIxResolver.create(base).resolve(resolveIRIs).allowRelative(false).build();
return RiotLib.createParserProfile(factoryRDF(labelToNode), handler, resolver, checking);
}
use of org.apache.jena.irix.IRIx 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());
}
}
}
Aggregations