source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDflattenModel.java @ 318

Last change on this file since 318 was 260, checked in by sherbold, 13 years ago
  • added command flattenModel
  • Property svn:mime-type set to text/plain
File size: 1.9 KB
Line 
1package de.ugoe.cs.eventbench.commands;
2
3import java.security.InvalidParameterException;
4import java.util.List;
5
6import de.ugoe.cs.eventbench.CommandHelpers;
7import de.ugoe.cs.eventbench.data.GlobalDataContainer;
8import de.ugoe.cs.eventbench.models.FirstOrderMarkovModel;
9import de.ugoe.cs.eventbench.models.HighOrderMarkovModel;
10import de.ugoe.cs.eventbench.models.ModelFlattener;
11import de.ugoe.cs.util.console.Command;
12import 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 */
23public 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}
Note: See TracBrowser for help on using the repository browser.