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