-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The miner can now accept very basic properties files. The query parsing part is very very basic. All rules will be generated with all events, no default placeholders are allowed. v1.1.0
- Loading branch information
Showing
7 changed files
with
210 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/ee/tkasekamp/ltlminer/RuleTemplateCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package ee.tkasekamp.ltlminer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class RuleTemplateCreator { | ||
private static Pattern queryParameter = Pattern.compile("\\?(\\w+)"); | ||
|
||
public static ArrayList<String> createTemplates(String queries) { | ||
ArrayList<String> templates = new ArrayList<>(); | ||
|
||
String[] s = queries.split(","); | ||
for (String string : s) { | ||
templates.add(bla(string)); | ||
} | ||
return templates; | ||
} | ||
|
||
private static String bla(String thing) { | ||
thing = thing.replaceAll("\"", ""); | ||
|
||
HashSet<String> a = getParameters(thing); | ||
|
||
thing = doSomething(thing); | ||
return makeProper(thing, a); | ||
|
||
} | ||
|
||
private static String makeProper(String thing, HashSet<String> parameters) { | ||
StringBuilder s = new StringBuilder(); | ||
|
||
s.append("formula rule("); | ||
for (String string : parameters) { | ||
s.append(string + ": activity,"); | ||
} | ||
if (parameters.size() != 0) { | ||
s.deleteCharAt(s.lastIndexOf(",")); | ||
} | ||
s.append(") := {} \n"); | ||
s.append(thing); | ||
s.append(";"); | ||
|
||
return s.toString(); | ||
} | ||
|
||
private static HashSet<String> getParameters(String query) { | ||
Matcher m = queryParameter.matcher(query); | ||
HashSet<String> asasdf = new HashSet<>(); | ||
|
||
while (m.find()) { | ||
String parameter = m.group(1); | ||
asasdf.add(parameter); | ||
|
||
} | ||
|
||
return asasdf; | ||
} | ||
|
||
private static String doSomething(String query) { | ||
Matcher m = queryParameter.matcher(query); | ||
|
||
StringBuffer sb = new StringBuffer(query.length()); | ||
|
||
while (m.find()) { | ||
String parameter = m.group(1); | ||
String text = "activity == " + parameter; | ||
m.appendReplacement(sb, Matcher.quoteReplacement(text)); | ||
|
||
} | ||
m.appendTail(sb); | ||
return sb.toString(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/test/java/ee/tkasekamp/ltlminer/RuleTemplateCreatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ee.tkasekamp.ltlminer; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class RuleTemplateCreatorTest { | ||
|
||
@Test | ||
public void test() { | ||
|
||
String queries = "\"[]( (?x) -> <>(?y))\", \"<>(?x)\", \"[]( (?x) -> <>(?y)\" , \"[]( (?x) -> <>(?y)\""; | ||
|
||
ArrayList<String> templates = RuleTemplateCreator | ||
.createTemplates(queries); | ||
// for (String string : templates) { | ||
// System.out.println(string); | ||
// } | ||
assertEquals(4, templates.size()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package ee.tkasekamp.ltlminer; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.util.Properties; | ||
|
||
import org.junit.Test; | ||
|
||
public class StarterTest { | ||
|
||
@Test | ||
public void test() throws Exception { | ||
LTLMinerStarter starter = new LTLMinerStarter(getProps()); | ||
starter.mine(); | ||
} | ||
|
||
@Test | ||
public void test2() throws Exception { | ||
Properties props = getProps(); | ||
props.setProperty("outputFormat", "text"); | ||
props.setProperty("outputPath", "rules.txt"); | ||
LTLMinerStarter starter = new LTLMinerStarter(props); | ||
starter.mine(); | ||
assertTrue(new File("rules.txt").exists()); | ||
} | ||
|
||
private Properties getProps() { | ||
Properties props = new Properties(); | ||
props.setProperty("logPath", "src/test/resources/exercise1.xes"); | ||
props.setProperty("considerEventTypes", "true"); | ||
props.setProperty("minSupport", "0.5"); | ||
props.setProperty("outputFormat", "console"); | ||
String queries = "\"[](( (?x) -> <>(?y)))\", \"<>(?x)\""; | ||
props.setProperty("queries", queries); | ||
|
||
return props; | ||
} | ||
|
||
} |