Changeset 227 for trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/efg
- Timestamp:
- 09/30/11 19:31:43 (13 years ago)
- Location:
- trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/efg
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/efg/commands/CMDefgTestCasesToSequences.java
r206 r227 9 9 import de.ugoe.cs.eventbench.data.Event; 10 10 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 11 import de.ugoe.cs.eventbench.efg. data.EFGEvent;11 import de.ugoe.cs.eventbench.efg.GUITARTestCaseParser; 12 12 import de.ugoe.cs.util.console.Command; 13 13 import de.ugoe.cs.util.console.Console; 14 import edu.umd.cs.guitar.model.IO;15 import edu.umd.cs.guitar.model.data.StepType;16 import edu.umd.cs.guitar.model.data.TestCase;17 14 18 15 /** … … 34 31 public void run(List<Object> parameters) { 35 32 String foldername; 36 String sequencesName = "sequences"; 33 String sequencesName; 34 String efgFileName = null; 37 35 try { 38 36 foldername = (String) parameters.get(0); 39 if (parameters.size() >= 2) { 40 sequencesName = (String) parameters.get(1); 37 sequencesName = (String) parameters.get(1); 38 if (parameters.size() >= 3) { 39 efgFileName = (String) parameters.get(2); 41 40 } 42 41 } catch (Exception e) { … … 48 47 File[] testcaseFiles = folder.listFiles(); 49 48 Collection<List<Event<?>>> sequences = new LinkedList<List<Event<?>>>(); 49 GUITARTestCaseParser parser; 50 if (efgFileName == null) { 51 parser = new GUITARTestCaseParser(); 52 } else { 53 parser = new GUITARTestCaseParser(efgFileName); 54 } 50 55 for (File testcaseFile : testcaseFiles) { 51 56 Console.traceln("Loading from file " 52 57 + testcaseFile.getAbsolutePath()); 53 TestCase testcase = (TestCase) IO.readObjFromFile( 54 testcaseFile.getAbsolutePath(), TestCase.class); 55 List<StepType> steps = testcase.getStep(); 56 List<Event<?>> sequence = new LinkedList<Event<?>>(); 57 for (StepType step : steps) { 58 step.getEventId(); 59 sequence.add(new EFGEvent(step.getEventId())); 60 /* 61 * Problem: widgetId unknown! Therefore, the events will not be 62 * equal to those in the generated from a EFG. 63 */ 64 } 65 sequences.add(sequence); 58 sequences.add(parser.parseTestCaseFile(testcaseFile)); 66 59 } 67 60 if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { … … 78 71 @Override 79 72 public void help() { 80 Console.println("Usage: efgTestCasesToSequences <folder> {<sequencesName>}");73 Console.println("Usage: efgTestCasesToSequences <folder> <sequencesName> {<efgFileName>}"); 81 74 } 82 75 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/efg/commands/CMDefgToMM.java
r206 r227 2 2 3 3 import java.security.InvalidParameterException; 4 import java.util.ArrayList;5 import java.util.Collection;6 import java.util.LinkedList;7 4 import java.util.List; 8 import java.util.Random;9 5 10 import de.ugoe.cs.eventbench.data.Event;11 6 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 12 import de.ugoe.cs.eventbench.efg. data.EFGEvent;7 import de.ugoe.cs.eventbench.efg.EFGModelGenerator; 13 8 import de.ugoe.cs.eventbench.models.FirstOrderMarkovModel; 14 9 import de.ugoe.cs.util.console.Command; 15 10 import de.ugoe.cs.util.console.Console; 16 import edu.umd.cs.guitar.model.GUITARConstants;17 import edu.umd.cs.guitar.model.IO;18 import edu.umd.cs.guitar.model.data.EFG;19 import edu.umd.cs.guitar.model.data.EventGraphType;20 import edu.umd.cs.guitar.model.data.EventType;21 11 22 12 /** … … 47 37 } 48 38 49 EFG efg = (EFG) IO.readObjFromFile(filename, EFG.class); 50 51 // extracting the events from the EFG 52 List<EventType> efgEvents = efg.getEvents().getEvent(); 53 List<Event<?>> myEvents = new ArrayList<Event<?>>(efgEvents.size()); 54 for (EventType event : efgEvents) { 55 /* 56 * the widgetId and eventId are only hash values, the 57 * "interpretation" is found in the GUI file. 58 */ 59 Event<?> myEvent = new EFGEvent(event.getEventId()); 60 /* 61 * The target is currently not set to event.widgetId() because the 62 * WidgetId is not available when loading sequences in form of test 63 * cases. 64 */ 65 // myEvent.setTarget(event.getWidgetId();); 66 myEvents.add(myEvent); 67 } 68 69 // extracting graph structure from the EFG 70 /* 71 * getEventGraph returns an adjacency matrix, i.e., a square matrix of 72 * efgEvents.size(), where a 1 in row i, column j means an edge 73 * efgEvents.get(i)->efgEvents.get(j) exists. 74 */ 75 EventGraphType efgGraph = efg.getEventGraph(); 76 77 FirstOrderMarkovModel model = new FirstOrderMarkovModel(new Random()); 78 Collection<List<Event<?>>> subsequences = new LinkedList<List<Event<?>>>(); 79 80 int efgSize = efgEvents.size(); 81 for (int row = 0; row < efgSize; row++) { 82 for (int col = 0; col < efgSize; col++) { 83 int relation = efgGraph.getRow().get(row).getE().get(col); 84 // otherEvent is followed by currentEvent 85 if (relation != GUITARConstants.NO_EDGE) { 86 List<Event<?>> edge = new LinkedList<Event<?>>(); 87 edge.add(myEvents.get(row)); 88 edge.add(myEvents.get(col)); 89 subsequences.add(edge); 90 } 91 } 92 } 93 model.train(subsequences); 39 EFGModelGenerator modelGenerator = new EFGModelGenerator(); 40 FirstOrderMarkovModel model = modelGenerator 41 .efgToFirstOrderMarkovModel(filename); 94 42 GlobalDataContainer.getInstance().addData(modelname, model); 95 43 }
Note: See TracChangeset
for help on using the changeset viewer.