source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/rules/metrics/NoLetterOrDigitRatioMetric.java @ 1152

Last change on this file since 1152 was 1152, checked in by pharms, 11 years ago
  • complete refactoring of task tree model with a separation of task models and task instances
  • Property svn:mime-type set to text/plain
File size: 4.1 KB
Line 
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
15package de.ugoe.cs.autoquest.usability.rules.metrics;
16
17import static de.ugoe.cs.autoquest.usability.tasktree.filters.EventTypeFilter.TEXT_INPUT;
18import static de.ugoe.cs.autoquest.usability.util.TextInputUtil.aggregateEnteredTextFromTextInputs;
19import static de.ugoe.cs.autoquest.usability.util.TextInputUtil.characterIsLetterOrDigitPredicate;
20
21import java.util.List;
22
23import com.google.common.base.CharMatcher;
24import com.google.common.base.Optional;
25import com.google.common.collect.Multiset;
26
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
29import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
30import de.ugoe.cs.autoquest.usability.result.DefectDescriptionResolver;
31import de.ugoe.cs.autoquest.usability.result.UsabilityDefect;
32import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
33import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
34import de.ugoe.cs.autoquest.usability.tasktree.FilterResult;
35import de.ugoe.cs.autoquest.usability.tasktree.IterativeDFSFilterStrategy;
36import de.ugoe.cs.autoquest.usability.tasktree.filters.TaskModelFilter;
37
38/**
39 * <p>
40 * TODO comment
41 * </p>
42 *
43 * @author Alexander Deicke
44 */
45public class NoLetterOrDigitRatioMetric extends UsabilityRule implements UsabilityMetric {
46
47    /**
48     * <p>
49     * TODO: comment
50     * </p>
51     *
52     * @param taskTree
53     */
54    public NoLetterOrDigitRatioMetric(ITaskModel taskModel) {
55        super(taskModel);
56        this.name = "NoLetterOrDigitRatio";
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
64    public Optional<UsabilityDefect> calculate() {
65        FilterResult textInputEvents = extractNodesFromTaskTree();
66        float evaluationMetric = calculateEvaluationMetric(textInputEvents.tasksMatchedFilter());
67        return this.defect.isPresent(evaluationMetric);
68    }
69   
70    private FilterResult extractNodesFromTaskTree() {
71        return new TaskModelFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
72            .from(this.taskModel);
73    }
74   
75    private float calculateEvaluationMetric(List<ITask> textInputEvents) {
76        Multiset<String> enteredTextFragments =
77            aggregateEnteredTextFromTextInputs(textInputEvents);
78        int allCharactersCount = 0;
79        int noLetterOrDigitCount = 0;
80        for (String textFragment : enteredTextFragments.elementSet()) {
81            int occurencesOfTextFragment = enteredTextFragments.count(textFragment);
82            allCharactersCount += CharMatcher.ANY.countIn(textFragment) * occurencesOfTextFragment;
83            noLetterOrDigitCount +=
84                CharMatcher.forPredicate(characterIsLetterOrDigitPredicate()).countIn(textFragment) *
85                    occurencesOfTextFragment;
86        }
87        return allCharactersCount != 0 ? (float) noLetterOrDigitCount / (float) allCharactersCount
88            : 0;
89    }
90
91    /* (non-Javadoc)
92     * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest.usability.EvaluationMethodCaller)
93     */
94    @Override
95    public Optional<UsabilityDefect> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
96    {
97        return evaluationMethodCaller.check(this);
98    }
99
100}
Note: See TracBrowser for help on using the repository browser.