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