Search in sources :

Example 46 with IRI

use of org.apache.jena.iri.IRI in project jena by apache.

the class BindingOutputStream method send.

@Override
public void send(Binding binding) {
    try {
        if (needOutputPMap) {
            if (pmap != null) {
                for (Map.Entry<String, IRI> e : pmap.getMapping().entrySet()) {
                    bw.write("PREFIX ");
                    bw.write(e.getKey());
                    bw.write(": <");
                    bw.write(e.getValue().toASCIIString());
                    bw.write("> .\n");
                }
            }
            needOutputPMap = false;
        }
        // Is the current VARS applicable?
        if (needVars(vars, binding)) {
            vars = Iter.toList(binding.vars());
            needOutputVars = true;
        }
        if (needOutputVars) {
            // No vars, empty binding.
            if (binding.size() == 0 && vars.size() == 0) {
                bw.write(".\n");
                needOutputVars = false;
                return;
            }
            bw.write("VARS");
            for (Var v2 : vars) {
                bw.write(" ?");
                bw.write(v2.getVarName());
            }
            bw.write(" .\n");
            needOutputVars = false;
        }
        for (Var v : vars) {
            Node n = binding.get(v);
            if (n == null) {
                bw.write("- ");
                continue;
            }
            // NodeFormatters should write safe bNode labels.
            nodeFormatter.format(bw, n);
            bw.write(" ");
        }
        bw.write(".\n");
    } catch (IOException ex) {
        throw new RiotException(ex);
    }
}
Also used : IRI(org.apache.jena.iri.IRI) RiotException(org.apache.jena.riot.RiotException) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) IOException(java.io.IOException) PrefixMap(org.apache.jena.riot.system.PrefixMap) Map(java.util.Map)

Example 47 with IRI

use of org.apache.jena.iri.IRI in project jena by apache.

the class FmtUtils method abbrevByBase.

public static String abbrevByBase(String uri, String base) {
    if (hasScheme(uri))
        return uri;
    IRI baseIRI = IRIResolver.iriFactory.construct(base);
    IRI rel = baseIRI.relativize(uri, relFlags);
    String r = rel.toString();
    return r;
}
Also used : IRI(org.apache.jena.iri.IRI)

Example 48 with IRI

use of org.apache.jena.iri.IRI in project jena by apache.

the class Main method check.

private void check(String string) {
    IRI iri = factory.create(string);
    if (iri.hasViolation(true)) {
        System.out.println("n: " + string);
        Iterator<Violation> it = iri.violations(true);
        while (it.hasNext()) {
            Violation v = it.next();
            System.out.println(v.getLongMessage());
        }
    } else {
        System.out.println("y: " + string);
    }
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI)

Example 49 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 50 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)

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