1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
7 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
8 | import de.ugoe.cs.eventbench.models.FirstOrderMarkovModel;
|
---|
9 | import de.ugoe.cs.eventbench.models.HighOrderMarkovModel;
|
---|
10 | import de.ugoe.cs.eventbench.models.ModelFlattener;
|
---|
11 | import de.ugoe.cs.util.console.Command;
|
---|
12 | import de.ugoe.cs.util.console.Console;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * <p>
|
---|
16 | * Command to flatten high-order models and create first-order markov models
|
---|
17 | * with the same stochastic properties.
|
---|
18 | * </p>
|
---|
19 | *
|
---|
20 | * @author Steffen Herbold
|
---|
21 | * @version 1.0
|
---|
22 | */
|
---|
23 | public class CMDflattenModel implements Command {
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * (non-Javadoc)
|
---|
27 | *
|
---|
28 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
29 | */
|
---|
30 | @Override
|
---|
31 | public void run(List<Object> parameters) {
|
---|
32 | String modelname;
|
---|
33 | String modelnameFOM;
|
---|
34 |
|
---|
35 | try {
|
---|
36 | modelname = (String) parameters.get(0);
|
---|
37 | modelnameFOM = (String) parameters.get(1);
|
---|
38 | } catch (Exception e) {
|
---|
39 | throw new InvalidParameterException();
|
---|
40 | }
|
---|
41 |
|
---|
42 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
43 | .getData(modelname);
|
---|
44 | if (dataObject == null) {
|
---|
45 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
46 | return;
|
---|
47 | }
|
---|
48 | if (!(dataObject instanceof HighOrderMarkovModel)) {
|
---|
49 | CommandHelpers.objectNotType(modelname, "HighOrderMarkovModel");
|
---|
50 | return;
|
---|
51 | }
|
---|
52 |
|
---|
53 | HighOrderMarkovModel model = (HighOrderMarkovModel) dataObject;
|
---|
54 | ModelFlattener flattener = new ModelFlattener();
|
---|
55 | FirstOrderMarkovModel modelFOM = flattener
|
---|
56 | .flattenHighOrderMarkovModel(model);
|
---|
57 |
|
---|
58 | if (GlobalDataContainer.getInstance().addData(modelnameFOM, modelFOM)) {
|
---|
59 | CommandHelpers.dataOverwritten(modelnameFOM);
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * (non-Javadoc)
|
---|
65 | *
|
---|
66 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
67 | */
|
---|
68 | @Override
|
---|
69 | public void help() {
|
---|
70 | Console.println("Usage: flattenModel <modelname> <modelname_flattened>");
|
---|
71 | }
|
---|
72 | }
|
---|