use of org.apache.jena.iri.IRI in project jena by apache.
the class N3IRIResolver method resolveIRI.
/*
* No exception thrown by this method.
*/
private static IRI resolveIRI(String relStr, String baseStr) {
IRI i = factory.create(relStr);
if (i.isAbsolute())
// removes excess . segments
return cwd.create(i);
IRI base = factory.create(baseStr);
if ("file".equalsIgnoreCase(base.getScheme()))
return cwd.create(base).create(i);
return base.create(i);
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class NodeFunctions method iri.
public static Node iri(Node nv, String baseIRI) {
if (nv.isURI())
return nv;
if (nv.isBlank()) {
// Skolemization of blank nodes to IRIs : Don't ask, just don't ask.
String x = nv.getBlankNodeLabel();
return NodeFactory.createURI("_:" + x);
}
// Simple literal or xsd:string
String str = simpleLiteralOrXSDString(nv);
if (str == null)
throw new ExprEvalException("Can't make an IRI from " + nv);
IRI iri = null;
String iriStr = nv.getLiteralLexicalForm();
// Level of checking?
if (baseIRI != null) {
IRI base = iriFactory.create(baseIRI);
iri = base.create(iriStr);
} else
iri = iriFactory.create(iriStr);
if (!iri.isAbsolute())
throw new ExprEvalException("Relative IRI string: " + iriStr);
if (warningsForIRIs && iri.hasViolation(false)) {
String msg = "unknown violation from IRI library";
Iterator<Violation> iter = iri.violations(false);
if (iter.hasNext()) {
Violation viol = iter.next();
msg = viol.getShortMessage();
}
Log.warn(NodeFunctions.class, "Bad IRI: " + msg + ": " + iri);
}
return NodeFactory.createURI(iri.toString());
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class iri method main.
public static void main(String[] args) {
//IRIFactory iriFactory = IRIFactory.iriImplementation() ;
IRIFactory iriFactory = IRIResolver.iriFactory;
boolean first = true;
for (String iriStr : args) {
if (iriStr.startsWith("<") && iriStr.endsWith(">"))
iriStr = iriStr.substring(1, iriStr.length() - 1);
if (!first)
System.out.println();
first = false;
IRI iri = iriFactory.create(iriStr);
System.out.println(iriStr + " ==> " + iri);
if (iri.isRelative())
System.out.println("Relative: " + iri.isRelative());
Iterator<Violation> vIter = iri.violations(true);
for (; vIter.hasNext(); ) {
System.out.println(vIter.next().getShortMessage());
}
}
}
use of org.apache.jena.iri.IRI 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(argSkip))
skipOnBadTerm = true;
if (cmdLine.contains(argNoSkip))
skipOnBadTerm = false;
if (cmdLine.contains(argBase)) {
baseIRI = cmdLine.getValue(argBase);
IRI iri = IRIResolver.resolveIRI(baseIRI);
if (iri.hasViolation(false))
throw new CmdException("Bad base IRI: " + baseIRI);
if (!iri.isAbsolute())
throw new CmdException("Base IRI must be an absolute IRI: " + baseIRI);
}
if (cmdLine.contains(argStop))
stopOnBadTerm = true;
if (cmdLine.contains(argSink))
bitbucket = true;
if (cmdLine.contains(argRDFS)) {
try {
rdfsVocabFilename = cmdLine.getArg(argRDFS).getValue();
rdfsVocab = FileManager.get().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.iri.IRI in project jena by apache.
the class LangTurtleBase method directivePrefix.
protected final void directivePrefix() {
// Raw - unresolved prefix name.
if (!lookingAt(PREFIXED_NAME))
exception(peekToken(), "@prefix or PREFIX requires a prefix (found '" + peekToken() + "')");
if (peekToken().getImage2().length() != 0)
exception(peekToken(), "@prefix or PREFIX requires a prefix with no suffix (found '" + peekToken() + "')");
String prefix = peekToken().getImage();
nextToken();
if (!lookingAt(IRI))
exception(peekToken(), "@prefix requires an IRI (found '" + peekToken() + "')");
String iriStr = peekToken().getImage();
IRI iri = profile.makeIRI(iriStr, currLine, currCol);
prefixMap.add(prefix, iri);
emitPrefix(prefix, iri.toString());
nextToken();
}
Aggregations