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.usability.evaluation.rule.evaluator;
|
---|
16 |
|
---|
17 | import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.TEXT_INPUT;
|
---|
18 | import static de.ugoe.cs.autoquest.usability.util.TextInputUtil.aggregateEnteredTextFromTextInputs;
|
---|
19 | import static java.lang.String.format;
|
---|
20 |
|
---|
21 | import com.google.common.base.Optional;
|
---|
22 | import com.google.common.base.Predicate;
|
---|
23 | import com.google.common.collect.Multiset;
|
---|
24 | import com.google.common.collect.Multisets;
|
---|
25 |
|
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
27 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectSeverityLevel;
|
---|
28 | import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule;
|
---|
29 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
|
---|
30 | import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
|
---|
31 | import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * <p>
|
---|
35 | * TODO comment
|
---|
36 | * </p>
|
---|
37 | *
|
---|
38 | * @author Alexander Deicke
|
---|
39 | */
|
---|
40 | public class TextInputEntryRepetitionsEvaluator extends RuleEvaluator {
|
---|
41 |
|
---|
42 | public TextInputEntryRepetitionsEvaluator(UsabilityRule evaluatedUsabilityRule,
|
---|
43 | ITaskTree taskTree)
|
---|
44 | {
|
---|
45 | super(evaluatedUsabilityRule, taskTree);
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | protected FilterStatistic nodesUnderEvaluation(ITaskTree taskTree) {
|
---|
50 | Optional<FilterStatistic> cachedNodes = loadFromCache(TEXT_INPUT);
|
---|
51 | return cachedNodes.isPresent() ? cachedNodes.get() : cacheAndReturnNodes(taskTree,
|
---|
52 | TEXT_INPUT);
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | protected FilterStatistic extractNodesFromTaskTree(ITaskTree taskTree) {
|
---|
57 | return new TaskTreeFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
|
---|
58 | .from(taskTree);
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | protected float calculateEvaluationMetric() {
|
---|
63 | Multiset<String> enteredTextFragments =
|
---|
64 | aggregateEnteredTextFromTextInputs(this.filteredNodes.nodesMatchedFilter());
|
---|
65 | Multiset<String> orderedTextFragmentsWithMultipleOccurences =
|
---|
66 | onlyTextFragmentsWithMultipleOccurences(enteredTextFragments);
|
---|
67 | if (orderedTextFragmentsWithMultipleOccurences.isEmpty())
|
---|
68 | return 0;
|
---|
69 | String wordWithHighestRepetitionInTextFragments =
|
---|
70 | orderedTextFragmentsWithMultipleOccurences.iterator().next();
|
---|
71 | int numberOfRepeatedWords = orderedTextFragmentsWithMultipleOccurences.entrySet().size();
|
---|
72 | int maxRepetitions =
|
---|
73 | orderedTextFragmentsWithMultipleOccurences
|
---|
74 | .count(wordWithHighestRepetitionInTextFragments);
|
---|
75 | storeEvaluationMetricForDefectDescription("textRepetitionRatio",
|
---|
76 | format("textRepetitionRatio %s repeated tokens, up to %s repetitions per token",
|
---|
77 | numberOfRepeatedWords, maxRepetitions));
|
---|
78 | return Math.max(numberOfRepeatedWords, maxRepetitions);
|
---|
79 | }
|
---|
80 |
|
---|
81 | private Multiset<String> onlyTextFragmentsWithMultipleOccurences(final Multiset<String> allTextInputs)
|
---|
82 | {
|
---|
83 | return Multisets.copyHighestCountFirst(Multisets.filter(allTextInputs,
|
---|
84 | new Predicate<String>() {
|
---|
85 |
|
---|
86 | @Override
|
---|
87 | public boolean apply(String word)
|
---|
88 | {
|
---|
89 | return allTextInputs
|
---|
90 | .count(word) > 1;
|
---|
91 | }
|
---|
92 |
|
---|
93 | }));
|
---|
94 | }
|
---|
95 |
|
---|
96 | @Override
|
---|
97 | protected Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric)
|
---|
98 | {
|
---|
99 | Optional<UsabilityDefectSeverityLevel> recommendationSeverityLevel = Optional.absent();
|
---|
100 | if (evaluationMetric > 10) {
|
---|
101 | recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.HIGH);
|
---|
102 | }
|
---|
103 | else if (evaluationMetric > 4) {
|
---|
104 | recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.MEDIUM);
|
---|
105 | }
|
---|
106 | else if (evaluationMetric > 2) {
|
---|
107 | recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.LOW);
|
---|
108 | }
|
---|
109 | else if (evaluationMetric > 1) {
|
---|
110 | recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.INFO);
|
---|
111 | }
|
---|
112 | return recommendationSeverityLevel;
|
---|
113 | }
|
---|
114 |
|
---|
115 | }
|
---|