PGF2 & PGFService: enable callbacks for named entities and chunks in the c-parse & c-translate web requests

This commit is contained in:
hallgren
2015-01-21 10:41:12 +00:00
parent 790738c82b
commit ffe1f74584
2 changed files with 7 additions and 5 deletions

View File

@@ -515,7 +515,7 @@ nerc pgf (lang,concr) lin_idx sentence offset =
expr = mkApp "SymbPN" [mkApp "MkSymb" [mkStr name]] expr = mkApp "SymbPN" [mkApp "MkSymb" [mkStr name]]
end_offset = length sentence-length rest end_offset = length sentence-length rest
name = trimRight (concat capwords) name = trimRight (concat capwords)
ls = [((l,getFunctionType pgf l),p)|(l,_,p)<-lookupMorpho concr name] ls = [((l,functionCat l),p)|(l,_,p)<-lookupMorpho concr name]
((lemma,cat),_) = maximumBy (compare `on` snd) ls ((lemma,cat),_) = maximumBy (compare `on` snd) ls
_ -> Nothing _ -> Nothing
where where
@@ -526,8 +526,7 @@ nerc pgf (lang,concr) lin_idx sentence offset =
Just (y,xs') -> (y:ys,xs'') Just (y,xs') -> (y:ys,xs'')
where (ys,xs'') = consume munch xs' where (ys,xs'') = consume munch xs'
getFunctionType :: PGF -> String -> Cat functionCat f = case functionType pgf f of DTyp _ cat _ -> cat
getFunctionType = undefined
-- | Callback to parse arbitrary words as chunks (from -- | Callback to parse arbitrary words as chunks (from
-- ../java/org/grammaticalframework/pgf/UnknownLiteralCallback.java) -- ../java/org/grammaticalframework/pgf/UnknownLiteralCallback.java)
@@ -540,6 +539,9 @@ chunk _ (_,concr) lin_idx sentence offset =
expr = mkApp "MkSymb" [mkStr (trimRight word)] expr = mkApp "MkSymb" [mkStr (trimRight word)]
_ -> Nothing _ -> Nothing
-- More helper functions
trimRight = reverse . dropWhile isSpace . reverse trimRight = reverse . dropWhile isSpace . reverse
capitalized = capitalized' isUpper capitalized = capitalized' isUpper

View File

@@ -155,8 +155,8 @@ cpgfMain command (t,(pgf,pc)) =
return $ return $
maybe id take mlimit . drop start # cparse maybe id take mlimit . drop start # cparse
where where
cparse = C.parse concr cat input --cparse = C.parse concr cat input
--cparse = C.parseWithHeuristics concr cat input (-1) callbacks cparse = C.parseWithHeuristics concr cat input (-1) callbacks
callbacks = maybe [] cb $ lookup (C.abstractName pgf) C.literalCallbacks callbacks = maybe [] cb $ lookup (C.abstractName pgf) C.literalCallbacks
cb fs = [(cat,f pgf (from,concr))|(cat,f)<-fs] cb fs = [(cat,f pgf (from,concr))|(cat,f)<-fs]
{- {-