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

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

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

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

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

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

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

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

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