mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
fracas: code to generate HTML treebank
This commit is contained in:
3
examples/fracas/FeedGF.hs
Normal file
3
examples/fracas/FeedGF.hs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import FraCaSBankI
|
||||||
|
|
||||||
|
main = putStr . unlines $ ["ps \"@"++n++"\"; l -treebank "++s|(n,s@('(':_))<-bank]
|
||||||
@@ -17,7 +17,7 @@ GF-FILES = $(wildcard src/*.gf)
|
|||||||
build: $(BUILD-FORMATS:%=build/$(BANK).%)
|
build: $(BUILD-FORMATS:%=build/$(BANK).%)
|
||||||
|
|
||||||
clean:
|
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
|
distclean: clean
|
||||||
rm -f build/$(BANK).*
|
rm -f build/$(BANK).*
|
||||||
@@ -31,3 +31,14 @@ dist: build clean
|
|||||||
build/$(BANK).%: $(GF-FILES)
|
build/$(BANK).%: $(GF-FILES)
|
||||||
python build_fracasbank.py $* src/$(BANK)I.gf $(LANGUAGES:%=src/$(BANK)%.gf) > $@
|
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/^}/ []/' < $< > $@
|
||||||
|
|||||||
43
examples/fracas/ToHTML.hs
Normal file
43
examples/fracas/ToHTML.hs
Normal file
@@ -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)
|
||||||
42
examples/fracas/prefix.html
Normal file
42
examples/fracas/prefix.html
Normal file
@@ -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>
|
||||||
Reference in New Issue
Block a user