Search in sources :

Example 1 with ShexSchema

use of org.apache.jena.shex.ShexSchema in project jena by apache.

the class shex_parse method exec.

private void exec(String fn, boolean multipleFiles) {
    ShexSchema shapes;
    PrintStream out = System.out;
    PrintStream err = System.err;
    if (!FileOps.exists(fn)) {
        err.println(fn + " : File not found");
        return;
    }
    try {
        shapes = Shex.readSchema(fn);
    } catch (RiotException ex) {
        /*ErrorHandler logged this */
        return;
    } catch (ShexParseException ex) {
        if (multipleFiles)
            err.println(fn + " : ");
        err.println(ex.getMessage());
        return;
    }
    boolean outputByPrev = false;
    if (printText) {
        outputByPrev = printText(out, err, shapes);
    }
    if (printCompact) {
        if (outputByPrev) {
            out.println("- - - - - - - - ");
            outputByPrev = false;
        }
        outputByPrev = printCompact(out, err, shapes);
    }
    if (printRDF) {
        if (outputByPrev) {
            out.println("- - - - - - - - ");
            outputByPrev = false;
        }
        outputByPrev = printRDF(out, err, shapes);
    }
}
Also used : PrintStream(java.io.PrintStream) RiotException(org.apache.jena.riot.RiotException) ShexParseException(org.apache.jena.shex.parser.ShexParseException) ShexSchema(org.apache.jena.shex.ShexSchema)

Example 2 with ShexSchema

use of org.apache.jena.shex.ShexSchema in project jena by apache.

the class RunnerShexSyntax method shapesFromFileBadSyntax.

public static ShexSchema shapesFromFileBadSyntax(String filename) {
    String str = IO.readWholeFileAsUTF8(filename);
    InputStream input = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
    try {
        ShexSchema shapes = ShExC.parse(input, filename, null);
        return shapes;
    } catch (RuntimeException ex) {
        System.out.print("-- ");
        System.out.println(FileOps.basename(filename));
        if (ex.getMessage() != null)
            System.out.println(ex.getMessage());
        else
            System.out.println(ex.getClass().getSimpleName());
        System.out.println(str);
        throw ex;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ShexSchema(org.apache.jena.shex.ShexSchema)

Example 3 with ShexSchema

use of org.apache.jena.shex.ShexSchema in project jena by apache.

the class ShExC method parse$.

// --------
private static ShexSchema parse$(ShExJavacc parser, String sourceURI, String baseURI, Context context) {
    ParserProfile profile = new ParserProfileStd(RiotLib.factoryRDF(), ErrorHandlerFactory.errorHandlerStd, IRIxResolver.create(baseURI).build(), PrefixMapFactory.create(), context, false, false);
    // addStandardPrefixes(profile.getPrefixMap());
    sourceURI = IRILib.filenameToIRI(sourceURI);
    parser.setProfile(profile);
    // We don't use the StreamRDF.
    parser.setDest(StreamRDFLib.sinkNull());
    parser.setSourceAndBase(sourceURI, baseURI);
    try {
        parser.parseShapesStart();
        parser.UnitShapes();
        ShexSchema shapes = parser.parseShapesFinish();
        validatePhase2(shapes);
        return shapes;
    } catch (ParseException ex) {
        throw new ShexParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (TokenMgrError tErr) {
        int col = parser.token.endColumn;
        int line = parser.token.endLine;
        throw new ShexParseException(tErr.getMessage(), line, col);
    }
}
Also used : TokenMgrError(org.apache.jena.shex.parser.javacc.TokenMgrError) ParseException(org.apache.jena.shex.parser.javacc.ParseException) ShexSchema(org.apache.jena.shex.ShexSchema)

Example 4 with ShexSchema

use of org.apache.jena.shex.ShexSchema in project jena by apache.

the class RunnerShexBadSyntax method fileBadSyntax.

public static ShexSchema fileBadSyntax(String filename) {
    String str = IO.readWholeFileAsUTF8(filename);
    InputStream input = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
    try {
        ShexSchema shapes = ShExC.parse(input, filename, null);
        // Should not get here.
        System.out.print("-- ");
        System.out.println(FileOps.basename(filename));
        System.out.println(str);
        fail("Parsed negative syntax test");
        return shapes;
    } catch (ShexParseException ex) {
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ShexParseException(org.apache.jena.shex.parser.ShexParseException) ShexSchema(org.apache.jena.shex.ShexSchema)

Aggregations

ShexSchema (org.apache.jena.shex.ShexSchema)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ShexParseException (org.apache.jena.shex.parser.ShexParseException)2 PrintStream (java.io.PrintStream)1 RiotException (org.apache.jena.riot.RiotException)1 ParseException (org.apache.jena.shex.parser.javacc.ParseException)1 TokenMgrError (org.apache.jena.shex.parser.javacc.TokenMgrError)1