Changeset 557 for trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRule.java
- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.