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

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