From c2d02e1fcab430f9e712640a08ba30ad2199df74 Mon Sep 17 00:00:00 2001 From: hallgren Date: Tue, 23 Oct 2012 12:55:32 +0000 Subject: [PATCH] fracas: code to generate HTML treebank --- examples/fracas/FeedGF.hs | 3 +++ examples/fracas/Makefile | 13 ++++++++++- examples/fracas/ToHTML.hs | 43 +++++++++++++++++++++++++++++++++++++ examples/fracas/prefix.html | 42 ++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 examples/fracas/FeedGF.hs create mode 100644 examples/fracas/ToHTML.hs create mode 100644 examples/fracas/prefix.html diff --git a/examples/fracas/FeedGF.hs b/examples/fracas/FeedGF.hs new file mode 100644 index 000000000..610d9ff4a --- /dev/null +++ b/examples/fracas/FeedGF.hs @@ -0,0 +1,3 @@ +import FraCaSBankI + +main = putStr . unlines $ ["ps \"@"++n++"\"; l -treebank "++s|(n,s@('(':_))<-bank] diff --git a/examples/fracas/Makefile b/examples/fracas/Makefile index c7ea0d617..189443b03 100644 --- a/examples/fracas/Makefile +++ b/examples/fracas/Makefile @@ -17,7 +17,7 @@ GF-FILES = $(wildcard src/*.gf) build: $(BUILD-FORMATS:%=build/$(BANK).%) clean: - rm -f src/*.gfo src/*.pyc .DS_Store */.DS_Store + rm -f src/*.gfo src/*.pyc .DS_Store */.DS_Store FraCaS.pgf $(BANK)I.hs distclean: clean rm -f build/$(BANK).* @@ -31,3 +31,14 @@ dist: build clean build/$(BANK).%: $(GF-FILES) python build_fracasbank.py $* src/$(BANK)I.gf $(LANGUAGES:%=src/$(BANK)%.gf) > $@ +#### HTML generation: + +build/$(BANK).html: FraCaS.pgf FeedGF.hs ToHTML.hs prefix.html $(BANK)I.hs + cat prefix.html > $@ + runhaskell FeedGF.hs | gf -run FraCaS.pgf | runhaskell ToHTML.hs >> $@ + +FraCaS.pgf: $(GF-FILES) + gf -s -make src/FraCaSEng.gf src/FraCaSSwe.gf + +$(BANK)I.hs: src/$(BANK)I.gf + sed -e 's/--#.*//' -e 's/incomplete.*/module $(BANK)I where/' -e 's/lincat.*/bank =/' -e 's/^lin / ("/' -e 's/ = /", "/' -e 's/;$$/"):/' -e 's/^}/ []/' < $< > $@ diff --git a/examples/fracas/ToHTML.hs b/examples/fracas/ToHTML.hs new file mode 100644 index 000000000..4eccfdcfe --- /dev/null +++ b/examples/fracas/ToHTML.hs @@ -0,0 +1,43 @@ +import Data.Char(isSpace) + +main = interact (unlines.wrap "dl".concatMap conv.paras.lines) + +conv (('@':n):ls) = (tag_class aname "dt"++(fmtnum n++": "++vt abs++" "++abs)):map conc concs + where + (aname,abs):concs = map (apSnd (dropWhile isSpace.drop 1).break (==':')) ls + conc (lang,s) = tag_class lang "dd"++vp abs lang++" "++s + +vt abs = tag' "img" ("src=\"http://cloud.grammaticalframework.org/minibar/tree-btn.png\""++a) + where + a = " onclick=\"vt(this,'"++abs++"')\"" + +vp abs lang = tag' "img" ("src=\"http://cloud.grammaticalframework.org/minibar/tree-btn.png\""++a) + where + a = " onclick=\"vp(this,'"++lang++"','"++abs++"')\"" + +fmtnum n = + case words (map u2s n) of + [_,n1,n2,_] -> dropWhile (=='0') n1++"."++n2 + _ -> n + where + u2s '_' = ' ' + u2s c = c + +-------------------------------------------------------------------------------- + +paras ls = + case dropWhile null ls of + [] -> [] + ls -> case break null ls of + (ls1,ls2) -> ls1:paras ls2 + +wrap t ls = tag t:ls++[endtag t] + +tag_class cls t = tag' t ("class="++cls) + +tag' t a = '<':t++" "++a++">" + +tag t = '<':t++">" +endtag t = tag ('/':t) + +apSnd f (x,y) = (x,f y) diff --git a/examples/fracas/prefix.html b/examples/fracas/prefix.html new file mode 100644 index 000000000..87e172a15 --- /dev/null +++ b/examples/fracas/prefix.html @@ -0,0 +1,42 @@ + + + + +FraCaS treebank visualization + + + + + +

FraCaS treebank visualization

+Languages: +