Search in sources :

Example 76 with Model

use of org.apache.jena.rdf.model.Model in project jena by apache.

the class rdflangtest method oneManifestEarl.

static void oneManifestEarl(String testManifest) {
    EarlReport report = new EarlReport(systemURI, name, version, homepage);
    FactoryTestRiot.report = report;
    TestSuite suite = FactoryTestRiot.make(testManifest, null, null);
    SimpleTestRunner.runSilent(suite);
    Model model = report.getModel();
    model.setNsPrefix("rdft", VocabLangRDF.getURI());
    model.setNsPrefix("turtletest", "http://www.w3.org/2013/TurtleTests/manifest.ttl#");
    insertMetaOld(report);
    RDFDataMgr.write(System.out, model, Lang.TURTLE);
}
Also used : TestSuite(junit.framework.TestSuite) Model(org.apache.jena.rdf.model.Model) EarlReport(org.apache.jena.sparql.junit.EarlReport)

Example 77 with Model

use of org.apache.jena.rdf.model.Model in project jena by apache.

the class TestGenericRuleReasonerConfig method testRuleLoadingWithOverridenBuiltins.

public void testRuleLoadingWithOverridenBuiltins() {
    List<Node> savedNode = new ArrayList<>();
    Builtin b = new BaseBuiltin() {

        @Override
        public String getName() {
            return "groo";
        }

        @Override
        public int getArgLength() {
            return 1;
        }

        @Override
        public void headAction(Node[] args, int length, RuleContext context) {
            savedNode.add(getArg(0, args, context));
        }
    };
    BuiltinRegistry r = new OverrideBuiltinRegistry(BuiltinRegistry.theRegistry);
    r.register(b);
    assertEquals(b, r.getImplementation("groo"));
    List<Rule> rules = new ArrayList<>();
    //
    // note that the head action does not appear to fire unless we put a triple in the head as well..  is
    // this expected?
    //
    rules.add(parseRule("[ (?instance rdf:type ?type) -> groo(?type) ]", r));
    GenericRuleReasoner article = new GenericRuleReasoner(rules);
    article.setMode(GenericRuleReasoner.FORWARD_RETE);
    Model input = ModelFactory.createDefaultModel();
    input.add(input.createResource(), RDF.type, input.createResource("http://example.com/Renegade"));
    InfModel output = ModelFactory.createInfModel(article, input);
    // not optional, inferences are not run if we don't trigger them
    output.size();
    assertEquals(1, savedNode.size());
    assertEquals("http://example.com/Renegade", savedNode.get(0).getURI());
}
Also used : Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) BaseBuiltin(org.apache.jena.reasoner.rulesys.builtins.BaseBuiltin) InfModel(org.apache.jena.rdf.model.InfModel) InfModel(org.apache.jena.rdf.model.InfModel) Model(org.apache.jena.rdf.model.Model) Rule.parseRule(org.apache.jena.reasoner.rulesys.Rule.parseRule) BaseBuiltin(org.apache.jena.reasoner.rulesys.builtins.BaseBuiltin)

Example 78 with Model

use of org.apache.jena.rdf.model.Model in project jena by apache.

the class TestXMLFeatures method doBadPropTest.

void doBadPropTest(String lg) throws IOException {
    Model m = createMemModel();
    m.add(m.createResource(), m.createProperty("http://example/", "foo#"), "foo");
    File file = File.createTempFile("rdf", ".xml");
    // file.deleteOnExit();
    FileOutputStream fwriter = new FileOutputStream(file);
    try {
        m.write(fwriter, lg);
        fwriter.close();
        fail("Writer did not detect bad property URI");
    } catch (InvalidPropertyURIException je) {
    // as required, so nowt to do.
    }
    file.delete();
}
Also used : Model(org.apache.jena.rdf.model.Model) InvalidPropertyURIException(org.apache.jena.shared.InvalidPropertyURIException)

Example 79 with Model

use of org.apache.jena.rdf.model.Model in project jena by apache.

the class XMLOutputTestBase method check.

