source: trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ui/commands/CMDcalcEntropy.java @ 664

Last change on this file since 664 was 664, checked in by sherbold, 12 years ago
  • modified Command.help(): the help now returns a string with its usage instead of writing directly to the console
  • modified listCommands: now writes the help string of each command instead of just the name; this way, the parameters are displayed directly
  • moved listCommands from quest-ui-core to java-utils
File size: 1.5 KB
RevLine 
[434]1package de.ugoe.cs.quest.ui.commands;
[209]2
[1]3import java.security.InvalidParameterException;
4import java.util.List;
5
[432]6import de.ugoe.cs.quest.CommandHelpers;
[434]7import de.ugoe.cs.quest.ui.GlobalDataContainer;
[433]8import de.ugoe.cs.quest.usageprofiles.FirstOrderMarkovModel;
[1]9import de.ugoe.cs.util.console.Command;
10import de.ugoe.cs.util.console.Console;
11
[171]12/**
13 * <p>
14 * Command to calculate the entropy of first-order Markov models.
15 * </p>
16 *
17 * @author Steffen Herbold
18 * @version 1.0
19 */
[1]20public class CMDcalcEntropy implements Command {
21
[209]22        /*
23         * (non-Javadoc)
24         *
[171]25         * @see de.ugoe.cs.util.console.Command#help()
26         */
[1]27        @Override
[664]28        public String help() {
29                return "calcEntropy <modelname>";
[1]30        }
31
[209]32        /*
33         * (non-Javadoc)
34         *
[171]35         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
36         */
[1]37        @Override
38        public void run(List<Object> parameters) {
39                String modelname = "";
40                try {
41                        modelname = (String) parameters.get(0);
42                } catch (Exception e) {
43                        throw new InvalidParameterException();
44                }
[209]45
46                FirstOrderMarkovModel model = null;
47                Object dataObject = GlobalDataContainer.getInstance()
48                                .getData(modelname);
49                if (dataObject == null) {
[240]50                        CommandHelpers.objectNotFoundMessage(modelname);
[209]51                        return;
[1]52                }
[209]53                if (!(dataObject instanceof FirstOrderMarkovModel)) {
[240]54                        CommandHelpers.objectNotType(modelname, "FirstOrderMarkovModel");
[209]55                        return;
[1]56                }
[209]57                model = (FirstOrderMarkovModel) dataObject;
58                double entropy = model.calcEntropy();
59                if (!Double.isNaN(entropy)) {
60                        Console.println("entropy: " + entropy);
61                }
[1]62        }
63
64}
Note: See TracBrowser for help on using the repository browser.