| 1 | package de.ugoe.cs.eventbench.commands;
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 | import java.security.InvalidParameterException;
|
|---|
| 5 | import java.util.List;
|
|---|
| 6 |
|
|---|
| 7 | import de.ugoe.cs.eventbench.data.Event;
|
|---|
| 8 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
|---|
| 9 | import de.ugoe.cs.eventbench.markov.MarkovModel;
|
|---|
| 10 | import de.ugoe.cs.util.console.Command;
|
|---|
| 11 | import de.ugoe.cs.util.console.Console;
|
|---|
| 12 |
|
|---|
| 13 | public class CMDtrainMarkovModel implements Command {
|
|---|
| 14 |
|
|---|
| 15 | @Override
|
|---|
| 16 | public void help() {
|
|---|
| 17 | Console.println("Usage: trainMarkovModel <modelName>");
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | @SuppressWarnings("unchecked")
|
|---|
| 21 | @Override
|
|---|
| 22 | public void run(List<Object> parameters) {
|
|---|
| 23 | String modelname;
|
|---|
| 24 | try {
|
|---|
| 25 | modelname = (String) parameters.get(0);
|
|---|
| 26 | } catch (Exception e) {
|
|---|
| 27 | throw new InvalidParameterException();
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | List<List<Event<?>>> sequences = null;
|
|---|
| 31 | Object dataObject = GlobalDataContainer.getInstance().getData("sequences");
|
|---|
| 32 |
|
|---|
| 33 | try {
|
|---|
| 34 | sequences = (List<List<Event<?>>>) dataObject;
|
|---|
| 35 | if( sequences.size()>0 ) {
|
|---|
| 36 | if( sequences.get(0).get(0) instanceof Event ) {
|
|---|
| 37 | MarkovModel model = new MarkovModel();
|
|---|
| 38 | model.train(sequences);
|
|---|
| 39 | if( GlobalDataContainer.getInstance().addData(modelname, model) ) {
|
|---|
| 40 | Console.traceln("Old model overwritten");
|
|---|
| 41 | }
|
|---|
| 42 | } else {
|
|---|
| 43 | Console.traceln("Illegal use of \"sequences\" parameter in the GlobalDataContainer.");
|
|---|
| 44 | Console.traceln("The parameter should always be of type List<List<Event>>!");
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 | catch(ClassCastException e) {
|
|---|
| 49 | Console.println("Sequences need to be loaded first using parseXML");
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | }
|
|---|