Changeset 1040 for trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/rule/evaluator/TextInputEntryRepetitionsEvaluator.java
- Timestamp:
- 01/16/13 17:51:51 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/rule/evaluator/TextInputEntryRepetitionsEvaluator.java
r1030 r1040 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 1 15 package de.ugoe.cs.autoquest.usability.evaluation.rule.evaluator; 2 16 3 17 import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.TEXT_INPUT; 4 18 import static de.ugoe.cs.autoquest.usability.util.TextInputUtil.aggregateEnteredTextFromTextInputs; 19 import static java.lang.String.format; 5 20 6 21 import com.google.common.base.Optional; … … 16 31 import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter; 17 32 33 /** 34 * <p> 35 * TODO comment 36 * </p> 37 * 38 * @author Alexander Deicke 39 */ 18 40 public class TextInputEntryRepetitionsEvaluator extends RuleEvaluator { 19 41 20 public TextInputEntryRepetitionsEvaluator(UsabilityRule evaluatedUsabilityRule, ITaskTree taskTree) { 42 public TextInputEntryRepetitionsEvaluator(UsabilityRule evaluatedUsabilityRule, 43 ITaskTree taskTree) 44 { 21 45 super(evaluatedUsabilityRule, taskTree); 22 46 } … … 25 49 protected FilterStatistic nodesUnderEvaluation(ITaskTree taskTree) { 26 50 Optional<FilterStatistic> cachedNodes = loadFromCache(TEXT_INPUT); 27 return cachedNodes.isPresent() ? cachedNodes.get() : cacheAndReturnNodes(taskTree, TEXT_INPUT); 51 return cachedNodes.isPresent() ? cachedNodes.get() : cacheAndReturnNodes(taskTree, 52 TEXT_INPUT); 28 53 } 29 54 30 55 @Override 31 56 protected FilterStatistic extractNodesFromTaskTree(ITaskTree taskTree) { 32 return new TaskTreeFilter(new IterativeDFSFilterStrategy()) 33 .f ilterByEventType(TEXT_INPUT).from(taskTree);57 return new TaskTreeFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT) 58 .from(taskTree); 34 59 } 35 60 36 61 @Override 37 62 protected float calculateEvaluationMetric() { 38 Multiset<String> enteredTextFragments = aggregateEnteredTextFromTextInputs(this.filteredNodes.nodesMatchedFilter()); 39 Multiset<String> orderedTextFragmentsWithMultipleOccurences = onlyTextFragmentsWithMultipleOccurences(enteredTextFragments); 40 if(orderedTextFragmentsWithMultipleOccurences.isEmpty()) return 0; 41 String wordWithHighestRepetitionInTextFragments = orderedTextFragmentsWithMultipleOccurences.iterator().next(); 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(); 42 71 int numberOfRepeatedWords = orderedTextFragmentsWithMultipleOccurences.entrySet().size(); 43 int maxRepetitions = orderedTextFragmentsWithMultipleOccurences.count(wordWithHighestRepetitionInTextFragments); 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)); 44 78 return Math.max(numberOfRepeatedWords, maxRepetitions); 45 79 } 46 47 private Multiset<String> onlyTextFragmentsWithMultipleOccurences(final Multiset<String> allTextInputs) { 48 return Multisets.copyHighestCountFirst(Multisets.filter(allTextInputs, new Predicate<String>() { 49 50 @Override 51 public boolean apply(String word) { 52 return allTextInputs.count(word) > 1; 53 } 54 55 })); 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 })); 56 94 } 57 95 58 96 @Override 59 protected Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric) { 97 protected Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric) 98 { 60 99 Optional<UsabilityDefectSeverityLevel> recommendationSeverityLevel = Optional.absent(); 61 100 if (evaluationMetric > 10) { … … 73 112 return recommendationSeverityLevel; 74 113 } 75 114 76 115 }
Note: See TracChangeset
for help on using the changeset viewer.