Skip to content

Commit 4e7c787

Browse files
authored
Test place predicates and transformers
1 parent 9c353e9 commit 4e7c787

File tree

16 files changed

+630
-71
lines changed

16 files changed

+630
-71
lines changed

src/org/processmining/placebasedlpmdiscovery/model/Place.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public Place(String id) {
3939
* Create a place from its string representation. The string representation differentiates input and output transitions
4040
* using a | character. For example, the string "a, b | c, d" represents a place with input transitions a and b,
4141
* and output transitions c and d. Each transition is represented by its label and is assumed to be visible.
42-
* Transitions are separated by commas. Whitespace around labels and the | character is ignored.
42+
* Transitions are separated by commas. Whitespace around labels and the | character is ignored. It is possible
43+
* to create places with empty input or output transition set, e.g., "|", "| a, b" or "a, b |".
4344
* @param stringRepresentation the string representation of the place
4445
* @return a Place object corresponding to the string representation
4546
* @throws IllegalArgumentException if the string representation is invalid

src/org/processmining/placebasedlpmdiscovery/placechooser/MainPlaceChooser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.deckfour.xes.model.XLog;
44
import org.processmining.placebasedlpmdiscovery.analysis.analyzers.loganalyzer.LEFRMatrix;
55
import org.processmining.placebasedlpmdiscovery.model.Place;
6-
import org.processmining.placebasedlpmdiscovery.placechooser.placepredicates.MostKArcsPredicate;
6+
import org.processmining.placebasedlpmdiscovery.placechooser.placepredicates.MostKArcsPlacePredicate;
77
import org.processmining.placebasedlpmdiscovery.placechooser.placepredicates.NonEmptyIOTransitionSetPlacePredicate;
88
import org.processmining.placebasedlpmdiscovery.placechooser.placepredicates.NonSelfLoopPlacePredicate;
99
import org.processmining.placebasedlpmdiscovery.placechooser.placerankconverters.RankedPlace;
@@ -40,7 +40,7 @@ public Set<Place> choose(Set<Place> places, int count) {
4040
.map(new PassageUsagePlaceTransformer(LogUtils.getFollowRelations(log, placeChooserParameters.getFollowRelationsLimit()))) // TODO: this might be duplicate work, since the lefr should already contain it
4141
.filter(new NonSelfLoopPlacePredicate())
4242
.filter(new NonEmptyIOTransitionSetPlacePredicate())
43-
.filter(new MostKArcsPredicate(5))
43+
.filter(new MostKArcsPlacePredicate(5))
4444
.map(p -> new RankedPlace(p, new TransitionCountPlaceRankConverter().convert(p) /*, new TotalPassageCoveragePlaceRankConverter(lefr).convert(p) */))
4545
.sorted(new RankedPlaceComparator())
4646
.map(RankedPlace::getPlace)

src/org/processmining/placebasedlpmdiscovery/placechooser/placepredicates/AndPredicate.java renamed to src/org/processmining/placebasedlpmdiscovery/placechooser/placepredicates/AndPlacePredicate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import java.util.Arrays;
77
import java.util.Collection;
88

9-
public class AndPredicate implements PlacePredicate {
9+
public class AndPlacePredicate implements PlacePredicate {
1010

1111
Collection<PlacePredicate> predicates;
1212

13-
public AndPredicate (PlacePredicate ... predicates) {
13+
public AndPlacePredicate(PlacePredicate ... predicates) {
1414
this.predicates = new ArrayList<>();
1515
this.predicates.addAll(Arrays.asList(predicates));
1616
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import org.processmining.placebasedlpmdiscovery.model.Place;
44

5-
public class MostKArcsPredicate implements PlacePredicate {
5+
public class MostKArcsPlacePredicate implements PlacePredicate {
66

77
private final int k;
88

9-
public MostKArcsPredicate(int k) {
9+
public MostKArcsPlacePredicate(int k) {
10+
if (k < 0) {
11+
throw new IllegalArgumentException("k must be a non-negative integer.");
12+
}
1013
this.k = k;
1114
}
1215

src/org/processmining/placebasedlpmdiscovery/placechooser/placepredicates/NonEmptyIOTransitionSetPlacePredicate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
public class NonEmptyIOTransitionSetPlacePredicate implements PlacePredicate {
66

77
/**
8-
* Checks for empty input or output transition set
8+
* Checks for an empty input or output transition set
99
* @param place that we want to check for filtering
1010
* @return false when the input or output transition set is empty, true otherwise
1111
*/
1212
@Override
1313
public boolean testPlace(Place place) {
14-
return place.getInputTransitions().size() > 0 && place.getOutputTransitions().size() > 0;
14+
return !place.getInputTransitions().isEmpty() && !place.getOutputTransitions().isEmpty();
1515
}
1616
}

src/org/processmining/placebasedlpmdiscovery/placechooser/placepredicates/OrPredicate.java renamed to src/org/processmining/placebasedlpmdiscovery/placechooser/placepredicates/OrPlacePredicate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import java.util.Arrays;
77
import java.util.Collection;
88

9-
public class OrPredicate implements PlacePredicate {
9+
public class OrPlacePredicate implements PlacePredicate {
1010
Collection<PlacePredicate> predicates;
1111

12-
public OrPredicate (PlacePredicate ... predicates) {
12+
public OrPlacePredicate(PlacePredicate ... predicates) {
1313
this.predicates = new ArrayList<>();
1414
this.predicates.addAll(Arrays.asList(predicates));
1515
}

src/org/processmining/placebasedlpmdiscovery/placechooser/placepredicates/PlacePredicateFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ private PlacePredicate getPredicate(ConfigElement el) {
2626

2727
private PlacePredicate getComplexPredicate(PlacePredicateType type, PlacePredicate... subPredicates) {
2828
if (type == PlacePredicateType.AND) {
29-
return new AndPredicate(subPredicates);
29+
return new AndPlacePredicate(subPredicates);
3030
} else if (type == PlacePredicateType.OR) {
31-
return new OrPredicate(subPredicates);
31+
return new OrPlacePredicate(subPredicates);
3232
} else {
3333
throw new IllegalArgumentException("The type: " + type + " is not complex or it doesn't exist.");
3434
}

src/org/processmining/placebasedlpmdiscovery/placechooser/placetransformers/PassageUsagePlaceTransformer.java

Lines changed: 25 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,42 @@
33
import org.apache.commons.math3.util.Pair;
44
import org.processmining.placebasedlpmdiscovery.model.Place;
55
import org.processmining.placebasedlpmdiscovery.model.Transition;
6-
import org.processmining.placebasedlpmdiscovery.utils.PlaceUtils;
76

8-
import java.util.HashSet;
9-
import java.util.Map;
107
import java.util.Set;
118
import java.util.stream.Collectors;
129

1310
public class PassageUsagePlaceTransformer implements PlaceTransformer {
1411

15-
private final Set<Pair<String, String>> eventuallyFollowedActivities;
12+
private final Set<Pair<String, String>> locallyOccurringPassages;
1613

17-
public PassageUsagePlaceTransformer(Set<Pair<String, String>> eventuallyFollowedActivities) {
18-
this.eventuallyFollowedActivities = eventuallyFollowedActivities;
14+
public PassageUsagePlaceTransformer(Set<Pair<String, String>> locallyOccurringPassages) {
15+
this.locallyOccurringPassages = locallyOccurringPassages;
1916
}
2017

2118
@Override
2219
public Place adapt(Place place) {
23-
// Transitions to be removed
24-
Set<String> inTransitionsToBeRemoved = new HashSet<>();
25-
Set<String> outTransitionsToBeRemoved = new HashSet<>();
26-
27-
// get all pairs of input-output transition labels
28-
Set<Pair<String, String>> placeInOutPair = PlaceUtils.getVisibleInoutPairsInPlace(place);
29-
// keep only the pairs that are not happening in the given window
30-
placeInOutPair.removeAll(eventuallyFollowedActivities);
31-
// extract all labels that appear as input in the set of uncovered input-output transition pairs
32-
Set<String> inputs = placeInOutPair.stream().map(Pair::getKey).collect(Collectors.toSet());
33-
// map every input label with which output labels doesn't appear
34-
Map<String, Set<String>> forwardMapping = inputs
35-
.stream()
36-
.collect(Collectors.toMap(
37-
x -> x,
38-
x -> placeInOutPair
39-
.stream()
40-
.filter(p -> p.getKey().equals(x))
41-
.map(Pair::getValue)
42-
.collect(Collectors.toSet())));
43-
// mark all input transitions which don't happen with any of the output transitions
44-
for (String inTr : forwardMapping.keySet()) {
45-
if (place.getOutputTransitions().size() > 0 &&
46-
place.getOutputTransitions().stream().map(Transition::getLabel).collect(Collectors.toSet())
47-
.equals(forwardMapping.get(inTr)))
48-
inTransitionsToBeRemoved.add(inTr);
49-
}
50-
// extract all labels that appear as output in the set of uncovered input-output transition pairs
51-
Set<String> outputs = placeInOutPair.stream().map(Pair::getValue).collect(Collectors.toSet());
52-
// map every output label with which input labels doesn't appear
53-
Map<String, Set<String>> backwardMapping = outputs
54-
.stream()
55-
.collect(Collectors.toMap(
56-
x -> x,
57-
x -> placeInOutPair
58-
.stream()
59-
.filter(p -> p.getValue().equals(x))
60-
.map(Pair::getKey)
61-
.collect(Collectors.toSet())));
62-
// mark all output transitions which don't happen with any of the input transitions
63-
for (String outTr : backwardMapping.keySet()) {
64-
if (place.getInputTransitions().size() > 0 &&
65-
place.getInputTransitions().stream().map(Transition::getLabel).collect(Collectors.toSet())
66-
.equals(backwardMapping.get(outTr)))
67-
outTransitionsToBeRemoved.add(outTr);
68-
}
69-
70-
// remove the transitions from the place
71-
for (String label : inTransitionsToBeRemoved)
72-
place.removeTransitions(label, true);
73-
for (String label : outTransitionsToBeRemoved)
74-
place.removeTransitions(label, false);
20+
// used input transitions given the proximity
21+
Set<String> usedInputTransitionLabels =
22+
locallyOccurringPassages.stream().map(Pair::getKey).collect(Collectors.toSet());
23+
// used output transitions given the proximity
24+
Set<String> usedOutputTransitionLabels =
25+
locallyOccurringPassages.stream().map(Pair::getValue).collect(Collectors.toSet());
26+
27+
// unused input transition labels
28+
Set<String> unusedInputTransitionLabels = place.getInputTransitions().stream()
29+
.map(Transition::getLabel)
30+
.filter(label -> !usedInputTransitionLabels.contains(label))
31+
.collect(Collectors.toSet());
32+
// unused output transition labels
33+
Set<String> unusedOutputTransitionLabels = place.getOutputTransitions().stream()
34+
.map(Transition::getLabel)
35+
.filter(label -> !usedOutputTransitionLabels.contains(label))
36+
.collect(Collectors.toSet());
37+
38+
// remove unused input transitions
39+
unusedInputTransitionLabels.forEach(label -> place.removeTransitions(label, true));
40+
// remove unused output transitions
41+
unusedOutputTransitionLabels.forEach(label -> place.removeTransitions(label, false));
7542

7643
return place;
7744
}

tests/src/org/processmining/placebasedlpmdiscovery/model/PlaceTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,24 @@ public void givenTwoInOneOutSingleLetter_whenFrom_thenPlaceWithTwoInOneOut() {
163163
.containsExactly(new Transition("c", false));
164164
}
165165

166+
@Test
167+
public void givenNoInNoOut_whenFrom_thenPlaceWithNoInNoOut() {
168+
// given
169+
String placeDescriptionEmptySpaces = " | ";
170+
String placeDescriptionNoSpaces = "|";
171+
172+
// when
173+
Place placeActualEmptySpaces = Place.from(placeDescriptionEmptySpaces);
174+
Place placeActualNoSpaces = Place.from(placeDescriptionNoSpaces);
175+
176+
// then
177+
Assert.assertEquals(0, placeActualEmptySpaces.getInputTransitions().size());
178+
Assert.assertEquals(0, placeActualEmptySpaces.getOutputTransitions().size());
179+
180+
Assert.assertEquals(0, placeActualNoSpaces.getInputTransitions().size());
181+
Assert.assertEquals(0, placeActualNoSpaces.getOutputTransitions().size());
182+
}
183+
166184
@Test
167185
public void givenOneInNoOutSingleLetter_whenFrom_thenPlaceWithOneInNoOut() {
168186
// given
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package src.org.processmining.placebasedlpmdiscovery.placechooser.placepredicates;
2+
3+
import org.junit.Test;
4+
import org.processmining.placebasedlpmdiscovery.model.Place;
5+
import org.processmining.placebasedlpmdiscovery.placechooser.placepredicates.AndPlacePredicate;
6+
7+
public class AndPlacePredicateTest {
8+
9+
@Test
10+
public void givenAllTruePredicates_whenTestPlace_thenReturnsTrue() {
11+
// given
12+
AndPlacePredicate andPredicate = new AndPlacePredicate((p) -> true, (p) -> true, (p) -> true);
13+
Place mockPlace = Place.from("a | b");
14+
15+
// when
16+
boolean actual = andPredicate.testPlace(mockPlace);
17+
18+
// then
19+
assert actual;
20+
}
21+
22+
@Test
23+
public void givenOneFalsePredicate_whenTestPlace_thenReturnsFalse() {
24+
// given
25+
AndPlacePredicate andPredicate = new AndPlacePredicate((p) -> true, (p) -> false, (p) -> true);
26+
Place mockPlace = Place.from("a | b");
27+
28+
// when
29+
boolean actual = andPredicate.testPlace(mockPlace);
30+
31+
// then
32+
assert !actual;
33+
}
34+
35+
@Test
36+
public void givenAllFalsePredicates_whenTestPlace_thenReturnsFalse() {
37+
// given
38+
AndPlacePredicate andPredicate = new AndPlacePredicate((p) -> false, (p) -> false, (p) -> false);
39+
Place mockPlace = Place.from("a | b");
40+
41+
// when
42+
boolean actual = andPredicate.testPlace(mockPlace);
43+
44+
// then
45+
assert !actual;
46+
}
47+
}

0 commit comments

Comments
 (0)