Ignore:
Timestamp:
01/16/13 17:51:51 (11 years ago)
Author:
adeicke
Message:
  • Removed lombok related annotations and util class
  • Added comments and formating due to match project defaults
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/rule/evaluator/TextInputEntryRepetitionsEvaluator.java

    r1030 r1040  
     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 
    115package de.ugoe.cs.autoquest.usability.evaluation.rule.evaluator; 
    216 
    317import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.TEXT_INPUT; 
    418import static de.ugoe.cs.autoquest.usability.util.TextInputUtil.aggregateEnteredTextFromTextInputs; 
     19import static java.lang.String.format; 
    520 
    621import com.google.common.base.Optional; 
     
    1631import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter; 
    1732 
     33/** 
     34 * <p> 
     35 * TODO comment 
     36 * </p> 
     37 *  
     38 * @author Alexander Deicke 
     39 */ 
    1840public class TextInputEntryRepetitionsEvaluator extends RuleEvaluator { 
    1941 
    20     public TextInputEntryRepetitionsEvaluator(UsabilityRule evaluatedUsabilityRule, ITaskTree taskTree) { 
     42    public TextInputEntryRepetitionsEvaluator(UsabilityRule evaluatedUsabilityRule, 
     43                                              ITaskTree taskTree) 
     44    { 
    2145        super(evaluatedUsabilityRule, taskTree); 
    2246    } 
     
    2549    protected FilterStatistic nodesUnderEvaluation(ITaskTree taskTree) { 
    2650        Optional<FilterStatistic> cachedNodes = loadFromCache(TEXT_INPUT); 
    27         return cachedNodes.isPresent() ? cachedNodes.get() : cacheAndReturnNodes(taskTree, TEXT_INPUT); 
     51        return cachedNodes.isPresent() ? cachedNodes.get() : cacheAndReturnNodes(taskTree, 
     52                                                                                 TEXT_INPUT); 
    2853    } 
    29      
     54 
    3055    @Override 
    3156    protected FilterStatistic extractNodesFromTaskTree(ITaskTree taskTree) { 
    32         return new TaskTreeFilter(new IterativeDFSFilterStrategy()) 
    33             .filterByEventType(TEXT_INPUT).from(taskTree); 
     57        return new TaskTreeFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT) 
     58            .from(taskTree); 
    3459    } 
    3560 
    3661    @Override 
    3762    protected float calculateEvaluationMetric() { 
    38         Multiset<String> enteredTextFragments = aggregateEnteredTextFromTextInputs(this.filteredNodes.nodesMatchedFilter()); 
    39         Multiset<String> orderedTextFragmentsWithMultipleOccurences = onlyTextFragmentsWithMultipleOccurences(enteredTextFragments); 
    40         if(orderedTextFragmentsWithMultipleOccurences.isEmpty()) return 0; 
    41         String wordWithHighestRepetitionInTextFragments = orderedTextFragmentsWithMultipleOccurences.iterator().next(); 
     63        Multiset<String> enteredTextFragments = 
     64            aggregateEnteredTextFromTextInputs(this.filteredNodes.nodesMatchedFilter()); 
     65        Multiset<String> orderedTextFragmentsWithMultipleOccurences = 
     66            onlyTextFragmentsWithMultipleOccurences(enteredTextFragments); 
     67        if (orderedTextFragmentsWithMultipleOccurences.isEmpty()) 
     68            return 0; 
     69        String wordWithHighestRepetitionInTextFragments = 
     70            orderedTextFragmentsWithMultipleOccurences.iterator().next(); 
    4271        int numberOfRepeatedWords = orderedTextFragmentsWithMultipleOccurences.entrySet().size(); 
    43         int maxRepetitions = orderedTextFragmentsWithMultipleOccurences.count(wordWithHighestRepetitionInTextFragments); 
     72        int maxRepetitions = 
     73            orderedTextFragmentsWithMultipleOccurences 
     74                .count(wordWithHighestRepetitionInTextFragments); 
     75        storeEvaluationMetricForDefectDescription("textRepetitionRatio", 
     76                                                  format("textRepetitionRatio %s repeated tokens, up to %s repetitions per token", 
     77                                                         numberOfRepeatedWords, maxRepetitions)); 
    4478        return Math.max(numberOfRepeatedWords, maxRepetitions); 
    4579    } 
    46      
    47     private Multiset<String> onlyTextFragmentsWithMultipleOccurences(final Multiset<String> allTextInputs) { 
    48         return Multisets.copyHighestCountFirst(Multisets.filter(allTextInputs, new Predicate<String>() { 
    49              
    50             @Override 
    51             public boolean apply(String word) { 
    52                 return allTextInputs.count(word) > 1; 
    53             } 
    54              
    55         })); 
     80 
     81    private Multiset<String> onlyTextFragmentsWithMultipleOccurences(final Multiset<String> allTextInputs) 
     82    { 
     83        return Multisets.copyHighestCountFirst(Multisets.filter(allTextInputs, 
     84                                                                new Predicate<String>() { 
     85 
     86                                                                    @Override 
     87                                                                    public boolean apply(String word) 
     88                                                                    { 
     89                                                                        return allTextInputs 
     90                                                                            .count(word) > 1; 
     91                                                                    } 
     92 
     93                                                                })); 
    5694    } 
    5795 
    5896    @Override 
    59     protected Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric) { 
     97    protected Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric) 
     98    { 
    6099        Optional<UsabilityDefectSeverityLevel> recommendationSeverityLevel = Optional.absent(); 
    61100        if (evaluationMetric > 10) { 
     
    73112        return recommendationSeverityLevel; 
    74113    } 
    75      
     114 
    76115} 
Note: See TracChangeset for help on using the changeset viewer.