[ 
https://issues.apache.org/jira/browse/RYA-292?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16128089#comment-16128089
 ] 

ASF GitHub Bot commented on RYA-292:
------------------------------------

Github user jessehatfield commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/206#discussion_r133323192
  
    --- Diff: 
sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java 
---
    @@ -467,126 +585,180 @@ private static void addParents(Vertex v, Set<URI> 
parents) {
             });
         }
     
    -    public boolean isSymmetricProperty(URI prop) {
    +    public boolean isSymmetricProperty(final URI prop) {
             return (symmetricPropertySet != null) && 
symmetricPropertySet.contains(prop);
         }
     
    -    public URI findInverseOf(URI prop) {
    +    public URI findInverseOf(final URI prop) {
             return (inverseOfMap != null) ? inverseOfMap.get(prop) : (null);
         }
     
    -    public boolean isTransitiveProperty(URI prop) {
    +    public boolean isTransitiveProperty(final URI prop) {
             return (transitivePropertySet != null) && 
transitivePropertySet.contains(prop);
         }
     
         /**
          * TODO: This chaining can be slow at query execution. the other 
option is to perform this in the query itself, but that will be constrained to 
how many levels we decide to go
          */
    -    public Set<Statement> findTransitiveProperty(Resource subj, URI prop, 
Value obj, Resource... contxts) throws InferenceEngineException {
    +    public Set<Statement> findTransitiveProperty(final Resource subj, 
final URI prop, final Value obj, final Resource... contxts) throws 
InferenceEngineException {
             if (transitivePropertySet.contains(prop)) {
    -            Set<Statement> sts = new HashSet();
    -            boolean goUp = subj == null;
    +            final Set<Statement> sts = new HashSet<>();
    +            final boolean goUp = subj == null;
                 chainTransitiveProperty(subj, prop, obj, (goUp) ? (obj) : 
(subj), sts, goUp, contxts);
                 return sts;
    -        } else
    +        } else {
                 return null;
    +        }
         }
     
         /**
          * TODO: This chaining can be slow at query execution. the other 
option is to perform this in the query itself, but that will be constrained to 
how many levels we decide to go
          */
    -    public Set<Resource> findSameAs(Resource value, Resource... contxts) 
throws InferenceEngineException{
    -           Set<Resource> sameAs = new HashSet<Resource>();
    -           sameAs.add(value);
    -           findSameAsChaining(value, sameAs, contxts);
    -           return sameAs;
    +    public Set<Resource> findSameAs(final Resource value, final 
Resource... contxts) throws InferenceEngineException{
    +        final Set<Resource> sameAs = new HashSet<Resource>();
    +        sameAs.add(value);
    +        findSameAsChaining(value, sameAs, contxts);
    +        return sameAs;
    +    }
    +
    +    public CloseableIteration<Statement, QueryEvaluationException> 
queryDao(final Resource subject, final URI predicate, final Value object, final 
Resource... contexts) throws QueryEvaluationException {
    +        return RyaDAOHelper.query(ryaDAO, subject, predicate, object, 
conf, contexts);
         }
     
         /**
          * TODO: This chaining can be slow at query execution. the other 
option is to perform this in the query itself, but that will be constrained to 
how many levels we decide to go
          */
    -    public void findSameAsChaining(Resource subj, Set<Resource> 
currentSameAs, Resource[] contxts) throws InferenceEngineException{
    +    public void findSameAsChaining(final Resource subj, final 
Set<Resource> currentSameAs, final Resource[] contxts) throws 
InferenceEngineException{
    +        CloseableIteration<Statement, QueryEvaluationException> subjIter = 
null;
    +        CloseableIteration<Statement, QueryEvaluationException> objIter = 
null;
             try {
    -                   CloseableIteration<Statement, QueryEvaluationException> 
subjIter = RyaDAOHelper.query(ryaDAO, subj, OWL.SAMEAS, null, conf, contxts);
    -                   while (subjIter.hasNext()){
    -                           Statement st = subjIter.next();
    -                           if (!currentSameAs.contains(st.getObject())){
    -                                   Resource castedObj = (Resource) 
st.getObject();
    -                                   currentSameAs.add(castedObj);
    -                                   findSameAsChaining(castedObj, 
currentSameAs, contxts);
    -                           }
    -                   }
    -                   subjIter.close();
    -                   CloseableIteration<Statement, QueryEvaluationException> 
objIter = RyaDAOHelper.query(ryaDAO, null, OWL.SAMEAS, subj, conf, contxts);
    -                   while (objIter.hasNext()){
    -                           Statement st = objIter.next();
    -                           if (!currentSameAs.contains(st.getSubject())){
    -                                   Resource sameAsSubj = st.getSubject();
    -                                   currentSameAs.add(sameAsSubj);
    -                                   findSameAsChaining(sameAsSubj, 
currentSameAs, contxts);
    -                           }
    -                   }
    -                   objIter.close();
    -           } catch (QueryEvaluationException e) {
    -                   throw new InferenceEngineException(e);
    -           }
    -
    -    }
    -
    -    protected void chainTransitiveProperty(Resource subj, URI prop, Value 
obj, Value core, Set<Statement> sts, boolean goUp, Resource[] contxts) throws 
InferenceEngineException {
    +            subjIter = queryDao(subj, OWL.SAMEAS, null, contxts);
    +            while (subjIter.hasNext()){
    +                final Statement st = subjIter.next();
    +                if (!currentSameAs.contains(st.getObject())){
    +                    final Resource castedObj = (Resource) st.getObject();
    +                    currentSameAs.add(castedObj);
    +                    findSameAsChaining(castedObj, currentSameAs, contxts);
    +                }
    +            }
    +            objIter = queryDao(null, OWL.SAMEAS, subj, contxts);
    +            while (objIter.hasNext()){
    +                final Statement st = objIter.next();
    +                if (!currentSameAs.contains(st.getSubject())){
    +                    final Resource sameAsSubj = st.getSubject();
    +                    currentSameAs.add(sameAsSubj);
    +                    findSameAsChaining(sameAsSubj, currentSameAs, contxts);
    +                }
    +            }
    +        } catch (final QueryEvaluationException e) {
    +            throw new InferenceEngineException(e);
    +        } finally {
    +            if (subjIter != null) {
    +                try {
    +                    subjIter.close();
    +                } catch (final QueryEvaluationException e) {
    +                    throw new InferenceEngineException("Error while 
closing \"same as chaining\" statement subject iterator.", e);
    +                }
    +            }
    +            if (objIter != null) {
    +                try {
    +                    objIter.close();
    +                } catch (final QueryEvaluationException e) {
    +                    throw new InferenceEngineException("Error while 
closing \"same as chaining\" statement object iterator.", e);
    +                }
    +            }
    +        }
    +    }
    +
    +    protected void chainTransitiveProperty(final Resource subj, final URI 
prop, final Value obj, final Value core, final Set<Statement> sts, final 
boolean goUp, final Resource[] contxts) throws InferenceEngineException {
    +        CloseableIteration<Statement, QueryEvaluationException> iter = 
null;
             try {
    -            CloseableIteration<Statement, QueryEvaluationException> iter = 
RyaDAOHelper.query(ryaDAO, subj, prop, obj, conf, contxts);
    +            iter = queryDao(subj, prop, obj, contxts);
                 while (iter.hasNext()) {
    -                Statement st = iter.next();
    +                final Statement st = iter.next();
                     sts.add(new StatementImpl((goUp) ? (st.getSubject()) : 
(Resource) (core), prop, (!goUp) ? (st.getObject()) : (core)));
                     if (goUp) {
                         chainTransitiveProperty(null, prop, st.getSubject(), 
core, sts, goUp, contxts);
                     } else {
                         chainTransitiveProperty((Resource) st.getObject(), 
prop, null, core, sts, goUp, contxts);
                     }
                 }
    -            iter.close();
    -        } catch (QueryEvaluationException e) {
    +        } catch (final QueryEvaluationException e) {
                 throw new InferenceEngineException(e);
    +        } finally {
    +            if (iter != null) {
    +                try {
    +                    iter.close();
    +                } catch (final QueryEvaluationException e) {
    +                    throw new InferenceEngineException("Error while 
closing \"chain transitive\" property statement iterator.", e);
    +                }
    +            }
             }
         }
     
         public boolean isInitialized() {
             return initialized;
         }
     
    -    public void setInitialized(boolean initialized) {
    +    public void setInitialized(final boolean initialized) {
             this.initialized = initialized;
         }
     
    -    public RyaDAO getRyaDAO() {
    +    public RyaDAO<?> getRyaDAO() {
             return ryaDAO;
         }
     
    -    public void setRyaDAO(RyaDAO ryaDAO) {
    +    public void setRyaDAO(final RyaDAO<?> ryaDAO) {
             this.ryaDAO = ryaDAO;
    +        this.ryaDaoQueryWrapper = new RyaDaoQueryWrapper(ryaDAO);
         }
     
         public RdfCloudTripleStoreConfiguration getConf() {
             return conf;
         }
     
    -    public void setConf(RdfCloudTripleStoreConfiguration conf) {
    +    public void setConf(final RdfCloudTripleStoreConfiguration conf) {
             this.conf = conf;
         }
     
         public Graph getSubClassOfGraph() {
             return subClassOfGraph;
         }
     
    +    /**
    +     * Returns all types for which the specified type is considered a 
subclassOf
    +     * based on the internal graph.
    +     * @param type the type {@link URI} to find what it is a subclassOf.
    +     * @return the {@link Set} of {@link URI} types that {@code type} is
    +     * considered a subclassOf. Returns an empty set if nothing was found.
    +     */
    +    public Set<URI> getSubClassOfTypes(final URI type) {
    --- End diff --
    
    I found both the name and description of this method slightly confusing -- 
wouldn't "superclasses", "parent classes", "parent types", or something be 
clearer than "types that the type is a subclass of"? (Admittedly it matches 
"subClassOfGraph" but at the logical level it seems strangely indirect.)


> Implement owl:intersectionOf inference
> --------------------------------------
>
>                 Key: RYA-292
>                 URL: https://issues.apache.org/jira/browse/RYA-292
>             Project: Rya
>          Issue Type: Sub-task
>          Components: sail
>            Reporter: Jesse Hatfield
>            Assignee: Eric White
>
> An *{{owl:intersectionOf}}* expression defines the set of resources who 
> belong to all of a particular set of classes.
> A basic implementation, if the ontology states that {{:Mother}} is the 
> intersection of {{:Parent}} and {{:Woman}}, should cause the inference engine 
> to:
> 1. Rewrite query patterns {{?x rdf:type :Mother}} (the intersection type) to 
> check for resources that have both types {{:Parent}} and {{:Woman}} (as well 
> as check for resources that are explicitly stated to be {{:Mother}} s)
> 2. Rewrite query patterns {{?y rdf:type :Parent}} (one of the intersecting 
> sets) to check for resources that are stated to be either {{:Mother}} or 
> {{:Parent}} , since belonging to the intersection type implies membership in 
> the component types. (Equivalent logic applies to {{Woman}} )



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to