Rank.dcl 2.12 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

/**
 * A rank is computed as the weighted sum of various metrics. The coefficients
 * are given by this record.
 */
:: RankSettings =
15 16
	{ rs_matching_ngrams_q  :: !Real //* matching n-grams in the query
	, rs_matching_ngrams_r  :: !Real //* matching n-grams in the result
17
	, rs_exact_result       :: !Real //* results with an exact match
18

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

22 23 24
	, 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
25 26
	, rs_unifier_n_args     :: !Real //* number of arguments of Type and Cons in the unifier

27 28 29
	, 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
30 31

	, rs_lib_stdenv         :: !Real //* thing comes from StdEnv
32 33 34 35 36 37 38 39
	}

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

40
distance :: !RankSettings !CloogleEntry ![Annotation] -> Real
41

42
symbolicDistance :: !CloogleEntry ![Annotation] -> RankInformation
43 44 45 46 47

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

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

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