summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorkrangelov <kr.angelov@gmail.com>2020-05-14 15:03:30 +0200
committerkrangelov <kr.angelov@gmail.com>2020-05-14 15:03:30 +0200
commit62bc78380e69af2de3253130204fc45bac00f3f0 (patch)
treeb2d633785ca1e9b4f6ac41bedc03dddd7dd0c677 /src/server
parent57a1ea5b56fa1e8cb3c8b9512ee421499a72a750 (diff)
lookupCohorts now detects and reports unknown words. Also:
- added added two filtering functions: filterLongest and filterBest - updated the PGF service to work with the new API
Diffstat (limited to 'src/server')
-rw-r--r--src/server/PGFService.hs25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs
index fa515e018..5817be7f0 100644
--- a/src/server/PGFService.hs
+++ b/src/server/PGFService.hs
@@ -159,7 +159,7 @@ cpgfMain qsem command (t,(pgf,pc)) =
"c-translate" -> withQSem qsem $
out t=<<join(trans # input % to % start % limit%treeopts)
"c-lookupmorpho"-> out t=<< morpho # from1 % textInput
- "c-lookupcohorts"->out t=<< cohorts # from1 % getInput "longest" % textInput
+ "c-lookupcohorts"->out t=<< cohorts # from1 % getInput "filter" % textInput
"c-flush" -> out t=<< flush
"c-grammar" -> out t grammar
"c-abstrtree" -> outputGraphviz=<< C.graphvizAbstractTree pgf C.graphvizDefaults # tree
@@ -251,29 +251,20 @@ cpgfMain qsem command (t,(pgf,pc)) =
,"prob".=p]
| (l,a,p)<-C.lookupMorpho concr input]
- cohorts (from,concr) longest input =
+ cohorts (from,concr) filter input =
showJSON [makeObj ["start" .=showJSON s
+ ,"word" .=showJSON w
,"morpho".=showJSON [makeObj ["lemma".=l
,"analysis".=a
,"prob".=p]
| (l,a,p)<-ms]
,"end" .=showJSON e
]
- | (s,ms,e) <- (if longest==Just "true" then filterLongest else id)
- (C.lookupCohorts concr input)]
- where
- filterLongest [] = []
- filterLongest (an:ans) = longest an ans
- where
- longest prev [] = [prev]
- longest prev@(start0,_,end0) (next@(start,an,end):ans)
- | start0 == start = longest next ans
- | otherwise = prev : filter end0 (next:ans)
-
- filter end [] = []
- filter end (next@(start,_,_):ans)
- | end <= start = filterLongest (next:ans)
- | otherwise = filter end ans
+ | (s,w,ms,e) <- (case filter of
+ Just "longest" -> C.filterLongest
+ Just "best" -> C.filterBest
+ _ -> id)
+ (C.lookupCohorts concr input)]
wordforword input@((from,_),_) = jsonWFW from . wordforword' input