Package org.apache.marmotta.kiwi.sail

Examples of org.apache.marmotta.kiwi.sail.KiWiSailConnection


    }

    @Override
    public NotifyingSailConnection getConnection() throws SailException {
        NotifyingSailConnection connection = super.getConnection();
        KiWiSailConnection root   = getRootConnection(connection);

        try {
            return new KiWiSparqlSailConnection(connection, new KiWiSparqlConnection(root.getDatabaseConnection(), root.getValueFactory()), root.getValueFactory());
        } catch (SQLException e) {
            throw new SailException(e);
        }
    }
View Full Code Here


        try {
            if(tripleIterator.hasNext()) {

                updateTaskStatus("deleting unsupported triples");
                SailConnection tc = store.getConnection();
                KiWiSailConnection ic = getWrappedConnection(tc);
                try {
                    tc.begin();
                    while(tripleIterator.hasNext()) {
                        ic.removeInferredStatement(tripleIterator.next());
                        count++;
                    }
                    log.debug("removed {} unsupported triples",count);
                    tc.commit();
                } catch(SailException ex) {
                    ic.rollback();
                    throw ex;
                } finally {
                    ic.close();
                }
            }
        } finally {
            Iterations.closeCloseable(tripleIterator);
View Full Code Here

        CloseableIteration<QueryResult, SQLException> bodyResult;

        KiWiReasoningConnection connection = persistence.getConnection();
        SailConnection     sail = store.getConnection();
        KiWiSailConnection isail = getWrappedConnection(sail);
        try {

            // if there are further patterns, evaluate them; if the matched pattern was the only pattern, then
            // simply take the match as binding
            if(body.size() > 0) {
                bodyResult = connection.query(body,match,null,null,true);
            } else if(match != null) {
                bodyResult = new SingletonIteration<QueryResult, SQLException>(match);
            } else {
                bodyResult = new EmptyIteration<QueryResult, SQLException>();
            }

            // construct triples out of the bindings and the rule heads
            long counter = 0;

            // initialise a new set of justifications
            Set<Justification> justifications = new HashSet<Justification>();

            sail.begin();
            while(bodyResult.hasNext()) {
                QueryResult row = bodyResult.next();
                Map<VariableField,KiWiNode> binding = row.getBindings();

                Resource subject = null;
                URI property = null;
                Value object;

                if(rule.getHead().getSubject() != null && rule.getHead().getSubject().isVariableField()) {
                    if(!binding.get(rule.getHead().getSubject()).isUriResource() && !binding.get(rule.getHead().getSubject()).isAnonymousResource()) {
                        log.info("cannot use value {} as subject, because it is not a resource",binding.get(rule.getHead().getSubject()));
                        continue;
                    }
                    subject = (KiWiResource)binding.get(rule.getHead().getSubject());
                } else if(rule.getHead().getSubject() != null && rule.getHead().getSubject().isResourceField()) {
                    subject = ((ResourceField)rule.getHead().getSubject()).getResource();
                } else
                    throw new IllegalArgumentException("Subject of rule head may only be a variable or a resource; rule: "+rule);

                if(rule.getHead().getProperty() != null && rule.getHead().getProperty().isVariableField()) {
                    if(!binding.get(rule.getHead().getProperty()).isUriResource()) {
                        log.info("cannot use value {} as property, because it is not a URI resource",binding.get(rule.getHead().getProperty()));
                        continue;
                    }
                    property = (KiWiUriResource)binding.get(rule.getHead().getProperty());
                } else if(rule.getHead().getProperty() != null && rule.getHead().getProperty().isResourceField()) {
                    property = (KiWiUriResource)((ResourceField)rule.getHead().getProperty()).getResource();
                } else
                    throw new IllegalArgumentException("Property of rule head may only be a variable or a resource; rule: "+rule);

                if(rule.getHead().getObject() != null && rule.getHead().getObject().isVariableField()) {
                    object = binding.get(rule.getHead().getObject());
                } else if(rule.getHead().getObject() != null && rule.getHead().getObject().isResourceField()) {
                    object = ((ResourceField)rule.getHead().getObject()).getResource();
                } else if(rule.getHead().getObject() != null && rule.getHead().getObject().isLiteralField()) {
                    object = ((LiteralField)rule.getHead().getObject()).getLiteral();
                } else
                    throw new IllegalArgumentException("Object of rule head may only be a variable, a literal, or a resource; rule: "+rule);


                KiWiTriple triple = isail.addInferredStatement(subject, property, object);

                Justification justification = new Justification();
                justification.setTriple(triple);
                justification.getSupportingRules().add(rule);
                justification.getSupportingTriples().addAll(row.getJustifications());
View Full Code Here

    }

    @Override
    public NotifyingSailConnection getConnection() throws SailException {
        NotifyingSailConnection connection = super.getConnection();
        KiWiSailConnection root   = getRootConnection(connection);

        try {
            return new KiWiSparqlSailConnection(connection, new KiWiSparqlConnection(root.getDatabaseConnection(), root.getValueFactory()), root.getValueFactory());
        } catch (SQLException e) {
            throw new SailException(e);
        }
    }
View Full Code Here

        try {
            if(tripleIterator.hasNext()) {

                updateTaskStatus("deleting unsupported triples");
                SailConnection tc = store.getConnection();
                KiWiSailConnection ic = getWrappedConnection(tc);
                try {
                    tc.begin();
                    while(tripleIterator.hasNext()) {
                        ic.removeInferredStatement(tripleIterator.next());
                        count++;
                    }
                    log.debug("removed {} unsupported triples",count);
                    tc.commit();
                } catch(SailException ex) {
                    ic.rollback();
                    throw ex;
                } finally {
                    ic.close();
                }
            }
        } finally {
            Iterations.closeCloseable(tripleIterator);
View Full Code Here

        CloseableIteration<QueryResult, SQLException> bodyResult;

        KiWiReasoningConnection connection = persistence.getConnection();
        SailConnection     sail = store.getConnection();
        KiWiSailConnection isail = getWrappedConnection(sail);
        try {

            // if there are further patterns, evaluate them; if the matched pattern was the only pattern, then
            // simply take the match as binding
            if(body.size() > 0) {
                bodyResult = connection.query(body,match,null,null,true);
            } else if(match != null) {
                bodyResult = new SingletonIteration<QueryResult, SQLException>(match);
            } else {
                bodyResult = new EmptyIteration<QueryResult, SQLException>();
            }

            // construct triples out of the bindings and the rule heads
            long counter = 0;

            // initialise a new set of justifications
            Set<Justification> justifications = new HashSet<Justification>();

            sail.begin();
            while(bodyResult.hasNext()) {
                QueryResult row = bodyResult.next();
                Map<VariableField,KiWiNode> binding = row.getBindings();

                Resource subject = null;
                URI property = null;
                Value object;

                if(rule.getHead().getSubject() != null && rule.getHead().getSubject().isVariableField()) {
                    if(!binding.get(rule.getHead().getSubject()).isUriResource() && !binding.get(rule.getHead().getSubject()).isAnonymousResource()) {
                        log.info("cannot use value {} as subject, because it is not a resource",binding.get(rule.getHead().getSubject()));
                        continue;
                    }
                    subject = (KiWiResource)binding.get(rule.getHead().getSubject());
                } else if(rule.getHead().getSubject() != null && rule.getHead().getSubject().isResourceField()) {
                    subject = ((ResourceField)rule.getHead().getSubject()).getResource();
                } else
                    throw new IllegalArgumentException("Subject of rule head may only be a variable or a resource; rule: "+rule);

                if(rule.getHead().getProperty() != null && rule.getHead().getProperty().isVariableField()) {
                    if(!binding.get(rule.getHead().getProperty()).isUriResource()) {
                        log.info("cannot use value {} as property, because it is not a URI resource",binding.get(rule.getHead().getProperty()));
                        continue;
                    }
                    property = (KiWiUriResource)binding.get(rule.getHead().getProperty());
                } else if(rule.getHead().getProperty() != null && rule.getHead().getProperty().isResourceField()) {
                    property = (KiWiUriResource)((ResourceField)rule.getHead().getProperty()).getResource();
                } else
                    throw new IllegalArgumentException("Property of rule head may only be a variable or a resource; rule: "+rule);

                if(rule.getHead().getObject() != null && rule.getHead().getObject().isVariableField()) {
                    object = binding.get(rule.getHead().getObject());
                } else if(rule.getHead().getObject() != null && rule.getHead().getObject().isResourceField()) {
                    object = ((ResourceField)rule.getHead().getObject()).getResource();
                } else if(rule.getHead().getObject() != null && rule.getHead().getObject().isLiteralField()) {
                    object = ((LiteralField)rule.getHead().getObject()).getLiteral();
                } else
                    throw new IllegalArgumentException("Object of rule head may only be a variable, a literal, or a resource; rule: "+rule);


                KiWiTriple triple = isail.addInferredStatement(subject, property, object);

                Justification justification = new Justification();
                justification.setTriple(triple);
                justification.getSupportingRules().add(rule);
                justification.getSupportingTriples().addAll(row.getJustifications());
View Full Code Here

        CloseableIteration<KiWiTriple,SQLException> tripleIterator = connection.listUnsupportedTriples();

        updateTaskStatus("deleting unsupported triples");
        SailConnection tc = store.getConnection();
        KiWiSailConnection ic = getWrappedConnection(tc);
        try {
            tc.begin();
            while(tripleIterator.hasNext()) {
                ic.removeInferredStatement(tripleIterator.next());
                count++;
            }
            log.debug("removed {} unsupported triples",count);
            tc.commit();
        } catch(SailException ex) {
            ic.rollback();
            throw ex;
        } finally {
            Iterations.closeCloseable(tripleIterator);
            ic.close();
        }
    }
View Full Code Here

        CloseableIteration<QueryResult, SQLException> bodyResult;

        try {
            KiWiReasoningConnection connection = persistence.getConnection();
            SailConnection     sail = store.getConnection();
            KiWiSailConnection isail = getWrappedConnection(sail);
            try {

                // if there are further patterns, evaluate them; if the matched pattern was the only pattern, then
                // simply take the match as binding
                if(body.size() > 0) {
                    bodyResult = connection.query(body,match,null,null,true);
                } else if(match != null) {
                    bodyResult = new SingletonIteration<QueryResult, SQLException>(match);
                } else {
                    bodyResult = new EmptyIteration<QueryResult, SQLException>();
                }

                // construct triples out of the bindings and the rule heads
                long counter = 0;

                // initialise a new set of justifications
                Set<Justification> justifications = new HashSet<Justification>();

                sail.begin();
                while(bodyResult.hasNext()) {
                    QueryResult row = bodyResult.next();
                    Map<VariableField,KiWiNode> binding = row.getBindings();

                    Resource subject = null;
                    URI property = null;
                    Value object;

                    if(rule.getHead().getSubject() != null && rule.getHead().getSubject().isVariableField()) {
                        if(!binding.get(rule.getHead().getSubject()).isUriResource() && !binding.get(rule.getHead().getSubject()).isAnonymousResource()) {
                            log.info("cannot use value {} as subject, because it is not a resource",binding.get(rule.getHead().getSubject()));
                            continue;
                        }
                        subject = (KiWiResource)binding.get(rule.getHead().getSubject());
                    } else if(rule.getHead().getSubject() != null && rule.getHead().getSubject().isResourceField()) {
                        subject = ((ResourceField)rule.getHead().getSubject()).getResource();
                    } else
                        throw new IllegalArgumentException("Subject of rule head may only be a variable or a resource; rule: "+rule);

                    if(rule.getHead().getProperty() != null && rule.getHead().getProperty().isVariableField()) {
                        if(!binding.get(rule.getHead().getProperty()).isUriResource()) {
                            log.info("cannot use value {} as property, because it is not a URI resource",binding.get(rule.getHead().getProperty()));
                            continue;
                        }
                        property = (KiWiUriResource)binding.get(rule.getHead().getProperty());
                    } else if(rule.getHead().getProperty() != null && rule.getHead().getProperty().isResourceField()) {
                        property = (KiWiUriResource)((ResourceField)rule.getHead().getProperty()).getResource();
                    } else
                        throw new IllegalArgumentException("Property of rule head may only be a variable or a resource; rule: "+rule);

                    if(rule.getHead().getObject() != null && rule.getHead().getObject().isVariableField()) {
                        object = binding.get(rule.getHead().getObject());
                    } else if(rule.getHead().getObject() != null && rule.getHead().getObject().isResourceField()) {
                        object = ((ResourceField)rule.getHead().getObject()).getResource();
                    } else if(rule.getHead().getObject() != null && rule.getHead().getObject().isLiteralField()) {
                        object = ((LiteralField)rule.getHead().getObject()).getLiteral();
                    } else
                        throw new IllegalArgumentException("Object of rule head may only be a variable, a literal, or a resource; rule: "+rule);


                    KiWiTriple triple = isail.addInferredStatement(subject, property, object);

                    Justification justification = new Justification();
                    justification.setTriple(triple);
                    justification.getSupportingRules().add(rule);
                    justification.getSupportingTriples().addAll(row.getJustifications());
View Full Code Here

TOP

Related Classes of org.apache.marmotta.kiwi.sail.KiWiSailConnection

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.