Search in sources :

Example 41 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class RDFWriterFImpl method setBaseWriterClassName.

/**
     * Use RIOT to add custom RDF parsers. See
     * {@code RDFWriterRegistry.registerLang}
     * 
     * @deprecated Register with RIOT.
     */
@Deprecated
public static String setBaseWriterClassName(String lang, String className) {
    if (rewiredAlternative != null)
        Log.error(RDFWriterFImpl.class, "Rewired RDFWriterFImpl2 - configuration changes have no effect on writing");
    String oldClassName = currentEntry(lang);
    try {
        @SuppressWarnings("unchecked") Class<? extends RDFWriter> newClass = (Class<? extends RDFWriter>) Class.forName(className, false, Thread.currentThread().getContextClassLoader());
        custom.put(lang, newClass);
        return oldClassName;
    } catch (ClassNotFoundException e) {
        throw new ConfigException("Reader not found on classpath", e);
    } catch (Exception e) {
        throw new JenaException(e);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) RDFWriter(org.apache.jena.rdf.model.RDFWriter) ConfigException(org.apache.jena.shared.ConfigException) NoWriterForLangException(org.apache.jena.shared.NoWriterForLangException) JenaException(org.apache.jena.shared.JenaException) ConfigException(org.apache.jena.shared.ConfigException)

Example 42 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class JenaHandler method statement.

@Override
public void statement(AResource subj, AResource pred, AResource obj) {
    try {
        Triple t = JenaReader.convert(subj, pred, obj);
        graph.add(t);
    } catch (JenaException e) {
        errorHandler.error(e);
    }
}
Also used : Triple(org.apache.jena.graph.Triple) JenaException(org.apache.jena.shared.JenaException)

Example 43 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class WGReasonerTester method runTestDetailedResponse.

/**
		 * Run a single designated test.
		 * @param uri the uri of the test, as defined in the manifest file
		 * @param reasonerF the factory for the reasoner to be tested
		 * @param testcase the JUnit test case which is requesting this test
		 * @param configuration optional configuration information
		 * @return true if the test passes
		 * @throws IOException if one of the test files can't be found
		 * @throws JenaException if the test can't be found or fails internally
		 */
public int runTestDetailedResponse(String uri, ReasonerFactory reasonerF, TestCase testcase, Resource configuration) throws IOException {
    // Find the specification for the named test
    Resource test = testManifest.getResource(uri);
    testType = (Resource) test.getRequiredProperty(RDF.type).getObject();
    if (!(testType.equals(NegativeEntailmentTest) || testType.equals(PositiveEntailmentTest))) {
        throw new JenaException("Can't find test: " + uri);
    }
    Statement descriptionS = test.getProperty(descriptionP);
    String description = (descriptionS == null) ? "no description" : descriptionS.getObject().toString();
    String status = test.getRequiredProperty(statusP).getObject().toString();
    logger.debug("WG test " + test.getURI() + " - " + status);
    if (!status.equals("APPROVED")) {
        return NOT_APPLICABLE;
    }
    // Skip the test designed for only non-datatype aware processors
    for (String blockedTest : blockedTests) {
        if (test.getURI().equals(blockedTest)) {
            return NOT_APPLICABLE;
        }
    }
    // Load up the premise documents
    Model premises = ModelFactory.createDefaultModel();
    for (StmtIterator premisesI = test.listProperties(premiseDocumentP); premisesI.hasNext(); ) {
        premises.add(loadFile(premisesI.nextStatement().getObject().toString()));
    }
    // Load up the conclusions document
    Model conclusions = null;
    Resource conclusionsRes = (Resource) test.getRequiredProperty(conclusionDocumentP).getObject();
    Resource conclusionsType = (Resource) conclusionsRes.getRequiredProperty(RDF.type).getObject();
    if (!conclusionsType.equals(FalseDocument)) {
        conclusions = loadFile(conclusionsRes.toString());
    }
    // Construct the inferred graph
    Reasoner reasoner = reasonerF.create(configuration);
    InfGraph graph = reasoner.bind(premises.getGraph());
    Model result = ModelFactory.createModelForGraph(graph);
    // Check the results against the official conclusions
    boolean correct = true;
    int goodResult = PASS;
    boolean noisy = !(baseDir.equals(DEFAULT_BASE_DIR) || ARPTests.internet);
    if (testType.equals(PositiveEntailmentTest)) {
        if (conclusions == null) {
            // Check that the result is flagged as semantically invalid
            correct = !graph.validate().isValid();
            if (noisy) {
                System.out.println("PositiveEntailmentTest of FalseDoc " + test.getURI() + (correct ? " - OK" : " - FAIL"));
            }
        } else {
            correct = testConclusions(conclusions.getGraph(), result.getGraph());
            if (!graph.validate().isValid()) {
                correct = false;
            }
            if (noisy) {
                System.out.println("PositiveEntailmentTest " + test.getURI() + (correct ? " - OK" : " - FAIL"));
            }
        }
    } else {
        goodResult = INCOMPLETE;
        // A negative entailment check
        if (conclusions == null) {
            // Check the result is not flagged as invalid
            correct = graph.validate().isValid();
            if (noisy) {
                System.out.println("NegativentailmentTest of FalseDoc " + test.getURI() + (correct ? " - OK" : " - FAIL"));
            }
        } else {
            correct = !testConclusions(conclusions.getGraph(), result.getGraph());
            if (noisy) {
                System.out.println("NegativeEntailmentTest " + test.getURI() + (correct ? " - OK" : " - FAIL"));
            }
        }
    }
    // Debug output on failure
    if (!correct) {
        logger.debug("Premises: ");
        for (StmtIterator i = premises.listStatements(); i.hasNext(); ) {
            logger.debug("  - " + i.nextStatement());
        }
        logger.debug("Conclusions: ");
        if (conclusions != null) {
            for (StmtIterator i = conclusions.listStatements(); i.hasNext(); ) {
                logger.debug("  - " + i.nextStatement());
            }
        }
    }
    // Signal the results        
    if (testcase != null) {
        //            if ( !correct )
        //            {
        //                boolean b = testConclusions(conclusions.getGraph(), result.getGraph());
        //                System.out.println("**** actual") ;
        //                result.write(System.out, "TTL") ; 
        //                System.out.println("**** expected") ;
        //                conclusions.write(System.out, "TTL") ;
        //            }
        Assert.assertTrue("Test: " + test + "\n" + description, correct);
    }
    return correct ? goodResult : FAIL;
}
Also used : JenaException(org.apache.jena.shared.JenaException) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 44 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class Matcher method process.

private static boolean process(Map<Node, Node> results, Node dataNode, Node varNode, boolean bindAny) {
    if (!varNode.isVariable()) {
        if (!dataNode.sameValueAs(varNode))
            throw new JenaException("Internal error in Matcher");
        return true;
    }
    Node x = results.get(varNode);
    if (x != null)
        // Bound already.  Match?
        return dataNode.equals(x);
    // Infered, can be anything.
    if (!bindAny && !dataNode.isBlank())
        return false;
    results.put(varNode, dataNode);
    return true;
}
Also used : JenaException(org.apache.jena.shared.JenaException) Node(org.apache.jena.graph.Node)

Example 45 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class DatasetGraphCollection method add.

@Override
public void add(Quad quad) {
    Graph g = fetchGraph(quad.getGraph());
    if (g == null)
        throw new JenaException("No such graph: " + quad.getGraph());
    g.add(quad.asTriple());
}
Also used : JenaException(org.apache.jena.shared.JenaException) GraphUtils.triples2quadsDftGraph(org.apache.jena.sparql.util.graph.GraphUtils.triples2quadsDftGraph) Graph(org.apache.jena.graph.Graph)

Aggregations

JenaException (org.apache.jena.shared.JenaException)70 Model (org.apache.jena.rdf.model.Model)12 RDFReader (org.apache.jena.rdf.model.RDFReader)8 IOException (java.io.IOException)7 QueryException (org.apache.jena.query.QueryException)5 QueryParseException (org.apache.jena.query.QueryParseException)5 java.io (java.io)4 InputStream (java.io.InputStream)4 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 Graph (org.apache.jena.graph.Graph)4 ServletOutputStream (javax.servlet.ServletOutputStream)3 CmdException (jena.cmd.CmdException)3 AmbiguousSpecificTypeException (org.apache.jena.assembler.exceptions.AmbiguousSpecificTypeException)3 MediaType (org.apache.jena.atlas.web.MediaType)3 Triple (org.apache.jena.graph.Triple)3 BadDescriptionMultipleRootsException (org.apache.jena.shared.BadDescriptionMultipleRootsException)3 BadDescriptionNoRootException (org.apache.jena.shared.BadDescriptionNoRootException)3 ARQParser (org.apache.jena.sparql.lang.arq.ARQParser)3 FileNotFoundException (java.io.FileNotFoundException)2