1
0
forked from GitHub/gf-core

the compiler now sorts the list of functions per category in probability order. this ensures probability order search in the C runtime

This commit is contained in:
kr.angelov
2013-04-15 19:58:57 +00:00
parent b9f530a805
commit 2f35964871

View File

@@ -50,9 +50,11 @@ readProbabilitiesFromFile file pgf = do
mkProbabilities :: PGF -> Map.Map CId Double -> Probabilities mkProbabilities :: PGF -> Map.Map CId Double -> Probabilities
mkProbabilities pgf probs = mkProbabilities pgf probs =
let funs1 = Map.fromList [(f,p) | (_,cf) <- Map.toList cats1, (p,f) <- cf] let funs1 = Map.fromList [(f,p) | (_,cf) <- Map.toList cats1, (p,f) <- cf]
cats1 = Map.map (\(_,fs,_) -> fill fs) (cats (abstract pgf)) cats1 = Map.map (\(_,fs,_) -> sortBy cmpProb (fill fs)) (cats (abstract pgf))
in Probs funs1 cats1 in Probs funs1 cats1
where where
cmpProb (p1,_) (p2,_) = compare p2 p1
fill fs = pad [(Map.lookup f probs,f) | (_,f) <- fs] fill fs = pad [(Map.lookup f probs,f) | (_,f) <- fs]
where where
pad :: [(Maybe Double,a)] -> [(Double,a)] pad :: [(Maybe Double,a)] -> [(Double,a)]