Package org.apache.marmotta.kiwi.reasoner.model.program

Examples of org.apache.marmotta.kiwi.reasoner.model.program.Program


    }

    @Test
    public void testStoreLoadProgram() throws Exception {
        KWRLProgramParserBase parser = new KWRLProgramParser(repository.getValueFactory(), this.getClass().getResourceAsStream("test-001.kwrl"));
        Program p = parser.parseProgram();
        p.setName("test-001");

        KiWiReasoningConnection connection = rpersistence.getConnection();
        try {
            // should not throw an exception and the program should have a database ID afterwards
            connection.storeProgram(p);
            connection.commit();

            Assert.assertNotNull("program did not get a database ID",p.getId());

            // load the program by name and check if it is equal to the original program
            Program p1 = connection.loadProgram("test-001");
            connection.commit();

            Assert.assertNotNull("load program by name: loaded program is null",p1);
            Assert.assertEquals("load program by name: loaded program differs from original",p,p1);

            // load the program by name and check if it is equal to the original program
            Program p2 = connection.loadProgram(p.getId());
            connection.commit();

            Assert.assertNotNull("load program by ID: loaded program is null",p2);
            Assert.assertEquals("load program by ID: loaded program differs from original",p,p2);
View Full Code Here


     * Test storing and then updating a program (by removing two rules)
     */
    @Test
    public void testUpdateProgram() throws Exception {
        KWRLProgramParserBase parser = new KWRLProgramParser(repository.getValueFactory(), this.getClass().getResourceAsStream("test-001.kwrl"));
        Program p = parser.parseProgram();
        p.setName("test-001");

        KiWiReasoningConnection connection = rpersistence.getConnection();
        try {
            // should not throw an exception and the program should have a database ID afterwards
            connection.storeProgram(p);
            connection.commit();

            Assert.assertNotNull("program did not get a database ID",p.getId());


            // load the program by name and check if it is equal to the original program
            Program p1 = connection.loadProgram("test-001");
            connection.commit();

            Assert.assertNotNull("load program by name: loaded program is null",p1);
            Assert.assertEquals("load program by name: loaded program differs from original",p,p1);


            PreparedStatement listRules1 = connection.getJDBCConnection().prepareStatement("SELECT count(*) AS count FROM reasoner_rules");
            ResultSet resultListRules1 = listRules1.executeQuery();

            Assert.assertTrue(resultListRules1.next());
            Assert.assertEquals(5, resultListRules1.getInt("count"));
            resultListRules1.close();
            connection.commit();



            // now remove two rules from the original and update the existing program
            p.getRules().remove(p.getRules().size()-1);
            p.getRules().remove(p.getRules().size()-1);
            p.addNamespace("myns","http://example.com/myns");

            connection.updateProgram(p);

            // load the program by name and check if it is equal to the original program
            Program p2 = connection.loadProgram(p.getName());
            connection.commit();

            Assert.assertNotNull("load program by name: loaded program is null",p2);
            Assert.assertEquals("load program by name: loaded program differs from original",p,p2);

View Full Code Here

        KiWiReasoningConnection connection = rpersistence.getConnection();
        try {
            List<Program> programs = new ArrayList<Program>();
            for(String name : new String[] {"test-001", "test-002", "test-003", "test-004"}) {
                KWRLProgramParserBase parser = new KWRLProgramParser(repository.getValueFactory(), this.getClass().getResourceAsStream(name+".kwrl"));
                Program p = parser.parseProgram();
                p.setName(name);
                connection.storeProgram(p);
                connection.commit();

                programs.add(p);
            }
View Full Code Here

    @GET
    @Path("/{name}")
    @Produces("text/plain")
    public Response getProgram(@PathParam("name") String name) {
        try {
            Program program = provider.getProgram(name);
            if (program == null) return Response.status(404).entity("Could not find program with name '" + name + "'").build();
            return Response.ok(program.toString()).build();
        } catch (Exception e) {
            return Response.serverError().entity(e.getMessage()).build();
        }
    }
View Full Code Here

        // store a program, very simple transitive and symmetric rules:
        // ($1 ex:property $2), ($2 ex:property $3) -> ($1 ex:property $3)
        // ($1 ex:symmetric $2) -> ($2 ex:symmetric $1)
        KWRLProgramParserBase parser = new KWRLProgramParser(repository.getValueFactory(), this.getClass().getResourceAsStream("simple.kwrl"));
        Program p = parser.parseProgram();
        p.setName("simple");

        KiWiReasoningConnection connection = rpersistence.getConnection();
        try {
            // should not throw an exception and the program should have a database ID afterwards
            connection.storeProgram(p);
View Full Code Here

            con.commit();


            // now we remove the rule2 (symmetric rule) from the program, update the program in the database and then
            // inform the reasoning engine about the removed rule
            Program p = rcon.loadProgram("simple");
            Rule removed = null;
            Iterator<Rule> it = p.getRules().iterator();
            while(it.hasNext()) {
                Rule r = it.next();
                if(r.getName().equals("rule2")) {
                    it.remove();
                    removed = r;
                }
            }
            Assert.assertNotNull("rule 2 not found in program", removed);
            rcon.updateProgram(p);
            rcon.commit();

            engine.notifyRemoveRules();

            // after removing, the inferred symmetric triple should be gone, but the others should still exist
            con.begin();
            Assert.assertTrue("expected inferred triple not found", con.hasStatement(a,t,c,true));
            Assert.assertTrue("expected inferred triple not found", con.hasStatement(b, t, d, true));
            Assert.assertFalse("unexpected inferred triple found", con.hasStatement(b, s, a, true));
            con.commit();


            // let's add the rule again to the program, update the database, and inform the engine
            p.getRules().add(removed);
            rcon.updateProgram(p);
            rcon.commit();

            engine.notifyAddRule(removed);
View Full Code Here

     * @throws SailException  in case the program already exists
     * @throws ParseException in case the program cannot be parsed
     */
    public void addProgram(String name, InputStream data) throws IOException, SailException, ParseException {
        KWRLProgramParserBase parser = new KWRLProgramParser(getValueFactory(), data);
        Program p = parser.parseProgram();
        p.setName(name);

        addProgram(p);
    }
View Full Code Here

     * @throws SailException  in case the program already exists
     * @throws ParseException in case the program cannot be parsed
     */
    public void updateProgram(String name, InputStream data) throws IOException, SailException, ParseException  {
        KWRLProgramParserBase parser = new KWRLProgramParser(getValueFactory(), data);
        Program p = parser.parseProgram();
        p.setName(name);

        updateProgram(p);
    }
View Full Code Here

        Set<Rule> removed = new HashSet<Rule>();
        try {
            KiWiReasoningConnection connection = persistence.getConnection();
            try {
                // load old version of program and calculate difference
                Program old = connection.loadProgram(program.getName());
                if(old != null) {
                    for(Rule r : old.getRules()) {
                        if(!program.getRules().contains(r)) {
                            removed.add(r);
                        }
                    }
                    for(Rule r : program.getRules()) {
                        if(!old.getRules().contains(r)) {
                            added.add(r);
                        }
                    }

                }
View Full Code Here

    public Program getProgram(String name) throws SailException {
        try {
            KiWiReasoningConnection connection = persistence.getConnection();
            try {
                // should not throw an exception and the program should have a database ID afterwards
                Program p = connection.loadProgram(name);
                connection.commit();
                return p;
            } finally {
                connection.close();
            }
View Full Code Here

TOP

Related Classes of org.apache.marmotta.kiwi.reasoner.model.program.Program

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.