diff options
| author | hallgren <hallgren@chalmers.se> | 2012-10-23 12:55:32 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2012-10-23 12:55:32 +0000 |
| commit | f273c643b56bf0ad285cf32407906dca380909a0 (patch) | |
| tree | d5d6865a688b9f627d43c33e8ccb620c616171bd /examples | |
| parent | bb93e18ec17a49be1c91d0890d1eb8b21d854950 (diff) | |
fracas: code to generate HTML treebank
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/fracas/FeedGF.hs | 3 | ||||
| -rw-r--r-- | examples/fracas/Makefile | 13 | ||||
| -rw-r--r-- | examples/fracas/ToHTML.hs | 43 | ||||
| -rw-r--r-- | examples/fracas/prefix.html | 42 |
4 files changed, 100 insertions, 1 deletions
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 @@ +<!DOCTYPE html> +<html> <head> +<meta charset="UTF-8"> +<link rel=stylesheet type="text/css" href="../gfse/editor.css"> +<title>FraCaS treebank visualization</title> +<style> +.OnlyEng .FraCaSSwe, .OnlySwe .FraCaSEng { display: none; } +dt { margin-top: 2ex; margin-bottom: 1ex; } +dt { margin-left: 3em; text-indent: -3em; } +dd:before { content: "— "; margin-left: 0; padding-left: 0; } +dd { margin-left: 3.5em; text-indent: -2.5em; } +</style> +<script> +function swap_img(img,newsrc) { + if(img.origsrc) { + img.src=img.origsrc + img.origsrc=null + } + else { + img.origsrc=img.src + img.src=newsrc + } +} + +function vt(img,abs) { + swap_img(img,"FraCaS.pgf?command=abstrtree&tree="+encodeURIComponent(abs)) +} + +function vp(img,lang,abs) { + swap_img(img,"FraCaS.pgf?command=parsetree&from="+lang+"&tree="+encodeURIComponent(abs)) +} +</script> +</head> + +<body> +<h1>FraCaS treebank visualization</h1> +Languages: +<select onchange="document.body.className=this.value"> + <option value="">English and Swedish</option> + <option value="OnlyEng">Only English</option> + <option value="OnlySwe">Only Swedish</option> +</select> |
