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 |
|
---|
15 | package de.ugoe.cs.autoquest.commands.usage;
|
---|
16 |
|
---|
17 | import java.util.Collection;
|
---|
18 | import java.util.List;
|
---|
19 |
|
---|
20 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
21 | import de.ugoe.cs.autoquest.SequenceInstanceOf;
|
---|
22 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
23 | import de.ugoe.cs.autoquest.usageprofiles.TrieBasedModel;
|
---|
24 | import de.ugoe.cs.util.console.Command;
|
---|
25 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * <p>
|
---|
29 | * Command to update a {@link TrieBasedModel}.
|
---|
30 | * </p>
|
---|
31 | *
|
---|
32 | * @author Steffen Herbold
|
---|
33 | * @version 1.0
|
---|
34 | */
|
---|
35 | public class CMDupdateModel implements Command {
|
---|
36 |
|
---|
37 | /*
|
---|
38 | * (non-Javadoc)
|
---|
39 | *
|
---|
40 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
41 | */
|
---|
42 | @SuppressWarnings("unchecked")
|
---|
43 | @Override
|
---|
44 | public void run(List<Object> parameters) {
|
---|
45 | String modelname;
|
---|
46 | String sequencesName;
|
---|
47 |
|
---|
48 | try {
|
---|
49 | modelname = (String) parameters.get(0);
|
---|
50 | sequencesName = (String) parameters.get(1);
|
---|
51 | } catch (Exception e) {
|
---|
52 | throw new IllegalArgumentException();
|
---|
53 | }
|
---|
54 |
|
---|
55 | Object dataObject = GlobalDataContainer.getInstance().getData(
|
---|
56 | sequencesName);
|
---|
57 | if (dataObject == null) {
|
---|
58 | CommandHelpers.objectNotFoundMessage(sequencesName);
|
---|
59 | return;
|
---|
60 | }
|
---|
61 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
62 | CommandHelpers.objectNotType(sequencesName,
|
---|
63 | "Collection<List<Event<?>>>");
|
---|
64 | return;
|
---|
65 | }
|
---|
66 | Collection<List<Event>> sequences = (Collection<List<Event>>) dataObject;
|
---|
67 |
|
---|
68 | dataObject = GlobalDataContainer.getInstance().getData(modelname);
|
---|
69 | if (dataObject == null) {
|
---|
70 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
71 | return;
|
---|
72 | }
|
---|
73 | if (!(dataObject instanceof TrieBasedModel)) {
|
---|
74 | CommandHelpers.objectNotType(modelname, "TrieBasedModel");
|
---|
75 | return;
|
---|
76 | }
|
---|
77 |
|
---|
78 | TrieBasedModel model = (TrieBasedModel) dataObject;
|
---|
79 | model.update(sequences);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * (non-Javadoc)
|
---|
84 | *
|
---|
85 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
86 | */
|
---|
87 | @Override
|
---|
88 | public String help() {
|
---|
89 | return "updateModel <modelname> <sequencesName>";
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|