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

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

26 27
	, rs_resolved_context   :: !Real //* class contexts with known instances
	, rs_unresolved_context :: !Real //* class contexts without known instances
28 29

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

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

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

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

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

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

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