[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;
|
---|
[31] | 16 |
|
---|
| 17 | import java.util.List;
|
---|
| 18 |
|
---|
[922] | 19 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 20 | import de.ugoe.cs.autoquest.usageprofiles.Trie;
|
---|
| 21 | import de.ugoe.cs.autoquest.usageprofiles.TrieBasedModel;
|
---|
[31] | 22 | import de.ugoe.cs.util.console.Command;
|
---|
| 23 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 24 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[31] | 25 |
|
---|
[171] | 26 | /**
|
---|
| 27 | * <p>
|
---|
| 28 | * Command that prints the {@link Trie} of a {@link TrieBasedModel} as dot to
|
---|
| 29 | * the console.
|
---|
| 30 | * </p>
|
---|
| 31 | *
|
---|
| 32 | * @author Steffen Herbold
|
---|
[223] | 33 | * @version 1.0
|
---|
[171] | 34 | */
|
---|
[31] | 35 | public class CMDprintTrieDot implements Command {
|
---|
[171] | 36 |
|
---|
| 37 | /*
|
---|
| 38 | * (non-Javadoc)
|
---|
| 39 | *
|
---|
| 40 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 41 | */
|
---|
[31] | 42 | @Override
|
---|
[664] | 43 | public String help() {
|
---|
| 44 | return "printTreeDot <modelname>";
|
---|
[31] | 45 | }
|
---|
| 46 |
|
---|
[171] | 47 | /*
|
---|
| 48 | * (non-Javadoc)
|
---|
| 49 | *
|
---|
| 50 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 51 | */
|
---|
[31] | 52 | @Override
|
---|
| 53 | public void run(List<Object> parameters) {
|
---|
| 54 | String modelname = "";
|
---|
| 55 | try {
|
---|
| 56 | modelname = (String) parameters.get(0);
|
---|
| 57 | } catch (Exception e) {
|
---|
[766] | 58 | throw new IllegalArgumentException();
|
---|
[31] | 59 | }
|
---|
[171] | 60 |
|
---|
| 61 | TrieBasedModel model = null;
|
---|
| 62 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
| 63 | .getData(modelname);
|
---|
| 64 | if (dataObject == null) {
|
---|
[240] | 65 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
[209] | 66 | return;
|
---|
| 67 | }
|
---|
| 68 | if (!(dataObject instanceof TrieBasedModel)) {
|
---|
[240] | 69 | CommandHelpers.objectNotType(modelname, "TrieBasedModel");
|
---|
[209] | 70 | return;
|
---|
[31] | 71 | }
|
---|
[209] | 72 |
|
---|
| 73 | model = (TrieBasedModel) dataObject;
|
---|
| 74 | Console.println(model.getTrieDotRepresentation());
|
---|
[31] | 75 | }
|
---|
[171] | 76 |
|
---|
[31] | 77 | }
|
---|