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