[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 |
|
---|
[1217] | 17 | import static de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTypeFilter.TEXT_INPUT;
|
---|
[1139] | 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;
|
---|
[1292] | 30 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
|
---|
[1217] | 31 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
|
---|
[1139] | 32 | import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
|
---|
| 33 | import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
|
---|
[1217] | 34 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.FilterResult;
|
---|
[1292] | 35 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.TaskModelFilter;
|
---|
[1139] | 36 |
|
---|
| 37 | /**
|
---|
| 38 | * <p>
|
---|
[1217] | 39 | * Metric, which measures either the repetition of entered words or the maximum repetition of a
|
---|
| 40 | * single word.
|
---|
[1139] | 41 | * </p>
|
---|
| 42 | *
|
---|
| 43 | * @author Alexander Deicke
|
---|
| 44 | */
|
---|
| 45 | public class TextInputEntryRepetitionsMetric extends UsabilityRule implements UsabilityMetric {
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * <p>
|
---|
[1217] | 49 | * Constructor. Creates a new {@link TextInputEntryRepetitionsMetric} for a given task model.
|
---|
[1139] | 50 | * </p>
|
---|
[1217] | 51 | *
|
---|
| 52 | * @param taskModel
|
---|
[1139] | 53 | */
|
---|
[1152] | 54 | public TextInputEntryRepetitionsMetric(ITaskModel taskModel) {
|
---|
| 55 | super(taskModel);
|
---|
[1139] | 56 | this.name = "TextInputEntryRepetitions";
|
---|
[1217] | 57 | this.defect =
|
---|
| 58 | new UsabilityProblemDescriptionResolver().descriptionFor(this.getClass()
|
---|
| 59 | .getSimpleName());
|
---|
[1139] | 60 | }
|
---|
| 61 |
|
---|
[1217] | 62 | /*
|
---|
| 63 | * (non-Javadoc)
|
---|
| 64 | *
|
---|
[1139] | 65 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
|
---|
| 66 | */
|
---|
| 67 | @Override
|
---|
[1217] | 68 | public Optional<UsabilityProblemDescription> calculate() {
|
---|
[1139] | 69 | FilterResult textInputEvents = extractNodesFromTaskTree();
|
---|
[1152] | 70 | float evaluationMetric = calculateEvaluationMetric(textInputEvents.tasksMatchedFilter());
|
---|
[1139] | 71 | return this.defect.isPresent(evaluationMetric);
|
---|
| 72 | }
|
---|
[1217] | 73 |
|
---|
| 74 | /**
|
---|
| 75 | *
|
---|
| 76 | * <p>
|
---|
| 77 | * Filters all text input events from task model.
|
---|
| 78 | * </p>
|
---|
| 79 | *
|
---|
| 80 | * @return {@code FilterResult}
|
---|
| 81 | */
|
---|
[1139] | 82 | private FilterResult extractNodesFromTaskTree() {
|
---|
[1292] | 83 | return new TaskModelFilter().filter(taskModel, TEXT_INPUT);
|
---|
[1139] | 84 | }
|
---|
[1217] | 85 |
|
---|
| 86 | /**
|
---|
| 87 | *
|
---|
| 88 | * <p>
|
---|
| 89 | * Calculates the metric.
|
---|
| 90 | * </p>
|
---|
| 91 | *
|
---|
| 92 | * @param textInputEvents
|
---|
| 93 | * all text input events
|
---|
| 94 | * @return either number of repeated words or the number of repetitions of the most entered word
|
---|
| 95 | */
|
---|
[1152] | 96 | private float calculateEvaluationMetric(List<ITask> textInputEvents) {
|
---|
[1217] | 97 | Multiset<String> enteredTextFragments = aggregateEnteredTextFromTextInputs(textInputEvents);
|
---|
[1139] | 98 | Multiset<String> orderedTextFragmentsWithMultipleOccurences =
|
---|
| 99 | onlyTextFragmentsWithMultipleOccurences(enteredTextFragments);
|
---|
| 100 | if (orderedTextFragmentsWithMultipleOccurences.isEmpty())
|
---|
| 101 | return 0;
|
---|
| 102 | String wordWithHighestRepetitionInTextFragments =
|
---|
| 103 | orderedTextFragmentsWithMultipleOccurences.iterator().next();
|
---|
| 104 | int numberOfRepeatedWords = orderedTextFragmentsWithMultipleOccurences.entrySet().size();
|
---|
| 105 | int maxRepetitions =
|
---|
| 106 | orderedTextFragmentsWithMultipleOccurences
|
---|
| 107 | .count(wordWithHighestRepetitionInTextFragments);
|
---|
[1217] | 108 | return Math.max(numberOfRepeatedWords, maxRepetitions - 1);
|
---|
[1139] | 109 | }
|
---|
[1217] | 110 |
|
---|
| 111 | /**
|
---|
| 112 | *
|
---|
| 113 | * <p>
|
---|
| 114 | * Return only words, which at least entered twice.
|
---|
| 115 | * </p>
|
---|
| 116 | *
|
---|
| 117 | * @param allTextInputs
|
---|
| 118 | * all text input events
|
---|
| 119 | * @return all word, which used min. twice
|
---|
| 120 | */
|
---|
[1139] | 121 | private Multiset<String> onlyTextFragmentsWithMultipleOccurences(final Multiset<String> allTextInputs)
|
---|
| 122 | {
|
---|
| 123 | return Multisets.copyHighestCountFirst(Multisets.filter(allTextInputs,
|
---|
| 124 | new Predicate<String>() {
|
---|
| 125 |
|
---|
| 126 | @Override
|
---|
| 127 | public boolean apply(String word)
|
---|
| 128 | {
|
---|
| 129 | return allTextInputs
|
---|
| 130 | .count(word) > 1;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | }));
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[1217] | 136 | /*
|
---|
| 137 | * (non-Javadoc)
|
---|
| 138 | *
|
---|
| 139 | * @see
|
---|
| 140 | * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
|
---|
| 141 | * .usability.EvaluationMethodCaller)
|
---|
[1150] | 142 | */
|
---|
| 143 | @Override
|
---|
[1217] | 144 | public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
|
---|
[1150] | 145 | {
|
---|
| 146 | return evaluationMethodCaller.check(this);
|
---|
| 147 | }
|
---|
[1217] | 148 |
|
---|
[1139] | 149 | }
|
---|