package org.processmining.tests.cost.filter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Collection; import org.deckfour.xes.extension.std.XConceptExtension; import org.deckfour.xes.in.XMxmlParser; import org.deckfour.xes.in.XParser; import org.deckfour.xes.in.XesXmlParser; import org.deckfour.xes.info.XLogInfo; import org.deckfour.xes.info.XLogInfoFactory; import org.deckfour.xes.model.XAttributeLiteral; import org.deckfour.xes.model.XAttributeMap; import org.deckfour.xes.model.XEvent; import org.deckfour.xes.model.XLog; import org.deckfour.xes.out.XSerializer; import org.deckfour.xes.out.XesXmlSerializer; import org.processmining.plugins.log.XContextMonitoredInputStream; import org.processmining.plugins.log.logfilters.LogFilter; import org.processmining.plugins.log.logfilters.XEventCondition; import org.processmining.tests.cost.dummy.DummyProgress; /** * * * @author */ public class TestLogFilter { // TODO find way to test individual plug-ins and write testing classes public static void main(String[] args) throws Exception { TestLogFilter tlf = new TestLogFilter(); tlf.execute(); } public void execute() throws Exception { // input and output files File input = new File("H:/tue/graduation/work log", "log_repair_test_input.xes"); File output = new File("H:/tue/graduation/work log", "log_repair_test_output.xes"); // concept:name tag value to filter for final String filterValue = "FirstContact"; // import log (copied from org.processmining.plugins.log.OpenLogFilePlugin) FileInputStream in = new FileInputStream(input); String filename = "log_repair_test_input.xes"; long fileSizeInBytes = input.length(); XParser parser; if (filename.toLowerCase().endsWith(".xes") || filename.toLowerCase().endsWith(".xez") || filename.toLowerCase().endsWith(".xes.gz")) { parser = new XesXmlParser(); } else { parser = new XMxmlParser(); } Collection logs = parser.parse(new XContextMonitoredInputStream(in, fileSizeInBytes, new DummyProgress())); if (logs.size() == 0) { throw new Exception("No processes contained in log!"); } XLog inputLog = logs.iterator().next(); XConceptExtension.instance().assignName(inputLog, filename); if (inputLog.isEmpty()) { throw new Exception("No process instances contained in log!"); } // execute log filter on log XEventCondition condition = new XEventCondition() { public boolean keepEvent(XEvent event) { XAttributeMap attributes = event.getAttributes(); XAttributeLiteral attribute = (XAttributeLiteral) attributes.get("concept:name"); return filterValue.equalsIgnoreCase(attribute.getValue()); } }; XLogInfo summary = XLogInfoFactory.createLogInfo(inputLog); long start = System.currentTimeMillis(); XLog outputlog = LogFilter.filter(new DummyProgress(), 1, inputLog, summary, condition); long end = System.currentTimeMillis(); System.out.println("Log filtered in milliseconds: " + (end - start)); // output log (copied from org.processmining.plugins.log.exporting.ExportLogXes) FileOutputStream out = new FileOutputStream(output); XSerializer logSerializer = new XesXmlSerializer(); logSerializer.serialize(outputlog, out); out.close(); } }