[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.commands.usage;
|
---|
[260] | 16 |
|
---|
| 17 | import java.util.List;
|
---|
| 18 |
|
---|
[922] | 19 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 20 | import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel;
|
---|
| 21 | import de.ugoe.cs.autoquest.usageprofiles.HighOrderMarkovModel;
|
---|
| 22 | import de.ugoe.cs.autoquest.usageprofiles.ModelFlattener;
|
---|
[260] | 23 | import de.ugoe.cs.util.console.Command;
|
---|
[667] | 24 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[260] | 25 |
|
---|
| 26 | /**
|
---|
| 27 | * <p>
|
---|
| 28 | * Command to flatten high-order models and create first-order markov models
|
---|
| 29 | * with the same stochastic properties.
|
---|
| 30 | * </p>
|
---|
| 31 | *
|
---|
| 32 | * @author Steffen Herbold
|
---|
| 33 | * @version 1.0
|
---|
| 34 | */
|
---|
| 35 | public class CMDflattenModel implements Command {
|
---|
| 36 |
|
---|
| 37 | /*
|
---|
| 38 | * (non-Javadoc)
|
---|
| 39 | *
|
---|
| 40 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 41 | */
|
---|
| 42 | @Override
|
---|
| 43 | public void run(List<Object> parameters) {
|
---|
| 44 | String modelname;
|
---|
| 45 | String modelnameFOM;
|
---|
| 46 |
|
---|
| 47 | try {
|
---|
| 48 | modelname = (String) parameters.get(0);
|
---|
| 49 | modelnameFOM = (String) parameters.get(1);
|
---|
| 50 | } catch (Exception e) {
|
---|
[766] | 51 | throw new IllegalArgumentException();
|
---|
[260] | 52 | }
|
---|
| 53 |
|
---|
| 54 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
| 55 | .getData(modelname);
|
---|
| 56 | if (dataObject == null) {
|
---|
| 57 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
| 58 | return;
|
---|
| 59 | }
|
---|
| 60 | if (!(dataObject instanceof HighOrderMarkovModel)) {
|
---|
| 61 | CommandHelpers.objectNotType(modelname, "HighOrderMarkovModel");
|
---|
| 62 | return;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | HighOrderMarkovModel model = (HighOrderMarkovModel) dataObject;
|
---|
| 66 | ModelFlattener flattener = new ModelFlattener();
|
---|
| 67 | FirstOrderMarkovModel modelFOM = flattener
|
---|
| 68 | .flattenHighOrderMarkovModel(model);
|
---|
| 69 |
|
---|
| 70 | if (GlobalDataContainer.getInstance().addData(modelnameFOM, modelFOM)) {
|
---|
| 71 | CommandHelpers.dataOverwritten(modelnameFOM);
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | /*
|
---|
| 76 | * (non-Javadoc)
|
---|
| 77 | *
|
---|
| 78 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 79 | */
|
---|
| 80 | @Override
|
---|
[664] | 81 | public String help() {
|
---|
| 82 | return "flattenModel <modelname> <modelname_flattened>";
|
---|
[260] | 83 | }
|
---|
| 84 | }
|
---|