Search in sources :

Example 1 with IRIx

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("-");
}
Also used : PrintStream(java.io.PrintStream) Arrays(java.util.Arrays) LogCtl(org.apache.jena.atlas.logging.LogCtl) IRIException(org.apache.jena.irix.IRIException) IRIx(org.apache.jena.irix.IRIx) CmdException(org.apache.jena.cmd.CmdException) ShaclcParseException(org.apache.jena.shacl.compact.reader.ShaclcParseException) Function(java.util.function.Function) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) Graph(org.apache.jena.graph.Graph) ArgDecl(org.apache.jena.cmd.ArgDecl) ShLib(org.apache.jena.shacl.lib.ShLib) List(java.util.List) ShaclException(org.apache.jena.shacl.ShaclException) Stream(java.util.stream.Stream) StreamOps(org.apache.jena.atlas.lib.StreamOps) org.apache.jena.riot(org.apache.jena.riot) CmdGeneral(org.apache.jena.cmd.CmdGeneral) ShaclcWriter(org.apache.jena.shacl.compact.ShaclcWriter) ShaclParseException(org.apache.jena.shacl.parser.ShaclParseException) IRIs(org.apache.jena.irix.IRIs) Shapes(org.apache.jena.shacl.Shapes) JenaSystem(org.apache.jena.sys.JenaSystem) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) IRIException(org.apache.jena.irix.IRIException) CmdException(org.apache.jena.cmd.CmdException) PrintStream(java.io.PrintStream) Stream(java.util.stream.Stream) IRIx(org.apache.jena.irix.IRIx)

Example 2 with IRIx

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

Example 3 with IRIx

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");
    }
}
Also used : IRI(org.apache.jena.iri.IRI) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) Calendar(java.util.Calendar) ParameterizedSparqlString(org.apache.jena.query.ParameterizedSparqlString) URI(java.net.URI) BigDecimal(java.math.BigDecimal) URL(java.net.URL) IRIx(org.apache.jena.irix.IRIx) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 4 with IRIx

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);
}
Also used : LabelToNode(org.apache.jena.riot.lang.LabelToNode) IRIx(org.apache.jena.irix.IRIx) IRIxResolver(org.apache.jena.irix.IRIxResolver)

Example 5 with IRIx

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());
        }
    }
}
Also used : IRIException(org.apache.jena.irix.IRIException) RiotException(org.apache.jena.riot.RiotException) Lang(org.apache.jena.riot.Lang) IRIx(org.apache.jena.irix.IRIx) RiotException(org.apache.jena.riot.RiotException) IRIException(org.apache.jena.irix.IRIException)

Aggregations

IRIx (org.apache.jena.irix.IRIx)10 IRIException (org.apache.jena.irix.IRIException)5 PrintStream (java.io.PrintStream)1 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 URL (java.net.URL)1 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 List (java.util.List)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)1 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)1 StreamOps (org.apache.jena.atlas.lib.StreamOps)1 LogCtl (org.apache.jena.atlas.logging.LogCtl)1 ArgDecl (org.apache.jena.cmd.ArgDecl)1 CmdException (org.apache.jena.cmd.CmdException)1 CmdGeneral (org.apache.jena.cmd.CmdGeneral)1 Endpoint (org.apache.jena.fuseki.server.Endpoint)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1