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

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