Changeset 557 for trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation
- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- Location:
- trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation
- Files:
-
- 8 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultEventTargetSequenceDetectionRule.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;12 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 //------------------------------------------------------------------------------------------------- 25 public class DefaultGUIElementSequenceDetectionRule implements TemporalRelationshipRule 26 { 22 public class DefaultEventTargetSequenceDetectionRule implements TemporalRelationshipRule { 27 23 28 //----------------------------------------------------------------------------------------------- 29 /* (non-Javadoc) 30 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 31 */ 32 //----------------------------------------------------------------------------------------------- 33 @Override 34 public RuleApplicationResult apply(TaskTreeNode parent, 35 TaskTreeBuilder builder, 36 TaskTreeNodeFactory nodeFactory, 37 boolean finalize) 38 { 39 if (!(parent instanceof Sequence)) 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 28 * TaskTreeBuilder, TaskTreeNodeFactory) 29 */ 30 @Override 31 public RuleApplicationResult apply(ITaskTreeNode parent, 32 ITaskTreeBuilder builder, 33 ITaskTreeNodeFactory nodeFactory, 34 boolean finalize) 40 35 { 41 return null; 36 if (!(parent instanceof ISequence)) { 37 return null; 38 } 39 40 RuleApplicationResult result = new RuleApplicationResult(); 41 42 IEventTarget currentEventTarget = null; 43 int startingIndex = -1; 44 45 int index = 0; 46 while (index < parent.getChildren().size()) { 47 ITaskTreeNode child = parent.getChildren().get(index); 48 49 IEventTarget eventTarget = determineEventTarget(child); 50 51 if ((eventTarget != null) && (!eventTarget.equals(currentEventTarget))) { 52 if (startingIndex < 0) { 53 startingIndex = index; 54 currentEventTarget = eventTarget; 55 } 56 else { 57 handleEventTargetSequence(parent, startingIndex, index - 1, builder, 58 nodeFactory, result); 59 60 return result; 61 } 62 } 63 64 index++; 65 } 66 67 if (startingIndex > -1) { 68 if (finalize && (startingIndex > 0)) { 69 handleEventTargetSequence(parent, startingIndex, parent.getChildren().size() - 1, 70 builder, nodeFactory, result); 71 } 72 else { 73 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 74 } 75 } 76 77 return result; 42 78 } 43 44 RuleApplicationResult result = new RuleApplicationResult(); 45 46 GUIElement currentGUIElement = null; 47 int startingIndex = -1; 48 49 int index = 0; 50 while (index < parent.getChildren().size()) 79 80 /** 81 * TODO: comment 82 * 83 * @param child 84 * @return 85 */ 86 private IEventTarget determineEventTarget(ITaskTreeNode node) { 87 if (node instanceof IEventTask) { 88 return ((IEventTask) node).getEventTarget(); 89 } 90 else { 91 return null; 92 } 93 } 94 95 /** 96 * TODO: comment 97 * 98 */ 99 private void handleEventTargetSequence(ITaskTreeNode parent, 100 int startIndex, 101 int endIndex, 102 ITaskTreeBuilder builder, 103 ITaskTreeNodeFactory nodeFactory, 104 RuleApplicationResult result) 51 105 { 52 TaskTreeNode child = parent.getChildren().get(index); 53 54 GUIElement guiElement = determineGUIElement(child); 55 56 if ((guiElement != null) && (!guiElement.equals(currentGUIElement))) 57 { 58 if (startingIndex < 0) 59 { 60 startingIndex = index; 61 currentGUIElement = guiElement; 106 ISequence sequence = nodeFactory.createNewSequence(); 107 108 for (int i = startIndex; i <= endIndex; i++) { 109 builder.addChild(sequence, parent.getChildren().get(startIndex)); 110 builder.removeChild((ISequence) parent, startIndex); 62 111 } 63 else64 {65 handleGuiElementSequence(parent, startingIndex, index - 1, builder, nodeFactory, result);66 112 67 return result; 68 } 69 } 70 71 index++; 113 builder.addChild((ISequence) parent, startIndex, sequence); 114 115 result.addNewlyCreatedParentNode(sequence); 116 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 72 117 } 73 74 if (startingIndex > -1)75 {76 if (finalize && (startingIndex > 0))77 {78 handleGuiElementSequence79 (parent, startingIndex, parent.getChildren().size() - 1, builder, nodeFactory, result);80 }81 else82 {83 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);84 }85 }86 87 return result;88 }89 90 //-----------------------------------------------------------------------------------------------91 /**92 * TODO: comment93 *94 * @param child95 * @return96 */97 //-----------------------------------------------------------------------------------------------98 private GUIElement determineGUIElement(TaskTreeNode node)99 {100 if (node instanceof InteractionTask)101 {102 return ((InteractionTask) node).getGUIElement();103 }104 else105 {106 return null;107 }108 }109 110 //-----------------------------------------------------------------------------------------------111 /**112 * TODO: comment113 *114 */115 //-----------------------------------------------------------------------------------------------116 private void handleGuiElementSequence(TaskTreeNode parent,117 int startIndex,118 int endIndex,119 TaskTreeBuilder builder,120 TaskTreeNodeFactory nodeFactory,121 RuleApplicationResult result)122 {123 Sequence sequence = nodeFactory.createNewSequence();124 125 for (int i = startIndex; i <= endIndex; i++)126 {127 builder.addChild(sequence, parent.getChildren().get(startIndex));128 builder.removeChild((Sequence) parent, startIndex);129 }130 131 builder.addChild((Sequence) parent, startIndex, sequence);132 133 result.addNewlyCreatedParentNode(sequence);134 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);135 }136 118 137 119 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRule.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 9 10 import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask; 11 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 12 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 13 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 14 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 10 import de.ugoe.cs.quest.eventcore.gui.IInteraction; 11 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 15 16 16 //-------------------------------------------------------------------------------------------------17 17 /** 18 18 * TODO comment … … 21 21 * @author 2012, last modified by $Author: patrick$ 22 22 */ 23 //------------------------------------------------------------------------------------------------- 24 public class DefaultSequenceDetectionRule implements TemporalRelationshipRule 25 { 23 public class DefaultGuiEventSequenceDetectionRule implements TemporalRelationshipRule { 26 24 27 //----------------------------------------------------------------------------------------------- 28 /* (non-Javadoc) 29 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 30 */ 31 //----------------------------------------------------------------------------------------------- 32 @Override 33 public RuleApplicationResult apply(TaskTreeNode parent, 34 TaskTreeBuilder builder, 35 TaskTreeNodeFactory nodeFactory, 36 boolean finalize) 37 { 38 if (!(parent instanceof Sequence)) 25 /* 26 * (non-Javadoc) 27 * 28 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 29 * TaskTreeBuilder, TaskTreeNodeFactory) 30 */ 31 @Override 32 public RuleApplicationResult apply(ITaskTreeNode parent, 33 ITaskTreeBuilder builder, 34 ITaskTreeNodeFactory nodeFactory, 35 boolean finalize) 39 36 { 40 return null; 37 if (!(parent instanceof ISequence)) { 38 return null; 39 } 40 41 RuleApplicationResult result = new RuleApplicationResult(); 42 int sequenceStartingIndex = -1; 43 44 int index = 0; 45 while (index < parent.getChildren().size()) { 46 ITaskTreeNode child = parent.getChildren().get(index); 47 48 if ((child instanceof IEventTask) && 49 (((IEventTask) child).getEventType() instanceof IInteraction)) 50 { 51 IInteraction eventType = (IInteraction) ((IEventTask) child).getEventType(); 52 53 if (eventType.finishesLogicalSequence() && (sequenceStartingIndex > -1)) 54 { 55 // There are several situations in which this implementation may cause infinite 56 // loops. This is because the rule manager will reapply rules until 57 // no rule is applied anymore. A sequence identified in a first iteration will 58 // be identified as a sequence also in a second iteration. As an example 59 // many sequences start with an interaction starting that sequence and end 60 // with an interaction ending that sequence. This will be reidentified as 61 // further subsequence. It must therefore be assured, that a sequence, that 62 // was once identified is not reidentified in a further application of the rule. 63 // For this, the implementation performs a kind of dry run. It creates a list of 64 // children that would belong to an identified sequence. Only if this list is 65 // not a reidentification then a new sequence is created and added to the 66 // parent. If it is a reidentification can be identified, if the list of 67 // children will contain all children of the parent, or if the list of children 68 // only consists of one sequence. Further, an identified sequence must at least 69 // have one child. 70 if (((sequenceStartingIndex != 0) || 71 (index != (parent.getChildren().size() - 1))) && 72 (((index - sequenceStartingIndex) > 0) || 73 (((index - sequenceStartingIndex) == 0) && 74 (!eventType.startsLogicalSequence())))) 75 { 76 boolean allNewChildrenAreSequences = true; 77 78 for (int j = sequenceStartingIndex; 79 ((allNewChildrenAreSequences) && (j < index)); j++) 80 { 81 allNewChildrenAreSequences &= 82 (parent.getChildren().get(j) instanceof ISequence); 83 } 84 85 if (!allNewChildrenAreSequences) { 86 ISequence sequence = nodeFactory.createNewSequence(); 87 88 for (int j = sequenceStartingIndex; j < index; j++) { 89 builder.addChild 90 (sequence, parent.getChildren().get(sequenceStartingIndex)); 91 builder.removeChild((ISequence) parent, sequenceStartingIndex); 92 } 93 94 if (!eventType.startsLogicalSequence()) { 95 builder.addChild 96 (sequence, parent.getChildren().get(sequenceStartingIndex)); 97 builder.removeChild((ISequence) parent, sequenceStartingIndex); 98 } 99 100 builder.addChild((ISequence) parent, sequenceStartingIndex, sequence); 101 102 result.addNewlyCreatedParentNode(sequence); 103 result.setRuleApplicationStatus 104 (RuleApplicationStatus.RULE_APPLICATION_FINISHED); 105 return result; 106 } 107 } 108 } 109 110 if (eventType.startsLogicalSequence()) { 111 sequenceStartingIndex = index; 112 } 113 } 114 115 index++; 116 } 117 118 if (sequenceStartingIndex >= 0) { 119 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 120 } 121 122 return result; 41 123 } 42 43 RuleApplicationResult result = new RuleApplicationResult();44 int sequenceStartingIndex = -1;45 46 int index = 0;47 while (index < parent.getChildren().size())48 {49 TaskTreeNode child = parent.getChildren().get(index);50 51 if (child instanceof InteractionTask)52 {53 if (((InteractionTask) child).getInteraction().finishesLogicalSequence() &&54 (sequenceStartingIndex > -1))55 {56 // There are several situations in which this implementation may cause infinite57 // loops. This is because the rule manager will reapply rules until58 // no rule is applied anymore. A sequence identified in a first iteration will59 // be identified as a sequence also in a second iteration. As an example60 // many sequences start with an interaction starting that sequence and end61 // with an interaction ending that sequence. This will be reidentified as further62 // subsequence. It must therefore be assured, that a sequence, that was once63 // identified is not reidentified in a further application of the rule. For this,64 // the implementation performs a kind of dry run. It creates a list of children65 // that would belong to an identified sequence. Only if this list is not a66 // reidentification then a new sequence is created and added to the parent. If it67 // is a reidentification can be identified, if the list of children will contain68 // all children of the parent, or if the list of children only consists of one69 // sequence. Further, an identified sequence must at least have one child.70 if (((sequenceStartingIndex != 0) || (index != (parent.getChildren().size() - 1))) &&71 (((index - sequenceStartingIndex) > 0) ||72 (((index - sequenceStartingIndex) == 0) &&73 (!((InteractionTask) child).getInteraction().startsLogicalSequence()))))74 {75 boolean allNewChildrenAreSequences = true;76 77 for (int j = sequenceStartingIndex; ((allNewChildrenAreSequences) && (j < index)); j++)78 {79 allNewChildrenAreSequences &= (parent.getChildren().get(j) instanceof Sequence);80 }81 82 if (!allNewChildrenAreSequences)83 {84 Sequence sequence = nodeFactory.createNewSequence();85 86 for (int j = sequenceStartingIndex; j < index; j++)87 {88 builder.addChild(sequence, parent.getChildren().get(sequenceStartingIndex));89 builder.removeChild((Sequence) parent, sequenceStartingIndex);90 }91 92 if (!((InteractionTask) child).getInteraction().startsLogicalSequence())93 {94 builder.addChild(sequence, parent.getChildren().get(sequenceStartingIndex));95 builder.removeChild((Sequence) parent, sequenceStartingIndex);96 }97 98 builder.addChild((Sequence) parent, sequenceStartingIndex, sequence);99 100 result.addNewlyCreatedParentNode(sequence);101 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);102 return result;103 }104 }105 }106 107 if (((InteractionTask) child).getInteraction().startsLogicalSequence())108 {109 sequenceStartingIndex = index;110 }111 }112 113 index++;114 }115 116 if (sequenceStartingIndex >= 0)117 {118 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);119 }120 121 return result;122 }123 124 124 125 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultIterationDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 13 12 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEquality; 14 13 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 15 import de.ugoe.cs.quest.tasktrees.treeifc.Iteration; 16 import de.ugoe.cs.quest.tasktrees.treeifc.Selection; 17 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 18 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 19 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 20 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 21 22 //------------------------------------------------------------------------------------------------- 14 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 20 23 21 /** 24 22 * TODO comment … … 27 25 * @author 2012, last modified by $Author: patrick$ 28 26 */ 29 //------------------------------------------------------------------------------------------------- 30 public class DefaultIterationDetectionRule implements TemporalRelationshipRule 31 { 32 /** */ 33 private NodeEqualityRuleManager mNodeEqualityRuleManager; 34 35 //----------------------------------------------------------------------------------------------- 36 /** 37 * TODO: comment 27 public class DefaultIterationDetectionRule implements TemporalRelationshipRule { 28 29 /** */ 30 private NodeEqualityRuleManager nodeEqualityRuleManager; 31 32 /** 33 * TODO: comment 34 * 35 */ 36 DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) { 37 super(); 38 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 39 } 40 41 /* 42 * (non-Javadoc) 43 * 44 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 45 */ 46 @Override 47 public RuleApplicationResult apply(ITaskTreeNode parent, 48 ITaskTreeBuilder treeBuilder, 49 ITaskTreeNodeFactory nodeFactory, 50 boolean finalize) 51 { 52 if (!(parent instanceof ISequence)) { 53 return null; 54 } 55 56 // parent must already have at least 2 children 57 if ((parent.getChildren() == null) || (parent.getChildren().size() < 2)) { 58 return null; 59 } 60 61 // iterations represent as a list of nodes that splits up in several equal sublists. If 62 // the remaining nodes also start an equal sublist, then the iteration may not be completed 63 // yet. So wait for further events to only identify completed iterations. 64 65 // to find longer iterations first, start with long sequences 66 for (int end = parent.getChildren().size() - 1; end > 0; end--) { 67 for (int start = 0; start < end; start++) { 68 List<ITaskTreeNode[]> equalVariants = 69 getEqualSublistVariantsInBoundaries(parent, start, end); 70 71 if (equalVariants != null) { 72 if (!finalize) { 73 // check, if the iteration may go on. This may be the case, if the detected 74 // iteration finishes with the last child of the parent, or if the 75 // remaining children, which were not identified as part of the iteration, 76 // start a further occurrence of the iteration 77 if (end == (parent.getChildren().size() - 1)) { 78 RuleApplicationResult result = new RuleApplicationResult(); 79 result.setRuleApplicationStatus 80 (RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 81 return result; 82 } 83 84 boolean allNodesEqual = true; 85 for (int i = 0; ((allNodesEqual) && (i < equalVariants.get(0).length)); i++) 86 { 87 if ((end + i + 1) >= parent.getChildren().size()) { 88 break; 89 } 90 91 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules 92 (equalVariants.get(0)[i], parent.getChildren().get(end + i + 1)); 93 94 allNodesEqual &= 95 nodeEquality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL); 96 } 97 98 if (allNodesEqual) { 99 RuleApplicationResult result = new RuleApplicationResult(); 100 result.setRuleApplicationStatus 101 (RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 102 return result; 103 } 104 } 105 106 RuleApplicationResult result = new RuleApplicationResult(); 107 IIteration newIteration = nodeFactory.createNewIteration(); 108 result.addNewlyCreatedParentNode(newIteration); 109 110 if (equalVariants.size() == 1) { 111 // all children are the same. Create an iteration of this child 112 if (equalVariants.get(0).length == 1) { 113 // all children are the same. Create an iteration of this child 114 treeBuilder.setChild(newIteration, equalVariants.get(0)[0]); 115 } 116 else { 117 // there was an iteration of structurally equal sequences 118 ISequence sequence = nodeFactory.createNewSequence(); 119 result.addNewlyCreatedParentNode(sequence); 120 121 for (ITaskTreeNode node : equalVariants.get(0)) { 122 treeBuilder.addChild(sequence, node); 123 } 124 125 treeBuilder.setChild(newIteration, sequence); 126 } 127 } 128 else { 129 // there are distinct variants of semantically equal subsequences or 130 // children --> 131 // create an iterated selection 132 ISelection selection = nodeFactory.createNewSelection(); 133 result.addNewlyCreatedParentNode(selection); 134 135 for (ITaskTreeNode[] variant : equalVariants) { 136 if (variant.length == 1) { 137 treeBuilder.addChild(selection, variant[0]); 138 } 139 else { 140 ISequence sequence = nodeFactory.createNewSequence(); 141 result.addNewlyCreatedParentNode(sequence); 142 143 for (ITaskTreeNode node : variant) { 144 treeBuilder.addChild(sequence, node); 145 } 146 147 treeBuilder.addChild(selection, sequence); 148 } 149 } 150 151 treeBuilder.setChild(newIteration, selection); 152 } 153 154 // remove iterated children 155 for (int j = end; j >= start; j--) { 156 treeBuilder.removeChild((ISequence) parent, j); 157 } 158 159 // add the new iteration instead 160 treeBuilder.addChild((ISequence) parent, start, newIteration); 161 162 result.setRuleApplicationStatus 163 (RuleApplicationStatus.RULE_APPLICATION_FINISHED); 164 return result; 165 } 166 } 167 } 168 169 return null; 170 } 171 172 /** 173 * TODO: comment 174 * 175 * @return 176 */ 177 private List<ITaskTreeNode[]> getEqualSublistVariantsInBoundaries(ITaskTreeNode parent, 178 int start, 179 int end) 180 { 181 List<ITaskTreeNode[]> equalVariants = null; 182 183 int noOfChildrenInBoundaries = end - start + 1; 184 185 for (int subListLen = 1; subListLen <= (noOfChildrenInBoundaries / 2); subListLen++) 186 { 187 if ((noOfChildrenInBoundaries % subListLen) == 0) { 188 equalVariants = 189 getEqualSublistVariantsForSubListLength(parent, start, end, subListLen); 190 191 if (equalVariants != null) { 192 return equalVariants; 193 } 194 } 195 } 196 197 return null; 198 } 199 200 /** 38 201 * 39 202 */ 40 //----------------------------------------------------------------------------------------------- 41 DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) 42 { 43 super(); 44 mNodeEqualityRuleManager = nodeEqualityRuleManager; 45 } 46 47 //----------------------------------------------------------------------------------------------- 48 /* (non-Javadoc) 49 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 50 */ 51 //----------------------------------------------------------------------------------------------- 52 @Override 53 public RuleApplicationResult apply(TaskTreeNode parent, 54 TaskTreeBuilder treeBuilder, 55 TaskTreeNodeFactory nodeFactory, 56 boolean finalize) 57 { 58 if (!(parent instanceof Sequence)) 203 private List<ITaskTreeNode[]> getEqualSublistVariantsForSubListLength(ITaskTreeNode parent, 204 int start, 205 int end, 206 int subListLen) 59 207 { 60 return null; 61 } 62 63 // parent must already have at least 2 children 64 if ((parent.getChildren() == null) || (parent.getChildren().size() < 2)) 65 { 66 return null; 67 } 68 69 // iterations represent as a list of nodes that splits up in several equal sublists. If 70 // the remaining nodes also start an equal sublist, then the iteration may not be completed 71 // yet. So wait for further interactions to only identify completed iterations. 72 73 // to find longer iterations first, start with long sequences 74 for (int end = parent.getChildren().size() - 1; end > 0; end--) 75 { 76 for (int start = 0; start < end; start++) 77 { 78 List<TaskTreeNode[]> equalVariants = 79 getEqualSublistVariantsInBoundaries(parent, start, end); 80 81 if (equalVariants != null) 208 List<ITaskTreeNode[]> equalVariants = new ArrayList<ITaskTreeNode[]>(); 209 ITaskTreeNode[] firstVariant = new ITaskTreeNode[subListLen]; 210 211 for (int i = 0; i < subListLen; i++) { 212 firstVariant[i] = parent.getChildren().get(start + i); 213 } 214 215 equalVariants.add(firstVariant); 216 217 for (int parentIdx = (start + subListLen); parentIdx <= end; parentIdx += subListLen) 82 218 { 83 if (!finalize) 84 { 85 // check, if the iteration may go on. This may be the case, if the detected iteration 86 // finishes with the last child of the parent, or if the remaining children, which were 87 // not identified as part of the iteration, start a further occurrence of the iteration 88 if (end == (parent.getChildren().size() - 1)) 89 { 90 RuleApplicationResult result = new RuleApplicationResult(); 91 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 92 return result; 93 } 94 95 boolean allNodesEqual = true; 96 for (int i = 0; ((allNodesEqual) && (i < equalVariants.get(0).length)); i++) 97 { 98 if ((end + i + 1) >= parent.getChildren().size()) 99 { 100 break; 101 } 102 103 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules 104 (equalVariants.get(0)[i], parent.getChildren().get(end + i + 1)); 105 106 allNodesEqual &= 107 nodeEquality.getStructuralEquality() || nodeEquality.getSemanticalEquality(); 108 } 109 110 if (allNodesEqual) 111 { 112 RuleApplicationResult result = new RuleApplicationResult(); 113 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 114 return result; 115 } 116 } 117 118 RuleApplicationResult result = new RuleApplicationResult(); 119 Iteration newIteration = nodeFactory.createNewIteration(); 120 result.addNewlyCreatedParentNode(newIteration); 121 122 if (equalVariants.size() == 1) 123 { 124 // all children are the same. Create an iteration of this child 125 if (equalVariants.get(0).length == 1) 126 { 127 // all children are the same. Create an iteration of this child 128 treeBuilder.setChild(newIteration, equalVariants.get(0)[0]); 129 } 130 else 131 { 132 // there was an iteration of structurally equal sequences 133 Sequence sequence = nodeFactory.createNewSequence(); 134 result.addNewlyCreatedParentNode(sequence); 135 136 for (TaskTreeNode node : equalVariants.get(0)) 137 { 138 treeBuilder.addChild(sequence, node); 139 } 140 141 treeBuilder.setChild(newIteration, sequence); 142 } 143 } 144 else 145 { 146 // there are distinct variants of semantically equal subsequences or children --> 147 // create an iterated selection 148 Selection selection = nodeFactory.createNewSelection(); 149 result.addNewlyCreatedParentNode(selection); 150 151 for (TaskTreeNode[] variant : equalVariants) 152 { 153 if (variant.length == 1) 154 { 155 treeBuilder.addChild(selection, variant[0]); 156 } 157 else 158 { 159 Sequence sequence = nodeFactory.createNewSequence(); 160 result.addNewlyCreatedParentNode(sequence); 161 162 for (TaskTreeNode node : variant) 163 { 164 treeBuilder.addChild(sequence, node); 165 } 166 167 treeBuilder.addChild(selection, sequence); 168 } 169 } 170 171 treeBuilder.setChild(newIteration, selection); 172 } 173 174 // remove iterated children 175 for (int j = end; j >= start; j--) 176 { 177 treeBuilder.removeChild((Sequence) parent, j); 178 } 179 180 // add the new iteration instead 181 treeBuilder.addChild((Sequence) parent, start, newIteration); 182 183 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 184 return result; 185 } 186 } 187 } 188 189 return null; 190 } 191 192 //----------------------------------------------------------------------------------------------- 193 /** 194 * TODO: comment 195 * 196 * @return 197 */ 198 //----------------------------------------------------------------------------------------------- 199 private List<TaskTreeNode[]> getEqualSublistVariantsInBoundaries(TaskTreeNode parent, 200 int start, 201 int end) 202 { 203 List<TaskTreeNode[]> equalVariants = null; 204 205 int noOfChildrenInBoundaries = end - start + 1; 206 207 for (int subListLength = 1; subListLength <= (noOfChildrenInBoundaries / 2); subListLength++) 208 { 209 if ((noOfChildrenInBoundaries % subListLength) == 0) 210 { 211 equalVariants = getEqualSublistVariantsForSubListLength(parent, start, end, subListLength); 212 213 if (equalVariants != null) 214 { 215 return equalVariants; 216 } 217 } 218 } 219 220 return null; 221 } 222 223 //----------------------------------------------------------------------------------------------- 224 /** 225 * 226 */ 227 //----------------------------------------------------------------------------------------------- 228 private List<TaskTreeNode[]> getEqualSublistVariantsForSubListLength(TaskTreeNode parent, 229 int start, 230 int end, 231 int subListLength) 232 { 233 List<TaskTreeNode[]> equalVariants = new ArrayList<TaskTreeNode[]>(); 234 TaskTreeNode[] firstVariant = new TaskTreeNode[subListLength]; 235 236 for (int i = 0; i < subListLength; i++) 237 { 238 firstVariant[i] = parent.getChildren().get(start + i); 239 } 240 241 equalVariants.add(firstVariant); 242 243 for (int parentIdx = (start + subListLength); parentIdx <= end; parentIdx += subListLength) 244 { 245 TaskTreeNode[] otherVariant = new TaskTreeNode[subListLength]; 246 247 for (int i = 0; i < subListLength; i++) 248 { 249 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules 250 (firstVariant[i], parent.getChildren().get(parentIdx + i)); 251 252 if (!nodeEquality.getStructuralEquality()) 253 { 254 if (nodeEquality.getSemanticalEquality()) 255 { 256 otherVariant[i] = parent.getChildren().get(parentIdx + i); 257 } 258 else 259 { 260 return null; 261 } 262 } 263 } 264 265 // check, if there is a semantically equal other variant. If so, add it to the list of 266 // variants 267 boolean semanticallyUnequal = false; 268 for (int i = 0; i < subListLength; i++) 269 { 270 if (otherVariant[i] == null) 271 { 272 otherVariant[i] = firstVariant[i]; 273 } 274 else 275 { 276 semanticallyUnequal = true; 277 } 278 } 279 280 if (semanticallyUnequal) 281 { 282 equalVariants.add(otherVariant); 283 } 284 } 285 286 return equalVariants; 287 } 219 ITaskTreeNode[] otherVariant = new ITaskTreeNode[subListLen]; 220 221 for (int i = 0; i < subListLen; i++) { 222 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules 223 (firstVariant[i], parent.getChildren().get(parentIdx + i)); 224 225 if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 226 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 227 otherVariant[i] = parent.getChildren().get(parentIdx + i); 228 } 229 else { 230 return null; 231 } 232 } 233 } 234 235 // check, if there is a semantically equal other variant. If so, add it to the list of 236 // variants 237 boolean semanticallyUnequal = false; 238 for (int i = 0; i < subListLen; i++) { 239 if (otherVariant[i] == null) { 240 otherVariant[i] = firstVariant[i]; 241 } 242 else { 243 semanticallyUnequal = true; 244 } 245 } 246 247 if (semanticallyUnequal) { 248 equalVariants.add(otherVariant); 249 } 250 } 251 252 return equalVariants; 253 } 288 254 289 255 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultMouseClickReductionRule.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonDown;12 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonInteraction;13 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonUp;14 import de.ugoe.cs.quest.eventcore. userinteraction.MouseClick;15 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;16 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;17 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;18 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;19 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.gui.MouseButtonDown; 11 import de.ugoe.cs.quest.eventcore.gui.MouseButtonInteraction; 12 import de.ugoe.cs.quest.eventcore.gui.MouseButtonUp; 13 import de.ugoe.cs.quest.eventcore.gui.MouseClick; 14 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 20 19 21 //-------------------------------------------------------------------------------------------------22 20 /** 23 21 * TODO comment … … 26 24 * @author 2012, last modified by $Author: patrick$ 27 25 */ 28 //------------------------------------------------------------------------------------------------- 29 public class DefaultMouseClickReductionRule implements TemporalRelationshipRule 30 { 26 public class DefaultMouseClickReductionRule implements TemporalRelationshipRule { 31 27 32 //----------------------------------------------------------------------------------------------- 33 /* (non-Javadoc) 34 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 35 */ 36 //----------------------------------------------------------------------------------------------- 37 @Override 38 public RuleApplicationResult apply(TaskTreeNode parent, 39 TaskTreeBuilder builder, 40 TaskTreeNodeFactory nodeFactory, 41 boolean finalize) 42 { 43 if (!(parent instanceof Sequence)) 28 /* 29 * (non-Javadoc) 30 * 31 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 32 * TaskTreeBuilder, TaskTreeNodeFactory) 33 */ 34 @Override 35 public RuleApplicationResult apply(ITaskTreeNode parent, 36 ITaskTreeBuilder builder, 37 ITaskTreeNodeFactory nodeFactory, 38 boolean finalize) 44 39 { 45 return null; 40 if (!(parent instanceof ISequence)) { 41 return null; 42 } 43 44 RuleApplicationResult result = new RuleApplicationResult(); 45 46 int index = 0; 47 while (index < parent.getChildren().size() - 2) // -2 because we don't need to go to the end 48 { 49 if (mouseClickSequenceFound(parent.getChildren().get(index), 50 parent.getChildren().get(index + 1), 51 parent.getChildren().get(index + 2))) 52 { 53 builder.removeChild((ISequence) parent, index); 54 builder.removeChild((ISequence) parent, index); 55 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 56 return result; 57 } 58 else if 59 ((parent.getChildren().get(index) instanceof ISequence) && 60 (parent.getChildren().get(index).getChildren().size() == 2) && 61 (mouseClickSequenceFound(parent.getChildren().get(index).getChildren().get(0), 62 parent.getChildren().get(index).getChildren().get(1), 63 parent.getChildren().get(index + 1)))) 64 { 65 builder.removeChild((ISequence) parent, index); 66 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 67 return result; 68 } 69 70 index++; 71 } 72 73 return result; 46 74 } 47 48 RuleApplicationResult result = new RuleApplicationResult();49 50 int index = 0;51 while (index < parent.getChildren().size() - 2) // -2 because we don't need to go to the end52 {53 if (mouseClickSequenceFound(parent.getChildren().get(index),54 parent.getChildren().get(index + 1),55 parent.getChildren().get(index + 2)))56 {57 builder.removeChild((Sequence) parent, index);58 builder.removeChild((Sequence) parent, index);59 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);60 return result;61 }62 else if ((parent.getChildren().get(index) instanceof Sequence) &&63 (parent.getChildren().get(index).getChildren().size() == 2) &&64 (mouseClickSequenceFound(parent.getChildren().get(index).getChildren().get(0),65 parent.getChildren().get(index).getChildren().get(1),66 parent.getChildren().get(index + 1))))67 {68 builder.removeChild((Sequence) parent, index);69 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);70 return result;71 }72 73 index++;74 }75 76 return result;77 }78 75 79 //----------------------------------------------------------------------------------------------- 80 /** 76 /** 81 77 * 82 78 */ 83 //----------------------------------------------------------------------------------------------- 84 private boolean mouseClickSequenceFound(TaskTreeNode mouseButtonDown, 85 TaskTreeNode mouseButtonUp, 86 TaskTreeNode mouseClick) 87 { 88 // check the first in a row of three for validity 89 if (!(mouseButtonDown instanceof InteractionTask)) 79 private boolean mouseClickSequenceFound(ITaskTreeNode mouseButtonDown, 80 ITaskTreeNode mouseButtonUp, 81 ITaskTreeNode mouseClick) 90 82 { 91 return false; 83 // check the first in a row of three for validity 84 if (!(mouseButtonDown instanceof IEventTask)) { 85 return false; 86 } 87 88 IEventTarget eventTarget = ((IEventTask) mouseButtonDown).getEventTarget(); 89 90 if (!(((IEventTask) mouseButtonDown).getEventType() instanceof MouseButtonDown)) { 91 return false; 92 } 93 94 MouseButtonInteraction.Button button = 95 ((MouseButtonDown) ((IEventTask) mouseButtonDown).getEventType()).getButton(); 96 97 // check the second node for validity 98 if (!(mouseButtonUp instanceof IEventTask)) { 99 return false; 100 } 101 102 if (!eventTarget.equals(((IEventTask) mouseButtonUp).getEventTarget())) { 103 return false; 104 } 105 106 if (!(((IEventTask) mouseButtonUp).getEventType() instanceof MouseButtonUp)) { 107 return false; 108 } 109 110 if (!button.equals(((MouseButtonUp) ((IEventTask) mouseButtonUp).getEventType()) 111 .getButton())) 112 { 113 return false; 114 } 115 116 // check the third node for validity 117 if (!(mouseClick instanceof IEventTask)) { 118 return false; 119 } 120 121 if (!eventTarget.equals(((IEventTask) mouseClick).getEventTarget())) { 122 return false; 123 } 124 125 if (!(((IEventTask) mouseClick).getEventType() instanceof MouseClick)) { 126 return false; 127 } 128 129 if (!button.equals(((MouseClick) ((IEventTask) mouseClick).getEventType()).getButton())) { 130 return false; 131 } 132 133 return true; 92 134 } 93 94 GUIElement guiElement = ((InteractionTask) mouseButtonDown).getGUIElement();95 96 if (!(((InteractionTask) mouseButtonDown).getInteraction() instanceof MouseButtonDown))97 {98 return false;99 }100 101 MouseButtonInteraction.Button button =102 ((MouseButtonDown) ((InteractionTask) mouseButtonDown).getInteraction()).getButton();103 104 105 // check the second node for validity106 if (!(mouseButtonUp instanceof InteractionTask))107 {108 return false;109 }110 111 if (!guiElement.equals(((InteractionTask) mouseButtonUp).getGUIElement()))112 {113 return false;114 }115 116 if (!(((InteractionTask) mouseButtonUp).getInteraction() instanceof MouseButtonUp))117 {118 return false;119 }120 121 if (!button.equals122 (((MouseButtonUp) ((InteractionTask) mouseButtonUp).getInteraction()).getButton()))123 {124 return false;125 }126 127 128 // check the third node for validity129 if (!(mouseClick instanceof InteractionTask))130 {131 return false;132 }133 134 if (!guiElement.equals(((InteractionTask) mouseClick).getGUIElement()))135 {136 return false;137 }138 139 if (!(((InteractionTask) mouseClick).getInteraction() instanceof MouseClick))140 {141 return false;142 }143 144 if (!button.equals(((MouseClick) ((InteractionTask) mouseClick).getInteraction()).getButton()))145 {146 return false;147 }148 149 return true;150 }151 135 152 136 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultTextInputReductionRule.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 12 11 import java.util.Locale; 13 12 14 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;15 import de.ugoe.cs.quest.eventcore.gui model.TextArea;16 import de.ugoe.cs.quest.eventcore.gui model.TextField;17 import de.ugoe.cs.quest.eventcore. userinteraction.KeyInteraction;18 import de.ugoe.cs.quest.eventcore. userinteraction.KeyPressed;19 import de.ugoe.cs.quest.eventcore. userinteraction.KeyReleased;20 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;21 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;22 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;23 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;24 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;25 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;13 import de.ugoe.cs.quest.eventcore.IEventTarget; 14 import de.ugoe.cs.quest.eventcore.gui.KeyInteraction; 15 import de.ugoe.cs.quest.eventcore.gui.KeyPressed; 16 import de.ugoe.cs.quest.eventcore.gui.KeyReleased; 17 import de.ugoe.cs.quest.eventcore.guimodel.ITextArea; 18 import de.ugoe.cs.quest.eventcore.guimodel.ITextField; 19 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 20 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 21 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 22 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 23 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 24 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 26 25 import de.ugoe.cs.tasktree.keyboardmaps.KeyboardMap; 27 26 import de.ugoe.cs.tasktree.keyboardmaps.KeyboardMapFactory; 28 27 import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey; 29 28 30 //-------------------------------------------------------------------------------------------------31 29 /** 32 30 * TODO comment … … 35 33 * @author 2012, last modified by $Author: patrick$ 36 34 */ 37 //------------------------------------------------------------------------------------------------- 38 public class DefaultTextInputReductionRule implements TemporalRelationshipRule 39 { 40 /** */ 41 private KeyboardMap mKeyboardMap = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 42 43 //----------------------------------------------------------------------------------------------- 44 /* (non-Javadoc) 45 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 46 */ 47 //----------------------------------------------------------------------------------------------- 48 @Override 49 public RuleApplicationResult apply(TaskTreeNode parent, 50 TaskTreeBuilder builder, 51 TaskTreeNodeFactory nodeFactory, 52 boolean finalize) 53 { 54 if ((!(parent instanceof Sequence)) || 55 (parent instanceof TextInputInteractionTask)) 35 public class DefaultTextInputReductionRule implements TemporalRelationshipRule { 36 37 /** */ 38 private KeyboardMap keyboardMap = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 39 40 /* 41 * (non-Javadoc) 42 * 43 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 44 */ 45 @Override 46 public RuleApplicationResult apply(ITaskTreeNode parent, 47 ITaskTreeBuilder builder, 48 ITaskTreeNodeFactory nodeFactory, 49 boolean finalize) 56 50 { 57 return null; 58 } 59 60 RuleApplicationResult result = new RuleApplicationResult(); 61 int textEntryStartIndex = -1; 62 GUIElement currentGUIElement = null; 63 64 int index = 0; 65 TaskTreeNode task = null; 66 while (index < parent.getChildren().size()) 51 if ((!(parent instanceof ISequence)) || (parent instanceof ITextInputEventTask)) { 52 return null; 53 } 54 55 RuleApplicationResult result = new RuleApplicationResult(); 56 int textEntryStartIndex = -1; 57 IEventTarget currentEventTarget = null; 58 59 int index = 0; 60 ITaskTreeNode task = null; 61 while (index < parent.getChildren().size()) { 62 task = parent.getChildren().get(index); 63 if (isKeyInteraction(task) && 64 isDataInputEventTarget(((IEventTask) task).getEventTarget())) 65 { 66 if (textEntryStartIndex < 0) { 67 textEntryStartIndex = index; 68 currentEventTarget = ((IEventTask) task).getEventTarget(); 69 } 70 else if (!currentEventTarget.equals(((IEventTask) task).getEventTarget())) { 71 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, 72 currentEventTarget, builder, nodeFactory, result); 73 return result; 74 } 75 } 76 else if (textEntryStartIndex >= 0) { 77 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, currentEventTarget, 78 builder, nodeFactory, result); 79 return result; 80 } 81 82 index++; 83 } 84 85 if (textEntryStartIndex >= 0) { 86 if (finalize) { 87 handleTextEntrySequence(parent, textEntryStartIndex, 88 parent.getChildren().size() - 1, currentEventTarget, 89 builder, nodeFactory, result); 90 } 91 else { 92 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 93 } 94 } 95 96 return result; 97 } 98 99 /** 100 * TODO: comment 101 * 102 * @param taskTreeNode 103 * @return 104 */ 105 private boolean isKeyInteraction(ITaskTreeNode taskTreeNode) { 106 if ((taskTreeNode instanceof IEventTask)) { 107 return (((IEventTask) taskTreeNode).getEventType() instanceof KeyInteraction); 108 } 109 else { 110 return false; 111 } 112 } 113 114 /** 115 * TODO: comment 116 * 117 * @param textEntryStartIndex 118 * @param i 119 * @param result 120 * @return 121 */ 122 private void handleTextEntrySequence(ITaskTreeNode parent, 123 int startIndex, 124 int endIndex, 125 IEventTarget eventTarget, 126 ITaskTreeBuilder builder, 127 ITaskTreeNodeFactory nodeFactory, 128 RuleApplicationResult result) 67 129 { 68 task = parent.getChildren().get(index); 69 if (isKeyInteraction(task) && isDataInputGUIElement(((InteractionTask) task).getGUIElement())) 70 { 71 if (textEntryStartIndex < 0) 72 { 73 textEntryStartIndex = index; 74 currentGUIElement = ((InteractionTask) task).getGUIElement(); 75 } 76 else if (!currentGUIElement.equals(((InteractionTask) task).getGUIElement())) 77 { 78 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, currentGUIElement, 79 builder, nodeFactory, result); 80 return result; 81 } 82 } 83 else if (textEntryStartIndex >= 0) 84 { 85 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, currentGUIElement, 86 builder, nodeFactory, result); 87 return result; 88 } 89 90 index++; 91 } 92 93 if (textEntryStartIndex >= 0) 130 ITextInputEventTask textInput = nodeFactory.createNewTextInputEventTask(eventTarget); 131 132 for (int i = startIndex; i <= endIndex; i++) { 133 builder.addChild(textInput, parent.getChildren().get(startIndex)); 134 builder.removeChild((ISequence) parent, startIndex); 135 } 136 137 builder.addChild((ISequence) parent, startIndex, textInput); 138 139 StringBuffer enteredText = new StringBuffer(); 140 determineEnteredText(textInput, new ArrayList<VirtualKey>(), enteredText); 141 textInput.setEnteredText(enteredText.toString()); 142 143 result.addNewlyCreatedParentNode(textInput); 144 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 145 } 146 147 /** 148 * TODO: comment 149 * 150 * @param eventTarget 151 * @return 152 */ 153 private boolean isDataInputEventTarget(IEventTarget eventTarget) { 154 return ((eventTarget instanceof ITextField) || (eventTarget instanceof ITextArea)); 155 } 156 157 /** 158 * TODO: comment 159 * 160 * @param sequence 161 * @param enteredText 162 */ 163 private void determineEnteredText(ITaskTreeNode node, 164 List<VirtualKey> pressedKeys, 165 StringBuffer enteredText) 94 166 { 95 if (finalize) 96 { 97 handleTextEntrySequence(parent, textEntryStartIndex, parent.getChildren().size() - 1, 98 currentGUIElement, builder, nodeFactory, result); 99 } 100 else 101 { 102 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 103 } 104 } 105 106 return result; 107 } 108 109 //----------------------------------------------------------------------------------------------- 110 /** 111 * TODO: comment 112 * 113 * @param taskTreeNode 114 * @return 115 */ 116 //----------------------------------------------------------------------------------------------- 117 private boolean isKeyInteraction(TaskTreeNode taskTreeNode) 118 { 119 if ((taskTreeNode instanceof InteractionTask)) 120 { 121 return (((InteractionTask) taskTreeNode).getInteraction() instanceof KeyInteraction); 122 } 123 else 124 { 125 return false; 126 } 127 } 128 129 //----------------------------------------------------------------------------------------------- 130 /** 131 * TODO: comment 132 * 133 * @param textEntryStartIndex 134 * @param i 135 * @param result 136 * @return 137 */ 138 //----------------------------------------------------------------------------------------------- 139 private void handleTextEntrySequence(TaskTreeNode parent, 140 int startIndex, 141 int endIndex, 142 GUIElement guiElement, 143 TaskTreeBuilder builder, 144 TaskTreeNodeFactory nodeFactory, 145 RuleApplicationResult result) 146 { 147 TextInputInteractionTask textInput = nodeFactory.createNewTextInputInteractionTask(guiElement); 148 149 for (int i = startIndex; i <= endIndex; i++) 150 { 151 builder.addChild(textInput, parent.getChildren().get(startIndex)); 152 builder.removeChild((Sequence) parent, startIndex); 153 } 154 155 builder.addChild((Sequence) parent, startIndex, textInput); 156 157 StringBuffer enteredText = new StringBuffer(); 158 determineEnteredText(textInput, new ArrayList<VirtualKey>(), enteredText); 159 textInput.setEnteredText(enteredText.toString()); 160 161 result.addNewlyCreatedParentNode(textInput); 162 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 163 } 164 165 //----------------------------------------------------------------------------------------------- 166 /** 167 * TODO: comment 168 * 169 * @param guiElement 170 * @return 171 */ 172 //----------------------------------------------------------------------------------------------- 173 private boolean isDataInputGUIElement(GUIElement guiElement) 174 { 175 return ((guiElement instanceof TextField) || (guiElement instanceof TextArea)); 176 } 177 178 //----------------------------------------------------------------------------------------------- 179 /** 180 * TODO: comment 181 * 182 * @param sequence 183 * @param enteredText 184 */ 185 //----------------------------------------------------------------------------------------------- 186 private void determineEnteredText(TaskTreeNode node, 187 List<VirtualKey> pressedKeys, 188 StringBuffer enteredText) 189 { 190 if ((node instanceof Sequence) || (node instanceof TextInputInteractionTask)) 191 { 192 for (TaskTreeNode child : node.getChildren()) 193 { 194 if (child instanceof InteractionTask) 195 { 196 if (((InteractionTask) child).getInteraction() instanceof KeyPressed) 197 { 198 VirtualKey key = ((KeyPressed) ((InteractionTask) child).getInteraction()).getKey(); 199 200 pressedKeys.add(key); 201 202 if (key == VirtualKey.BACK_SPACE) 203 { 204 if (enteredText.length() > 0) 205 { 206 enteredText.deleteCharAt(enteredText.length() - 1); 207 } 208 } 209 else if (key == VirtualKey.ENTER) 210 { 211 // text fields only contain one line of code. Therefore the return is ignored. 212 if (!(((InteractionTask) child).getGUIElement() instanceof TextField)) 213 { 214 enteredText.append(getCharacter(key, pressedKeys)); 215 } 216 } 217 else 218 { 219 char theChar = getCharacter(key, pressedKeys); 220 if (theChar != Character.UNASSIGNED) 221 { 222 enteredText.append(theChar); 223 } 224 } 225 } 226 else if (((InteractionTask) child).getInteraction() instanceof KeyReleased) 227 { 228 pressedKeys.remove(((KeyReleased) ((InteractionTask) child).getInteraction()).getKey()); 229 } 230 } 231 else 232 { 233 determineEnteredText(child, pressedKeys, enteredText); 234 } 235 } 236 } 237 } 238 239 //----------------------------------------------------------------------------------------------- 240 /** 241 * TODO: comment 242 * 243 * @param key 244 * @param pressedKeys 245 * @return 246 */ 247 //----------------------------------------------------------------------------------------------- 248 private char getCharacter(VirtualKey key, List<VirtualKey> pressedKeys) 249 { 250 boolean numlock = false; 251 boolean shift = false; 252 boolean altgr = false; 253 254 for (VirtualKey pressedKey : pressedKeys) 255 { 256 if (pressedKey.isShiftKey()) 257 { 258 shift = !shift; 259 } 260 else if (pressedKey == VirtualKey.ALT_GRAPH) 261 { 262 altgr = !altgr; 263 } 264 else if (pressedKey == VirtualKey.NUM_LOCK) 265 { 266 numlock = !numlock; 267 } 268 } 269 270 return mKeyboardMap.getCharacterFor(key, numlock, shift, altgr, false); 271 } 167 if ((node instanceof ISequence) || (node instanceof ITextInputEventTask)) { 168 for (ITaskTreeNode child : node.getChildren()) { 169 if (child instanceof IEventTask) { 170 if (((IEventTask) child).getEventType() instanceof KeyPressed) { 171 VirtualKey key = 172 ((KeyPressed) ((IEventTask) child).getEventType()).getKey(); 173 174 pressedKeys.add(key); 175 176 if (key == VirtualKey.BACK_SPACE) { 177 if (enteredText.length() > 0) { 178 enteredText.deleteCharAt(enteredText.length() - 1); 179 } 180 } 181 else if (key == VirtualKey.ENTER) { 182 // text fields only contain one line of code. Therefore the return is 183 // ignored. 184 if (!(((IEventTask) child).getEventTarget() instanceof ITextField)) { 185 enteredText.append(getCharacter(key, pressedKeys)); 186 } 187 } 188 else { 189 char theChar = getCharacter(key, pressedKeys); 190 if (theChar != Character.UNASSIGNED) { 191 enteredText.append(theChar); 192 } 193 } 194 } 195 else if (((IEventTask) child).getEventType() instanceof KeyReleased) { 196 pressedKeys.remove 197 (((KeyReleased) ((IEventTask) child).getEventType()).getKey()); 198 } 199 } 200 else { 201 determineEnteredText(child, pressedKeys, enteredText); 202 } 203 } 204 } 205 } 206 207 /** 208 * TODO: comment 209 * 210 * @param key 211 * @param pressedKeys 212 * @return 213 */ 214 private char getCharacter(VirtualKey key, List<VirtualKey> pressedKeys) { 215 boolean numlock = false; 216 boolean shift = false; 217 boolean altgr = false; 218 219 for (VirtualKey pressedKey : pressedKeys) { 220 if (pressedKey.isShiftKey()) { 221 shift = !shift; 222 } 223 else if (pressedKey == VirtualKey.ALT_GRAPH) { 224 altgr = !altgr; 225 } 226 else if (pressedKey == VirtualKey.NUM_LOCK) { 227 numlock = !numlock; 228 } 229 } 230 231 return keyboardMap.getCharacterFor(key, numlock, shift, altgr, false); 232 } 272 233 273 234 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/RuleApplicationResult.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: RuleApplicationResult.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 9 … … 11 11 import java.util.List; 12 12 13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 14 14 15 //-------------------------------------------------------------------------------------------------16 15 /** 17 16 * TODO comment … … 20 19 * @author 2012, last modified by $Author: patrick$ 21 20 */ 22 //------------------------------------------------------------------------------------------------- 23 public class RuleApplicationResult 24 { 21 public class RuleApplicationResult { 25 22 26 /** */ 27 private RuleApplicationStatus mStatus = RuleApplicationStatus.RULE_NOT_APPLIED; 28 29 /** */ 30 private List<TaskTreeNode> mNewParents = new ArrayList<TaskTreeNode>(); 23 /** */ 24 private RuleApplicationStatus status = RuleApplicationStatus.RULE_NOT_APPLIED; 31 25 32 //----------------------------------------------------------------------------------------------- 33 /** 34 * TODO: comment 35 * 36 * @param b 37 */ 38 //----------------------------------------------------------------------------------------------- 39 public RuleApplicationResult() 40 { 41 // this is the default indicating nothing so far 42 } 26 /** */ 27 private List<ITaskTreeNode> newParents = new ArrayList<ITaskTreeNode>(); 43 28 44 //----------------------------------------------------------------------------------------------- 45 /** 46 * TODO: comment 47 * 48 * @param b 49 */ 50 //----------------------------------------------------------------------------------------------- 51 public void setRuleApplicationStatus(RuleApplicationStatus status) 52 { 53 mStatus = status; 54 } 29 /** 30 * TODO: comment 31 * 32 * @param b 33 */ 34 public RuleApplicationResult() { 35 // this is the default indicating nothing so far 36 } 55 37 56 //----------------------------------------------------------------------------------------------- 57 /** 58 * TODO: comment 59 * 60 * @return 61 */ 62 //----------------------------------------------------------------------------------------------- 63 public RuleApplicationStatus getRuleApplicationStatus() 64 { 65 return mStatus; 66 } 38 /** 39 * TODO: comment 40 * 41 * @param b 42 */ 43 public void setRuleApplicationStatus(RuleApplicationStatus status) { 44 this.status = status; 45 } 67 46 68 //----------------------------------------------------------------------------------------------- 69 /** 70 * TODO: comment 71 * 72 * @param sequence 73 */ 74 //----------------------------------------------------------------------------------------------- 75 public void addNewlyCreatedParentNode(TaskTreeNode newParent) 76 { 77 mNewParents.add(newParent); 78 } 47 /** 48 * TODO: comment 49 * 50 * @return 51 */ 52 public RuleApplicationStatus getRuleApplicationStatus() { 53 return status; 54 } 79 55 80 //----------------------------------------------------------------------------------------------- 81 /** 82 * TODO: comment 83 * 84 * @return 85 */ 86 //----------------------------------------------------------------------------------------------- 87 public List<TaskTreeNode> getNewlyCreatedParentNodes() 88 { 89 return mNewParents; 90 } 56 /** 57 * TODO: comment 58 * 59 * @param sequence 60 */ 61 public void addNewlyCreatedParentNode(ITaskTreeNode newParent) { 62 newParents.add(newParent); 63 } 64 65 /** 66 * TODO: comment 67 * 68 * @return 69 */ 70 public List<ITaskTreeNode> getNewlyCreatedParentNodes() { 71 return newParents; 72 } 91 73 92 74 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/RuleApplicationStatus.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: RuleApplicationStatus.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: pharms $ $Date: 09.07.2012 $ … … 5 4 // Creation : 2012 by pharms 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 9 10 //-------------------------------------------------------------------------------------------------11 10 /** 12 11 * TODO comment … … 15 14 * @author 2012, last modified by $Author: pharms$ 16 15 */ 17 //------------------------------------------------------------------------------------------------- 18 public enum RuleApplicationStatus 19 { 20 RULE_APPLICATION_FINISHED, 21 RULE_APPLICATION_FEASIBLE, 22 RULE_NOT_APPLIED; 16 public enum RuleApplicationStatus { 17 RULE_APPLICATION_FINISHED, 18 RULE_APPLICATION_FEASIBLE, 19 RULE_NOT_APPLIED; 23 20 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TemporalRelationshipRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TemporalRelationshipRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;11 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;9 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 13 12 14 //-------------------------------------------------------------------------------------------------15 13 /** 16 14 * TODO comment … … 19 17 * @author 2012, last modified by $Author: patrick$ 20 18 */ 21 //------------------------------------------------------------------------------------------------- 22 public interface TemporalRelationshipRule 23 { 19 public interface TemporalRelationshipRule { 24 20 25 //-----------------------------------------------------------------------------------------------26 21 /** 27 22 * applies the rule to the given situation and returns a rule application result, if this was 28 23 * successful 29 24 */ 30 //----------------------------------------------------------------------------------------------- 31 public RuleApplicationResult apply(TaskTreeNode parent, 32 TaskTreeBuilder builder, 33 TaskTreeNodeFactory nodeFactory, 34 boolean finalize); 25 public RuleApplicationResult apply(ITaskTreeNode parent, 26 ITaskTreeBuilder builder, 27 ITaskTreeNodeFactory nodeFactory, 28 boolean finalize); 35 29 36 30 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TemporalRelationshipRuleManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 13 12 14 13 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;16 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;17 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;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; 18 17 19 //-------------------------------------------------------------------------------------------------20 18 /** 21 19 * TODO comment … … 24 22 * @author 2012, last modified by $Author: patrick$ 25 23 */ 26 //------------------------------------------------------------------------------------------------- 27 public class TemporalRelationshipRuleManager 28 { 29 /** */ 30 private static Logger LOG = Logger.getLogger(TemporalRelationshipRuleManager.class.getName()); 24 public class TemporalRelationshipRuleManager { 25 26 /** */ 27 private static Logger LOG = Logger.getLogger(TemporalRelationshipRuleManager.class.getName()); 31 28 32 /** */33 private NodeEqualityRuleManager mNodeEqualityRuleManager;29 /** */ 30 private NodeEqualityRuleManager nodeEqualityRuleManager; 34 31 35 /** */36 private List<TemporalRelationshipRule> mRuleIndex = new ArrayList<TemporalRelationshipRule>();32 /** */ 33 private List<TemporalRelationshipRule> ruleIndex = new ArrayList<TemporalRelationshipRule>(); 37 34 38 //----------------------------------------------------------------------------------------------- 39 /** 40 * TODO: comment 35 /** 36 * TODO: comment 37 * 38 */ 39 public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager) { 40 super(); 41 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 42 } 43 44 /** 45 * TODO: comment 46 * 47 */ 48 public void init() { 49 LOG.info("initializing"); 50 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 } 58 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) 71 { 72 applyRules(parent, builder, nodeFactory, finalize, ""); 73 } 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) 88 { 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; 131 } 132 133 /** 41 134 * 42 135 */ 43 //----------------------------------------------------------------------------------------------- 44 public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager) 45 { 46 super(); 47 mNodeEqualityRuleManager = nodeEqualityRuleManager; 48 } 49 50 //----------------------------------------------------------------------------------------------- 51 /** 52 * TODO: comment 53 * 54 */ 55 //----------------------------------------------------------------------------------------------- 56 public void init() 57 { 58 LOG.info("initializing"); 59 60 mRuleIndex.add(new DefaultMouseClickReductionRule()); 61 mRuleIndex.add(new DefaultTextInputReductionRule()); 62 mRuleIndex.add(new DefaultGUIElementSequenceDetectionRule()); 63 mRuleIndex.add(new TrackBarSelectionDetectionRule(mNodeEqualityRuleManager)); 64 mRuleIndex.add(new DefaultSequenceDetectionRule()); 65 mRuleIndex.add(new DefaultIterationDetectionRule(mNodeEqualityRuleManager)); 66 } 67 68 //----------------------------------------------------------------------------------------------- 69 /** 70 * returns true, if there is a rule that matches the current situation and if, therefore, a 71 * new temporal relationship has been added to the tree. 72 * 73 * @param parent 74 * @param newChild 75 * @return 76 */ 77 //----------------------------------------------------------------------------------------------- 78 public void applyRules(TaskTreeNode parent, 79 TaskTreeBuilder builder, 80 TaskTreeNodeFactory nodeFactory, 81 boolean finalize) 82 { 83 applyRules(parent, builder, nodeFactory, finalize, ""); 84 } 85 86 //----------------------------------------------------------------------------------------------- 87 /** 88 * returns true, if there is a rule that matches the current situation and if, therefore, a 89 * new temporal relationship has been added to the tree. 90 * 91 * @param parent 92 * @param newChild 93 * @return 94 */ 95 //----------------------------------------------------------------------------------------------- 96 private int applyRules(TaskTreeNode parent, 97 TaskTreeBuilder builder, 98 TaskTreeNodeFactory nodeFactory, 99 boolean finalize, 100 String logIndent) 101 { 102 LOG.info(logIndent + "applying rules for " + parent); 103 104 int noOfRuleApplications = 0; 105 106 for (TemporalRelationshipRule rule : mRuleIndex) 107 { 108 RuleApplicationResult result; 109 do 110 { 111 //LOG.info(logIndent + "trying to apply rule " + rule + " on " + parent); 112 result = rule.apply(parent, builder, nodeFactory, finalize); 113 114 if ((result != null) && 115 (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FINISHED)) 116 { 117 LOG.info(logIndent + "applied rule " + rule + " on " + parent); 118 noOfRuleApplications++; 119 120 for (TaskTreeNode newParent : result.getNewlyCreatedParentNodes()) 121 { 122 noOfRuleApplications += 123 applyRules(newParent, builder, nodeFactory, true, logIndent + " "); 124 } 125 } 126 } 127 while ((result != null) && 128 (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FINISHED)); 129 130 if ((!finalize) && (result != null) && 131 (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FEASIBLE)) 132 { 133 // in this case, don't go on applying rules, which should not be applied yet 134 break; 135 } 136 } 137 138 if (noOfRuleApplications <= 0) 139 { 140 LOG.warning(logIndent + "no rules applied --> no temporal relationship generated"); 141 } 142 143 return noOfRuleApplications; 144 } 145 146 //----------------------------------------------------------------------------------------------- 147 /** 148 * 149 */ 150 //----------------------------------------------------------------------------------------------- 151 /*private void dumpTask(TaskTreeNode task, String indent) 152 { 153 System.err.print(indent); 154 System.err.print(task); 155 System.err.println(" "); 156 157 if ((task.getChildren() != null) && (task.getChildren().size() > 0)) 158 { 159 for (TaskTreeNode child : task.getChildren()) 160 { 161 dumpTask(child, indent + " "); 162 } 163 } 164 }*/ 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 */ 165 143 166 144 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TrackBarSelectionDetectionRule.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TrackBarSelectionDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.eventcore.gui model.TrackBar;11 import de.ugoe.cs.quest.eventcore. userinteraction.ValueSelection;9 import de.ugoe.cs.quest.eventcore.gui.ValueSelection; 10 import de.ugoe.cs.quest.eventcore.guimodel.ITrackBar; 12 11 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEquality; 13 12 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 14 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;15 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;16 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;17 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;18 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;19 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;20 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;13 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 14 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 21 20 22 //-------------------------------------------------------------------------------------------------23 21 /** 24 22 * TODO comment … … 27 25 * @author 2012, last modified by $Author: patrick$ 28 26 */ 29 //------------------------------------------------------------------------------------------------- 30 public class TrackBarSelectionDetectionRule implements TemporalRelationshipRule 31 { 27 public class TrackBarSelectionDetectionRule implements TemporalRelationshipRule { 32 28 33 /** */34 private NodeEqualityRuleManager mNodeEqualityRuleManager;29 /** */ 30 private NodeEqualityRuleManager nodeEqualityRuleManager; 35 31 36 //----------------------------------------------------------------------------------------------- 37 /** 38 * TODO: comment 32 /** 33 * TODO: comment 34 * 35 */ 36 TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) { 37 super(); 38 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 39 } 40 41 /* 42 * (non-Javadoc) 43 * 44 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 45 */ 46 @Override 47 public RuleApplicationResult apply(ITaskTreeNode parent, 48 ITaskTreeBuilder builder, 49 ITaskTreeNodeFactory nodeFactory, 50 boolean finalize) 51 { 52 if (!(parent instanceof ISequence)) { 53 return null; 54 } 55 56 RuleApplicationResult result = new RuleApplicationResult(); 57 58 int valueSelectionStartIndex = -1; 59 60 int index = 0; 61 while (index < parent.getChildren().size()) { 62 ITaskTreeNode child = parent.getChildren().get(index); 63 64 if ((child instanceof IEventTask) && 65 (((IEventTask) child).getEventTarget() instanceof ITrackBar) && 66 (((IEventTask) child).getEventType() instanceof ValueSelection)) 67 { 68 if (valueSelectionStartIndex < 0) { 69 // let the show begin 70 valueSelectionStartIndex = index; 71 } 72 } 73 else if (valueSelectionStartIndex >= 0) { 74 // current child is no more value selection. But the preceding tasks were. 75 // Therefore, 76 // create an iteration with the different selectable values as selection children 77 handleValueSelections(valueSelectionStartIndex, index - 1, parent, builder, 78 nodeFactory, result); 79 80 return result; 81 } 82 83 index++; 84 } 85 86 if (valueSelectionStartIndex >= 0) { 87 if (finalize) { 88 handleValueSelections(valueSelectionStartIndex, parent.getChildren().size() - 1, 89 parent, builder, nodeFactory, result); 90 } 91 else { 92 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 93 } 94 } 95 96 return result; 97 } 98 99 /** 100 * TODO: comment 101 * 102 * @param valueSelectionStartIndex 103 * @param i 104 */ 105 private void handleValueSelections(int startIndex, 106 int endIndex, 107 ITaskTreeNode parent, 108 ITaskTreeBuilder builder, 109 ITaskTreeNodeFactory nodeFactory, 110 RuleApplicationResult result) 111 { 112 IIteration iteration = nodeFactory.createNewIteration(); 113 result.addNewlyCreatedParentNode(iteration); 114 115 ISelection selection = nodeFactory.createNewSelection(); 116 result.addNewlyCreatedParentNode(selection); 117 builder.setChild(iteration, selection); 118 119 for (int i = endIndex - startIndex; i >= 0; i--) { 120 addChildIfNecessary(selection, parent.getChildren().get(startIndex), builder, 121 nodeFactory, result); 122 builder.removeChild((ISequence) parent, startIndex); 123 } 124 125 builder.addChild((ISequence) parent, startIndex, iteration); 126 127 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 128 } 129 130 /** 39 131 * 40 132 */ 41 //----------------------------------------------------------------------------------------------- 42 TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) 43 { 44 super(); 45 mNodeEqualityRuleManager = nodeEqualityRuleManager; 46 } 133 private void addChildIfNecessary(ISelection parentSelection, 134 ITaskTreeNode node, 135 ITaskTreeBuilder builder, 136 ITaskTreeNodeFactory nodeFactory, 137 RuleApplicationResult result) 138 { 139 for (int i = 0; i < parentSelection.getChildren().size(); i++) { 140 ITaskTreeNode child = parentSelection.getChildren().get(i); 47 141 48 //----------------------------------------------------------------------------------------------- 49 /* (non-Javadoc) 50 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 51 */ 52 //----------------------------------------------------------------------------------------------- 53 @Override 54 public RuleApplicationResult apply(TaskTreeNode parent, 55 TaskTreeBuilder builder, 56 TaskTreeNodeFactory nodeFactory, 57 boolean finalize) 58 { 59 if (!(parent instanceof Sequence)) 60 { 61 return null; 62 } 63 64 RuleApplicationResult result = new RuleApplicationResult(); 65 66 int valueSelectionStartIndex = -1; 67 68 int index = 0; 69 while (index < parent.getChildren().size()) 70 { 71 TaskTreeNode child = parent.getChildren().get(index); 72 73 if ((child instanceof InteractionTask) && 74 (((InteractionTask) child).getGUIElement() instanceof TrackBar) && 75 (((InteractionTask) child).getInteraction() instanceof ValueSelection)) 76 { 77 if (valueSelectionStartIndex < 0) 78 { 79 // let the show begin 80 valueSelectionStartIndex = index; 81 } 82 } 83 else if (valueSelectionStartIndex >= 0) 84 { 85 // current child is no more value selection. But the preceding tasks were. Therefore, 86 // create an iteration with the different selectable values as selection children 87 handleValueSelections 88 (valueSelectionStartIndex, index - 1, parent, builder, nodeFactory, result); 89 90 return result; 91 } 92 93 index++; 94 } 95 96 if (valueSelectionStartIndex >= 0) 97 { 98 if (finalize) 99 { 100 handleValueSelections(valueSelectionStartIndex, parent.getChildren().size() - 1, parent, 101 builder, nodeFactory, result); 102 } 103 else 104 { 105 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 106 } 107 } 108 109 return result; 110 } 142 if (child instanceof IEventTask) { 143 // check, if the new node is a variant for the current event task 144 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules(child, node); 145 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 146 // the node is a variant. If it not structurally equal, a new sub-selection for 147 // the existing and the new node must be created. Otherwise, the new node does 148 // not need to be added 149 if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 150 ISelection selection = nodeFactory.createNewSelection(); 151 result.addNewlyCreatedParentNode(selection); 152 builder.addChild(parentSelection, selection); 111 153 112 //----------------------------------------------------------------------------------------------- 113 /** 114 * TODO: comment 115 * 116 * @param valueSelectionStartIndex 117 * @param i 118 */ 119 //----------------------------------------------------------------------------------------------- 120 private void handleValueSelections(int startIndex, 121 int endIndex, 122 TaskTreeNode parent, 123 TaskTreeBuilder builder, 124 TaskTreeNodeFactory nodeFactory, 125 RuleApplicationResult result) 126 { 127 Iteration iteration = nodeFactory.createNewIteration(); 128 result.addNewlyCreatedParentNode(iteration); 129 130 Selection selection = nodeFactory.createNewSelection(); 131 result.addNewlyCreatedParentNode(selection); 132 builder.setChild(iteration, selection); 133 134 for (int i = endIndex - startIndex; i >= 0 ; i--) 135 { 136 addChildIfNecessary 137 (selection, parent.getChildren().get(startIndex), builder, nodeFactory, result); 138 builder.removeChild((Sequence) parent, startIndex); 139 } 140 141 builder.addChild((Sequence) parent, startIndex, iteration); 142 143 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 144 } 154 builder.addChild(selection, child); 155 builder.addChild(selection, node); 156 builder.removeChild(parentSelection, child); 157 } 145 158 146 //----------------------------------------------------------------------------------------------- 147 /** 148 * 149 */ 150 //----------------------------------------------------------------------------------------------- 151 private void addChildIfNecessary(Selection parentSelection, 152 TaskTreeNode node, 153 TaskTreeBuilder builder, 154 TaskTreeNodeFactory nodeFactory, 155 RuleApplicationResult result) 156 { 157 for (int i = 0; i < parentSelection.getChildren().size(); i++) 158 { 159 TaskTreeNode child = parentSelection.getChildren().get(i); 159 return; 160 } 161 } 162 else if (child instanceof ISelection) { 163 // check, if the new node is a variant for the semantically equal children of the 164 // current 165 // selection 166 boolean addNode = true; 167 for (int j = 0; j < child.getChildren().size(); j++) { 168 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules(child, node); 169 if (!nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 170 // the new node is no semantical equivalent of the nodes in the current 171 // selection - break up 172 addNode = false; 173 break; 174 } 175 else if (nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 176 addNode = false; 177 break; 178 } 179 } 160 180 161 if (child instanceof InteractionTask) 162 { 163 // check, if the new node is a variant for the current interaction task 164 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules(child, node); 165 if (nodeEquality.getSemanticalEquality()) 166 { 167 // the node is a variant. If it not structurally equal, a new sub-selection for the 168 // existing and the new node must be created. Otherwise, the new node does not need 169 // to be added 170 if (!nodeEquality.getStructuralEquality()) 171 { 172 Selection selection = nodeFactory.createNewSelection(); 173 result.addNewlyCreatedParentNode(selection); 174 builder.addChild(parentSelection, selection); 175 176 builder.addChild(selection, child); 177 builder.addChild(selection, node); 178 builder.removeChild(parentSelection, child); 179 } 180 181 return; 182 } 183 } 184 else if (child instanceof Selection) 185 { 186 // check, if the new node is a variant for the semantically equal children of the current 187 // selection 188 boolean addNode = true; 189 for (int j = 0; j < child.getChildren().size(); j++) 190 { 191 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules(child, node); 192 if (!nodeEquality.getSemanticalEquality()) 193 { 194 // the new node is no semantical equivalent of the nodes in the current selection - 195 // break up 196 addNode = false; 197 break; 198 } 199 else if (nodeEquality.getStructuralEquality()) 200 { 201 addNode = false; 202 break; 203 } 181 if (addNode) { 182 // the node is a semantical equivalent to all the nodes in the existing 183 // sub-selection 184 // but it is not structurally identical to either of them. Therefore add it. 185 builder.addChild((ISelection) child, node); 186 return; 187 } 188 } 204 189 } 205 190 206 if (addNode) 207 { 208 // the node is a semantical equivalent to all the nodes in the existing sub-selection 209 // but it is not structurally identical to either of them. Therefore add it. 210 builder.addChild((Selection) child, node); 211 return; 212 } 213 } 191 // if we did not return in the previous checks, then the node must be added 192 builder.addChild(parentSelection, node); 214 193 } 215 216 // if we did not return in the previous checks, then the node must be added217 builder.addChild(parentSelection, node);218 }219 194 220 195 }
Note: See TracChangeset
for help on using the changeset viewer.