Skip to content

Commit 1234c09

Browse files
committed
Properties file handler class
No actual logic yet
1 parent 9c9a643 commit 1234c09

File tree

4 files changed

+66
-198
lines changed

4 files changed

+66
-198
lines changed

src/main/java/ee/tkasekamp/ltlminer/LTLMiner.java

Lines changed: 6 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ee.tkasekamp.ltlminer;
22

33
import java.util.ArrayList;
4-
import java.util.HashMap;
4+
import java.util.Properties;
55
import java.util.Vector;
66

77
import org.deckfour.xes.model.XLog;
@@ -59,6 +59,11 @@ public ArrayList<RuleModel> mineWithEventTypes(XLog log,
5959
Object[] objList = checkRules(log, rules);
6060
return filter(objList, threshold);
6161
}
62+
63+
public ArrayList<RuleModel> mine(XLog log, Properties properties) {
64+
// TODO
65+
return null;
66+
}
6267

6368
private Object[] checkRules(XLog log, ArrayList<String> rules) {
6469
String modelString = LTLFileCreator.createLTLModel(rules);
@@ -68,145 +73,6 @@ private Object[] checkRules(XLog log, ArrayList<String> rules) {
6873
return checker.analyse(log, model);
6974
}
7075

71-
// public ArrayList<RuleModel> mine(XLog log, String rule, double threshold)
72-
// {
73-
// ArrayList<String> ac = logFilter.getFrequent(log);
74-
// Object[] objList = analyseRule(log, rule, ac);
75-
// return filter(objList, threshold);
76-
// }
77-
//
78-
// public ArrayList<RuleModel> mine(XLog log, String[] rules, double
79-
// threshold) {
80-
// ArrayList<String> ac = logFilter.getFrequent(log);
81-
// Object[] objList = analyseRules(log, rules, ac);
82-
// return filter(objList, threshold);
83-
// }
84-
//
85-
// public ArrayList<RuleModel> mine(XLog log, String rule, double threshold,
86-
// int howManyEvents) {
87-
// ArrayList<String> ac = logFilter.getFrequent(log, howManyEvents);
88-
// Object[] objList = analyseRule(log, rule, ac);
89-
// return filter(objList, threshold);
90-
// }
91-
//
92-
// public ArrayList<RuleModel> mine(XLog log, String[] rules,
93-
// double threshold, int howManyEvents) {
94-
// ArrayList<String> ac = logFilter.getFrequent(log, howManyEvents);
95-
// Object[] objList = analyseRules(log, rules, ac);
96-
// return filter(objList, threshold);
97-
// }
98-
//
99-
// public ArrayList<RuleModel> mineAll(XLog log, String rule, double
100-
// threshold) {
101-
//
102-
// ArrayList<String> ac = logFilter.getAllEvents(log);
103-
// Object[] objList = analyseRule(log, rule, ac);
104-
// return filter(objList, threshold);
105-
// }
106-
//
107-
// public ArrayList<RuleModel> mineAll(XLog log, String[] rules,
108-
// double threshold) {
109-
//
110-
// ArrayList<String> ac = logFilter.getAllEvents(log);
111-
// Object[] objList = analyseRules(log, rules, ac);
112-
// return filter(objList, threshold);
113-
// }
114-
//
115-
// public ArrayList<RuleModel> mineAllLifecycles(XLog log, String rule,
116-
// double threshold) {
117-
//
118-
// ArrayList<String> ac = logFilter.getAllEvents(log);
119-
// ArrayList<String> li = logFilter.getLifecycles(log);
120-
// // System.out.println(li.size());
121-
// Object[] objList = analyseRule(log, rule, ac, li);
122-
// return filter(objList, threshold);
123-
// }
124-
// public ArrayList<RuleModel> mine(XLog log, String rule, double threshold,
125-
// HashMap<String, String[]> eventReplacement) {
126-
//
127-
// ArrayList<String> ac = logFilter.getAllEvents(log);
128-
// Object[] objList = analyseRule(log, rule, ac, eventReplacement);
129-
// return filter(objList, threshold);
130-
// }
131-
//
132-
// public ArrayList<RuleModel> mine(XLog log, String[] rules,
133-
// double threshold, HashMap<String, String[]> eventReplacement) {
134-
//
135-
// ArrayList<String> ac = logFilter.getAllEvents(log);
136-
// Object[] objList = analyseRules(log, rules, ac, eventReplacement);
137-
// return filter(objList, threshold);
138-
// }
139-
//
140-
// /**
141-
// * This is the first part of the miner. It creates all possible
142-
// combinations
143-
// * of rules using the input rule as a template. It then uses the
144-
// * {@link LTLChecker} to create an output.
145-
// *
146-
// * @param log
147-
// * {@link XLog}
148-
// * @param rule
149-
// * Valid LTL formula with no default arguments.
150-
// * @return Object [] form {@link LTLChecker}
151-
// */
152-
// public Object[] analyseRule(XLog log, String rule,
153-
// ArrayList<String> activities) {
154-
// String[] rules = creator.createRule(rule, activities);
155-
// String modelString = createLTLModel(rules);
156-
//
157-
// addRulesToChecker(rules);
158-
// LTLModel model = new LTLModel();
159-
// model.setFile(modelString);
160-
// return checker.analyse(log, model);
161-
// }
162-
//
163-
// public Object[] analyseRule(XLog log, String rule,
164-
// ArrayList<String> activities, ArrayList<String> lifecycles) {
165-
// String[] rules = creator.createRule(rule, activities,lifecycles);
166-
// String modelString = createLTLModel(rules);
167-
//
168-
// addRulesToChecker(rules);
169-
// LTLModel model = new LTLModel();
170-
// model.setFile(modelString);
171-
// return checker.analyse(log, model);
172-
// }
173-
//
174-
// public Object[] analyseRule(XLog log, String rule,
175-
// ArrayList<String> activities,
176-
// HashMap<String, String[]> eventReplacement) {
177-
// String[] rules = creator.createRule(rule, activities, eventReplacement);
178-
// String modelString = createLTLModel(rules);
179-
//
180-
// addRulesToChecker(rules);
181-
// LTLModel model = new LTLModel();
182-
// model.setFile(modelString);
183-
// return checker.analyse(log, model);
184-
// }
185-
//
186-
// public Object[] analyseRules(XLog log, String[] ltlFormulas,
187-
// ArrayList<String> activities) {
188-
// String[] rules = creator.createRules(ltlFormulas, activities);
189-
// String modelString = createLTLModel(rules);
190-
//
191-
// addRulesToChecker(rules);
192-
// LTLModel model = new LTLModel();
193-
// model.setFile(modelString);
194-
// return checker.analyse(log, model);
195-
// }
196-
//
197-
// public Object[] analyseRules(XLog log, String[] ltlFormulas,
198-
// ArrayList<String> activities,
199-
// HashMap<String, String[]> eventReplacement) {
200-
// String[] rules = creator.createRules(ltlFormulas, activities,
201-
// eventReplacement);
202-
// String modelString = createLTLModel(rules);
203-
//
204-
// addRulesToChecker(rules);
205-
// LTLModel model = new LTLModel();
206-
// model.setFile(modelString);
207-
// return checker.analyse(log, model);
208-
// }
209-
21076
private void addRulesToChecker(ArrayList<String> rules) {
21177
Vector<String> selectedRules = new Vector<>();
21278
// Can do this because rules were just renamed and there are exactly
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package ee.tkasekamp.ltlminer;
2+
3+
import java.io.FileNotFoundException;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.util.ArrayList;
7+
import java.util.Properties;
8+
9+
import org.deckfour.xes.model.XLog;
10+
import org.processmining.plugins.ltlchecker.RuleModel;
11+
12+
import ee.tkasekamp.ltlminer.util.XLogReader;
13+
14+
public class LTLMinerStarter {
15+
// Here the properties file reading and starting LTLMiner
16+
// Read in XLog and after handle the output
17+
Properties config;
18+
LTLMiner miner;
19+
20+
public LTLMinerStarter() throws IOException {
21+
config = loadProperties("config.properties");
22+
miner = new LTLMiner();
23+
}
24+
25+
public LTLMinerStarter(Properties properties) {
26+
config = properties;
27+
miner = new LTLMiner();
28+
}
29+
30+
public void mine() throws Exception {
31+
XLog log = readLogFile(config.getProperty("logPath"));
32+
ArrayList<RuleModel> output = miner.mine(log, config);
33+
}
34+
35+
private Properties loadProperties(String propFileName) throws IOException {
36+
Properties prop = new Properties();
37+
InputStream inputStream = getClass().getClassLoader()
38+
.getResourceAsStream(propFileName);
39+
40+
if (inputStream != null) {
41+
prop.load(inputStream);
42+
} else {
43+
throw new FileNotFoundException("property file '" + propFileName
44+
+ "' not found in the classpath");
45+
}
46+
return prop;
47+
}
48+
49+
private XLog readLogFile(String logPath) throws Exception {
50+
return XLogReader.openLog(logPath);
51+
}
52+
}

src/test/java/ee/tkasekamp/ltlminer/LTLMinerTest.java

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22

33
import static org.junit.Assert.*;
44

5-
import java.util.ArrayList;
6-
import java.util.Arrays;
7-
85
import org.deckfour.xes.model.XLog;
96
import org.junit.Before;
107
import org.junit.Test;
11-
import org.processmining.plugins.ltlchecker.CheckResultObject;
12-
import org.processmining.plugins.ltlchecker.LTLChecker;
13-
import org.processmining.plugins.ltlchecker.RuleModel;
148

159
import ee.tkasekamp.ltlminer.util.XLogReader;
1610

1711
public class LTLMinerTest {
1812
LTLMiner miner;
19-
LTLChecker checker;
2013
XLog log;
2114

2215
@Before
@@ -25,48 +18,4 @@ public void setUp() throws Exception {
2518
log = XLogReader.openLog("src/test/resources/exercise1.xes");
2619
}
2720

28-
@Test
29-
public void mineTest() {
30-
String rule = "formula always_when_A_then_eventually_E( A: activity , E: activity ) := {}\n"
31-
+ " []( ( activity == A -> <>( activity==E ) ) ); ";
32-
ArrayList<RuleModel> result = miner.mine(log, rule, 0.5);
33-
assertEquals("Counted them. So should be 16", 16, result.size());
34-
35-
String rule2 = "formula is_activity_of_first_state_A( A: activity ) :="
36-
+ "{"
37-
+ "<h2>Is the activity of the first state equal to <b>A</b>?</h2>"
38-
+ "<p> Compare the activity of the first state with <b>A</b> </p>"
39-
+ "<p> Arguments:<br>"
40-
+ "<ul>"
41-
+ "<li><b>A</b> of type set (<i>ate.WorkflowModelElement</i>)</li>"
42-
+ "</ul>" + "</p>}" + "activity == A;";
43-
ArrayList<RuleModel> result2 = miner.mine(log, rule2, 0.2);
44-
assertEquals(1, result2.size());
45-
46-
String rule3 = "formula query(A :activity, E: activity) := {} \n"
47-
+ "(<>(activity == A) /\\ !(<>(activity == E)));";
48-
ArrayList<RuleModel> result3 = miner.mine(log, rule3, 0.5);
49-
assertEquals(4, result3.size());
50-
51-
}
52-
53-
@Test
54-
public void difficultFormula() {
55-
String rule4 = "formula query(A :activity, B: activity) := {} \n"
56-
+ " (( activity !=B _U activity == A) \\/ [] ( activity != B));";
57-
ArrayList<RuleModel> result4 = miner.mine(log, rule4, 0.5);
58-
assertEquals(16, result4.size());
59-
}
60-
61-
@Test
62-
public void multipleFormulaTest() {
63-
String rule4 = "formula query(A :activity, B: activity) := {} \n"
64-
+ " (( activity !=B _U activity == A) \\/ [] ( activity != B));";
65-
String rule = "formula always_when_A_then_eventually_E( A: activity , E: activity ) := {}\n"
66-
+ " []( ( activity == A -> <>( activity==E ) ) ); ";
67-
String[] rules = { rule, rule4 };
68-
ArrayList<RuleModel> result4 = miner.mineAll(log, rules, 0.0);
69-
assertEquals(50, result4.size());
70-
}
71-
7221
}

src/test/java/ee/tkasekamp/ltlminer/UsageTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ee.tkasekamp.ltlminer;
22

3+
import static org.junit.Assert.*;
34
import java.util.ArrayList;
45
import java.util.Arrays;
56

@@ -21,14 +22,14 @@ public class UsageTest {
2122
public void notCoExistence() throws Exception {
2223
String formula = "formula notCoExistence( A: activity , B: activity ) := { }"
2324
+ "!( (<>(activity == A) /\\ <>(activity == B) ));";
24-
LTLMiner miner = new LTLMiner();
25+
LTLMiner miner = new LTLMiner();
2526
XLog log = XLogReader.openLog("src/test/resources/orderGoodsLog.xes");
26-
ArrayList<RuleModel> result = miner.mine(log, new ArrayList<>(Arrays.asList(formula)), 0.0);
27-
28-
for (RuleModel rule : result) {
29-
System.out.println(rule.getCoverage() + " " + rule.getLtlRule());
30-
}
27+
ArrayList<RuleModel> result = miner.mine(log,
28+
new ArrayList<>(Arrays.asList(formula)), 0.0);
29+
assertEquals(42, result.size());
30+
// for (RuleModel rule : result) {
31+
// System.out.println(rule.getCoverage() + " " + rule.getLtlRule());
32+
// }
3133
}
32-
3334

3435
}

0 commit comments

Comments
 (0)