[1139] | 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.rules.metrics;
|
---|
| 16 |
|
---|
| 17 | import static de.ugoe.cs.autoquest.usability.tasktree.filters.EventTypeFilter.TEXT_INPUT;
|
---|
| 18 | import static de.ugoe.cs.autoquest.usability.util.TextInputUtil.aggregateEnteredTextFromTextInputs;
|
---|
| 19 |
|
---|
| 20 | import java.util.List;
|
---|
| 21 |
|
---|
| 22 | import com.google.common.base.Optional;
|
---|
| 23 | import com.google.common.base.Predicate;
|
---|
| 24 | import com.google.common.collect.Multiset;
|
---|
| 25 | import com.google.common.collect.Multisets;
|
---|
| 26 |
|
---|
| 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
| 28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
| 29 | import de.ugoe.cs.autoquest.usability.result.DefectDescriptionResolver;
|
---|
| 30 | import de.ugoe.cs.autoquest.usability.result.UsabilityDefect;
|
---|
| 31 | import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
|
---|
| 32 | import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
|
---|
| 33 | import de.ugoe.cs.autoquest.usability.tasktree.FilterResult;
|
---|
| 34 | import de.ugoe.cs.autoquest.usability.tasktree.IterativeDFSFilterStrategy;
|
---|
| 35 | import de.ugoe.cs.autoquest.usability.tasktree.filters.TaskTreeFilter;
|
---|
| 36 |
|
---|
| 37 | /**
|
---|
| 38 | * <p>
|
---|
| 39 | * TODO comment
|
---|
| 40 | * </p>
|
---|
| 41 | *
|
---|
| 42 | * @author Alexander Deicke
|
---|
| 43 | */
|
---|
| 44 | public class TextInputEntryRepetitionsMetric extends UsabilityRule implements UsabilityMetric {
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
| 47 | * <p>
|
---|
| 48 | * TODO: comment
|
---|
| 49 | * </p>
|
---|
| 50 | *
|
---|
| 51 | * @param taskTree
|
---|
| 52 | */
|
---|
| 53 | public TextInputEntryRepetitionsMetric(ITaskTree taskTree) {
|
---|
| 54 | super(taskTree);
|
---|
| 55 | this.name = "TextInputEntryRepetitions";
|
---|
| 56 | this.defect = new DefectDescriptionResolver().descriptionFor(this.getClass().getSimpleName());
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | /* (non-Javadoc)
|
---|
| 60 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
|
---|
| 61 | */
|
---|
| 62 | @Override
|
---|
| 63 | public Optional<UsabilityDefect> check() {
|
---|
| 64 | FilterResult textInputEvents = extractNodesFromTaskTree();
|
---|
| 65 | float evaluationMetric = calculateEvaluationMetric(textInputEvents.nodesMatchedFilter());
|
---|
| 66 | return this.defect.isPresent(evaluationMetric);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | private FilterResult extractNodesFromTaskTree() {
|
---|
| 70 | return new TaskTreeFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
|
---|
| 71 | .from(this.taskTree);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | private float calculateEvaluationMetric(List<ITaskTreeNode> textInputEvents) {
|
---|
| 75 | Multiset<String> enteredTextFragments =
|
---|
| 76 | aggregateEnteredTextFromTextInputs(textInputEvents);
|
---|
| 77 | Multiset<String> orderedTextFragmentsWithMultipleOccurences =
|
---|
| 78 | onlyTextFragmentsWithMultipleOccurences(enteredTextFragments);
|
---|
| 79 | if (orderedTextFragmentsWithMultipleOccurences.isEmpty())
|
---|
| 80 | return 0;
|
---|
| 81 | String wordWithHighestRepetitionInTextFragments =
|
---|
| 82 | orderedTextFragmentsWithMultipleOccurences.iterator().next();
|
---|
| 83 | int numberOfRepeatedWords = orderedTextFragmentsWithMultipleOccurences.entrySet().size();
|
---|
| 84 | int maxRepetitions =
|
---|
| 85 | orderedTextFragmentsWithMultipleOccurences
|
---|
| 86 | .count(wordWithHighestRepetitionInTextFragments);
|
---|
| 87 | return Math.max(numberOfRepeatedWords, maxRepetitions);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | private Multiset<String> onlyTextFragmentsWithMultipleOccurences(final Multiset<String> allTextInputs)
|
---|
| 91 | {
|
---|
| 92 | return Multisets.copyHighestCountFirst(Multisets.filter(allTextInputs,
|
---|
| 93 | new Predicate<String>() {
|
---|
| 94 |
|
---|
| 95 | @Override
|
---|
| 96 | public boolean apply(String word)
|
---|
| 97 | {
|
---|
| 98 | return allTextInputs
|
---|
| 99 | .count(word) > 1;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | }));
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | }
|
---|