Rank.dcl 1.95 KB
Newer Older
1 2 3
definition module Cloogle.Search.Rank

from Clean.Types import :: TypeDef
4
from Data.Error import :: MaybeError
5 6 7
from Data.Maybe import :: Maybe

from Cloogle.API import :: Request, :: LocationResult, :: FunctionKind
8
from Cloogle.DB import :: Annotation, :: CloogleEntry, :: CloogleDB
9 10 11 12 13 14 15 16

/**
 * A rank is computed as the weighted sum of various metrics. The coefficients
 * are given by this record.
 */
:: RankSettings =
	{ rs_ngram_distance     :: !Real //* n-gram distance
	, rs_exact_result       :: !Real //* results with an exact match
17

18 19
	, rs_record_field       :: !Real //* record fields
	, rs_constructor        :: !Real //* constructors
20

21 22 23
	, rs_unifier_n_types    :: !Real //* number of Type constructors in the unifier
	, rs_unifier_n_funcs    :: !Real //* number of Func constructors in the unifier
	, rs_unifier_n_conss    :: !Real //* number of Cons constructors in the unifier
24 25 26
	, rs_used_synonyms      :: !Real //* the number of synonyms required
	, rs_resolved_context   :: !Real //* class contexts with known instances
	, rs_unresolved_context :: !Real //* class contexts without known instances
27 28

	, rs_lib_stdenv         :: !Real //* thing comes from StdEnv
29 30 31 32 33 34 35 36
	}

/**
 * This record is the same as {{`RankSettings`}}, but the members are
 * interpreted as the values rather than the weights.
 */
:: RankInformation :== RankSettings

37
distance :: !RankSettings !CloogleEntry ![Annotation] -> Real
38

39
symbolicDistance :: !CloogleEntry ![Annotation] -> RankInformation
40 41 42 43 44

:: RankConstraint
	= LT !UniqueResultIdentifier !UniqueResultIdentifier //* arg1 should have lower distance than arg2

/**
45
 * @representation kind (e.g. Function for FunctionEntry), module name, name of element
46
 */
47
:: UniqueResultIdentifier :== (!String, !String, !String)
48 49

/**
50 51
 * Find suitable ranking settings given a set of constraints. This requires Z3
 * to be installed on the system.
52
 */
53 54
findRankSettings :: ![(Request, RankConstraint)] !*CloogleDB !*World
	-> *(!MaybeError String RankSettings, *CloogleDB, !*World)