mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-26 03:08:55 -06:00
Make removal of record fields recursive. Latest results with Phrasebook:
Bul ✓ Cat ✗ Chi ✓ Dan ✓ Dut ✓ Eng ✓ Est ✓ Fin ✓ Fre ✗ Ger ✓ Hin ✓ Ita ✗ Jpn ✓ Lav ✓ Nor ✓ Pol ✓ Ron ✓ Snd ✗ Spa ✓ Swe ✓ Tha ✓ Urd ✓ Passed 18 | Failed 4 | Total 22
This commit is contained in:
@@ -100,14 +100,23 @@ mkCanon2lpgf opts gr am = do
|
|||||||
|
|
||||||
-- Filter out record fields from definitions which don't appear in lincat.
|
-- Filter out record fields from definitions which don't appear in lincat.
|
||||||
-- Workaround for https://github.com/GrammaticalFramework/gf-core/issues/101
|
-- Workaround for https://github.com/GrammaticalFramework/gf-core/issues/101
|
||||||
|
cleanupRecordFields :: C.LinValue -> C.LinType -> C.LinValue
|
||||||
|
cleanupRecordFields (C.RecordValue rrvs) (C.RecordType rrs) =
|
||||||
|
let defnFields = Map.fromList [ (lid, lt) | (C.RecordRow lid lt) <- rrs ]
|
||||||
|
in C.RecordValue
|
||||||
|
[ C.RecordRow lid lv'
|
||||||
|
| C.RecordRow lid lv <- rrvs
|
||||||
|
, Map.member lid defnFields
|
||||||
|
, let Just lt = Map.lookup lid defnFields
|
||||||
|
, let lv' = cleanupRecordFields lv lt
|
||||||
|
]
|
||||||
|
cleanupRecordFields lv _ = lv
|
||||||
|
|
||||||
lindefs' =
|
lindefs' =
|
||||||
[ C.LinDef funId varIds linValue'
|
[ C.LinDef funId varIds linValue'
|
||||||
| (C.LinDef funId varIds linValue) <- lindefs
|
| (C.LinDef funId varIds linValue) <- lindefs
|
||||||
, let linValue' = case (linValue, lookupLinType funId) of
|
, let Right linType = lookupLinType funId
|
||||||
(C.RecordValue rrvs, Right (C.RecordType rrs)) ->
|
, let linValue' = cleanupRecordFields linValue linType
|
||||||
let defnFields = [ lid | (C.RecordRow lid _) <- rrs ]
|
|
||||||
in C.RecordValue [ rrv | rrv@(C.RecordRow lid _) <- rrvs, lid `elem` defnFields ]
|
|
||||||
(x,_) -> x
|
|
||||||
]
|
]
|
||||||
es = map mkLin lindefs'
|
es = map mkLin lindefs'
|
||||||
lins = Map.fromList $ rights es
|
lins = Map.fromList $ rights es
|
||||||
@@ -115,7 +124,7 @@ mkCanon2lpgf opts gr am = do
|
|||||||
-- | Main code generation function
|
-- | Main code generation function
|
||||||
mkLin :: C.LinDef -> Either String (CId, L.LinFun)
|
mkLin :: C.LinDef -> Either String (CId, L.LinFun)
|
||||||
mkLin (C.LinDef funId varIds linValue) = do
|
mkLin (C.LinDef funId varIds linValue) = do
|
||||||
when debug $ trace funId
|
-- when debug $ trace funId
|
||||||
(lf, _) <- val2lin linValue
|
(lf, _) <- val2lin linValue
|
||||||
return (fi2i funId, lf)
|
return (fi2i funId, lf)
|
||||||
where
|
where
|
||||||
|
|||||||
2399
testsuite/lpgf/phrasebook/Phrasebook-100.treebank
Normal file
2399
testsuite/lpgf/phrasebook/Phrasebook-100.treebank
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user