Verified Commit 98c487d1 authored by Camil Staps's avatar Camil Staps 🚀

Hardcode ranking of ExactResult; add StdMaybe with Just xdg-open progress.pdf

parent 7f9aa332
......@@ -16,6 +16,7 @@ import Data.Functor
import Data.List
import qualified Data.Map as M
import Data.Maybe
import Data.Maybe.Ord
import Data.Tuple
from Database.Native import :: Entry{value}
from Text import class Text(concat,indexOf,toLowerCase,split),
......
......@@ -14,7 +14,6 @@ from Cloogle.DB import :: Annotation, :: CloogleEntry, :: CloogleDB
:: RankSettings =
{ rs_matching_ngrams_q :: !Real //* matching n-grams in the query
, rs_matching_ngrams_r :: !Real //* matching n-grams in the result
, rs_exact_result :: !Real //* results with an exact match
, rs_record_field :: !Real //* record fields
, rs_constructor :: !Real //* constructors
......@@ -24,7 +23,6 @@ from Cloogle.DB import :: Annotation, :: CloogleEntry, :: CloogleDB
, rs_unifier_n_conss :: !Real //* number of Cons constructors in the unifier
, rs_unifier_n_args :: !Real //* number of arguments of Type and Cons in the unifier
, 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
......@@ -37,7 +35,7 @@ from Cloogle.DB import :: Annotation, :: CloogleEntry, :: CloogleDB
*/
:: RankInformation :== RankSettings
distance :: !RankSettings !CloogleEntry ![Annotation] -> Real
distance :: !RankSettings !CloogleEntry ![Annotation] -> Maybe Real
symbolicDistance :: !CloogleEntry ![Annotation] -> RankInformation
......
......@@ -26,18 +26,17 @@ import Cloogle.API
import Cloogle.DB
import Cloogle.Search
distance :: !RankSettings !CloogleEntry ![Annotation] -> Real
distance settings entry annots = let info = symbolicDistance entry annots in
distance :: !RankSettings !CloogleEntry ![Annotation] -> Maybe Real
distance _ _ annots | not (isEmpty [a \\ a=:ExactResult <- annots]) = Nothing
distance settings entry annots = let info = symbolicDistance entry annots in Just $
settings.rs_matching_ngrams_q * info.rs_matching_ngrams_q +
settings.rs_matching_ngrams_r * info.rs_matching_ngrams_r +
settings.rs_exact_result * info.rs_exact_result +
settings.rs_record_field * info.rs_record_field +
settings.rs_constructor * info.rs_constructor +
settings.rs_unifier_n_types * info.rs_unifier_n_types +
settings.rs_unifier_n_funcs * info.rs_unifier_n_funcs +
settings.rs_unifier_n_conss * info.rs_unifier_n_conss +
settings.rs_unifier_n_args * info.rs_unifier_n_args +
settings.rs_used_synonyms * info.rs_used_synonyms +
settings.rs_resolved_context * info.rs_resolved_context +
settings.rs_unresolved_context * info.rs_unresolved_context +
settings.rs_lib_stdenv * info.rs_lib_stdenv
......@@ -46,14 +45,12 @@ symbolicDistance :: !CloogleEntry ![Annotation] -> RankInformation
symbolicDistance entry annots =
{ rs_matching_ngrams_q = case [r \\ MatchingNGramsQuery r <- annots] of [r:_] -> r; _ -> 0.0
, rs_matching_ngrams_r = case [r \\ MatchingNGramsResult r <- annots] of [r:_] -> r; _ -> 0.0
, rs_exact_result = if (isEmpty [a \\ a=:ExactResult <- annots]) 0.0 1.0
, rs_record_field = if entry=:(FunctionEntry {fe_kind=RecordField}) 1.0 0.0
, rs_constructor = if entry=:(FunctionEntry {fe_kind=Constructor}) 1.0 0.0
, rs_unifier_n_types = ntype
, rs_unifier_n_funcs = nfunc
, rs_unifier_n_conss = ncons
, rs_unifier_n_args = nargs
, rs_used_synonyms = case [s \\ UsedSynonyms s <- annots] of [s:_] -> toReal s; _ -> 0.0
, rs_resolved_context = resolved_context
, rs_unresolved_context = unresolved_context
, rs_lib_stdenv = if (getLocation entry)=:(Just (Location "StdEnv" _ _ _ _ _)) 1.0 0.0
......@@ -127,14 +124,12 @@ findRankSettings constraints cdb w
# settings = findSettings out
{ rs_matching_ngrams_q = 0.0
, rs_matching_ngrams_r = 0.0
, rs_exact_result = 0.0
, rs_record_field = 0.0
, rs_constructor = 0.0
, rs_unifier_n_types = 0.0
, rs_unifier_n_funcs = 0.0
, rs_unifier_n_conss = 0.0
, rs_unifier_n_args = 0.0
, rs_used_synonyms = 0.0
, rs_resolved_context = 0.0
, rs_unresolved_context = 0.0
, rs_lib_stdenv = 0.0
......@@ -149,14 +144,12 @@ where
# rs = case name of
"rs_matching_ngrams_q" -> {rs & rs_matching_ngrams_q =val}
"rs_matching_ngrams_r" -> {rs & rs_matching_ngrams_r =val}
"rs_exact_result" -> {rs & rs_exact_result =val}
"rs_record_field" -> {rs & rs_record_field =val}
"rs_constructor" -> {rs & rs_constructor =val}
"rs_unifier_n_types" -> {rs & rs_unifier_n_types =val}
"rs_unifier_n_funcs" -> {rs & rs_unifier_n_funcs =val}
"rs_unifier_n_conss" -> {rs & rs_unifier_n_conss =val}
"rs_unifier_n_args" -> {rs & rs_unifier_n_args =val}
"rs_used_synonyms" -> {rs & rs_used_synonyms =val}
"rs_resolved_context" -> {rs & rs_resolved_context =val}
"rs_unresolved_context" -> {rs & rs_unresolved_context=val}
"rs_lib_stdenv" -> {rs & rs_lib_stdenv =val}
......@@ -172,14 +165,12 @@ where
default =
[ "(declare-const rs_matching_ngrams_q Real)"
, "(declare-const rs_matching_ngrams_r Real)"
, "(declare-const rs_exact_result Real)"
, "(declare-const rs_record_field Real)"
, "(declare-const rs_constructor Real)"
, "(declare-const rs_unifier_n_types Real)"
, "(declare-const rs_unifier_n_funcs Real)"
, "(declare-const rs_unifier_n_conss Real)"
, "(declare-const rs_unifier_n_args Real)"
, "(declare-const rs_used_synonyms Real)"
, "(declare-const rs_resolved_context Real)"
, "(declare-const rs_unresolved_context Real)"
, "(declare-const rs_lib_stdenv Real)"
......@@ -224,14 +215,12 @@ where
formula ri = sum
[ "* rs_matching_ngrams_q " <+ ri.rs_matching_ngrams_q
, "* rs_matching_ngrams_r " <+ ri.rs_matching_ngrams_r
, "* rs_exact_result " <+ ri.rs_exact_result
, "* rs_record_field " <+ ri.rs_record_field
, "* rs_constructor " <+ ri.rs_constructor
, "* rs_unifier_n_types " <+ ri.rs_unifier_n_types
, "* rs_unifier_n_funcs " <+ ri.rs_unifier_n_funcs
, "* rs_unifier_n_conss " <+ ri.rs_unifier_n_conss
, "* rs_unifier_n_args " <+ ri.rs_unifier_n_args
, "* rs_used_synonyms " <+ ri.rs_used_synonyms
, "* rs_resolved_context " <+ ri.rs_resolved_context
, "* rs_unresolved_context " <+ ri.rs_unresolved_context
, "* rs_lib_stdenv " <+ ri.rs_lib_stdenv
......
......@@ -32,6 +32,12 @@ Cloogle/compiler: .FORCE
.PHONY: .FORCE
```
## Performance
To obtain full performance, ensure that you use the `StdMaybe` module
distributed here instead of that in StdEnv. The version in this library uses a
strict argument for `Just`. For `clm` this means adding the options
`-P ./path/to/Cloogle -IL StdEnv` to the beginning of the arguments.
## Copyright &amp; License
Copyright &copy; 2016&ndash;present Mart Lubbers and Camil Staps.
Licensed under MIT; See the [LICENSE](/LICENSE) file.
......
definition module StdMaybe
from StdOverloaded import class ==
:: Maybe x = Just !x | Nothing
isJust :: !(Maybe .x) -> Bool
isNothing :: !(Maybe .x) -> Bool
fromJust :: !(Maybe .x) -> .x
isJustU :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
isNothingU :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
mapMaybe :: .(.x -> .y) !(Maybe .x) -> Maybe .y
instance == (Maybe x) | == x
maybeToList :: !(Maybe .a) -> [.a];
listToMaybe :: ![.a] -> .Maybe .a;
catMaybes :: ![Maybe .a] -> .[.a];
Subproject commit 6379c20283a97f37fb76b44dc7869869f0f32065
Subproject commit 8fab601097a62552d235679853564fb28f307158
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment