Search in sources :

Example 1 with IRIException

use of org.apache.jena.irix.IRIException 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 IRIException

use of org.apache.jena.irix.IRIException in project jena by apache.

the class CmdLangParse method parseRIOT.

protected ParseRecord parseRIOT(RDFParserBuilder builder, String filename) {
    boolean checking = true;
    if (modLangParse.explicitChecking())
        checking = true;
    if (modLangParse.explicitNoChecking())
        checking = false;
    builder.checking(checking);
    if (checking)
        builder.strict(true);
    // Should use ErrorHandlerRecorder
    ErrorHandlerTracking errHandler = ErrorHandlerFactory.errorHandlerTracking(ErrorHandlerFactory.stdLogger, true, modLangParse.stopOnWarnings());
    builder.errorHandler(errHandler);
    // Make into a cmd flag. (input and output subflags?)
    // If input is "label, then output using NodeToLabel.createBNodeByLabelRaw() ;
    // else use NodeToLabel.createBNodeByLabel() ;
    // Also, as URI.
    final boolean labelsAsGiven = false;
    // labels = NodeToLabel.createBNodeByLabelEncoded() ;
    if (labelsAsGiven)
        builder.labelToNode(LabelToNode.createUseLabelAsGiven());
    StreamRDF s = outputStream;
    if (setup != null)
        s = RDFSFactory.streamRDFS(s, setup);
    StreamRDFCounting sink = StreamRDFLib.count(s);
    s = null;
    boolean successful = true;
    modTime.startTimer();
    RDFParser parser = builder.build();
    try {
        sink.start();
        parser.parse(sink);
        successful = true;
    } catch (RiotNotFoundException ex) {
        errHandler.error(ex.getMessage(), -1, -1);
        successful = false;
    } catch (RiotException ex) {
        successful = false;
    } catch (IRIException ex) {
        successful = false;
    }
    sink.finish();
    long x = modTime.endTimer();
    ParseRecord outcome = new ParseRecord(filename, successful, x, sink.countTriples(), sink.countQuads(), errHandler);
    return outcome;
}
Also used : IRIException(org.apache.jena.irix.IRIException) StreamRDF(org.apache.jena.riot.system.StreamRDF) StreamRDFCounting(org.apache.jena.riot.lang.StreamRDFCounting) ErrorHandlerTracking(org.apache.jena.riot.system.ErrorHandlerFactory.ErrorHandlerTracking)

Example 3 with IRIException

use of org.apache.jena.irix.IRIException 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)

Example 4 with IRIException

use of org.apache.jena.irix.IRIException in project jena by apache.

the class NodeFunctions method resolveCheckIRI.

// 
private static String resolveCheckIRI(String baseIRI, String iriStr) {
    try {
        IRIx iri = IRIx.create(iriStr);
        IRIx base = (baseIRI != null) ? IRIx.create(baseIRI) : IRIs.getSystemBase();
        IRIx result = base.resolve(iri);
        if (!result.isReference())
            throw new IRIException("Not suitable: " + result.str());
        return result.str();
    } catch (IRIException ex) {
        throw new ExprEvalException("Bad IRI: " + iriStr);
    }
}
Also used : IRIException(org.apache.jena.irix.IRIException) IRIx(org.apache.jena.irix.IRIx) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 5 with IRIException

use of org.apache.jena.irix.IRIException in project jena by apache.

the class FmtUtils method abbrevByBase.

public static String abbrevByBase(String uriStr, String base) {
    try {
        IRIx baseIRI = IRIx.create(base);
        if (baseIRI == null)
            return null;
        IRIx relInput = IRIx.create(uriStr);
        IRIx relativized = baseIRI.relativize(relInput);
        return (relativized == null) ? null : relativized.toString();
    } catch (IRIException ex) {
        return null;
    }
}
Also used : IRIException(org.apache.jena.irix.IRIException) IRIx(org.apache.jena.irix.IRIx)

Aggregations

IRIException (org.apache.jena.irix.IRIException)6 IRIx (org.apache.jena.irix.IRIx)5 PrintStream (java.io.PrintStream)1 Arrays (java.util.Arrays)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 IRIs (org.apache.jena.irix.IRIs)1 org.apache.jena.riot (org.apache.jena.riot)1 Lang (org.apache.jena.riot.Lang)1 RiotException (org.apache.jena.riot.RiotException)1 StreamRDFCounting (org.apache.jena.riot.lang.StreamRDFCounting)1