protected void check(String filename, String encoding, String regexPresent, String regexAbsent, boolean errorExpected, Change code, String base) throws IOException {
    blockLogger();
    boolean errorsFound;
    Model m = createMemModel();
    try (InputStream in = new FileInputStream(filename)) {
        m.read(in, base);
    }
    @SuppressWarnings("resource") Writer sw;
    ByteArrayOutputStream bos = null;
    if (encoding == null)
        sw = new StringWriter();
    else {
        bos = new ByteArrayOutputStream();
        sw = new OutputStreamWriter(bos, encoding);
    }
    Properties p = (Properties) System.getProperties().clone();
    RDFWriter writer = m.getWriter(lang);
    code.modify(m, writer);
    writer.write(m, sw, base);
    sw.close();
    String contents;
    if (encoding == null)
        contents = sw.toString();
    else {
        contents = bos.toString(encoding);
    }
    try {
        Model m2 = createMemModel();
        m2.read(new StringReader(contents), base);
        assertTrue("Data got changed.", m.isIsomorphicWith(m2));
        if (regexPresent != null)
            assertTrue("Should find /" + regexPresent + "/", Pattern.compile(regexPresent, Pattern.DOTALL).matcher(contents).find());
        if (regexAbsent != null)
            assertTrue("Should not find /" + regexAbsent + "/", !Pattern.compile(regexAbsent, Pattern.DOTALL).matcher(contents).find());
        contents = null;
    } finally {
        errorsFound = unblockLogger();
        System.setProperties(p);
        if (contents != null) {
            System.err.println("===================");
            System.err.println("Offending content - " + toString());
            System.err.println("===================");
            System.err.println(contents);
            System.err.println("===================");
        }
    }
    assertEquals("Errors (not) detected.", errorExpected, errorsFound);
}
Also used : Properties(java.util.Properties) Model(org.apache.jena.rdf.model.Model) RDFWriter(org.apache.jena.rdf.model.RDFWriter) RDFWriter(org.apache.jena.rdf.model.RDFWriter) BaseXMLWriter(org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter)

Example 80 with Model

use of org.apache.jena.rdf.model.Model in project jena by apache.

the class sdbdump method execCmd.

@Override
protected void execCmd(List<String> args) {
    // This is a streamable syntax.
    String syntax = "N-QUADS";
    if (contains(argDeclSyntax))
        syntax = getArg(argDeclSyntax).getValue();
    Lang lang = RDFLanguages.nameToLang(syntax);
    try {
        if (modGraph.getGraphName() == null) {
            if (!RDFLanguages.isQuads(lang))
                cmdError("Not a 'quads' language (try 'N-Quads' or 'TriG')", true);
            Dataset dataset = getModStore().getDataset();
            RDFDataMgr.write(System.out, dataset, lang);
        } else {
            Model model = modGraph.getModel(getStore());
            RDFDataMgr.write(System.out, model, lang);
        }
    } catch (CmdException ex) {
        throw ex;
    } catch (Exception ex) {
        System.err.println("Exception: " + ex + " :: " + ex.getMessage());
        ex.printStackTrace(System.err);
    }
}
Also used : CmdException(jena.cmd.CmdException) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Lang(org.apache.jena.riot.Lang) CmdException(jena.cmd.CmdException)

Aggregations

Model (org.apache.jena.rdf.model.Model)444 Test (org.junit.Test)177 BaseTest (org.apache.jena.atlas.junit.BaseTest)96 Resource (org.apache.jena.rdf.model.Resource)87 StringReader (java.io.StringReader)43 Dataset (org.apache.jena.query.Dataset)31 RDFReader (org.apache.jena.rdf.model.RDFReader)30 Property (org.apache.jena.rdf.model.Property)24 DatasetAccessor (org.apache.jena.query.DatasetAccessor)20 InfModel (org.apache.jena.rdf.model.InfModel)20 Node (org.apache.jena.graph.Node)19 Statement (org.apache.jena.rdf.model.Statement)18 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)15 Reader (java.io.Reader)14 JsonString (org.apache.jena.atlas.json.JsonString)14 AbstractFusekiTest (org.apache.jena.fuseki.AbstractFusekiTest)14 FusekiTest (org.apache.jena.fuseki.FusekiTest)14 Graph (org.apache.jena.graph.Graph)14 JenaException (org.apache.jena.shared.JenaException)14 Triple (org.apache.jena.graph.Triple)13