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

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

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

    https://github.com/apache/incubator-rya/pull/255#discussion_r160793851
  
    --- Diff: 
extras/rya.forwardchain/src/main/java/org/apache/rya/forwardchain/rule/Ruleset.java
 ---
    @@ -0,0 +1,166 @@
    +/*
    + * 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.
    + */
    +package org.apache.rya.forwardchain.rule;
    +
    +import java.util.Collection;
    +import java.util.HashSet;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.concurrent.ConcurrentHashMap;
    +
    +import org.apache.log4j.Logger;
    +import org.openrdf.query.algebra.StatementPattern;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * Represents a set of forward-chaining {@link Rule}s and their 
relationships.
    + */
    +public class Ruleset {
    +    private final Set<Rule> rules;
    +    private final Map<Rule, Set<Rule>> successors;
    +    private final Map<Rule, Set<Rule>> predecessors;
    +
    +    private final Logger logger = Logger.getLogger(this.getClass());
    +
    +    /**
    +     * Constructor. Takes in a set of rules and determines their 
dependencies.
    +     * @param rules The complete set of rules to process; should not be 
null.
    +     */
    +    public Ruleset(Collection<Rule> rules) {
    +        Preconditions.checkNotNull(rules);
    +        this.rules = new HashSet<>();
    +        for (Rule rule : rules) {
    +            if (rule != null) {
    +                this.rules.add(rule);
    +            }
    +        }
    +        successors = new ConcurrentHashMap<>();
    +        predecessors = new ConcurrentHashMap<>();
    +        // Build the dependency graph of all the rules, in both directions
    +        for (Rule rule : rules) {
    +            successors.put(rule, new HashSet<>());
    +            predecessors.put(rule, new HashSet<>());
    +        }
    +        for (Rule rule1 : rules) {
    +            for (Rule rule2 : rules) {
    +                if (canTrigger(rule1, rule2)) {
    --- End diff --
    
    Yep, that can happen. (Example from the tests is 
LUBM/suborganization-transitivity: `CONSTRUCT { ?this lubm:subOrganizationOf 
?parent } WHERE { ?this lubm:subOrganizationOf ?child . ?chlid 
lubm:subOrganizationOf ?parent }`). This means whenever such a rule produces 
results, we'll want to re-run it later to see if those results create further 
results. But we check for duplicates and make sure only to do this if the 
inferred triples are actually new, so it will terminate at some point. (If the 
rule could generate new entities, it could go on indefinitely -- that's why any 
rule that constructs bnodes is not supported.)


> Implement a forward-chaining rules engine (SPIN)
> ------------------------------------------------
>
>                 Key: RYA-417
>                 URL: https://issues.apache.org/jira/browse/RYA-417
>             Project: Rya
>          Issue Type: New Feature
>            Reporter: Jesse Hatfield
>            Assignee: Jesse Hatfield
>
> Implement a forward-chaining reasoner that:
> * Runs as a batch process
> * Operates on user-defined [SPIN|http://spinrdf.org] rules
> * Inserts derived information back into Rya
> * Iterates until no new information can be derived



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

Reply via email to