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

Last change on this file since 655 was 655, checked in by pharms, 12 years ago
  • removed old copyright file header
  • Property svn:executable set to *
File size: 4.7 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 DefaultMouseClickReductionRule());
46        ruleIndex.add(new DefaultTextInputReductionRule());
47        ruleIndex.add(new DefaultEventTargetSequenceDetectionRule());
48        ruleIndex.add(new TrackBarSelectionDetectionRule(nodeEqualityRuleManager));
49        ruleIndex.add(new DefaultGuiEventSequenceDetectionRule());
50        ruleIndex.add(new DefaultIterationDetectionRule(nodeEqualityRuleManager));
51    }
52
53    /**
54     * returns true, if there is a rule that matches the current situation and if, therefore, a new
55     * temporal relationship has been added to the tree.
56     *
57     * @param parent
58     * @param newChild
59     * @return
60     */
61    public void applyRules(ITaskTreeNode        parent,
62                           ITaskTreeBuilder     builder,
63                           ITaskTreeNodeFactory nodeFactory,
64                           boolean              finalize)
65    {
66        applyRules(parent, builder, nodeFactory, finalize, "");
67    }
68
69    /**
70     * returns true, if there is a rule that matches the current situation and if, therefore, a new
71     * temporal relationship has been added to the tree.
72     *
73     * @param parent
74     * @param newChild
75     * @return
76     */
77    private int applyRules(ITaskTreeNode        parent,
78                           ITaskTreeBuilder     builder,
79                           ITaskTreeNodeFactory nodeFactory,
80                           boolean              finalize,
81                           String               logIndent)
82    {
83        LOG.info(logIndent + "applying rules for " + parent);
84
85        int noOfRuleApplications = 0;
86
87        for (TemporalRelationshipRule rule : ruleIndex) {
88            RuleApplicationResult result;
89            do {
90                // LOG.info(logIndent + "trying to apply rule " + rule + " on " + parent);
91                result = rule.apply(parent, builder, nodeFactory, finalize);
92
93                if ((result != null) &&
94                    (result.getRuleApplicationStatus() ==
95                     RuleApplicationStatus.RULE_APPLICATION_FINISHED))
96                {
97                    LOG.info(logIndent + "applied rule " + rule + " on " + parent);
98                    noOfRuleApplications++;
99
100                    for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) {
101                        noOfRuleApplications +=
102                            applyRules(newParent, builder, nodeFactory, true, logIndent + "  ");
103                    }
104                }
105            }
106            while ((result != null) &&
107                   (result.getRuleApplicationStatus() ==
108                    RuleApplicationStatus.RULE_APPLICATION_FINISHED));
109
110            if ((!finalize) &&
111                (result != null) &&
112                (result.getRuleApplicationStatus() ==
113                 RuleApplicationStatus.RULE_APPLICATION_FEASIBLE))
114            {
115                // in this case, don't go on applying rules, which should not be applied yet
116                break;
117            }
118        }
119
120        if (noOfRuleApplications <= 0) {
121            LOG.warning(logIndent + "no rules applied --> no temporal relationship generated");
122        }
123
124        return noOfRuleApplications;
125    }
126
127    /**
128   *
129   */
130    /*
131     * private void dumpTask(TaskTreeNode task, String indent) { System.err.print(indent);
132     * System.err.print(task); System.err.println(" ");
133     *
134     * if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { for (TaskTreeNode
135     * child : task.getChildren()) { dumpTask(child, indent + "  "); } } }
136     */
137
138}
Note: See TracBrowser for help on using the repository browser.