Verified Commit a69fc683 authored by Camil Staps's avatar Camil Staps
Browse files

Fix distance measure for record fields and constructors

parent 685a073e
...@@ -88,11 +88,11 @@ makeResult orgsearchtype allsyns usedsyns (entry, annots) db ...@@ -88,11 +88,11 @@ makeResult orgsearchtype allsyns usedsyns (entry, annots) db
Just ds -> appFst Just $ getIndices ds db Just ds -> appFst Just $ getIndices ds db
= (FunctionResult ( = (FunctionResult (
{ general { general
& distance = toInt $ kindPenalty fe.fe_kind * toReal (general.distance + sum & distance = kindPenalty fe.fe_kind $ general.distance + sum
[ fromMaybe 0 $ contextPenalty <$> required_context [ fromMaybe 0 $ contextPenalty <$> required_context
, fromMaybe 0 $ 'M'.get UnifierSize annots , fromMaybe 0 $ 'M'.get UnifierSize annots
, length usedsyns , length usedsyns
]) ]
, documentation = docDescription =<< fe.fe_documentation , documentation = docDescription =<< fe.fe_documentation
}, },
{ kind = fe.fe_kind { kind = fe.fe_kind
...@@ -127,10 +127,14 @@ makeResult orgsearchtype allsyns usedsyns (entry, annots) db ...@@ -127,10 +127,14 @@ makeResult orgsearchtype allsyns usedsyns (entry, annots) db
where where
toStr (var, type) = (var, concat $ print False type) toStr (var, type) = (var, concat $ print False type)
kindPenalty :: FunctionKind -> Real kindPenalty :: FunctionKind Int -> Int
kindPenalty RecordField = 1.2 kindPenalty k d = toInt $ penalty * toReal d
kindPenalty Constructor = 1.1 where
kindPenalty _ = 1.0 penalty = case k of
RecordField -> further 0.2
Constructor -> further 0.1
_ -> 1.0
further s = if (d < 0) (1.0 - s) (1.0 + s)
contextPenalty :: [(String, [LocationResult])] -> Int contextPenalty :: [(String, [LocationResult])] -> Int
contextPenalty required_context = length [0 \\ (_,[]) <- required_context] contextPenalty required_context = length [0 \\ (_,[]) <- required_context]
...@@ -254,7 +258,7 @@ where ...@@ -254,7 +258,7 @@ where
distance = sum distance = sum
[ case 'M'.get MatchingNGrams annots of [ case 'M'.get MatchingNGrams annots of
Nothing -> 0 Nothing -> 0
Just n -> 0 - toInt (toReal n * 100.0 / toReal (size $ getName $ fromJust mbLoc)) Just n -> 0 - toInt (toReal n * 100.0 / toReal (size name))
, case 'M'.get ExactResult annots of , case 'M'.get ExactResult annots of
Just 1 -> -1 Just 1 -> -1
_ -> 0 _ -> 0
......
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