source: trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java @ 721

Last change on this file since 721 was 721, checked in by pharms, 12 years ago
  • moved condensing mouse clicks to a dedicated command
  • Property svn:executable set to *
File size: 4.5 KB
Line 
1package de.ugoe.cs.quest.tasktrees.temporalrelation;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.logging.Logger;
6
7import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager;
8import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder;
9import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode;
10import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory;
11
12/**
13 * TODO comment
14 *
15 * @version $Revision: $ $Date: 12.02.2012$
16 * @author 2012, last modified by $Author: patrick$
17 */
18public class TemporalRelationshipRuleManager {
19   
20    /** */
21    private static Logger LOG = Logger.getLogger(TemporalRelationshipRuleManager.class.getName());
22
23    /** */
24    private NodeEqualityRuleManager nodeEqualityRuleManager;
25
26    /** */
27    private List<TemporalRelationshipRule> ruleIndex = new ArrayList<TemporalRelationshipRule>();
28
29    /**
30     * TODO: comment
31     *
32     */
33    public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager) {
34        super();
35        this.nodeEqualityRuleManager = nodeEqualityRuleManager;
36    }
37
38    /**
39     * TODO: comment
40     *
41     */
42    public void init() {
43        LOG.info("initializing");
44
45        ruleIndex.add(new DefaultEventTargetSequenceDetectionRule());
46        ruleIndex.add(new TrackBarSelectionDetectionRule(nodeEqualityRuleManager));
47        ruleIndex.add(new DefaultGuiEventSequenceDetectionRule());
48        ruleIndex.add(new DefaultIterationDetectionRule(nodeEqualityRuleManager));
49    }
50
51    /**
52     * returns true, if there is a rule that matches the current situation and if, therefore, a new
53     * temporal relationship has been added to the tree.
54     *
55     * @param parent
56     * @param newChild
57     * @return
58     */
59    public void applyRules(ITaskTreeNode        parent,
60                           ITaskTreeBuilder     builder,
61                           ITaskTreeNodeFactory nodeFactory,
62                           boolean              finalize)
63    {
64        applyRules(parent, builder, nodeFactory, finalize, "");
65    }
66
67    /**
68     * returns true, if there is a rule that matches the current situation and if, therefore, a new
69     * temporal relationship has been added to the tree.
70     *
71     * @param parent
72     * @param newChild
73     * @return
74     */
75    private int applyRules(ITaskTreeNode        parent,
76                           ITaskTreeBuilder     builder,
77                           ITaskTreeNodeFactory nodeFactory,
78                           boolean              finalize,
79                           String               logIndent)
80    {
81        LOG.info(logIndent + "applying rules for " + parent);
82
83        int noOfRuleApplications = 0;
84
85        for (TemporalRelationshipRule rule : ruleIndex) {
86            RuleApplicationResult result;
87            do {
88                // LOG.info(logIndent + "trying to apply rule " + rule + " on " + parent);
89                result = rule.apply(parent, builder, nodeFactory, finalize);
90
91                if ((result != null) &&
92                    (result.getRuleApplicationStatus() ==
93                     RuleApplicationStatus.RULE_APPLICATION_FINISHED))
94                {
95                    LOG.info(logIndent + "applied rule " + rule + " on " + parent);
96                    noOfRuleApplications++;
97
98                    for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) {
99                        noOfRuleApplications +=
100                            applyRules(newParent, builder, nodeFactory, true, logIndent + "  ");
101                    }
102                }
103            }
104            while ((result != null) &&
105                   (result.getRuleApplicationStatus() ==
106                    RuleApplicationStatus.RULE_APPLICATION_FINISHED));
107
108            if ((!finalize) &&
109                (result != null) &&
110                (result.getRuleApplicationStatus() ==
111                 RuleApplicationStatus.RULE_APPLICATION_FEASIBLE))
112            {
113                // in this case, don't go on applying rules, which should not be applied yet
114                break;
115            }
116        }
117
118        if (noOfRuleApplications <= 0) {
119            LOG.warning(logIndent + "no rules applied --> no temporal relationship generated");
120        }
121
122        return noOfRuleApplications;
123    }
124
125    /**
126   *
127   */
128    /*
129     * private void dumpTask(TaskTreeNode task, String indent) { System.err.print(indent);
130     * System.err.print(task); System.err.println(" ");
131     *
132     * if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { for (TaskTreeNode
133     * child : task.getChildren()) { dumpTask(child, indent + "  "); } } }
134     */
135
136}
Note: See TracBrowser for help on using the repository browser.