[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;
|
---|
[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 calculates the ratio ratio between non letter or digit characters and all entered
|
---|
| 40 | * characters.
|
---|
[1139] | 41 | * </p>
|
---|
| 42 | *
|
---|
| 43 | * @author Alexander Deicke
|
---|
| 44 | */
|
---|
| 45 | public class NoLetterOrDigitRatioMetric extends UsabilityRule implements UsabilityMetric {
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * <p>
|
---|
[1217] | 49 | * Constructor. Creates a new {@code NoLetterOrDigitRatioMetric} for a given task model.
|
---|
[1139] | 50 | * </p>
|
---|
[1217] | 51 | *
|
---|
| 52 | * @param taskModel
|
---|
[1139] | 53 | */
|
---|
[1152] | 54 | public NoLetterOrDigitRatioMetric(ITaskModel taskModel) {
|
---|
| 55 | super(taskModel);
|
---|
[1139] | 56 | this.name = "NoLetterOrDigitRatio";
|
---|
[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 ratio between non letter or digit characters and all entered characters
|
---|
| 95 | */
|
---|
[1152] | 96 | private float calculateEvaluationMetric(List<ITask> textInputEvents) {
|
---|
[1217] | 97 | Multiset<String> enteredTextFragments = aggregateEnteredTextFromTextInputs(textInputEvents);
|
---|
[1139] | 98 | int allCharactersCount = 0;
|
---|
| 99 | int noLetterOrDigitCount = 0;
|
---|
| 100 | for (String textFragment : enteredTextFragments.elementSet()) {
|
---|
| 101 | int occurencesOfTextFragment = enteredTextFragments.count(textFragment);
|
---|
| 102 | allCharactersCount += CharMatcher.ANY.countIn(textFragment) * occurencesOfTextFragment;
|
---|
| 103 | noLetterOrDigitCount +=
|
---|
[1217] | 104 | CharMatcher.forPredicate(characterIsNoLetterOrDigitPredicate())
|
---|
| 105 | .countIn(textFragment) * occurencesOfTextFragment;
|
---|
[1139] | 106 | }
|
---|
| 107 | return allCharactersCount != 0 ? (float) noLetterOrDigitCount / (float) allCharactersCount
|
---|
| 108 | : 0;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[1217] | 111 | /*
|
---|
| 112 | * (non-Javadoc)
|
---|
| 113 | *
|
---|
| 114 | * @see
|
---|
| 115 | * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
|
---|
| 116 | * .usability.EvaluationMethodCaller)
|
---|
[1150] | 117 | */
|
---|
| 118 | @Override
|
---|
[1217] | 119 | public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
|
---|
[1150] | 120 | {
|
---|
| 121 | return evaluationMethodCaller.check(this);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[1139] | 124 | }
|
---|