[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;
|
---|
[1217] | 19 | import static de.ugoe.cs.autoquest.usability.util.TextInputUtil.characterIsNoLetterOrDigitPredicate;
|
---|
[1139] | 20 |
|
---|
| 21 | import java.util.List;
|
---|
| 22 |
|
---|
| 23 | import com.google.common.base.CharMatcher;
|
---|
| 24 | import com.google.common.base.Optional;
|
---|
| 25 | import com.google.common.collect.Multiset;
|
---|
| 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;
|
---|
[1217] | 30 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
|
---|
| 31 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
|
---|
[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;
|
---|
| 35 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.IterativeDFSFilterStrategy;
|
---|
| 36 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskModelFilter;
|
---|
[1139] | 37 |
|
---|
| 38 | /**
|
---|
| 39 | * <p>
|
---|
[1217] | 40 | * Metric, which calculates the ratio ratio between non letter or digit characters and all entered
|
---|
| 41 | * characters.
|
---|
[1139] | 42 | * </p>
|
---|
| 43 | *
|
---|
| 44 | * @author Alexander Deicke
|
---|
| 45 | */
|
---|
| 46 | public class NoLetterOrDigitRatioMetric extends UsabilityRule implements UsabilityMetric {
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * <p>
|
---|
[1217] | 50 | * Constructor. Creates a new {@code NoLetterOrDigitRatioMetric} for a given task model.
|
---|
[1139] | 51 | * </p>
|
---|
[1217] | 52 | *
|
---|
| 53 | * @param taskModel
|
---|
[1139] | 54 | */
|
---|
[1152] | 55 | public NoLetterOrDigitRatioMetric(ITaskModel taskModel) {
|
---|
| 56 | super(taskModel);
|
---|
[1139] | 57 | this.name = "NoLetterOrDigitRatio";
|
---|
[1217] | 58 | this.defect =
|
---|
| 59 | new UsabilityProblemDescriptionResolver().descriptionFor(this.getClass()
|
---|
| 60 | .getSimpleName());
|
---|
[1139] | 61 | }
|
---|
| 62 |
|
---|
[1217] | 63 | /*
|
---|
| 64 | * (non-Javadoc)
|
---|
| 65 | *
|
---|
[1139] | 66 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
|
---|
| 67 | */
|
---|
| 68 | @Override
|
---|
[1217] | 69 | public Optional<UsabilityProblemDescription> calculate() {
|
---|
[1139] | 70 | FilterResult textInputEvents = extractNodesFromTaskTree();
|
---|
[1152] | 71 | float evaluationMetric = calculateEvaluationMetric(textInputEvents.tasksMatchedFilter());
|
---|
[1139] | 72 | return this.defect.isPresent(evaluationMetric);
|
---|
| 73 | }
|
---|
[1217] | 74 |
|
---|
| 75 | /**
|
---|
| 76 | *
|
---|
| 77 | * <p>
|
---|
| 78 | * Filters all text input events from task model.
|
---|
| 79 | * </p>
|
---|
| 80 | *
|
---|
| 81 | * @return {@code FilterResult}
|
---|
| 82 | */
|
---|
[1139] | 83 | private FilterResult extractNodesFromTaskTree() {
|
---|
[1152] | 84 | return new TaskModelFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
|
---|
| 85 | .from(this.taskModel);
|
---|
[1139] | 86 | }
|
---|
[1217] | 87 |
|
---|
| 88 | /**
|
---|
| 89 | *
|
---|
| 90 | * <p>
|
---|
| 91 | * Calculates the metric.
|
---|
| 92 | * </p>
|
---|
| 93 | *
|
---|
| 94 | * @param textInputEvents
|
---|
| 95 | * all text input events
|
---|
| 96 | * @return ratio between non letter or digit characters and all entered characters
|
---|
| 97 | */
|
---|
[1152] | 98 | private float calculateEvaluationMetric(List<ITask> textInputEvents) {
|
---|
[1217] | 99 | Multiset<String> enteredTextFragments = aggregateEnteredTextFromTextInputs(textInputEvents);
|
---|
[1139] | 100 | int allCharactersCount = 0;
|
---|
| 101 | int noLetterOrDigitCount = 0;
|
---|
| 102 | for (String textFragment : enteredTextFragments.elementSet()) {
|
---|
| 103 | int occurencesOfTextFragment = enteredTextFragments.count(textFragment);
|
---|
| 104 | allCharactersCount += CharMatcher.ANY.countIn(textFragment) * occurencesOfTextFragment;
|
---|
| 105 | noLetterOrDigitCount +=
|
---|
[1217] | 106 | CharMatcher.forPredicate(characterIsNoLetterOrDigitPredicate())
|
---|
| 107 | .countIn(textFragment) * occurencesOfTextFragment;
|
---|
[1139] | 108 | }
|
---|
| 109 | return allCharactersCount != 0 ? (float) noLetterOrDigitCount / (float) allCharactersCount
|
---|
| 110 | : 0;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[1217] | 113 | /*
|
---|
| 114 | * (non-Javadoc)
|
---|
| 115 | *
|
---|
| 116 | * @see
|
---|
| 117 | * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
|
---|
| 118 | * .usability.EvaluationMethodCaller)
|
---|
[1150] | 119 | */
|
---|
| 120 | @Override
|
---|
[1217] | 121 | public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
|
---|
[1150] | 122 | {
|
---|
| 123 | return evaluationMethodCaller.check(this);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[1139] | 126 | }
|
---|