Search in sources :

Example 41 with IRI

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);
}
Also used : IRI(org.apache.jena.iri.IRI)

Example 42 with IRI

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());
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 43 with IRI

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());
        }
    }
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI) IRIFactory(org.apache.jena.iri.IRIFactory)

Example 44 with IRI

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());
        }
    }
}
Also used : IRI(org.apache.jena.iri.IRI) RiotException(org.apache.jena.riot.RiotException) CmdException(jena.cmd.CmdException) Lang(org.apache.jena.riot.Lang) RiotException(org.apache.jena.riot.RiotException) CmdException(jena.cmd.CmdException)

Example 45 with IRI

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();
}
Also used : IRI(org.apache.jena.riot.tokens.TokenType.IRI) IRI(org.apache.jena.iri.IRI)

Aggregations

IRI (org.apache.jena.iri.IRI)51 Violation (org.apache.jena.iri.Violation)12 IRIFactory (org.apache.jena.iri.IRIFactory)9 IOException (java.io.IOException)3 Node (org.apache.jena.graph.Node)3 Test (org.junit.Test)3 PrintStream (java.io.PrintStream)2 MalformedURLException (java.net.MalformedURLException)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 Lang (org.apache.jena.riot.Lang)2 RiotException (org.apache.jena.riot.RiotException)2 CheckerIRI (org.apache.jena.riot.checker.CheckerIRI)2 IRI (org.apache.jena.riot.tokens.TokenType.IRI)2 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 URL (java.net.URL)1 Date (java.sql.Date)1 SQLException (java.sql.SQLException)1 Time (java.sql.Time)1