You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@rya.apache.org by jessehatfield <gi...@git.apache.org> on 2017/08/04 17:47:11 UTC

[GitHub] incubator-rya pull request #197: RYA-298, RYA-299 Domain/range inference.

GitHub user jessehatfield opened a pull request:

    https://github.com/apache/incubator-rya/pull/197

    RYA-298, RYA-299 Domain/range inference.

    <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
    
      http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
    ## Description
    InferenceEngine: Added a method to query for and infer domain/range schema, incorporating subclass, subproperty, and inverse property information to compute the closure. Extended graph traversal methods to allow traversal in each direction (findParents has the same behavior as before, but is joined by findChildren, both of which call findConnections with a direction parameter).
    
    DomainRangeVisitor: New class rewrites queries for members of a specific defined type to check for domain and range implications as well. Applies to StatementPatterns of the form <?s a Class>, where Class is not a variable, and produces (if domain and/or range exist for that type) a union which includes the original pattern as well.
    
    RdfCloudTripleStoreConnection: Call the DomainRangeVisitor if inference is enabled. Called at the beginning of the sequence of visitors because the original statement is preserved as one branch of the union, so this won't stop other inference rules from being applied in that branch. However, as with the other visitors, the inferred branches of the unions won't be expanded. This means we won't infer the type by applying multiple rules at once (regardless of order of visitor calls), but we will have a union of alternative ways of inferring the type.
    
    ### Tests
    Added tests to: Verify that InferenceEngine loads and infers expected schema (taking into account class hierarchy, property graph, and inverse properties); verify that the visitor produces the expected query tree; and verify that a type query returns the expected results given an ontology.
    
    ### Links
    [RYA-298](https://issues.apache.org/jira/browse/RYA-298)
    [RYA-299](https://issues.apache.org/jira/browse/RYA-299)
    
    ### Checklist
    - [ ] Code Review
    - [ ] Squash Commits
    
    #### People To Reivew
    @meiercaleb 
    @ejwhite922 
    @pujav65
    @amihalik 

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/jessehatfield/incubator-rya RYA-298-299-domain-range-inference

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-rya/pull/197.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #197
    
----
commit 36d8f752da4a3c5e8d7ebbbcb790ec0117c790ea
Author: Jesse Hatfield <je...@parsons.com>
Date:   2017-08-04T17:05:45Z

    RYA-298, RYA-299 Domain/range inference.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya issue #197: RYA-298, RYA-299 Domain/range inference.

Posted by jessehatfield <gi...@git.apache.org>.
Github user jessehatfield commented on the issue:

    https://github.com/apache/incubator-rya/pull/197
  
    Note that the results of a domain/range query can be huge, and hugely redundant, because: A) there can be many predicates inferring the same type, and we'll query for all of them; and B) even for one predicate, we'll generate a result for each instance of that predicate even if we end up inferring the same resource's type many times. (E.g. in a LUBM dataset, querying for all universities will give you the same solution of :University0 for every triple <?student lubm:degreeFrom :University0>.) Wrapping the query in a Distinct introduces its own computational costs, so the decision to do that is left to the caller.
    
    Some optimizations could be possible if we knew we were starting with a relatively small set of candidates: Asking "does this have the type?" for each candidate could be faster than asking for all the ways of inferring the type. But that optimization is more general than just domain and range queries (and could potentially be generalized even further), so I'd consider something like that outside the scope of this problem.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya issue #197: RYA-298, RYA-299 Domain/range inference.

Posted by jessehatfield <gi...@git.apache.org>.
Github user jessehatfield commented on the issue:

    https://github.com/apache/incubator-rya/pull/197
  
    Updated. At some point it would be nice to make a pass over the inference engine for thread-safety across both the old and new logic, maybe once the currently-pending extensions are added.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya issue #197: RYA-298, RYA-299 Domain/range inference.

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:

    https://github.com/apache/incubator-rya/pull/197
  
    
    Refer to this link for build results (access rights to CI server needed): 
    https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/355/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya pull request #197: RYA-298, RYA-299 Domain/range inference.

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/197#discussion_r133814275
  
    --- Diff: sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java ---
    @@ -73,6 +74,8 @@
         private Set<URI> transitivePropertySet;
         private Map<Resource, Map<URI, Value>> hasValueByType;
         private Map<URI, Map<Resource, Value>> hasValueByProperty;
    +    private Map<URI, Set<URI>> domainByType;
    --- End diff --
    
    Can one of you create a ticket for this?  The solution of this is probably not within the scope of this task, but this should be resolved.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya pull request #197: RYA-298, RYA-299 Domain/range inference.

Posted by ejwhite922 <gi...@git.apache.org>.
Github user ejwhite922 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/197#discussion_r132466657
  
    --- Diff: sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java ---
    @@ -73,6 +74,8 @@
         private Set<URI> transitivePropertySet;
         private Map<Resource, Map<URI, Value>> hasValueByType;
         private Map<URI, Map<Resource, Value>> hasValueByProperty;
    +    private Map<URI, Set<URI>> domainByType;
    --- End diff --
    
    We should probably start using ConcurrentHashMaps for all these maps.  The InferenceEngine is not very thread safe right now.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya pull request #197: RYA-298, RYA-299 Domain/range inference.

Posted by ejwhite922 <gi...@git.apache.org>.
Github user ejwhite922 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/197#discussion_r132466881
  
    --- Diff: sail/src/test/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitorTest.java ---
    @@ -0,0 +1,140 @@
    +package org.apache.rya.rdftriplestore.inference;
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +import static org.mockito.Mockito.mock;
    +import static org.mockito.Mockito.when;
    +
    +import java.util.HashSet;
    +import java.util.Set;
    +import java.util.Stack;
    +
    +import org.apache.rya.accumulo.AccumuloRdfConfiguration;
    +import org.apache.rya.rdftriplestore.utils.FixedStatementPattern;
    +import org.junit.Assert;
    +import org.junit.Test;
    +import org.openrdf.model.Resource;
    +import org.openrdf.model.Statement;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.impl.ValueFactoryImpl;
    +import org.openrdf.model.vocabulary.RDF;
    +import org.openrdf.model.vocabulary.RDFS;
    +import org.openrdf.query.algebra.Join;
    +import org.openrdf.query.algebra.Projection;
    +import org.openrdf.query.algebra.ProjectionElem;
    +import org.openrdf.query.algebra.ProjectionElemList;
    +import org.openrdf.query.algebra.StatementPattern;
    +import org.openrdf.query.algebra.TupleExpr;
    +import org.openrdf.query.algebra.Union;
    +import org.openrdf.query.algebra.Var;
    +
    +public class DomainRangeVisitorTest {
    +    private final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    +    private final ValueFactory vf = new ValueFactoryImpl();
    +    private final URI person = vf.createURI("lubm:Person");
    --- End diff --
    
    These URI's can be made static final


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya pull request #197: RYA-298, RYA-299 Domain/range inference.

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/197#discussion_r133815357
  
    --- Diff: sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java ---
    @@ -363,13 +367,173 @@ public void refreshGraph() throws InferenceEngineException {
                 	}
                 }
     
    +            refreshDomainRange();
    +
                 refreshPropertyRestrictions();
     
             } catch (QueryEvaluationException e) {
                 throw new InferenceEngineException(e);
             }
         }
     
    +    /**
    +     * Queries domain and range information, then populates the inference engine with direct
    +     * domain/range relations and any that can be inferred from the subclass graph, subproperty
    +     * graph, and inverse property map. Should be called after that class and property information
    +     * has been refreshed.
    +     *
    +     * Computes indirect domain/range:
    +     *  - If p1 has domain c, and p2 is a subproperty of p1, then p2 also has domain c.
    +     *  - If p1 has range c, and p2 is a subproperty of p1, then p2 also has range c.
    +     *  - If p1 has domain c, and p2 is the inverse of p1, then p2 has range c.
    +     *  - If p1 has range c, and p2 is the inverse of p1, then p2 has domain c.
    +     *  - If p has domain c1, and c1 is a subclass of c2, then p also has domain c2.
    +     *  - If p has range c1, and c1 is a subclass of c2, then p also has range c2.
    +     * @throws QueryEvaluationException
    +     */
    +    private void refreshDomainRange() throws QueryEvaluationException {
    +        Map<URI, Set<URI>> domainByTypePartial = new ConcurrentHashMap<>();
    +        Map<URI, Set<URI>> rangeByTypePartial = new ConcurrentHashMap<>();
    +        // First, populate domain and range based on direct domain/range triples.
    +        CloseableIteration<Statement, QueryEvaluationException> iter = RyaDAOHelper.query(ryaDAO, null, RDFS.DOMAIN, null, conf);
    +        try {
    +            while (iter.hasNext()) {
    --- End diff --
    
    It seems like this map building loop is extremely prevalent in the refresh methods for all of the property restrictions.  Is there any way to pull this logic out into a buildRestrictionMap(...) method that takes in the map that is being updated/created/refreshed, and/or the iterator/property URI used to create the iterator?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya pull request #197: RYA-298, RYA-299 Domain/range inference.

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-rya/pull/197


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya pull request #197: RYA-298, RYA-299 Domain/range inference.

Posted by ejwhite922 <gi...@git.apache.org>.
Github user ejwhite922 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/197#discussion_r132463450
  
    --- Diff: sail/src/test/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitorTest.java ---
    @@ -0,0 +1,140 @@
    +package org.apache.rya.rdftriplestore.inference;
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +import static org.mockito.Mockito.mock;
    +import static org.mockito.Mockito.when;
    +
    +import java.util.HashSet;
    +import java.util.Set;
    +import java.util.Stack;
    +
    +import org.apache.rya.accumulo.AccumuloRdfConfiguration;
    +import org.apache.rya.rdftriplestore.utils.FixedStatementPattern;
    +import org.junit.Assert;
    +import org.junit.Test;
    +import org.openrdf.model.Resource;
    +import org.openrdf.model.Statement;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.impl.ValueFactoryImpl;
    +import org.openrdf.model.vocabulary.RDF;
    +import org.openrdf.model.vocabulary.RDFS;
    +import org.openrdf.query.algebra.Join;
    +import org.openrdf.query.algebra.Projection;
    +import org.openrdf.query.algebra.ProjectionElem;
    +import org.openrdf.query.algebra.ProjectionElemList;
    +import org.openrdf.query.algebra.StatementPattern;
    +import org.openrdf.query.algebra.TupleExpr;
    +import org.openrdf.query.algebra.Union;
    +import org.openrdf.query.algebra.Var;
    +
    +public class DomainRangeVisitorTest {
    +    private final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    +    private final ValueFactory vf = new ValueFactoryImpl();
    +    private final URI person = vf.createURI("lubm:Person");
    +    private final URI advisor = vf.createURI("lubm:advisor");
    +    private final URI takesCourse = vf.createURI("lubm:takesCourse");
    +
    +    @Test
    +    public void testRewriteTypePattern() throws Exception {
    +        final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
    +        final Set<URI> domainPredicates = new HashSet<>();
    +        final Set<URI> rangePredicates = new HashSet<>();
    +        domainPredicates.add(advisor);
    +        domainPredicates.add(takesCourse);
    +        rangePredicates.add(advisor);
    +        when(inferenceEngine.getPropertiesWithDomain(person)).thenReturn(domainPredicates);
    +        when(inferenceEngine.getPropertiesWithRange(person)).thenReturn(rangePredicates);
    +        final Var subjVar = new Var("s");
    +        final StatementPattern originalSP = new StatementPattern(subjVar, new Var("p", RDF.TYPE), new Var("o", person));
    +        final Projection query = new Projection(originalSP, new ProjectionElemList(new ProjectionElem("s", "subject")));
    +        new DomainRangeVisitor(conf, inferenceEngine).meet(query);
    --- End diff --
    
    Should this be query.visit(new DomainRangeVisitor(conf, inferenceEngine))?  Or does it not matter?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya issue #197: RYA-298, RYA-299 Domain/range inference.

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:

    https://github.com/apache/incubator-rya/pull/197
  
    
    Refer to this link for build results (access rights to CI server needed): 
    https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/408/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-rya issue #197: RYA-298, RYA-299 Domain/range inference.

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:

    https://github.com/apache/incubator-rya/pull/197
  
    
    Refer to this link for build results (access rights to CI server needed): 
    https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/389/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---