use of org.iobserve.analysis.userbehavior.data.ISequenceElement in project iobserve-analysis by research-iobserve.
the class BranchModelCreator method setBranchSequence.
/**
* Sets the passed events as branch sequence of the passed branch. The sequenceStartIndex
* defines at which position of the passed events the branch sequence starts
*
* @param examinedBranch
* for that the branchSequence will be set
* @param events
* represent the sequence to set
* @param sequenceStartIndex
* states at which position of the passed events the branch sequence starts
*/
private void setBranchSequence(final Branch examinedBranch, final List<EntryCallEvent> events, final int sequenceStartIndex) {
final List<ISequenceElement> branchSequence = new ArrayList<>();
for (int j = sequenceStartIndex; j < events.size(); j++) {
final EntryCallEvent callEvent = events.get(j);
final CallElement callElement = new CallElement(callEvent.getClassSignature(), callEvent.getOperationSignature());
callElement.setAbsoluteCount(1);
branchSequence.add(callElement);
}
final ExitElement exitElement = new ExitElement();
exitElement.setAbsoluteCount(1);
branchSequence.add(exitElement);
examinedBranch.setBranchSequence(branchSequence);
}
use of org.iobserve.analysis.userbehavior.data.ISequenceElement in project iobserve-analysis by research-iobserve.
the class BranchModelCreator method mergeBranches.
/**
* Merges branches.
*
* @param branch
* whose child branches are merged
* @param doChildBranchesExist
* @return
*/
private boolean mergeBranches(final Branch branch, final boolean doChildBranchesExist) {
int indexOfEqualElements = 0;
boolean isElementEqual = false;
// their sequences
for (int i = branch.getChildBranches().get(0).getBranchSequence().size() - 1; i >= 0; i--) {
final ISequenceElement branchElement = branch.getChildBranches().get(0).getBranchSequence().get(i);
isElementEqual = false;
for (final Branch childBranch : branch.getChildBranches()) {
if (childBranch.getBranchSequence().size() - 1 - indexOfEqualElements < 0) {
isElementEqual = false;
break;
} else if (this.doBranchElementsMatch(branchElement, childBranch.getBranchSequence().get(childBranch.getBranchSequence().size() - 1 - indexOfEqualElements))) {
isElementEqual = true;
} else {
isElementEqual = false;
break;
}
}
if (!isElementEqual) {
break;
}
indexOfEqualElements++;
}
// Creates a new branch element that replaces the child branches that are merged
final BranchElement branchElement = new BranchElement();
final List<ISequenceElement> sequenceToAddToBranch = new ArrayList<>();
for (int i = 0; i < indexOfEqualElements; i++) {
sequenceToAddToBranch.add(0, branch.getChildBranches().get(0).getBranchSequence().get(branch.getChildBranches().get(0).getBranchSequence().size() - 1));
for (final Branch childBranch : branch.getChildBranches()) {
childBranch.getBranchSequence().remove(childBranch.getBranchSequence().size() - 1);
}
}
for (final Branch childBranch : branch.getChildBranches()) {
final BranchTransitionElement branchTransition = new BranchTransitionElement();
branchTransition.setBranchSequence(childBranch.getBranchSequence());
branchTransition.setTransitionLikelihood(childBranch.getBranchLikelihood());
branchElement.addBranchTransition(branchTransition);
}
branch.getBranchSequence().add(branchElement);
branch.getBranchSequence().addAll(sequenceToAddToBranch);
// Removes the replaced child branches
if (doChildBranchesExist) {
final List<Branch> newChildBranches = branch.getChildBranches().get(0).getChildBranches();
branch.getChildBranches().clear();
branch.setChildBranches(newChildBranches);
} else {
branch.getChildBranches().clear();
}
if (doChildBranchesExist || indexOfEqualElements > 0) {
this.fusionPerformed = true;
return true;
} else {
return false;
}
}
use of org.iobserve.analysis.userbehavior.data.ISequenceElement in project iobserve-analysis by research-iobserve.
the class LoopBranchModelCreator method determineLoopCount.
/**
* Determines the loop count by checking how often the loop is iterated in a row.
*
* @param loopElement
* whose loopCount is determined
* @param branchSequence
* within the loopCount is determined
*/
private void determineLoopCount(final LoopElement loopElement, final List<ISequenceElement> branchSequence) {
int loopCount = 2;
for (int i = loopElement.getEndIndexInBranchSequence(); i + loopElement.getLoopSequence().size() < branchSequence.size(); i = i + loopElement.getLoopSequence().size()) {
boolean isAdditionalLoop = true;
for (int j = 0; j < loopElement.getLoopSequence().size(); j++) {
final ISequenceElement element1 = branchSequence.get(loopElement.getStartIndexInBranchSequence() + j);
final ISequenceElement element2 = branchSequence.get(i + 1 + j);
if (element1.getClass().equals(CallElement.class) && element2.getClass().equals(CallElement.class)) {
if (!this.areSequenceElementsEqual(element1, element2)) {
isAdditionalLoop = false;
break;
}
} else if (element1.getClass().equals(BranchElement.class) && element2.getClass().equals(BranchElement.class)) {
if (!this.areSequenceElementsEqual(element1, element2)) {
isAdditionalLoop = false;
break;
}
} else {
isAdditionalLoop = false;
break;
}
}
if (isAdditionalLoop) {
loopCount++;
} else {
break;
}
}
loopElement.setLoopCount(loopCount);
loopElement.setNumberOfReplacedElements(loopCount * loopElement.getLoopSequence().size());
loopElement.setEndIndexInBranchSequence(loopElement.getStartIndexInBranchSequence() + loopElement.getNumberOfReplacedElements() - 1);
}
use of org.iobserve.analysis.userbehavior.data.ISequenceElement in project iobserve-analysis by research-iobserve.
the class BranchModelCreator method splitBranch.
/**
* It splits the passed branch at the passed position of its branch sequence into two child
* branches. The branch sequence of the passed branch is shorted to the position the split is
* performed. The first child branch receives the remaining branch sequence, starting at the
* position the split is performed. The second child branch´s sequence stays empty and is filled
* later
*
* @param examinedBranch
* is split into two branches
* @param positionInBranch
* is the position in the branch sequence where the split is performed
* @param numberOfBranches
* is the current overall number of branches. Defines the new branch ids
*/
private void splitBranch(final Branch examinedBranch, final int positionInBranch, final int numberOfBranches) {
final Branch childBranch1 = new Branch();
final Branch childBranch2 = new Branch();
final List<ISequenceElement> branchSequence = new ArrayList<>(examinedBranch.getBranchSequence().subList(0, positionInBranch));
final List<ISequenceElement> branchSequence1 = new ArrayList<>(examinedBranch.getBranchSequence().subList(positionInBranch, examinedBranch.getBranchSequence().size()));
final List<ISequenceElement> branchSequence2 = new ArrayList<>();
examinedBranch.setBranchSequence(branchSequence);
childBranch1.setBranchSequence(branchSequence1);
childBranch2.setBranchSequence(branchSequence2);
childBranch1.setBranchId(numberOfBranches + 1);
childBranch2.setBranchId(numberOfBranches + 2);
for (final Branch childBranch : examinedBranch.getChildBranches()) {
childBranch1.addBranch(childBranch);
}
examinedBranch.getChildBranches().clear();
examinedBranch.addBranch(childBranch1);
examinedBranch.addBranch(childBranch2);
}
use of org.iobserve.analysis.userbehavior.data.ISequenceElement in project iobserve-analysis by research-iobserve.
the class LoopBranchModelCreator method doSequencesMatch.
/**
* Checks whether two sequences are equal.
*
* @param sequence1
* is matched against sequence 2
* @param sequence2
* is matched against sequence 1
* @return whether the two passed sequences are equal
*/
private boolean doSequencesMatch(final List<ISequenceElement> sequence1, final List<ISequenceElement> sequence2) {
if (sequence1.size() < sequence2.size()) {
return false;
}
for (int i = 0; i < sequence2.size(); i++) {
final ISequenceElement branchElementOfSequence1 = sequence1.get(i);
final ISequenceElement branchElementOfSequence2 = sequence2.get(i);
if (!branchElementOfSequence1.getClass().equals(branchElementOfSequence2.getClass())) {
return false;
}
if (branchElementOfSequence1.getClass().equals(CallElement.class) && branchElementOfSequence2.getClass().equals(CallElement.class)) {
if (!branchElementOfSequence1.getClassSignature().equals(branchElementOfSequence2.getClassSignature()) || !branchElementOfSequence1.getOperationSignature().equals(branchElementOfSequence2.getOperationSignature())) {
return false;
}
} else if (branchElementOfSequence1.getClass().equals(LoopElement.class) && branchElementOfSequence2.getClass().equals(LoopElement.class)) {
final LoopElement loopElement1 = (LoopElement) branchElementOfSequence1;
final LoopElement loopElement2 = (LoopElement) branchElementOfSequence2;
if (!this.doSequencesMatch(loopElement1.getLoopSequence(), loopElement2.getLoopSequence())) {
return false;
}
}
}
return true;
}
Aggregations