Skip to content

Commit

Permalink
If parse fails, try parsing the lowercase version
Browse files Browse the repository at this point in the history
  • Loading branch information
anka-213 committed Mar 25, 2022
1 parent fc3c2ce commit 3057fee
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions UD2GF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ analyseWords env = mapRTree lemma2fun

-- find all functions that are possible parses of the word in any appropriate category
--- it is still possible that some other category is meant
getWordTrees wf w cs = case morphoFallback wf $ concatMap (parseWord w) cs of
getWordTrees wf w cs = case concatMap (parseWord w) cs `ifEmpty` concatMap (parseWord (map toLower w)) cs `ifEmpty` morphoFallback wf of
[] -> case cs of
[] -> (True,[(newWordTree w unknownCat, unknownCat)])
_ -> (True,[(newWordTree w ec, ec) | c <- cs, let ec = either id id c, strFunExists ec]
Expand All @@ -473,7 +473,7 @@ analyseWords env = mapRTree lemma2fun
-- | Return the first non-empty list
ifEmpty [] xs = xs
ifEmpty xs _ = xs
infixl 3 `ifEmpty`
infixr 3 `ifEmpty`

-- Verify that a StrSomeCat function exists in grammar
strFunExists c | Just typ <- functionType (pgfGrammar env) f = True
Expand All @@ -494,14 +494,13 @@ analyseWords env = mapRTree lemma2fun

-- Fall back to morphoanalysis if gf parse fails
-- TODO: We might want to use the morphoanalysis for all words, not just when parse fails
morphoFallback :: String -> [(RTree Lemma, CId)] -> [(RTree CId, CId)]
morphoFallback w [] =
morphoFallback :: String -> [(RTree CId, CId)]
morphoFallback w =
[(RTree name [], c)
| (name, _) <- lookupMorpho morpho w
, Just tp <- pure $ functionType (pgfGrammar env) name
, ([], c, []) <- pure $ unType tp
]
morphoFallback _ xs = xs

-- auxiliaries
-- newWordTree w c = RTree (mkCId (w ++ "_" ++ showCId c)) [] ---
Expand Down

0 comments on commit 3057fee

Please sign in to comment.