net.sourceforge.nite.search.rewriter
Class DefaultDeclarationOrderingScheme

java.lang.Object
  extended by net.sourceforge.nite.search.rewriter.DefaultDeclarationOrderingScheme
All Implemented Interfaces:
DeclarationOrderingScheme

public class DefaultDeclarationOrderingScheme
extends java.lang.Object
implements DeclarationOrderingScheme

This implementation of DeclarationOrderingScheme uses corpus statistics concerning the frequency of declared types to calculate scores for declarations.

NOTE: We should probably create an abstract class CorpusDeclarationOrderingScheme for general schemes based on corpus statistics, which this implements.

Author:
nmayo@inf.ed.ac.uk

Constructor Summary
DefaultDeclarationOrderingScheme(SearchableCorpus corpus)
          Create a DeclarationOrderingScheme with a reference to a corpus whose properties are used in calculating the ordering.
 
Method Summary
 int calculateVariableScore(java.util.List types)
          Calculate a score for the given list of variable types.
 java.util.List getOrdering(java.util.List declarableVariables)
          Orders variable declarations based on their scores, from low score to high.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultDeclarationOrderingScheme

public DefaultDeclarationOrderingScheme(SearchableCorpus corpus)
Create a DeclarationOrderingScheme with a reference to a corpus whose properties are used in calculating the ordering.

Parameters:
corpus - the SearchableCorpus to use in calculating scores
Method Detail

getOrdering

public java.util.List getOrdering(java.util.List declarableVariables)
Orders variable declarations based on their scores, from low score to high.

Specified by:
getOrdering in interface DeclarationOrderingScheme
Parameters:
declarableVariables - a list of names mapped to type Lists
Returns:
a list of names in a preferred order of declaration

calculateVariableScore

public int calculateVariableScore(java.util.List types)
Calculate a score for the given list of variable types. This implementation uses frequency counts from a NOMCorpus.

Specified by:
calculateVariableScore in interface DeclarationOrderingScheme
Parameters:
types - a List of types to which a variable is bound
Returns:
the sum of the frequency counts for the provided types