Skip to content

Commit 7be8f66

Browse files
authored
Make PlacesProvider not always depend on an event log and give a PlacesProviderFactory instead to the PlaceBasedLPMDiscovery
1 parent 0f0e13c commit 7be8f66

File tree

9 files changed

+122
-64
lines changed

9 files changed

+122
-64
lines changed

src/org/processmining/lpms/discovery/DiscoveryParameters.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package org.processmining.lpms.discovery;
22

33
public class DiscoveryParameters {
4+
public static class PlaceBased {
5+
public static int placeLimit = 100;
6+
}
7+
48
public static class Default {
59
public static int proximity = 7;
610
}

src/org/processmining/placebasedlpmdiscovery/lpmdiscovery/LPMDiscovery.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@
88
public interface LPMDiscovery {
99

1010
static LPMDiscovery getInstance() {
11-
return placeBased(PlacesProvider.getInstance(), 100);
11+
return placeBased();
1212
}
1313

14-
static LPMDiscovery treeBased() {return new ProcessTreeBasedLPMDiscovery(); }
14+
static LPMDiscovery treeBased() { return new ProcessTreeBasedLPMDiscovery(); }
15+
16+
static LPMDiscovery placeBased() {
17+
return new PlaceBasedLPMDiscovery(PlacesProvider::fromLog);
18+
}
1519

1620
static LPMDiscovery placeBased(PlacesProvider placesProvider) {
17-
return new PlaceBasedLPMDiscovery(placesProvider);
21+
return new PlaceBasedLPMDiscovery((XLog log) -> placesProvider);
1822
}
1923

2024
static LPMDiscovery placeBased(PlacesProvider placesProvider, int placeLimit) {
21-
return new PlaceBasedLPMDiscovery(placesProvider, placeLimit);
25+
return new PlaceBasedLPMDiscovery((XLog log) -> placesProvider, placeLimit);
2226
}
2327

2428
static LPMDiscovery placeBased(PlacesProvider placesProvider, int placeLimit, int concurrencyLimit) {
25-
return new PlaceBasedLPMDiscovery(placesProvider, placeLimit, concurrencyLimit);
29+
return new PlaceBasedLPMDiscovery((XLog log) -> placesProvider, placeLimit, concurrencyLimit);
2630
}
2731

2832
static LPMDiscovery ladaBased(int proximityLimit) {

src/org/processmining/placebasedlpmdiscovery/lpmdiscovery/PlaceBasedLPMDiscovery.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,31 @@
1111
import org.processmining.placebasedlpmdiscovery.model.discovery.LPMDiscoveryResult;
1212
import org.processmining.placebasedlpmdiscovery.model.logs.EventLog;
1313
import org.processmining.placebasedlpmdiscovery.model.logs.XLogWrapper;
14-
import org.processmining.placebasedlpmdiscovery.prom.PlacesProvider;
14+
import org.processmining.placebasedlpmdiscovery.prom.PlacesProviderFactory;
1515

1616
import java.util.Set;
1717

1818
public class PlaceBasedLPMDiscovery implements LPMDiscovery {
1919

2020
private final int placeLimit;
21-
private final PlacesProvider placesProvider;
21+
private final PlacesProviderFactory placesProviderFactory;
2222
private final int proximity;
2323
private final int concurrencyLimit;
2424

25-
26-
public PlaceBasedLPMDiscovery(PlacesProvider placesProvider) {
27-
this(placesProvider, 50);
25+
public PlaceBasedLPMDiscovery(PlacesProviderFactory placesProviderFactory) {
26+
this(placesProviderFactory, DiscoveryParameters.PlaceBased.placeLimit);
2827
}
2928

30-
public PlaceBasedLPMDiscovery(PlacesProvider placesProvider, int placeLimit) {
31-
this(placesProvider, placeLimit, DiscoveryParameters.Default.proximity);
29+
public PlaceBasedLPMDiscovery(PlacesProviderFactory placesProviderFactory, int placeLimit) {
30+
this(placesProviderFactory, placeLimit, DiscoveryParameters.Default.proximity);
3231
}
3332

34-
public PlaceBasedLPMDiscovery(PlacesProvider placesProvider, int placeLimit, int proximity) {
35-
this(placesProvider, placeLimit, proximity, 2);
33+
public PlaceBasedLPMDiscovery(PlacesProviderFactory placesProviderFactory, int placeLimit, int proximity) {
34+
this(placesProviderFactory, placeLimit, proximity, 2);
3635
}
3736

38-
public PlaceBasedLPMDiscovery(PlacesProvider placesProvider, int placeLimit, int proximity, int concurrencyLimit) {
39-
this.placesProvider = placesProvider;
37+
public PlaceBasedLPMDiscovery(PlacesProviderFactory placesProviderFactory, int placeLimit, int proximity, int concurrencyLimit) {
38+
this.placesProviderFactory = placesProviderFactory;
4039
this.placeLimit = placeLimit;
4140
this.proximity = proximity;
4241
this.concurrencyLimit = concurrencyLimit;
@@ -52,7 +51,7 @@ public LPMDiscoveryResult from(XLog log) {
5251
parameters.getLpmCombinationParameters().setConcurrencyCardinality(this.concurrencyLimit);
5352

5453
LPMDiscoveryAlgBuilder builder = Main.createDefaultBuilder(log, parameters);
55-
Set<Place> places = this.placesProvider.from(log);
54+
Set<Place> places = this.placesProviderFactory.create(log).provide();
5655

5756
FPGrowthForPlacesLPMBuildingInput lpmBuildingInput = new FPGrowthForPlacesLPMBuildingInput(eventLog, places);
5857
StandardLPMDiscoveryInput discoveryInput =

src/org/processmining/placebasedlpmdiscovery/prom/DiscoveryPlacesProvider.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/org/processmining/placebasedlpmdiscovery/prom/FromFilePlacesProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.processmining.placebasedlpmdiscovery.prom;
22

3-
import org.deckfour.xes.model.XLog;
43
import org.processmining.models.graphbased.directed.petrinet.Petrinet;
54
import org.processmining.placebasedlpmdiscovery.model.Place;
65
import org.processmining.placebasedlpmdiscovery.model.exporting.importers.ImporterFactory;
@@ -23,7 +22,7 @@ public FromFilePlacesProvider(String fileName) {
2322
}
2423

2524
@Override
26-
public Set<Place> from(XLog log) {
25+
public Set<Place> provide() {
2726
try {
2827
if (this.fileName.endsWith("pnml")) {
2928
Petrinet net = PlaceUtils.extractPetriNet(fileName);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.processmining.placebasedlpmdiscovery.prom;
2+
3+
import org.deckfour.xes.model.XLog;
4+
import org.processmining.placebasedlpmdiscovery.model.Place;
5+
import org.processmining.placebasedlpmdiscovery.prom.placediscovery.algorithms.PlaceDiscoveryAlgorithm;
6+
import org.processmining.placebasedlpmdiscovery.prom.placediscovery.algorithms.PlaceDiscoveryAlgorithmFactory;
7+
import org.processmining.placebasedlpmdiscovery.prom.placediscovery.parameters.EstMinerPlaceDiscoveryParameters;
8+
import org.processmining.placebasedlpmdiscovery.prom.placediscovery.parameters.SPECppPlaceDiscoveryParameters;
9+
10+
import java.util.Set;
11+
12+
public class FromLogPlacesProvider implements PlacesProvider {
13+
14+
private final XLog log;
15+
private final PlaceDiscoveryAlgorithm<?, ?> algorithm;
16+
17+
public FromLogPlacesProvider(XLog log, PlaceDiscoveryAlgorithm<?, ?> algorithm) {
18+
this.log = log;
19+
this.algorithm = algorithm;
20+
}
21+
22+
@Override
23+
public Set<Place> provide() {
24+
return algorithm.getPlaces(this.log).getPlaces();
25+
}
26+
27+
/**
28+
* Creates a PlacesProvider that discovers places using the recommended algorithm (SPECpp).
29+
* @param log the XLog to discover places from
30+
* @return a PlacesProvider that discovers places using the recommended algorithm
31+
*/
32+
public static PlacesProvider recommended(XLog log) {
33+
return specpp(log);
34+
}
35+
36+
/**
37+
* Creates a PlacesProvider that discovers places using the EST-Miner algorithm.
38+
* @param log the XLog to discover places from
39+
* @return a PlacesProvider that discovers places using the EST-Miner algorithm
40+
*/
41+
public static PlacesProvider est(XLog log) {
42+
PlaceDiscoveryAlgorithmFactory factory = new PlaceDiscoveryAlgorithmFactory();
43+
EstMinerPlaceDiscoveryParameters parameters = new EstMinerPlaceDiscoveryParameters();
44+
return new FromLogPlacesProvider(log, parameters.getAlgorithm(factory));
45+
}
46+
47+
/**
48+
* Creates a PlacesProvider that discovers places using the SPECpp algorithm.
49+
* @param log the XLog to discover places from
50+
* @return a PlacesProvider that discovers places using the SPECpp algorithm
51+
*/
52+
public static PlacesProvider specpp(XLog log) {
53+
PlaceDiscoveryAlgorithmFactory factory = new PlaceDiscoveryAlgorithmFactory();
54+
SPECppPlaceDiscoveryParameters parameters = new SPECppPlaceDiscoveryParameters();
55+
return new FromLogPlacesProvider(log, parameters.getAlgorithm(factory));
56+
}
57+
58+
}

src/org/processmining/placebasedlpmdiscovery/prom/PlacesProvider.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,45 @@
22

33
import org.deckfour.xes.model.XLog;
44
import org.processmining.placebasedlpmdiscovery.model.Place;
5-
import org.processmining.placebasedlpmdiscovery.prom.placediscovery.algorithms.PlaceDiscoveryAlgorithmFactory;
6-
import org.processmining.placebasedlpmdiscovery.prom.placediscovery.parameters.EstMinerPlaceDiscoveryParameters;
7-
import org.processmining.placebasedlpmdiscovery.prom.placediscovery.parameters.SPECppPlaceDiscoveryParameters;
85

96
import java.util.Set;
107

8+
/**
9+
* A provider of places for LPM discovery. Implementations can provide places from various sources,
10+
* such as files, sets, or by discovering them from an event log.
11+
*/
1112
public interface PlacesProvider {
1213

13-
static PlacesProvider getInstance() {
14-
return specpp();
15-
}
16-
17-
static PlacesProvider est() {
18-
PlaceDiscoveryAlgorithmFactory factory = new PlaceDiscoveryAlgorithmFactory();
19-
EstMinerPlaceDiscoveryParameters parameters = new EstMinerPlaceDiscoveryParameters();
20-
return new DiscoveryPlacesProvider(parameters.getAlgorithm(factory));
21-
}
22-
23-
static PlacesProvider specpp() {
24-
PlaceDiscoveryAlgorithmFactory factory = new PlaceDiscoveryAlgorithmFactory();
25-
SPECppPlaceDiscoveryParameters parameters = new SPECppPlaceDiscoveryParameters();
26-
return new DiscoveryPlacesProvider(parameters.getAlgorithm(factory));
27-
}
28-
14+
/**
15+
* Creates a PlacesProvider that reads places from a file.
16+
* @param fileName the name of the file to read places from
17+
* @return a PlacesProvider that reads places from the specified file
18+
*/
2919
static PlacesProvider fromFile(String fileName) {
3020
return new FromFilePlacesProvider(fileName);
3121
}
3222

23+
/**
24+
* Creates a PlacesProvider that provides the given set of places.
25+
* @param places the set of places to provide
26+
* @return a PlacesProvider that provides the given set of places
27+
*/
3328
static PlacesProvider fromSet(Set<Place> places) {
34-
return log -> places;
29+
return () -> places;
30+
}
31+
32+
/**
33+
* Creates a PlacesProvider that provides the given set of places by discovering them in the event log.
34+
* @param log the XLog to discover places from
35+
* @return a PlacesProvider that discovers places from the given log
36+
*/
37+
static PlacesProvider fromLog(XLog log) {
38+
return FromLogPlacesProvider.recommended(log);
3539
}
3640

37-
Set<Place> from(XLog log);
41+
/**
42+
* Provides a set of places.
43+
* @return a set of places
44+
*/
45+
Set<Place> provide();
3846
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.processmining.placebasedlpmdiscovery.prom;
2+
3+
import org.deckfour.xes.model.XLog;
4+
5+
public interface PlacesProviderFactory {
6+
7+
PlacesProvider create(XLog log);
8+
}

tests-integration/TestPlaceBasedLPMDiscoveryGivenLogAbcWithPlacesAbAc.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.junit.BeforeClass;
55
import org.junit.Test;
66
import org.processmining.placebasedlpmdiscovery.lpmdiscovery.LPMDiscovery;
7-
import org.processmining.placebasedlpmdiscovery.lpmdiscovery.PlaceBasedLPMDiscovery;
87
import org.processmining.placebasedlpmdiscovery.model.LocalProcessModel;
98
import org.processmining.placebasedlpmdiscovery.model.Place;
109
import org.processmining.placebasedlpmdiscovery.model.discovery.LPMDiscoveryResult;
@@ -37,7 +36,7 @@ public static void setup() {
3736
@Test
3837
public void givenDefault_whenFrom_thenLPMsAbAc() {
3938
// given
40-
LPMDiscovery lpmDiscovery = new PlaceBasedLPMDiscovery(placesProvider);
39+
LPMDiscovery lpmDiscovery = LPMDiscovery.placeBased(placesProvider);
4140

4241
// when
4342
LPMDiscoveryResult result = lpmDiscovery.from(eventLog);
@@ -52,7 +51,7 @@ public void givenDefault_whenFrom_thenLPMsAbAc() {
5251
@Test
5352
public void givenDefaultWithPlaceLimit_whenFrom_thenLPMsEmpty() {
5453
// given
55-
LPMDiscovery lpmDiscovery = new PlaceBasedLPMDiscovery(placesProvider, 1);
54+
LPMDiscovery lpmDiscovery = LPMDiscovery.placeBased(placesProvider, 1);
5655

5756
// when
5857
LPMDiscoveryResult result = lpmDiscovery.from(eventLog);

0 commit comments

Comments
 (0)