{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-rya/pulls/comments/135110039","pull_request_review_id":58486159,"id":135110039,"diff_hunk":"@@ -0,0 +1,81 @@\n+package org.apache.rya.rdftriplestore.inference;\n+\n+import org.apache.rya.api.RdfCloudTripleStoreConfiguration;\n+import org.openrdf.model.Resource;\n+import org.openrdf.model.URI;\n+import org.openrdf.model.vocabulary.RDF;\n+import org.openrdf.query.algebra.Extension;\n+import org.openrdf.query.algebra.ExtensionElem;\n+import org.openrdf.query.algebra.StatementPattern;\n+import org.openrdf.query.algebra.Var;\n+\n+/**\n+ * Expands the query tree to account for any relevant has-self class expressions\n+ * in the ontology known to the {@link InferenceEngine}.\n+ *\n+ * Only operates on {@link StatementPattern} nodes, and only those including a\n+ * defined type or defined predicate which is relevant to a has-self expression\n+ * in the ontology. When applicable, replaces the node with one or more\n+ * {@link InferUnion}s, one of whose leaves is the original StatementPattern.\n+ *\n+ * A has-self restriction defines the set of resources that are connected to\n+ * themselves by a property. If the ontology states that a type is a resource\n+ * that has a self referencing property, then the inference engine should:\n+ * <li>1. Rewrite queries of the from ?x rdf:type :T to find all resources\n+ * matching ?x :P ?x (as well as anything explicitly stated to be of type :T)\n+ * </li>\n+ * <li>2. Rewrite queries of the from :CONST :P ?o or ?subj :P :CONST to match\n+ * :CONST if :CONST is known to have the type :T\n+ * </li>\n+ */\n+public class HasSelfVisitor extends AbstractInferVisitor {\n+    private static final Var TYPE_VAR = new Var(\"p\", RDF.TYPE);\n+\n+    /**\n+     * Creates a new {@link HasSelfVisitor}, which is enabled by default.\n+     * @param conf The {@link RdfCloudTripleStoreConfiguration}.\n+     * @param inferenceEngine The InferenceEngine containing the relevant ontology.\n+     */\n+    public HasSelfVisitor(final RdfCloudTripleStoreConfiguration conf, final InferenceEngine inferenceEngine) {\n+        super(conf, inferenceEngine);\n+        include = conf.hasSelf();\n+    }\n+\n+    @Override\n+    protected void meetSP(final StatementPattern node) throws Exception {\n+        final URI pred = (URI) node.getPredicateVar().getValue();\n+        final Var obj = node.getObjectVar();\n+        //if originalSP like (?s rdf:type :C1):  require that C1 is defined, i.e. not a variable\n+        // node <- originalSP\n+        final StatementPattern clone = node.clone();\n+        if(pred.equals(RDF.TYPE) && obj.isConstant()) {\n+            //for property in getHasSelfImplyingType(C1):\n+            for (final URI property : inferenceEngine.getHasSelfImplyingType((URI) obj.getValue())) {\n+                //node <- InferUnion(node, StatementPattern(?s, property, ?s)).\n+                final InferUnion union = new InferUnion(clone, new StatementPattern(clone.getSubjectVar(), new Var(\"p\", property), clone.getSubjectVar()));\n+                //originalSP.replaceWith(node)\n+                node.replaceWith(union);\n+            }\n+        //else if originalSP like (s :p o):  where p is not a variable and at least one of s and o are variables\n+        } else if (node.getPredicateVar().isConstant()\n+               && (!node.getSubjectVar().isConstant() ||\n+                   !node.getObjectVar().isConstant())) {\n+            //for type in getHasSelfImplyingProperty(p):\n+            for (final Resource type : inferenceEngine.getHasSelfImplyingProperty(pred)) {\n+                final Extension extension;\n+                if(obj.isConstant()) { // subject is the variable\n+                    //Extension(StatementPattern(o, rdf:type, type), ExtensionElem(o, \"s\"))\n+                    extension = new Extension(new StatementPattern(obj, TYPE_VAR, obj),\n+                            new ExtensionElem(obj, \"o\"));","path":"sail/src/main/java/org/apache/rya/rdftriplestore/inference/HasSelfVisitor.java","position":69,"original_position":69,"commit_id":"b127d10b90397cc707280f51100bf2dbfdd043cc","original_commit_id":"b127d10b90397cc707280f51100bf2dbfdd043cc","user":{"login":"isper3at","id":12698945,"avatar_url":"https://avatars2.githubusercontent.com/u/12698945?v=4","gravatar_id":"","url":"https://api.github.com/users/isper3at","html_url":"https://github.com/isper3at","followers_url":"https://api.github.com/users/isper3at/followers","following_url":"https://api.github.com/users/isper3at/following{/other_user}","gists_url":"https://api.github.com/users/isper3at/gists{/gist_id}","starred_url":"https://api.github.com/users/isper3at/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isper3at/subscriptions","organizations_url":"https://api.github.com/users/isper3at/orgs","repos_url":"https://api.github.com/users/isper3at/repos","events_url":"https://api.github.com/users/isper3at/events{/privacy}","received_events_url":"https://api.github.com/users/isper3at/received_events","type":"User","site_admin":false},"body":"done","created_at":"2017-08-24T19:35:18Z","updated_at":"2017-08-24T19:35:18Z","html_url":"https://github.com/apache/incubator-rya/pull/209#discussion_r135110039","pull_request_url":"https://api.github.com/repos/apache/incubator-rya/pulls/209","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-rya/pulls/comments/135110039"},"html":{"href":"https://github.com/apache/incubator-rya/pull/209#discussion_r135110039"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-rya/pulls/209"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-rya/pulls/209","id":136077639,"html_url":"https://github.com/apache/incubator-rya/pull/209","diff_url":"https://github.com/apache/incubator-rya/pull/209.diff","patch_url":"https://github.com/apache/incubator-rya/pull/209.patch","issue_url":"https://api.github.com/repos/apache/incubator-rya/issues/209","number":209,"state":"open","locked":false,"title":"Rya 296 hasSelf","user":{"login":"isper3at","id":12698945,"avatar_url":"https://avatars2.githubusercontent.com/u/12698945?v=4","gravatar_id":"","url":"https://api.github.com/users/isper3at","html_url":"https://github.com/isper3at","followers_url":"https://api.github.com/users/isper3at/followers","following_url":"https://api.github.com/users/isper3at/following{/other_user}","gists_url":"https://api.github.com/users/isper3at/gists{/gist_id}","starred_url":"https://api.github.com/users/isper3at/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isper3at/subscriptions","organizations_url":"https://api.github.com/users/isper3at/orgs","repos_url":"https://api.github.com/users/isper3at/repos","events_url":"https://api.github.com/users/isper3at/events{/privacy}","received_events_url":"https://api.github.com/users/isper3at/received_events","type":"User","site_admin":false},"body":"## Description\r\n>What Changed?\r\n\r\nAdded rule for hasSelf to inferencing\r\n\r\n### Tests\r\n>Coverage?\r\n\r\ntests for hasSelf from type, inferring property\r\ntests for hasSelf from property with constant subject, inferring type\r\ntests for hasSelf from property with constant object, inferring type\r\n\r\n### Links\r\n[Jira](https://issues.apache.org/jira/browse/RYA-296)\r\n\r\n### Checklist\r\n- [ ] Code Review\r\n- [ ] Squash Commits\r\n\r\n#### People To Reivew\r\n@jessehatfield - give extra scrutiny towards the tests, I want to make sure it was all done correctly \r\n@meiercaleb \r\n@ejwhite922 \r\n","created_at":"2017-08-16T17:16:30Z","updated_at":"2017-08-24T19:35:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a891476c84dd09dea6c5fb7027b0e56895f78eb8","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-rya/pulls/209/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-rya/pulls/209/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-rya/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-rya/issues/209/comments","statuses_url":"https://api.github.com/repos/apache/incubator-rya/statuses/b127d10b90397cc707280f51100bf2dbfdd043cc","head":{"label":"isper3at:RYA-296","ref":"RYA-296","sha":"b127d10b90397cc707280f51100bf2dbfdd043cc","user":{"login":"isper3at","id":12698945,"avatar_url":"https://avatars2.githubusercontent.com/u/12698945?v=4","gravatar_id":"","url":"https://api.github.com/users/isper3at","html_url":"https://github.com/isper3at","followers_url":"https://api.github.com/users/isper3at/followers","following_url":"https://api.github.com/users/isper3at/following{/other_user}","gists_url":"https://api.github.com/users/isper3at/gists{/gist_id}","starred_url":"https://api.github.com/users/isper3at/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isper3at/subscriptions","organizations_url":"https://api.github.com/users/isper3at/orgs","repos_url":"https://api.github.com/users/isper3at/repos","events_url":"https://api.github.com/users/isper3at/events{/privacy}","received_events_url":"https://api.github.com/users/isper3at/received_events","type":"User","site_admin":false},"repo":{"id":54146858,"name":"incubator-rya","full_name":"isper3at/incubator-rya","owner":{"login":"isper3at","id":12698945,"avatar_url":"https://avatars2.githubusercontent.com/u/12698945?v=4","gravatar_id":"","url":"https://api.github.com/users/isper3at","html_url":"https://github.com/isper3at","followers_url":"https://api.github.com/users/isper3at/followers","following_url":"https://api.github.com/users/isper3at/following{/other_user}","gists_url":"https://api.github.com/users/isper3at/gists{/gist_id}","starred_url":"https://api.github.com/users/isper3at/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isper3at/subscriptions","organizations_url":"https://api.github.com/users/isper3at/orgs","repos_url":"https://api.github.com/users/isper3at/repos","events_url":"https://api.github.com/users/isper3at/events{/privacy}","received_events_url":"https://api.github.com/users/isper3at/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/isper3at/incubator-rya","description":"Mirror of Apache Rya (Incubating)","fork":true,"url":"https://api.github.com/repos/isper3at/incubator-rya","forks_url":"https://api.github.com/repos/isper3at/incubator-rya/forks","keys_url":"https://api.github.com/repos/isper3at/incubator-rya/keys{/key_id}","collaborators_url":"https://api.github.com/repos/isper3at/incubator-rya/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/isper3at/incubator-rya/teams","hooks_url":"https://api.github.com/repos/isper3at/incubator-rya/hooks","issue_events_url":"https://api.github.com/repos/isper3at/incubator-rya/issues/events{/number}","events_url":"https://api.github.com/repos/isper3at/incubator-rya/events","assignees_url":"https://api.github.com/repos/isper3at/incubator-rya/assignees{/user}","branches_url":"https://api.github.com/repos/isper3at/incubator-rya/branches{/branch}","tags_url":"https://api.github.com/repos/isper3at/incubator-rya/tags","blobs_url":"https://api.github.com/repos/isper3at/incubator-rya/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/isper3at/incubator-rya/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/isper3at/incubator-rya/git/refs{/sha}","trees_url":"https://api.github.com/repos/isper3at/incubator-rya/git/trees{/sha}","statuses_url":"https://api.github.com/repos/isper3at/incubator-rya/statuses/{sha}","languages_url":"https://api.github.com/repos/isper3at/incubator-rya/languages","stargazers_url":"https://api.github.com/repos/isper3at/incubator-rya/stargazers","contributors_url":"https://api.github.com/repos/isper3at/incubator-rya/contributors","subscribers_url":"https://api.github.com/repos/isper3at/incubator-rya/subscribers","subscription_url":"https://api.github.com/repos/isper3at/incubator-rya/subscription","commits_url":"https://api.github.com/repos/isper3at/incubator-rya/commits{/sha}","git_commits_url":"https://api.github.com/repos/isper3at/incubator-rya/git/commits{/sha}","comments_url":"https://api.github.com/repos/isper3at/incubator-rya/comments{/number}","issue_comment_url":"https://api.github.com/repos/isper3at/incubator-rya/issues/comments{/number}","contents_url":"https://api.github.com/repos/isper3at/incubator-rya/contents/{+path}","compare_url":"https://api.github.com/repos/isper3at/incubator-rya/compare/{base}...{head}","merges_url":"https://api.github.com/repos/isper3at/incubator-rya/merges","archive_url":"https://api.github.com/repos/isper3at/incubator-rya/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/isper3at/incubator-rya/downloads","issues_url":"https://api.github.com/repos/isper3at/incubator-rya/issues{/number}","pulls_url":"https://api.github.com/repos/isper3at/incubator-rya/pulls{/number}","milestones_url":"https://api.github.com/repos/isper3at/incubator-rya/milestones{/number}","notifications_url":"https://api.github.com/repos/isper3at/incubator-rya/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/isper3at/incubator-rya/labels{/name}","releases_url":"https://api.github.com/repos/isper3at/incubator-rya/releases{/id}","deployments_url":"https://api.github.com/repos/isper3at/incubator-rya/deployments","created_at":"2016-03-17T19:47:58Z","updated_at":"2016-03-17T19:48:00Z","pushed_at":"2017-08-24T17:51:08Z","git_url":"git://github.com/isper3at/incubator-rya.git","ssh_url":"git@github.com:isper3at/incubator-rya.git","clone_url":"https://github.com/isper3at/incubator-rya.git","svn_url":"https://github.com/isper3at/incubator-rya","homepage":null,"size":5902,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"2e88f1050b095ade37586562398cd02e162da639","user":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":43734923,"name":"incubator-rya","full_name":"apache/incubator-rya","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-rya","description":"Mirror of Apache Rya (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-rya","forks_url":"https://api.github.com/repos/apache/incubator-rya/forks","keys_url":"https://api.github.com/repos/apache/incubator-rya/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-rya/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-rya/teams","hooks_url":"https://api.github.com/repos/apache/incubator-rya/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-rya/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-rya/events","assignees_url":"https://api.github.com/repos/apache/incubator-rya/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-rya/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-rya/tags","blobs_url":"https://api.github.com/repos/apache/incubator-rya/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-rya/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-rya/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-rya/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-rya/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-rya/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-rya/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-rya/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-rya/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-rya/subscription","commits_url":"https://api.github.com/repos/apache/incubator-rya/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-rya/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-rya/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-rya/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-rya/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-rya/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-rya/merges","archive_url":"https://api.github.com/repos/apache/incubator-rya/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-rya/downloads","issues_url":"https://api.github.com/repos/apache/incubator-rya/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-rya/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-rya/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-rya/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-rya/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-rya/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-rya/deployments","created_at":"2015-10-06T07:00:05Z","updated_at":"2017-08-17T16:47:29Z","pushed_at":"2017-08-24T19:29:34Z","git_url":"git://github.com/apache/incubator-rya.git","ssh_url":"git@github.com:apache/incubator-rya.git","clone_url":"https://github.com/apache/incubator-rya.git","svn_url":"https://github.com/apache/incubator-rya","homepage":null,"size":5275,"stargazers_count":41,"watchers_count":41,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":46,"mirror_url":"git://git.apache.org/incubator-rya.git","open_issues_count":16,"forks":46,"open_issues":16,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-rya/pulls/209"},"html":{"href":"https://github.com/apache/incubator-rya/pull/209"},"issue":{"href":"https://api.github.com/repos/apache/incubator-rya/issues/209"},"comments":{"href":"https://api.github.com/repos/apache/incubator-rya/issues/209/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-rya/pulls/209/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-rya/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-rya/pulls/209/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-rya/statuses/b127d10b90397cc707280f51100bf2dbfdd043cc"}}}}
{"actor":{"display_login":"isper3at"}}