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.usability;
|
---|
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.tasktrees.manager.TaskTreeManager;
|
---|
24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
25 | import de.ugoe.cs.util.console.Command;
|
---|
26 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * <p>
|
---|
30 | * This command generates a task tree based on the provided sequences. It uses
|
---|
31 | * the {@link TaskTreeManager} for this purpose. Please consult the
|
---|
32 | * documentation of the task tree manager for more details.
|
---|
33 | * </p>
|
---|
34 | *
|
---|
35 | * @author Patrick Harms
|
---|
36 | * @version 1.0
|
---|
37 | */
|
---|
38 | public class CMDgenerateTaskTree implements Command {
|
---|
39 |
|
---|
40 | /*
|
---|
41 | * (non-Javadoc)
|
---|
42 | *
|
---|
43 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
44 | */
|
---|
45 | @Override
|
---|
46 | public String help() {
|
---|
47 | return "generateTaskTree <sequences> {<tasktree>} {<boolean: harmonize sequences or not (true or false)>} {<integer: number of threads>}";
|
---|
48 | }
|
---|
49 |
|
---|
50 | /*
|
---|
51 | * (non-Javadoc)
|
---|
52 | *
|
---|
53 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
54 | */
|
---|
55 | @SuppressWarnings("unchecked")
|
---|
56 | @Override
|
---|
57 | public void run(List<Object> parameters) {
|
---|
58 | String sequencesName;
|
---|
59 | String tasktreeName;
|
---|
60 | try {
|
---|
61 | sequencesName = (String) parameters.get(0);
|
---|
62 | if (parameters.size() > 1) {
|
---|
63 | tasktreeName = (String) parameters.get(1);
|
---|
64 | } else {
|
---|
65 | tasktreeName = "tasktree";
|
---|
66 | }
|
---|
67 | } catch (Exception e) {
|
---|
68 | throw new IllegalArgumentException("must provide a sequences name");
|
---|
69 | }
|
---|
70 | if (parameters.size() > 2) {
|
---|
71 | String harmonize = (String) parameters.get(2);
|
---|
72 | de.ugoe.cs.autoquest.tasktrees.temporalrelation.SequenceForTaskDetectionRuleAlignment.harmonizeSequences = true;
|
---|
73 | System.out.println(harmonize);
|
---|
74 | if (harmonize.equals("false")) {
|
---|
75 | System.out.println("Not harmonizing");
|
---|
76 | de.ugoe.cs.autoquest.tasktrees.temporalrelation.SequenceForTaskDetectionRuleAlignment.harmonizeSequences = false;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | if (parameters.size() > 3) {
|
---|
80 | String threadCount = (String) parameters.get(3);
|
---|
81 | de.ugoe.cs.autoquest.tasktrees.temporalrelation.SequenceForTaskDetectionRuleAlignment.nThreads = 1;
|
---|
82 | try {
|
---|
83 | int tmp = Integer.parseInt(threadCount);
|
---|
84 | de.ugoe.cs.autoquest.tasktrees.temporalrelation.SequenceForTaskDetectionRuleAlignment.nThreads = tmp;
|
---|
85 | } catch (Exception e) {
|
---|
86 | throw new IllegalArgumentException(
|
---|
87 | "The fourth parameter must be an integer. Did you forget to name the tasktree?");
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | Collection<List<Event>> sequences = null;
|
---|
92 | Object dataObject = GlobalDataContainer.getInstance().getData(
|
---|
93 | sequencesName);
|
---|
94 | if (dataObject == null) {
|
---|
95 | CommandHelpers.objectNotFoundMessage(sequencesName);
|
---|
96 | return;
|
---|
97 | }
|
---|
98 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
99 | CommandHelpers.objectNotType(sequencesName,
|
---|
100 | "Collection<List<Event<?>>>");
|
---|
101 | return;
|
---|
102 | }
|
---|
103 |
|
---|
104 | sequences = (Collection<List<Event>>) dataObject;
|
---|
105 |
|
---|
106 | ITaskModel taskModel = new TaskTreeManager().createTaskModel(sequences);
|
---|
107 |
|
---|
108 | if (GlobalDataContainer.getInstance().addData(tasktreeName, taskModel)) {
|
---|
109 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
110 | }
|
---|
111 |
|
---|
112 | }
|
---|
113 |
|
---|
114 | }
|
---|