forked from GitHub/gf-core
Compare commits
8 Commits
GF-3.10
...
sense-disa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8406a1e381 | ||
|
|
438e18c78f | ||
|
|
b0cf72f0ec | ||
|
|
fd2aa96e65 | ||
|
|
7239a45ac5 | ||
|
|
7f84cc22e9 | ||
|
|
0db213f993 | ||
|
|
bf5abe2948 |
19
.gitignore
vendored
19
.gitignore
vendored
@@ -39,23 +39,8 @@ src/runtime/c/sg/.dirstamp
|
||||
src/runtime/c/stamp-h1
|
||||
src/runtime/java/.libs/
|
||||
src/runtime/python/build/
|
||||
src/ui/android/libs/
|
||||
src/ui/android/obj/
|
||||
.cabal-sandbox
|
||||
cabal.sandbox.config
|
||||
.stack-work
|
||||
DATA_DIR
|
||||
|
||||
# Generated documentation (not exhaustive)
|
||||
demos/index-numbers.html
|
||||
demos/resourcegrammars.html
|
||||
demos/translation.html
|
||||
doc/tutorial/gf-tutorial.html
|
||||
doc/gf-bibliography.html
|
||||
doc/gf-developers.html
|
||||
doc/gf-editor-modes.html
|
||||
doc/gf-people.html
|
||||
doc/gf-reference.html
|
||||
doc/gf-shell-reference.html
|
||||
doc/icfp-2012.html
|
||||
download/*.html
|
||||
gf-book/index.html
|
||||
src/www/gf-web-api.html
|
||||
|
||||
19
LICENSE
19
LICENSE
@@ -8,9 +8,24 @@ other. For this reason the different components have different licenses.
|
||||
In summary:
|
||||
|
||||
- the GF compiler in the folder src/compiler and the PGF Web service in src/server
|
||||
are under the GNU GENERAL PUBLIC LICENSE.
|
||||
are under the GNU GENERAL PUBLIC LICENSE.
|
||||
|
||||
- the GF runtime in src/runtime is under dual GNU LESSER GENERAL PUBLIC LICENSE and BSD LICENSE
|
||||
- the GF runtime in src/runtime is under dual GNU LESSER GENERAL PUBLIC LICENSE
|
||||
and BSD LICENSE
|
||||
|
||||
- the resource grammar library in lib/src is under GNU LESSER GENERAL PUBLIC LICENSE.
|
||||
However the user have the right to choose any license for any application grammar
|
||||
derived from the resource grammar by using the grammar API.
|
||||
|
||||
- the resource grammar library also includes large coverage lexicons for some languages.
|
||||
Since these lexicons are derived from external sources they might be under different licenses.
|
||||
Look at the source file for every lexicon for details. The lexicons that we currently have
|
||||
are:
|
||||
|
||||
lib/src/bulgarian/ DictBul.gf DictBulAbs.gf for Bulgarian
|
||||
lib/src/english/ DictEng.gf DictEngAbs.gf for English
|
||||
lib/src/turkish/ DictTur.gf DictTurAbs.gf for Turkish
|
||||
lib/src/swedish/ DictSwe.gf DictSweAbs.gf for Swedish
|
||||
|
||||
The rest of this document contains copies of the GPL, LGPL and BSD licenses
|
||||
which are applicable to the different components of Grammatical Framework
|
||||
|
||||
3
Makefile
3
Makefile
@@ -20,7 +20,6 @@ doc:
|
||||
|
||||
clean:
|
||||
cabal clean
|
||||
bash bin/clean_html
|
||||
|
||||
gf:
|
||||
cabal build rgl-none
|
||||
@@ -33,7 +32,7 @@ html::
|
||||
# number to the top of debian/changelog.
|
||||
# (Tested on Ubuntu 15.04. You need to install dpkg-dev & debhelper.)
|
||||
deb:
|
||||
dpkg-buildpackage -b -uc
|
||||
dpkg-buildpackage -b
|
||||
|
||||
# Make an OS X Installer package
|
||||
pkg:
|
||||
|
||||
@@ -37,6 +37,13 @@ The simplest way of installing GF is with the command:
|
||||
cabal install
|
||||
```
|
||||
|
||||
This can be broken down into the usual sub-steps:
|
||||
```
|
||||
cabal configure
|
||||
cabal build
|
||||
cabal copy
|
||||
```
|
||||
|
||||
For more details, see the [download page](http://www.grammaticalframework.org/download/index.html)
|
||||
and [developers manual](http://www.grammaticalframework.org/doc/gf-developers.html).
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ buildWeb gf flags (pkg,lbi) = do
|
||||
gf_lib_path = datadir (absoluteInstallDirs pkg lbi dest) </> "lib"
|
||||
args = numJobs flags++["-make","-s"] -- ,"-optimize-pgf"
|
||||
++["--gfo-dir="++tmp_dir,
|
||||
--"--gf-lib-path="++gf_lib_path,
|
||||
"--gf-lib-path="++gf_lib_path,
|
||||
"--name="++dropExtension pgf,
|
||||
"--output-dir="++gfo_dir]
|
||||
++[dir</>file|file<-src]
|
||||
@@ -104,10 +104,9 @@ setupWeb dest (pkg,lbi) = do
|
||||
copy_pgf (pgf,subdir,_) =
|
||||
do let src = gfo_dir </> pgf
|
||||
let dst = grammars_dir </> pgf
|
||||
putStrLn $ "Installing "++dst
|
||||
ex <- doesFileExist src
|
||||
if ex then do putStrLn $ "Installing "++dst
|
||||
copyFile src dst
|
||||
else putStrLn $ "Not installing "++dst
|
||||
if ex then copyFile src dst else return ()
|
||||
|
||||
gf_logo = "gf0.png"
|
||||
|
||||
|
||||
@@ -16,14 +16,13 @@ name="gf-$ver"
|
||||
destdir="$PWD/dist/$name" # assemble binary dist here
|
||||
prefix=${PREFIX:-/usr/local} # where to install
|
||||
fmt=${FMT:-tar.gz} # binary package format (tar.gz or pkg)
|
||||
ghc=${GHC:-ghc} # which Haskell compiler to use
|
||||
|
||||
extralib="$destdir$prefix/lib"
|
||||
extrainclude="$destdir$prefix/include"
|
||||
extra="--extra-lib-dirs=$extralib --extra-include-dirs=$extrainclude"
|
||||
|
||||
set -e # Stop if an error occurs
|
||||
set -x # print commands before executing them
|
||||
set -x # print commands before exuting them
|
||||
|
||||
## First configure & build the C run-time system
|
||||
pushd src/runtime/c
|
||||
@@ -65,30 +64,13 @@ else
|
||||
fi
|
||||
|
||||
## Build GF, with C run-time support enabled
|
||||
cabal install -w "$ghc" --only-dependencies -fserver -fc-runtime $extra
|
||||
cabal configure -w "$ghc" --prefix="$prefix" -fserver -fc-runtime $extra
|
||||
cabal install --only-dependencies -fserver -fc-runtime $extra
|
||||
cabal configure --prefix="$prefix" -fserver -fc-runtime $extra
|
||||
DYLD_LIBRARY_PATH="$extralib" LD_LIBRARY_PATH="$extralib" cabal build
|
||||
# Building the example grammars will fail, because the RGL is missing
|
||||
cabal copy --destdir="$destdir" # create www directory
|
||||
|
||||
## Build the RGL and copy it to $destdir
|
||||
PATH=$PWD/dist/build/gf:$PATH
|
||||
export GF_LIB_PATH="$(dirname $(find "$destdir" -name www))/lib" # hmm
|
||||
mkdir -p "$GF_LIB_PATH"
|
||||
pushd ../gf-rgl
|
||||
make build
|
||||
make copy
|
||||
popd
|
||||
|
||||
# Build GF again, including example grammars that need the RGL
|
||||
DYLD_LIBRARY_PATH="$extralib" LD_LIBRARY_PATH="$extralib" cabal build
|
||||
|
||||
## Copy GF to $destdir
|
||||
cabal copy --destdir="$destdir"
|
||||
libdir=$(dirname $(find "$destdir" -name PGF.hi))
|
||||
cabal register --gen-pkg-config=$libdir/gf-$ver.conf
|
||||
|
||||
## Create the binary distribution package
|
||||
case $fmt in
|
||||
tar.gz)
|
||||
targz="$name-bin-$hw-$os.tar.gz" # the final tar file
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
### This script finds all .t2t (txt2tags) files and deletes the corresponding html file
|
||||
|
||||
find . -name '*.t2t' | while read t2t ; do
|
||||
html="${t2t%.t2t}.html"
|
||||
rm -f "$html"
|
||||
done
|
||||
@@ -1,135 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang$" xml:lang="$lang$"$if(dir)$ dir="$dir$"$endif$>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
$for(author-meta)$
|
||||
<meta name="author" content="$author-meta$" />
|
||||
$endfor$
|
||||
$if(date-meta)$
|
||||
<meta name="dcterms.date" content="$date-meta$" />
|
||||
$endif$
|
||||
$if(keywords)$
|
||||
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
|
||||
$endif$
|
||||
<title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.2/css/all.css" integrity="sha384-/rXc/GQVaYpyDdyxK+ecHPVYJSN9bmVFBvjA/9eOB+pb3F2w2N6fc5qB9Ew5yIns" crossorigin="anonymous">
|
||||
$for(css)$
|
||||
<link rel="stylesheet" href="$css$" />
|
||||
$endfor$
|
||||
$if(math)$
|
||||
$math$
|
||||
$endif$
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
|
||||
<![endif]-->
|
||||
$for(header-includes)$
|
||||
$header-includes$
|
||||
$endfor$
|
||||
</head>
|
||||
<body>
|
||||
$for(include-before)$
|
||||
$include-before$
|
||||
$endfor$
|
||||
<div class="container-fluid my-5" style="max-width:1200px">
|
||||
|
||||
$if(title)$
|
||||
<header id="title-block-header">
|
||||
<a href="$rel-root$" title="Home">
|
||||
<img src="$rel-root$/doc/Logos/gf1.svg" height="200px" class="float-md-right mb-3 bg-white" alt="GF Logo">
|
||||
</a>
|
||||
<h1 class="title">$title$</h1>
|
||||
$if(subtitle)$
|
||||
<p class="subtitle">$subtitle$</p>
|
||||
$endif$
|
||||
$for(author)$
|
||||
<p class="author">$author$</p>
|
||||
$endfor$
|
||||
$if(date)$
|
||||
<p class="date">$date$</p>
|
||||
$endif$
|
||||
</header>
|
||||
$endif$
|
||||
$if(toc)$
|
||||
<nav id="$idprefix$TOC">
|
||||
$table-of-contents$
|
||||
</nav>
|
||||
$endif$
|
||||
$body$
|
||||
</div><!-- .container -->
|
||||
|
||||
<footer class="bg-light mt-5 py-5">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-6 col-sm-3">
|
||||
<a href="$rel-root$">
|
||||
<i class="fas fa-home"></i>
|
||||
Home
|
||||
</a>
|
||||
<h6 class="text-muted mt-3">Get started</h6>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.youtube.com/watch?v=x1LFbDQhbso">Google Tech Talk</a></li>
|
||||
<li><a href="http://cloud.grammaticalframework.org/">GF Cloud</a></li>
|
||||
<li><a href="$rel-root$/doc/tutorial/gf-tutorial.html">Tutorial</a></li>
|
||||
<li><a href="$rel-root$/download"><strong>Download GF</strong></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="col-6 col-sm-3">
|
||||
<h6 class="text-muted">Learn more</h6>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="$rel-root$/gf-book">The GF Book</a></li>
|
||||
<li><a href="$rel-root$/doc/gf-refman.html">Reference Manual</a></li>
|
||||
<li><a href="$rel-root$/doc/gf-shell-reference.html">GF Shell Reference</a></li>
|
||||
<li><a href="http://www.molto-project.eu/sites/default/files/MOLTO_D2.3.pdf">Best Practices</a></li>
|
||||
<li><a href="$rel-root$/lib/doc/synopsis/index.html"><strong>RGL Synopsis</strong></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="col-6 col-sm-3">
|
||||
<h6 class="text-muted">Develop</h6>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="$rel-root$/doc/gf-developers.html">Developers Guide</a></li>
|
||||
<li><a href="http://hackage.haskell.org/package/gf/docs/PGF.html">PGF library API (Haskell runtime)</a></li>
|
||||
<li><a href="$rel-root$/doc/runtime-api.html">PGF library API (C runtime)</a></li>
|
||||
<li><a href="http://hackage.haskell.org/package/gf/docs/GF.html">GF compiler API</a></li>
|
||||
<li><a href="$rel-root$/doc/gf-editor-modes.html">Text Editor Support</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="col-6 col-sm-3">
|
||||
<h6 class="text-muted">Contribute</i>
|
||||
</h6>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="http://groups.google.com/group/gf-dev">Mailing List</a></li>
|
||||
<li><a href="https://github.com/GrammaticalFramework/gf-core/issues">Issue Tracker</a></li>
|
||||
<li><a href="$rel-root$/doc/gf-people.html">Authors</a></li>
|
||||
<li><a href="http://school.grammaticalframework.org/2018/">Summer School</a></li>
|
||||
</ul>
|
||||
<h6 class="text-muted">
|
||||
Repositories
|
||||
<i class="fab fa-github ml-1"></i>
|
||||
</h6>
|
||||
<a href="https://github.com/GrammaticalFramework/gf-core">GF</a> ·
|
||||
<a href="https://github.com/GrammaticalFramework/gf-rgl">RGL</a> ·
|
||||
<a href="https://github.com/GrammaticalFramework/gf-contrib">Contributions</a>
|
||||
</div>
|
||||
<div>
|
||||
<div>
|
||||
</footer>
|
||||
$for(include-after)$
|
||||
$include-after$
|
||||
$endfor$
|
||||
<script type="text/javascript">
|
||||
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
||||
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
var pageTracker = _gat._getTracker("UA-7811807-3");
|
||||
pageTracker._trackPageview();
|
||||
} catch(err) {}</script>
|
||||
</body>
|
||||
</html>
|
||||
117
bin/update_html
117
bin/update_html
@@ -1,114 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Path to directory where this script is
|
||||
# https://stackoverflow.com/a/246128/98600
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
### This script finds all .t2t (txt2tags) files and updates the corresponding
|
||||
### .html file, if it is out-of-date.
|
||||
|
||||
# Render txt2tags into html file
|
||||
# Arguments:
|
||||
# 1. txt2tags source file, e.g. download/index.t2t
|
||||
# 2. html target file, e.g. download/index.html
|
||||
function render_t2t_html {
|
||||
t2t="$1"
|
||||
html="$2"
|
||||
tmp="$2.tmp"
|
||||
relroot="$( dirname $t2t | sed -E 's/^.\///' | sed -E 's/[^/]+/../g' )"
|
||||
|
||||
# First render with txt2tags to handle pre/post processing
|
||||
txt2tags \
|
||||
--target=html \
|
||||
--no-headers \
|
||||
--quiet \
|
||||
--outfile="$tmp" \
|
||||
--infile="$t2t"
|
||||
|
||||
# Capture first 3 lines of t2t file: title, author, date
|
||||
# Documentation here: https://txt2tags.org/userguide/headerarea
|
||||
l1=$(head -n 1 "$t2t")
|
||||
l2=$(tail -n+2 "$t2t" | head -n 1)
|
||||
l3=$(tail -n+3 "$t2t" | head -n 1)
|
||||
title=
|
||||
author=
|
||||
date=
|
||||
if [ -n "$l1" ] ; then
|
||||
title="$l1"
|
||||
if [ -n "$l2" ] ; then author="$l2" ; fi
|
||||
if [ -n "$l3" ] ; then date="$l3" ; fi
|
||||
find . -name '*.t2t' | while read t2t ; do
|
||||
html="${t2t%.t2t}.html"
|
||||
if [ "$t2t" -nt "$html" ] ; then
|
||||
txt2tags -thtml "$t2t"
|
||||
fi
|
||||
|
||||
# Run txt2tag's HTML through Pandoc for cleanup
|
||||
pandoc \
|
||||
--from=html \
|
||||
--to=html5 \
|
||||
--standalone \
|
||||
--template="$DIR/template.html" \
|
||||
--variable="rel-root:$relroot" \
|
||||
--metadata="title:$title" \
|
||||
--metadata="author:$author" \
|
||||
--metadata="date:$date" \
|
||||
"$tmp" \
|
||||
--output="$html"
|
||||
rm -f "$tmp"
|
||||
|
||||
# Final post-processing
|
||||
if [ -f "$html" ] ; then
|
||||
sed -i.bak "s/<table/<table class=\"table\"/" "$html" && rm "$html.bak"
|
||||
echo "$html"
|
||||
fi
|
||||
}
|
||||
|
||||
# Render markdown into html file
|
||||
# Arguments:
|
||||
# 1. markdown source file, e.g. download/index.md
|
||||
# 2. html target filen, e.g. download/index.html
|
||||
function render_md_html {
|
||||
md="$1"
|
||||
html="$2"
|
||||
relroot="$( dirname $md | sed -E 's/^.\///' | sed -E 's/[^/]+/../g' )"
|
||||
|
||||
pandoc \
|
||||
--from=markdown \
|
||||
--to=html5 \
|
||||
--standalone \
|
||||
--template="$DIR/template.html" \
|
||||
--variable="rel-root:$relroot" \
|
||||
"$md" \
|
||||
--output="$html"
|
||||
|
||||
# Final post-processing
|
||||
if [ -f "$html" ] ; then
|
||||
sed -i.bak "s/<table/<table class=\"table\"/" "$html" && rm "$html.bak"
|
||||
echo "$html"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ $# -gt 0 ] ; then
|
||||
# Render specific file(s) from args, ignoring dates
|
||||
for file in "$@" ; do
|
||||
ext="${file##*.}"
|
||||
html="${file%.$ext}.html"
|
||||
case $ext in
|
||||
"md")
|
||||
render_md_html "$file" "$html"
|
||||
;;
|
||||
"t2t")
|
||||
render_t2t_html "$file" "$html"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
# Render all files found in cwd and deeper if source is newer
|
||||
find . -name '*.t2t' | while read file ; do
|
||||
html="${file%.t2t}.html"
|
||||
if [ "$file" -nt "$html" ] ; then
|
||||
render_t2t_html "$file" "$html"
|
||||
fi
|
||||
done
|
||||
find . -name '*.md' | while read file ; do
|
||||
if [[ "$file" == *"README.md" ]] ; then continue ; fi
|
||||
html="${file%.md}.html"
|
||||
if [ "$file" -nt "$html" ] ; then
|
||||
render_md_html "$file" "$html"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
@@ -17,7 +17,10 @@ h1 img.nofloat { float: none; }
|
||||
img.right { float: right; }
|
||||
|
||||
ol.languages {
|
||||
column-width: 12em;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: wrap;
|
||||
height: 12em;
|
||||
}
|
||||
|
||||
.grow {
|
||||
|
||||
6
debian/changelog
vendored
6
debian/changelog
vendored
@@ -1,9 +1,3 @@
|
||||
gf (3.10-1) xenial bionic cosmic; urgency=low
|
||||
|
||||
* GF 3.10
|
||||
|
||||
-- Thomas Hallgren <hallgren@chalmers.se> Fri, 30 Nov 2018 20:00:00 +0100
|
||||
|
||||
gf (3.9-1) vivid xenial zesty; urgency=low
|
||||
|
||||
* GF 3.9
|
||||
|
||||
2
debian/rules
vendored
Executable file → Normal file
2
debian/rules
vendored
Executable file → Normal file
@@ -18,8 +18,6 @@ override_dh_auto_build:
|
||||
cd src/runtime/java && make CFLAGS="-I$(CURDIR)/src/runtime/c -L$(CURDIR)/src/runtime/c/.libs" INSTALL_PATH=/usr/lib
|
||||
echo LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(CURDIR)/src/runtime/c/.libs
|
||||
LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(CURDIR)/src/runtime/c/.libs cabal build
|
||||
LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(CURDIR)/src/runtime/c/.libs cabal copy --destdir=$(CURDIR)/debian/gf # create www directory
|
||||
PATH=$(CURDIR)/dist/build/gf:$$PATH && export GF_LIB_PATH="$$(dirname $$(find "$(CURDIR)/debian/gf" -name www))/lib" && echo "GF_LIB_PATH=$$GF_LIB_PATH" && mkdir -p "$$GF_LIB_PATH" && ( cd ../gf-rgl && make build && make copy ) && LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(CURDIR)/src/runtime/c/.libs cabal build
|
||||
make html
|
||||
|
||||
override_dh_auto_clean:
|
||||
|
||||
15
doc/Makefile
15
doc/Makefile
@@ -1,3 +1,18 @@
|
||||
resource:
|
||||
gfdoc -txt2 ../lib/resource-1.0/abstract/*.gf
|
||||
gfdoc -txt2 ../lib/resource-1.0/*/Paradigms*.gf
|
||||
txt2tags --toc resource.txt
|
||||
# cat resource-preamble resource.tex >final-resource.tex
|
||||
sed -i 's/\\docum/%\\docum/g' resource.tex
|
||||
sed -i 's/ion\*{/ion{/g' resource.tex
|
||||
sed -i 's/\\paragraph{}//g' resource.tex
|
||||
sed -i 's/}\\\\/}/g' resource.tex
|
||||
cat resource-preamble resource.tex >resource.tmp
|
||||
mv resource.tmp resource.tex
|
||||
latex resource.tex
|
||||
latex resource.tex
|
||||
dvipdf resource.dvi
|
||||
|
||||
gf-help-full.txt::
|
||||
{ echo ; echo ; echo ; } > $@
|
||||
echo help -full -t2t | gf -run >> $@
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
GF Developers Guide
|
||||
Authors: Björn Bringert, Krasimir Angelov and Thomas Hallgren
|
||||
Last update: %%mtime(%F, %H:%M)
|
||||
|
||||
2018-07-26
|
||||
% NOTE: this is a txt2tags file.
|
||||
% Create an html file from this file using:
|
||||
% txt2tags -t html gf-developers.t2t
|
||||
|
||||
%!style:../css/style.css
|
||||
%!target:html
|
||||
%!options(html): --toc
|
||||
%!encoding:utf-8
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
== Before you start ==
|
||||
|
||||
@@ -55,6 +63,18 @@ Other required tools included in the Haskell Platform are
|
||||
and
|
||||
[Happy http://www.haskell.org/happy/].
|
||||
|
||||
%=== Darcs ===
|
||||
%
|
||||
%To get the GF source code, you also need //Darcs//, version 2 or later.
|
||||
%Darcs 2.10 is recommended (July 2015).
|
||||
%
|
||||
%//Darcs//
|
||||
%is a distributed version control system, see http://darcs.net/ for
|
||||
%more information. There are precompiled packages for many platforms
|
||||
%available and source code if you want to compile it yourself. Darcs
|
||||
%is also written in Haskell and so you can use GHC to compile it.
|
||||
|
||||
|
||||
=== Git ===
|
||||
|
||||
To get the GF source code, you also need //Git//.
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
Editor modes & IDE integration for GF
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!options(html): --toc
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!encoding:utf-8
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
We collect GF modes for various editors on this page. Contributions are
|
||||
welcome!
|
||||
|
||||
|
||||
91
doc/gf-faq.t2t
Normal file
91
doc/gf-faq.t2t
Normal file
@@ -0,0 +1,91 @@
|
||||
Grammatical Framework: Frequently Asked Quuestions
|
||||
Aarne Ranta
|
||||
%%date(%c)
|
||||
|
||||
% NOTE: this is a txt2tags file.
|
||||
% Create an html file from this file using:
|
||||
% txt2tags gf-bibliography.t2t
|
||||
|
||||
%!style:../css/style.css
|
||||
%!target:html
|
||||
%!options(html): --toc
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): #BR <br>
|
||||
%!encoding:utf-8
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
|
||||
===What has been done with GF?===
|
||||
|
||||
**Translation**: systems with any number of parallel languages, with input in one language and output in all the others.
|
||||
|
||||
**Natural language generation** (NLG): translation from a formal language to natural languages.
|
||||
|
||||
**Ontology verbalization** is a special case of NLG.
|
||||
|
||||
**Language training**: grammar and vocabulary training systems.
|
||||
|
||||
**Human-computer interaction**: natural language interfaces, spoken dialogue systems.
|
||||
|
||||
**Linguistics**: comparisons between languages.
|
||||
|
||||
|
||||
|
||||
===What parts does GF have?===
|
||||
|
||||
A **grammar compiler**, used for compiling grammars to parsing, generation, and translation code.
|
||||
|
||||
A **run-time system**, used for parsing, generation and translation. The run-time system is available in several languages:
|
||||
Haskell, Java, C, C++, Javascript, and Python. The point with this is that you can include GF-based parsing and generation in
|
||||
larger programs written in any of these languages.
|
||||
|
||||
A **resource grammar library**, containing the morphology and basic syntax of currently 26 languages.
|
||||
|
||||
A **web application toolkit**, containing server-side (Haskell) and client-side (Javascript) libraries.
|
||||
|
||||
An **integrated development environment**, the GF-Eclipse plug-in.
|
||||
|
||||
A **shell**, i.e. a command interpreter for testing and developing GF grammars. This is the program started by the command ``gf`` in a terminal.
|
||||
|
||||
|
||||
|
||||
===Is GF open-source?===
|
||||
|
||||
|
||||
===Can I use GF for commercial applications?===
|
||||
|
||||
Yes. Those parts of GF that you will need to distribute - the run-time system and the libraries - are licensed under LGPL and BSD; it's up to you to choose which.
|
||||
|
||||
|
||||
|
||||
===When was GF started?===
|
||||
|
||||
|
||||
===Where does the name GF come from?===
|
||||
|
||||
GF = Grammatical Framework = LF + concrete syntax
|
||||
|
||||
LF = Logical Framework
|
||||
|
||||
Logical Frameworks are implementations of type theory, which have been built since the 1980's to support formalized mathematics. GF has its roots in
|
||||
type theory, which is widely used in the semantics of natural language. Some of these ideas were first implemented in ALF, Another Logical Framework,
|
||||
in 1992; the book //Type-Theoretical Grammar// (by A. Ranta, OUP 1994) has a chapter and an appendix on this. The first implementations did not have
|
||||
a parser, and GF proper, started in 1998, was an implementation of yet another LF together with concrete syntax supporting generation and parsing.
|
||||
Grammatical Framework was a natural name for this. We tried to avoid it in the beginning, because it sounded pretentious in its generality. But the
|
||||
name was just too natural to be avoided.
|
||||
|
||||
|
||||
|
||||
===Is GF backward compatible?===
|
||||
|
||||
|
||||
|
||||
===Do I need Haskell to use GF?===
|
||||
|
||||
No. GF is a language of its own, and you don't need to know Haskell. And if you download the GF binary, you don't need any Haskell tools. But if you want to
|
||||
become a GF developer, then it's better you install GF from the latest source, and then you need the GHC Haskell compiler to compile GF. But even then, you
|
||||
don't need to know Haskell yourself.
|
||||
|
||||
|
||||
===What is a lock field?===
|
||||
|
||||
@@ -68,9 +68,9 @@ metavariables and the type of the expression.
|
||||
Prints a set of strings in the .dot format (the graphviz format).
|
||||
The graph can be saved in a file by the wf command as usual.
|
||||
If the -view flag is defined, the graph is saved in a temporary file
|
||||
which is processed by 'dot' (graphviz) and displayed by the program indicated
|
||||
by the view flag. The target format is png, unless overridden by the
|
||||
flag -format. Results from multiple trees are combined to pdf with convert (ImageMagick).
|
||||
which is processed by graphviz and displayed by the program indicated
|
||||
by the flag. The target format is postscript, unless overridden by the
|
||||
flag -format.
|
||||
|
||||
|
||||
- Options:
|
||||
@@ -151,7 +151,6 @@ of a pipe.
|
||||
| ``-one`` | pick the first strings, if there is any, from records and tables
|
||||
| ``-table`` | show all strings labelled by parameters
|
||||
| ``-unqual`` | hide qualifying module names
|
||||
| ``-trace`` | trace computations
|
||||
|
||||
|
||||
#NORMAL
|
||||
@@ -243,7 +242,7 @@ and thus cannot be a part of a pipe.
|
||||
|
||||
====e = empty====
|
||||
#NOINDENT
|
||||
``e`` = ``empty``: //empty the environment (except the command history).//
|
||||
``e`` = ``empty``: //empty the environment.//
|
||||
|
||||
#TINY
|
||||
|
||||
@@ -282,19 +281,6 @@ but the resulting .gf file must be imported separately.
|
||||
#NORMAL
|
||||
|
||||
|
||||
#VSPACE
|
||||
|
||||
====eh = execute_history====
|
||||
#NOINDENT
|
||||
``eh`` = ``execute_history``: //read commands from a file and execute them.//
|
||||
|
||||
#TINY
|
||||
|
||||
- Syntax: ``eh FILE``
|
||||
|
||||
#NORMAL
|
||||
|
||||
|
||||
#VSPACE
|
||||
|
||||
====gr = generate_random====
|
||||
@@ -448,14 +434,12 @@ sequences; see example.
|
||||
| ``-list`` | show all forms and variants, comma-separated on one line (cf. l -all)
|
||||
| ``-multi`` | linearize to all languages (default)
|
||||
| ``-table`` | show all forms labelled by parameters
|
||||
| ``-tabtreebank`` | show the tree and its linearizations on a tab-separated line
|
||||
| ``-treebank`` | show the tree and tag linearizations with language names
|
||||
| ``-bind`` | bind tokens separated by Prelude.BIND, i.e. &+
|
||||
| ``-chars`` | lexer that makes every non-space character a token
|
||||
| ``-from_amharic`` | from unicode to GF Amharic transliteration
|
||||
| ``-from_ancientgreek`` | from unicode to GF ancient Greek transliteration
|
||||
| ``-from_arabic`` | from unicode to GF Arabic transliteration
|
||||
| ``-from_arabic_unvocalized`` | from unicode to GF unvocalized Arabic transliteration
|
||||
| ``-from_cp1251`` | decode from cp1251 (Cyrillic used in Bulgarian resource)
|
||||
| ``-from_devanagari`` | from unicode to GF Devanagari transliteration
|
||||
| ``-from_greek`` | from unicode to GF modern Greek transliteration
|
||||
@@ -469,14 +453,11 @@ sequences; see example.
|
||||
| ``-from_urdu`` | from unicode to GF Urdu transliteration
|
||||
| ``-from_utf8`` | decode from utf8 (default)
|
||||
| ``-lexcode`` | code-like lexer
|
||||
| ``-lexgreek`` | lexer normalizing ancient Greek accentuation
|
||||
| ``-lexgreek2`` | lexer normalizing ancient Greek accentuation for text with vowel length annotations
|
||||
| ``-lexmixed`` | mixture of text and code, as in LaTeX (code between $...$, \(...)\, \[...\])
|
||||
| ``-lextext`` | text-like lexer
|
||||
| ``-to_amharic`` | from GF Amharic transliteration to unicode
|
||||
| ``-to_ancientgreek`` | from GF ancient Greek transliteration to unicode
|
||||
| ``-to_arabic`` | from GF Arabic transliteration to unicode
|
||||
| ``-to_arabic_unvocalized`` | from GF unvocalized Arabic transliteration to unicode
|
||||
| ``-to_cp1251`` | encode to cp1251 (Cyrillic used in Bulgarian resource)
|
||||
| ``-to_devanagari`` | from GF Devanagari transliteration to unicode
|
||||
| ``-to_greek`` | from GF modern Greek transliteration to unicode
|
||||
@@ -492,7 +473,6 @@ sequences; see example.
|
||||
| ``-to_utf8`` | encode to utf8 (default)
|
||||
| ``-unchars`` | unlexer that puts no spaces between tokens
|
||||
| ``-unlexcode`` | code-like unlexer
|
||||
| ``-unlexgreek`` | unlexer de-normalizing ancient Greek accentuation
|
||||
| ``-unlexmixed`` | mixture of text and code (code between $...$, \(...)\, \[...\])
|
||||
| ``-unlextext`` | text-like unlexer
|
||||
| ``-unwords`` | unlexer that puts a single space between tokens (default)
|
||||
@@ -533,7 +513,6 @@ trees where a function node is a metavariable.
|
||||
| ``-from_amharic`` | from unicode to GF Amharic transliteration
|
||||
| ``-from_ancientgreek`` | from unicode to GF ancient Greek transliteration
|
||||
| ``-from_arabic`` | from unicode to GF Arabic transliteration
|
||||
| ``-from_arabic_unvocalized`` | from unicode to GF unvocalized Arabic transliteration
|
||||
| ``-from_cp1251`` | decode from cp1251 (Cyrillic used in Bulgarian resource)
|
||||
| ``-from_devanagari`` | from unicode to GF Devanagari transliteration
|
||||
| ``-from_greek`` | from unicode to GF modern Greek transliteration
|
||||
@@ -547,14 +526,11 @@ trees where a function node is a metavariable.
|
||||
| ``-from_urdu`` | from unicode to GF Urdu transliteration
|
||||
| ``-from_utf8`` | decode from utf8 (default)
|
||||
| ``-lexcode`` | code-like lexer
|
||||
| ``-lexgreek`` | lexer normalizing ancient Greek accentuation
|
||||
| ``-lexgreek2`` | lexer normalizing ancient Greek accentuation for text with vowel length annotations
|
||||
| ``-lexmixed`` | mixture of text and code, as in LaTeX (code between $...$, \(...)\, \[...\])
|
||||
| ``-lextext`` | text-like lexer
|
||||
| ``-to_amharic`` | from GF Amharic transliteration to unicode
|
||||
| ``-to_ancientgreek`` | from GF ancient Greek transliteration to unicode
|
||||
| ``-to_arabic`` | from GF Arabic transliteration to unicode
|
||||
| ``-to_arabic_unvocalized`` | from GF unvocalized Arabic transliteration to unicode
|
||||
| ``-to_cp1251`` | encode to cp1251 (Cyrillic used in Bulgarian resource)
|
||||
| ``-to_devanagari`` | from GF Devanagari transliteration to unicode
|
||||
| ``-to_greek`` | from GF modern Greek transliteration to unicode
|
||||
@@ -570,7 +546,6 @@ trees where a function node is a metavariable.
|
||||
| ``-to_utf8`` | encode to utf8 (default)
|
||||
| ``-unchars`` | unlexer that puts no spaces between tokens
|
||||
| ``-unlexcode`` | code-like unlexer
|
||||
| ``-unlexgreek`` | unlexer de-normalizing ancient Greek accentuation
|
||||
| ``-unlexmixed`` | mixture of text and code (code between $...$, \(...)\, \[...\])
|
||||
| ``-unlextext`` | text-like unlexer
|
||||
| ``-unwords`` | unlexer that puts a single space between tokens (default)
|
||||
@@ -691,9 +666,10 @@ command (flag -printer):
|
||||
fa finite automaton in graphviz format
|
||||
gsl Nuance speech recognition format
|
||||
haskell Haskell (abstract syntax)
|
||||
java Java (abstract syntax)
|
||||
js JavaScript (whole grammar)
|
||||
jsgf JSGF speech recognition format
|
||||
lambda_prolog LambdaProlog (abstract syntax)
|
||||
lp_byte_code Bytecode for Teyjus (abstract syntax, experimental)
|
||||
pgf_pretty human-readable pgf
|
||||
prolog Prolog (whole grammar)
|
||||
python Python (whole grammar)
|
||||
@@ -777,7 +753,6 @@ To see transliteration tables, use command ut.
|
||||
| ``-from_amharic`` | from unicode to GF Amharic transliteration
|
||||
| ``-from_ancientgreek`` | from unicode to GF ancient Greek transliteration
|
||||
| ``-from_arabic`` | from unicode to GF Arabic transliteration
|
||||
| ``-from_arabic_unvocalized`` | from unicode to GF unvocalized Arabic transliteration
|
||||
| ``-from_cp1251`` | decode from cp1251 (Cyrillic used in Bulgarian resource)
|
||||
| ``-from_devanagari`` | from unicode to GF Devanagari transliteration
|
||||
| ``-from_greek`` | from unicode to GF modern Greek transliteration
|
||||
@@ -791,14 +766,11 @@ To see transliteration tables, use command ut.
|
||||
| ``-from_urdu`` | from unicode to GF Urdu transliteration
|
||||
| ``-from_utf8`` | decode from utf8 (default)
|
||||
| ``-lexcode`` | code-like lexer
|
||||
| ``-lexgreek`` | lexer normalizing ancient Greek accentuation
|
||||
| ``-lexgreek2`` | lexer normalizing ancient Greek accentuation for text with vowel length annotations
|
||||
| ``-lexmixed`` | mixture of text and code, as in LaTeX (code between $...$, \(...)\, \[...\])
|
||||
| ``-lextext`` | text-like lexer
|
||||
| ``-to_amharic`` | from GF Amharic transliteration to unicode
|
||||
| ``-to_ancientgreek`` | from GF ancient Greek transliteration to unicode
|
||||
| ``-to_arabic`` | from GF Arabic transliteration to unicode
|
||||
| ``-to_arabic_unvocalized`` | from GF unvocalized Arabic transliteration to unicode
|
||||
| ``-to_cp1251`` | encode to cp1251 (Cyrillic used in Bulgarian resource)
|
||||
| ``-to_devanagari`` | from GF Devanagari transliteration to unicode
|
||||
| ``-to_greek`` | from GF modern Greek transliteration to unicode
|
||||
@@ -814,7 +786,6 @@ To see transliteration tables, use command ut.
|
||||
| ``-to_utf8`` | encode to utf8 (default)
|
||||
| ``-unchars`` | unlexer that puts no spaces between tokens
|
||||
| ``-unlexcode`` | code-like unlexer
|
||||
| ``-unlexgreek`` | unlexer de-normalizing ancient Greek accentuation
|
||||
| ``-unlexmixed`` | mixture of text and code (code between $...$, \(...)\, \[...\])
|
||||
| ``-unlextext`` | text-like unlexer
|
||||
| ``-unwords`` | unlexer that puts a single space between tokens (default)
|
||||
@@ -828,14 +799,13 @@ To see transliteration tables, use command ut.
|
||||
|
||||
- Examples:
|
||||
|
||||
| ``l (EAdd 3 4) | ps -unlexcode`` | linearize code-like output
|
||||
| ``ps -lexcode | p -cat=Exp`` | parse code-like input
|
||||
| ``l (EAdd 3 4) | ps -code`` | linearize code-like output
|
||||
| ``ps -lexer=code | p -cat=Exp`` | parse code-like input
|
||||
| ``gr -cat=QCl | l | ps -bind`` | linearization output from LangFin
|
||||
| ``ps -to_devanagari "A-p"`` | show Devanagari in UTF8 terminal
|
||||
| ``rf -file=Hin.gf | ps -env=quotes -to_devanagari`` | convert translit to UTF8
|
||||
| ``rf -file=Ara.gf | ps -from_utf8 -env=quotes -from_arabic`` | convert UTF8 to transliteration
|
||||
| ``ps -to=chinese.trans "abc"`` | apply transliteration defined in file chinese.trans
|
||||
| ``ps -lexgreek "a)gavoi` a)'nvrwpoi' tines*"`` | normalize ancient greek accentuation
|
||||
|
||||
|
||||
#NORMAL
|
||||
@@ -858,6 +828,7 @@ are type checking and semantic computation.
|
||||
- Options:
|
||||
|
||||
| ``-compute`` | compute by using semantic definitions (def)
|
||||
| ``-paraphrase`` | paraphrase by using semantic definitions (def)
|
||||
| ``-largest`` | sort trees from largest to smallest, in number of nodes
|
||||
| ``-nub`` | remove duplicate trees
|
||||
| ``-smallest`` | sort trees from smallest to largest, in number of nodes
|
||||
@@ -867,10 +838,12 @@ are type checking and semantic computation.
|
||||
- Flags:
|
||||
|
||||
| ``-number`` | take at most this many trees
|
||||
| ``-transfer`` | syntactic transfer by applying function, recursively in subtrees
|
||||
|
||||
- Examples:
|
||||
|
||||
| ``pt -compute (plus one two)`` | compute value
|
||||
| ``p "4 dogs love 5 cats" | pt -transfer=digits2numeral | l`` | four...five...
|
||||
|
||||
|
||||
#NORMAL
|
||||
@@ -1017,6 +990,8 @@ This command requires a source grammar to be in scope, imported with 'import -re
|
||||
The operations include the parameter constructors that are in scope.
|
||||
The optional TYPE filters according to the value type.
|
||||
The grep STRINGs filter according to other substrings of the type signatures.
|
||||
This command must be a line of its own, and thus cannot be a part
|
||||
of a pipe.
|
||||
|
||||
- Syntax: ``so (-grep=STRING)* TYPE?``
|
||||
- Options:
|
||||
@@ -1027,12 +1002,6 @@ The grep STRINGs filter according to other substrings of the type signatures.
|
||||
|
||||
| ``-grep`` | substring used for filtering (the command can have many of these)
|
||||
|
||||
- Examples:
|
||||
|
||||
| ``so Det`` | show all opers that create a Det
|
||||
| ``so -grep=Prep`` | find opers relating to Prep
|
||||
| ``so | wf -file=/tmp/opers`` | write the list of opers to a file
|
||||
|
||||
|
||||
#NORMAL
|
||||
|
||||
@@ -1144,7 +1113,6 @@ This command must be a line of its own, and thus cannot be a part of a pipe.
|
||||
| ``-amharic`` | Amharic
|
||||
| ``-ancientgreek`` | ancient Greek
|
||||
| ``-arabic`` | Arabic
|
||||
| ``-arabic_unvocalized`` | unvocalized Arabic
|
||||
| ``-devanagari`` | Devanagari
|
||||
| ``-greek`` | modern Greek
|
||||
| ``-hebrew`` | unvocalized Hebrew
|
||||
@@ -1169,41 +1137,35 @@ This command must be a line of its own, and thus cannot be a part of a pipe.
|
||||
#TINY
|
||||
|
||||
Prints a dependency tree in the .dot format (the graphviz format, default)
|
||||
or LaTeX (flag -output=latex)
|
||||
or the CoNLL/MaltParser format (flag -output=conll for training, malt_input
|
||||
for unanalysed input).
|
||||
By default, the last argument is the head of every abstract syntax
|
||||
function; moreover, the head depends on the head of the function above.
|
||||
The graph can be saved in a file by the wf command as usual.
|
||||
If the -view flag is defined, the graph is saved in a temporary file
|
||||
which is processed by dot (graphviz) and displayed by the program indicated
|
||||
by the view flag. The target format is png, unless overridden by the
|
||||
flag -format. Results from multiple trees are combined to pdf with convert (ImageMagick).
|
||||
See also 'vp -showdep' for another visualization of dependencies.
|
||||
which is processed by graphviz and displayed by the program indicated
|
||||
by the flag. The target format is png, unless overridden by the
|
||||
flag -format.
|
||||
|
||||
|
||||
- Options:
|
||||
|
||||
| ``-v`` | show extra information
|
||||
| ``-conll2latex`` | convert conll to latex
|
||||
|
||||
- Flags:
|
||||
|
||||
| ``-abslabels`` | abstract configuration file for labels, format per line 'fun label*'
|
||||
| ``-cnclabels`` | concrete configuration file for labels, format per line 'fun {words|*} pos label head'
|
||||
| ``-file`` | same as abslabels (abstract configuration file)
|
||||
| ``-format`` | format of the visualization file using dot (default "png")
|
||||
| ``-output`` | output format of graph source (latex, conll, dot (default but deprecated))
|
||||
| ``-view`` | program to open the resulting graph file (default "open")
|
||||
| ``-file`` | configuration file for labels per fun, format 'fun l1 ... label ... l2'
|
||||
| ``-format`` | format of the visualization file (default "png")
|
||||
| ``-output`` | output format of graph source (default "dot")
|
||||
| ``-view`` | program to open the resulting file (default "open")
|
||||
| ``-lang`` | the language of analysis
|
||||
|
||||
- Examples:
|
||||
|
||||
| ``gr | vd`` | generate a tree and show dependency tree in .dot
|
||||
| ``gr | vd -view=open`` | generate a tree and display dependency tree on with Mac's 'open'
|
||||
| ``gr | vd -view=open -output=latex`` | generate a tree and display latex dependency tree with Mac's 'open'
|
||||
| ``gr -number=1000 | vd -abslabels=Lang.labels -cnclabels=LangSwe.labels -output=conll`` | generate a random treebank
|
||||
| ``rf -file=ex.conll | vd -conll2latex | wf -file=ex.tex`` | convert conll file to latex
|
||||
| ``gr | vd -view=open`` | generate a tree and display dependency tree on a Mac
|
||||
| ``gr -number=1000 | vd -file=dep.labels -output=malt`` | generate training treebank
|
||||
| ``gr -number=100 | vd -file=dep.labels -output=malt_input`` | generate test sentences
|
||||
|
||||
|
||||
#NORMAL
|
||||
@@ -1220,16 +1182,15 @@ See also 'vp -showdep' for another visualization of dependencies.
|
||||
Prints a parse tree in the .dot format (the graphviz format).
|
||||
The graph can be saved in a file by the wf command as usual.
|
||||
If the -view flag is defined, the graph is saved in a temporary file
|
||||
which is processed by dot (graphviz) and displayed by the program indicated
|
||||
by the view flag. The target format is png, unless overridden by the
|
||||
flag -format. Results from multiple trees are combined to pdf with convert (ImageMagick).
|
||||
which is processed by graphviz and displayed by the program indicated
|
||||
by the flag. The target format is png, unless overridden by the
|
||||
flag -format.
|
||||
|
||||
|
||||
- Options:
|
||||
|
||||
| ``-showcat`` | show categories in the tree nodes (default)
|
||||
| ``-nocat`` | don't show categories
|
||||
| ``-showdep`` | show dependency labels
|
||||
| ``-showfun`` | show function names in the tree nodes
|
||||
| ``-nofun`` | don't show function names (default)
|
||||
| ``-showleaves`` | show the leaves of the tree (default)
|
||||
@@ -1237,8 +1198,6 @@ flag -format. Results from multiple trees are combined to pdf with convert (Imag
|
||||
|
||||
- Flags:
|
||||
|
||||
| ``-lang`` | the language to visualize
|
||||
| ``-file`` | configuration file for dependency labels with -deps, format per line 'fun label*'
|
||||
| ``-format`` | format of the visualization file (default "png")
|
||||
| ``-view`` | program to open the resulting file (default "open")
|
||||
| ``-nodefont`` | font for tree nodes (default: Times -- graphviz standard font)
|
||||
@@ -1251,8 +1210,7 @@ flag -format. Results from multiple trees are combined to pdf with convert (Imag
|
||||
- Examples:
|
||||
|
||||
| ``p "John walks" | vp`` | generate a tree and show parse tree as .dot script
|
||||
| ``gr | vp -view=open`` | generate a tree and display parse tree on a Mac
|
||||
| ``p "she loves us" | vp -view=open -showdep -file=uddeps.labels -nocat`` | show a visual variant of a dependency tree
|
||||
| ``gr | vp -view="open"`` | generate a tree and display parse tree on a Mac
|
||||
|
||||
|
||||
#NORMAL
|
||||
@@ -1269,9 +1227,9 @@ flag -format. Results from multiple trees are combined to pdf with convert (Imag
|
||||
Prints a set of trees in the .dot format (the graphviz format).
|
||||
The graph can be saved in a file by the wf command as usual.
|
||||
If the -view flag is defined, the graph is saved in a temporary file
|
||||
which is processed by dot (graphviz) and displayed by the command indicated
|
||||
by the view flag. The target format is postscript, unless overridden by the
|
||||
flag -format. Results from multiple trees are combined to pdf with convert (ImageMagick).
|
||||
which is processed by graphviz and displayed by the program indicated
|
||||
by the flag. The target format is postscript, unless overridden by the
|
||||
flag -format.
|
||||
With option -mk, use for showing library style function names of form 'mkC'.
|
||||
|
||||
|
||||
|
||||
BIN
doc/gf-lrec-2010.pdf
Normal file
BIN
doc/gf-lrec-2010.pdf
Normal file
Binary file not shown.
132
doc/gf-people.html
Normal file
132
doc/gf-people.html
Normal file
@@ -0,0 +1,132 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>GF People</title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel=stylesheet href="../css/style.css">
|
||||
<meta name = "viewport" content = "width = device-width">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<center>
|
||||
<IMG SRC="Logos/gf0.png" alt="[GF]">
|
||||
|
||||
<h1>Grammatical Framework: Authors and Acknowledgements</h1>
|
||||
|
||||
</center>
|
||||
|
||||
The current developers and maintainers are
|
||||
<a href="http://www.chalmers.se/cse/EN/organization/divisions/computing-science/people/angelov-krasimir">Krasimir Angelov</a>,
|
||||
<a href="http://www.cse.chalmers.se/~hallgren/">Thomas Hallgren</a>,
|
||||
and
|
||||
<a href="http://www.cse.chalmers.se/~aarne/">Aarne Ranta</a>. Bug reports should be
|
||||
posted via the
|
||||
<a href="http://code.google.com/p/grammatical-framework/issues/list">GF bug tracker</a>.
|
||||
|
||||
|
||||
<p>
|
||||
|
||||
Also the following people have contributed code to some of the versions:
|
||||
|
||||
<dl>
|
||||
|
||||
<dt>Grégoire Détrez (University of Gothenburg)
|
||||
<dt>Ramona Enache (University of Gothenburg)
|
||||
<dt>
|
||||
<a href="http://www.cse.chalmers.se/alumni/bringert">Björn Bringert</a> (University of Gothenburg)
|
||||
<dt>
|
||||
Håkan Burden (University of Gothenburg)
|
||||
<dt>
|
||||
Hans-Joachim Daniels (Karlsruhe)
|
||||
<dt>
|
||||
<a href="http://www.cs.chalmers.se/~markus">Markus Forsberg</a> (Chalmers)
|
||||
<dt>
|
||||
<a href="http://www.cs.chalmers.se/~krijo">Kristofer Johannisson</a> (University of Gothenburg)
|
||||
<dt>
|
||||
<a href="http://www.cs.chalmers.se/~janna">Janna Khegai</a> (Chalmers)
|
||||
<dt>
|
||||
<a href="http://www.cse.chalmers.se/~peb">Peter Ljunglöf</a> (University of Gothenburg)
|
||||
<dt>
|
||||
Petri Mäenpää (Nokia)
|
||||
</dl>
|
||||
|
||||
|
||||
At least the following colleagues are thanked for suggestions,
|
||||
bug reports, and other indirect contributions to the code. (Notice:
|
||||
these are early contributors - the list has not been updated since 2004 or so).
|
||||
|
||||
<p>
|
||||
|
||||
<a href="http://www.di.unito.it/~stefano/">Stefano Berardi</a> (Torino),
|
||||
|
||||
Pascal Boldini (Paris),
|
||||
|
||||
<a href="http://www.dur.ac.uk/~dcs0pcc/">Paul Callaghan</a> (Durham),
|
||||
|
||||
Lauri Carlson (Helsinki),
|
||||
|
||||
<a href="http://www.cse.chalmers.se/~koen">Koen Claessen</a> (Chalmers),
|
||||
|
||||
<a href="http://www.cling.gu.se/~cooper">Robin Cooper</a> (Gothenburg),
|
||||
|
||||
<a href="http://www.cse.chalmers.se/~coquand">Thierry Coquand</a> (Chalmers),
|
||||
|
||||
<a
|
||||
href="http://www.xrce.xerox.com/people/dymetman/dymetman.html">Marc
|
||||
Dymetman</a> (XRCE),
|
||||
|
||||
Bertrand Grégoire (Tudor Institure, Luxembourg),
|
||||
|
||||
<a href="http://www.cse.chalmers.se/~reiner">Reiner Hähnle</a> (Chalmers),
|
||||
|
||||
<a href="http://pauillac.inria.fr/~huet/">Gérard Huet</a> (INRIA),
|
||||
|
||||
<a href="http://www.cse.chalmers.se/~patrikj">Patrik Jansson</a> (Chalmers),
|
||||
|
||||
Bernard Jaulin (Paris),
|
||||
|
||||
<a href="http://www.xrce.xerox.com/people/karttunen/karttunen.html">
|
||||
Lauri Karttunen</a> (PARC),
|
||||
|
||||
Matti Kinnunen (Nokia),
|
||||
|
||||
<a
|
||||
href="http://www.xrce.xerox.com/people/lux/">Veronika
|
||||
Lux</a> (XRCE),
|
||||
|
||||
Per Martin-Löf (Stockholm),
|
||||
|
||||
<a href="http://www.cse.chalmers.se/~bengt">Bengt Nordström</a> (Chalmers),
|
||||
|
||||
<a
|
||||
href="http://www.cis.uni-muenchen.de/studenten/stud_homepages/okrslar/reklame.html">
|
||||
Martin Okrslar</a> (CIS),
|
||||
|
||||
Jianmin Pang (Durham),
|
||||
|
||||
<a
|
||||
href="http://www.xrce.xerox.com/people/pogodalla/index.fr.html">Sylvain
|
||||
Pogodalla</a> (XRCE),
|
||||
|
||||
<a href="http://www.inria.fr/Loic.Pottier">Loïc Pottier</a> (INRIA),
|
||||
|
||||
|
||||
<a href="http://www2.parc.com/istl/members/zaenen/">Annie Zaenen</a> (PARC)
|
||||
|
||||
<p>
|
||||
|
||||
The GF logo was designed by Uula Ranta.
|
||||
|
||||
<p>
|
||||
|
||||
From 2001 to 2004, GF enjoyed funding from the
|
||||
<a href="http://www.vinnova.se">Vinnova</a> foundation, within the
|
||||
<a href="http://www.cse.chalmers.se/research/group/Language-technology/ILT.html">
|
||||
Interactive Languge Technology</a> project.
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
---
|
||||
title: "Grammatical Framework: Authors and Acknowledgements"
|
||||
---
|
||||
|
||||
## Current maintainers
|
||||
|
||||
The current maintainers of GF are
|
||||
|
||||
[Krasimir Angelov](http://www.chalmers.se/cse/EN/organization/divisions/computing-science/people/angelov-krasimir),
|
||||
[Thomas Hallgren](http://www.cse.chalmers.se/~hallgren/),
|
||||
[Aarne Ranta](http://www.cse.chalmers.se/~aarne/),
|
||||
[John J. Camilleri](http://johnjcamilleri.com), and
|
||||
[Inari Listenmaa](https://inariksit.github.io/).
|
||||
|
||||
This page is otherwise not up to date.
|
||||
For detailed data about contributors to the code repositories since 2007, see
|
||||
[here (gf-core)](https://github.com/GrammaticalFramework/gf-core/graphs/contributors)
|
||||
and
|
||||
[here (gf-rgl)](https://github.com/GrammaticalFramework/gf-rgl/graphs/contributors).
|
||||
|
||||
## Previous contributors
|
||||
|
||||
The following people have contributed code to some of the versions:
|
||||
|
||||
- Grégoire Détrez (University of Gothenburg)
|
||||
- Ramona Enache (University of Gothenburg)
|
||||
- [Björn Bringert](http://www.cse.chalmers.se/alumni/bringert) (University of Gothenburg)
|
||||
- Håkan Burden (University of Gothenburg)
|
||||
- Hans-Joachim Daniels (Karlsruhe)
|
||||
- [Markus Forsberg](http://www.cs.chalmers.se/~markus) (Chalmers)
|
||||
- [Kristofer Johannisson](http://www.cs.chalmers.se/~krijo) (University of Gothenburg)
|
||||
- [Janna Khegai](http://www.cs.chalmers.se/~janna) (Chalmers)
|
||||
- [Peter Ljunglöf](http://www.cse.chalmers.se/~peb) (University of Gothenburg)
|
||||
- Petri Mäenpää (Nokia)
|
||||
|
||||
At least the following colleagues are thanked for suggestions, bug
|
||||
reports, and other indirect contributions to the code.
|
||||
|
||||
- [Stefano Berardi](http://www.di.unito.it/~stefano/) (Torino)
|
||||
- Pascal Boldini (Paris)
|
||||
- [Paul Callaghan](http://www.dur.ac.uk/~dcs0pcc/) (Durham)
|
||||
- Lauri Carlson (Helsinki)
|
||||
- [Koen Claessen](http://www.cse.chalmers.se/~koen) (Chalmers)
|
||||
- [Robin Cooper](http://www.cling.gu.se/~cooper) (Gothenburg)
|
||||
- [Thierry Coquand](http://www.cse.chalmers.se/~coquand) (Chalmers)
|
||||
- [Marc Dymetman](http://www.xrce.xerox.com/people/dymetman/dymetman.html) (XRCE)
|
||||
- Bertrand Grégoire (Tudor Institute, Luxembourg)
|
||||
- [Reiner Hähnle](http://www.cse.chalmers.se/~reiner) (Chalmers)
|
||||
- [Gérard Huet](http://pauillac.inria.fr/~huet/) (INRIA)
|
||||
- [Patrik Jansson](http://www.cse.chalmers.se/~patrikj) (Chalmers)
|
||||
- Bernard Jaulin (Paris)
|
||||
- [Lauri Karttunen](http://www.xrce.xerox.com/people/karttunen/karttunen.html) (PARC)
|
||||
- Matti Kinnunen (Nokia)
|
||||
- [Veronika Lux](http://www.xrce.xerox.com/people/lux/) (XRCE)
|
||||
- Per Martin-Löf (Stockholm)
|
||||
- [Bengt Nordström](http://www.cse.chalmers.se/~bengt) (Chalmers)
|
||||
- [Martin Okrslar](http://www.cis.uni-muenchen.de/studenten/stud_homepages/okrslar/reklame.html) (CIS)
|
||||
- Jianmin Pang (Durham)
|
||||
- [Sylvain Pogodalla](http://www.xrce.xerox.com/people/pogodalla/index.fr.html) (XRCE)
|
||||
- [Loïc Pottier](http://www.inria.fr/Loic.Pottier) (INRIA)
|
||||
- [Annie Zaenen](http://www2.parc.com/istl/members/zaenen/) (PARC)
|
||||
|
||||
The GF logo was designed by Uula Ranta.
|
||||
158
doc/gf-quickstart.html
Normal file
158
doc/gf-quickstart.html
Normal file
@@ -0,0 +1,158 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>GF Quickstart</title>
|
||||
<link rel=stylesheet href="../css/style.css">
|
||||
<meta name = "viewport" content = "width = device-width">
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
|
||||
<center>
|
||||
<img src="Logos/gf0.png">
|
||||
<p>
|
||||
Aarne Ranta
|
||||
<p>
|
||||
October 2011 for GF 3.3
|
||||
|
||||
<p>
|
||||
|
||||
<h1>Grammatical Framework Quick Start</h1>
|
||||
|
||||
</center>
|
||||
|
||||
This Quick Start shows a few examples of how GF can be used.
|
||||
We assume that you have downloaded and installed GF, so that
|
||||
the command <tt>gf</tt> works for you. See download and install
|
||||
instructions <a href="../download/index.html">here</a>.
|
||||
|
||||
<h2>Want to try without downloading?</h2>
|
||||
|
||||
<a href="../demos/phrasebook/">Using GF translation</a> with an existing grammar.
|
||||
|
||||
<p>
|
||||
|
||||
<a href="../demos/gfse/">Writing GF grammars</a> in the cloud, without installing GF.
|
||||
|
||||
|
||||
|
||||
|
||||
<h2>Using GF for translation and generation</h2>
|
||||
|
||||
When you have downloaded and installed GF:
|
||||
<ol>
|
||||
<li> Copy the files
|
||||
<a href="../examples/tutorial/food/Food.gf"><tt>Food.gf</tt></a>,
|
||||
<a href="../examples/tutorial/food/FoodEng.gf"><tt>FoodEng.gf</tt></a>, and
|
||||
<a href="../examples/tutorial/food/FoodIta.gf"><tt>FoodIta.gf</tt></a>.
|
||||
Or go to <tt>GF/examples/tutorial/food/</tt>, if you have downloaded the
|
||||
GF sources.
|
||||
|
||||
<li> Start GF with the shell command (without the prompt <tt>$</tt>)
|
||||
<pre>
|
||||
$ gf FoodIta.gf FoodEng.gf
|
||||
</pre>
|
||||
Alternatively, start GF with <tt>gf</tt> and give the GF command <tt>import FoodIta.gf FoodEng.gf</tt>.
|
||||
|
||||
<li> <b>Translation</b>. Try your first translation by giving the GF command
|
||||
<pre>
|
||||
parse "this cheese is very very Italian" | linearize
|
||||
</pre>
|
||||
Notice that the parser accept the tabulator for word completion.
|
||||
|
||||
<li> <b>Generation</b>. Random-generate sentences in two languages:
|
||||
<pre>
|
||||
generate_random | linearize
|
||||
</pre>
|
||||
|
||||
<li> <b>Other commands</b>. Use the help command
|
||||
<pre>
|
||||
help
|
||||
</pre>
|
||||
<li> <b>More examples</b>. Go to <tt>GF/examples/phrasebook</tt> or some other
|
||||
subdirectory of <tt>GF/examples/</tt>. Or try a resource grammar by, for instance,
|
||||
<pre>
|
||||
import alltenses/LangEng.gfo alltenses/LangGer.gfo
|
||||
|
||||
parse -lang=Eng "I love you" | linearize -treebank
|
||||
</pre>
|
||||
The resource grammars are found relative to the value of <tt>GF_LIB_PATH</tt>, which
|
||||
you may have to set; see <a href="../download/index.html">here</a> for instructions.
|
||||
|
||||
|
||||
|
||||
</ol>
|
||||
|
||||
|
||||
|
||||
<h2>Grammar development</h2>
|
||||
|
||||
Add words to the <tt>Food</tt>
|
||||
grammars and try the above commands again. For instance, add the following lines:
|
||||
<pre>
|
||||
Bread : Kind ; -- in Food.gf
|
||||
Bread = {s = "bread"} ; -- in FoodEng.gf
|
||||
Bread = {s = "pane"} ; -- in FoodIta.gf
|
||||
</pre>
|
||||
and start GF again with the same command. Now you can even translate
|
||||
<i>this bread is very Italian</i>.
|
||||
</ol>
|
||||
To lear more on GF commands and
|
||||
grammar development, go to the one of the tutorials:
|
||||
<ul>
|
||||
<li> <a href="tutorial/gf-tutorial.html">GF Tutorial</a>: older, more programmer-oriented
|
||||
<li> <a href="gf-lrec-2010.pdf">GF Resource Tutorial</a>: newer, more linguist-oriented
|
||||
</ul>
|
||||
To learn about how GF is used for easily writing grammars for 16 languages, consult the
|
||||
<ul>
|
||||
<li> <a href="../lib/doc/synopsis.html">GF Resource Grammar Library</a>.
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<h2>Run-time grammars and web applications</h2>
|
||||
|
||||
GF has its own "machine language", PGF (Portable Grammar Format),
|
||||
which is recommended for use in applications at run time. To produce a PGF file from
|
||||
the two grammars above, do
|
||||
<pre>
|
||||
gf -make FoodIta.gf FoodEng.gf
|
||||
wrote Food.pgf
|
||||
</pre>
|
||||
You can use this in Haskell and Java programs, and also on web services, such as
|
||||
<ul>
|
||||
<li> the
|
||||
<a href="http://cloud.grammaticalframework.org/minibar/minibar.html">minibar</a>
|
||||
fridge magnets
|
||||
</ul>
|
||||
|
||||
The quickest way to provide a GF web service is to start GF with the <tt>-server</tt> option:
|
||||
<pre>
|
||||
$ gf -server
|
||||
This is GF version 3.3
|
||||
Built on linux/i386 with ghc-7.0, flags: interrupt server cclazy
|
||||
Document root = /usr/local/share/gf-3.3/www
|
||||
Starting HTTP server, open http://localhost:41296/ in your web browser.
|
||||
</pre>
|
||||
You can view it locally by pointing your
|
||||
browser to the URL shown. You can add your own <tt>.pgf</tt> grammar to the service by
|
||||
copying it over to the <tt>documentRoot</tt> directory. Just push "reload" in
|
||||
your browser after each such update.
|
||||
|
||||
<p>
|
||||
|
||||
To build more customized web application, consult the
|
||||
<a href="http://code.google.com/p/grammatical-framework/wiki/SideBar?tm=6">developer wiki</a>.
|
||||
|
||||
|
||||
<h2>User group</h2>
|
||||
|
||||
You are welcome to join the <A HREF="http://groups.google.com/group/gf-dev">User Group</A>
|
||||
to get help and discuss GF-related issues!
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body></html>
|
||||
BIN
doc/gf-reference.pdf
Normal file
BIN
doc/gf-reference.pdf
Normal file
Binary file not shown.
493
doc/gf-reference.t2t
Normal file
493
doc/gf-reference.t2t
Normal file
@@ -0,0 +1,493 @@
|
||||
GF Quick Reference
|
||||
Aarne Ranta
|
||||
April 4, 2006
|
||||
|
||||
% NOTE: this is a txt2tags file.
|
||||
% Create an html file from this file using:
|
||||
% txt2tags -thtml gf-reference.t2t
|
||||
|
||||
%!style:../css/style.css
|
||||
%!target:html
|
||||
%!options: --toc
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
This is a quick reference on GF grammars. It aims to
|
||||
cover all forms of expression available when writing
|
||||
grammars. It assumes basic knowledge of GF, which
|
||||
can be acquired from the
|
||||
[GF Tutorial http://www.grammaticalframework.org/doc/tutorial/gf-tutorial.html].
|
||||
Help on GF commands is obtained on line by the
|
||||
help command (``help``), and help on invoking
|
||||
GF with (``gf -help``).
|
||||
|
||||
|
||||
===A complete example===
|
||||
|
||||
This is a complete example of a GF grammar divided
|
||||
into three modules in files. The grammar recognizes the
|
||||
phrases //one pizza// and //two pizzas//.
|
||||
|
||||
File ``Order.gf``:
|
||||
```
|
||||
abstract Order = {
|
||||
cat
|
||||
Order ;
|
||||
Item ;
|
||||
fun
|
||||
One, Two : Item -> Order ;
|
||||
Pizza : Item ;
|
||||
}
|
||||
```
|
||||
File ``OrderEng.gf`` (the top file):
|
||||
```
|
||||
--# -path=.:prelude
|
||||
concrete OrderEng of Order =
|
||||
open Res, Prelude in {
|
||||
flags startcat=Order ;
|
||||
lincat
|
||||
Order = SS ;
|
||||
Item = {s : Num => Str} ;
|
||||
lin
|
||||
One it = ss ("one" ++ it.s ! Sg) ;
|
||||
Two it = ss ("two" ++ it.s ! Pl) ;
|
||||
Pizza = regNoun "pizza" ;
|
||||
}
|
||||
```
|
||||
File ``Res.gf``:
|
||||
```
|
||||
resource Res = open Prelude in {
|
||||
param Num = Sg | Pl ;
|
||||
oper regNoun : Str -> {s : Num => Str} =
|
||||
\dog -> {s = table {
|
||||
Sg => dog ;
|
||||
_ => dog + "s"
|
||||
}
|
||||
} ;
|
||||
}
|
||||
```
|
||||
To use this example, do
|
||||
```
|
||||
% gf -- in shell: start GF
|
||||
> i OrderEng.gf -- in GF: import grammar
|
||||
> p "one pizza" -- parse string
|
||||
> l Two Pizza -- linearize tree
|
||||
```
|
||||
|
||||
|
||||
|
||||
===Modules and files===
|
||||
|
||||
One module per file.
|
||||
File named ``Foo.gf`` contains module named
|
||||
``Foo``.
|
||||
|
||||
Each module has the structure
|
||||
```
|
||||
moduletypename =
|
||||
Inherits ** -- optional
|
||||
open Opens in -- optional
|
||||
{ Judgements }
|
||||
```
|
||||
Inherits are names of modules of the same type.
|
||||
Inheritance can be restricted:
|
||||
```
|
||||
Mo[f,g], -- inherit only f,g from Mo
|
||||
Lo-[f,g] -- inheris all but f,g from Lo
|
||||
```
|
||||
Opens are possible in ``concrete`` and ``resource``.
|
||||
They are names of modules of these two types, possibly
|
||||
qualified:
|
||||
```
|
||||
(M = Mo), -- refer to f as M.f or Mo.f
|
||||
(Lo = Lo) -- refer to f as Lo.f
|
||||
```
|
||||
Module types and judgements in them:
|
||||
```
|
||||
abstract A -- cat, fun, def, data
|
||||
concrete C of A -- lincat, lin, lindef, printname
|
||||
resource R -- param, oper
|
||||
|
||||
interface I -- like resource, but can have
|
||||
oper f : T without definition
|
||||
instance J of I -- like resource, defines opers
|
||||
that I leaves undefined
|
||||
incomplete -- functor: concrete that opens
|
||||
concrete CI of A = one or more interfaces
|
||||
open I in ...
|
||||
concrete CJ of A = -- completion: concrete that
|
||||
CI with instantiates a functor by
|
||||
(I = J) instances of open interfaces
|
||||
```
|
||||
The forms
|
||||
``param``, ``oper``
|
||||
may appear in ``concrete`` as well, but are then
|
||||
not inherited to extensions.
|
||||
|
||||
All modules can moreover have ``flags`` and comments.
|
||||
Comments have the forms
|
||||
```
|
||||
-- till the end of line
|
||||
{- any number of lines between -}
|
||||
--# used for compiler pragmas
|
||||
```
|
||||
A ``concrete`` can be opened like a ``resource``.
|
||||
It is translated as follows:
|
||||
```
|
||||
cat C ---> oper C : Type =
|
||||
lincat C = T T ** {lock_C : {}}
|
||||
|
||||
fun f : G -> C ---> oper f : A* -> C* = \g ->
|
||||
lin f = t t g ** {lock_C = <>}
|
||||
```
|
||||
An ``abstract`` can be opened like an ``interface``.
|
||||
Any ``concrete`` of it then works as an ``instance``.
|
||||
|
||||
|
||||
|
||||
===Judgements===
|
||||
|
||||
```
|
||||
cat C -- declare category C
|
||||
cat C (x:A)(y:B x) -- dependent category C
|
||||
cat C A B -- same as C (x : A)(y : B)
|
||||
fun f : T -- declare function f of type T
|
||||
def f = t -- define f as t
|
||||
def f p q = t -- define f by pattern matching
|
||||
data C = f | g -- set f,g as constructors of C
|
||||
data f : A -> C -- same as
|
||||
fun f : A -> C; data C=f
|
||||
|
||||
lincat C = T -- define lin.type of cat C
|
||||
lin f = t -- define lin. of fun f
|
||||
lin f x y = t -- same as lin f = \x y -> t
|
||||
lindef C = \s -> t -- default lin. of cat C
|
||||
printname fun f = s -- printname shown in menus
|
||||
printname cat C = s -- printname shown in menus
|
||||
printname f = s -- same as printname fun f = s
|
||||
|
||||
param P = C | D Q R -- define parameter type P
|
||||
with constructors
|
||||
C : P, D : Q -> R -> P
|
||||
oper h : T = t -- define oper h of type T
|
||||
oper h = t -- omit type, if inferrable
|
||||
|
||||
flags p=v -- set value of flag p
|
||||
```
|
||||
Judgements are terminated by semicolons (``;``).
|
||||
Subsequent judgments of the same form may share the
|
||||
keyword:
|
||||
```
|
||||
cat C ; D ; -- same as cat C ; cat D ;
|
||||
```
|
||||
Judgements can also share RHS:
|
||||
```
|
||||
fun f,g : A -- same as fun f : A ; g : A
|
||||
```
|
||||
|
||||
|
||||
===Types===
|
||||
|
||||
Abstract syntax (in ``fun``):
|
||||
```
|
||||
C -- basic type, if cat C
|
||||
C a b -- basic type for dep. category
|
||||
(x : A) -> B -- dep. functions from A to B
|
||||
(_ : A) -> B -- nondep. functions from A to B
|
||||
(p,q : A) -> B -- same as (p : A)-> (q : A) -> B
|
||||
A -> B -- same as (_ : A) -> B
|
||||
Int -- predefined integer type
|
||||
Float -- predefined float type
|
||||
String -- predefined string type
|
||||
```
|
||||
Concrete syntax (in ``lincat``):
|
||||
```
|
||||
Str -- token lists
|
||||
P -- parameter type, if param P
|
||||
P => B -- table type, if P param. type
|
||||
{s : Str ; p : P}-- record type
|
||||
{s,t : Str} -- same as {s : Str ; t : Str}
|
||||
{a : A} **{b : B}-- record type extension, same as
|
||||
{a : A ; b : B}
|
||||
A * B * C -- tuple type, same as
|
||||
{p1 : A ; p2 : B ; p3 : C}
|
||||
Ints n -- type of n first integers
|
||||
```
|
||||
Resource (in ``oper``): all those of concrete, plus
|
||||
```
|
||||
Tok -- tokens (subtype of Str)
|
||||
A -> B -- functions from A to B
|
||||
Int -- integers
|
||||
Strs -- list of prefixes (for pre)
|
||||
PType -- parameter type
|
||||
Type -- any type
|
||||
```
|
||||
As parameter types, one can use any finite type:
|
||||
``P`` defined in ``param P``,
|
||||
``Ints n``, and record types of parameter types.
|
||||
|
||||
|
||||
|
||||
===Expressions===
|
||||
|
||||
Syntax trees = full function applications
|
||||
```
|
||||
f a b -- : C if fun f : A -> B -> C
|
||||
1977 -- : Int
|
||||
3.14 -- : Float
|
||||
"foo" -- : String
|
||||
```
|
||||
Higher-Order Abstract syntax (HOAS): functions as arguments:
|
||||
```
|
||||
F a (\x -> c) -- : C if a : A, c : C (x : B),
|
||||
fun F : A -> (B -> C) -> C
|
||||
```
|
||||
Tokens and token lists
|
||||
```
|
||||
"hello" -- : Tok, singleton Str
|
||||
"hello" ++ "world" -- : Str
|
||||
["hello world"] -- : Str, same as "hello" ++ "world"
|
||||
"hello" + "world" -- : Tok, computes to "helloworld"
|
||||
[] -- : Str, empty list
|
||||
```
|
||||
Parameters
|
||||
```
|
||||
Sg -- atomic constructor
|
||||
VPres Sg P2 -- applied constructor
|
||||
{n = Sg ; p = P3} -- record of parameters
|
||||
```
|
||||
Tables
|
||||
```
|
||||
table { -- by full branches
|
||||
Sg => "mouse" ;
|
||||
Pl => "mice"
|
||||
}
|
||||
table { -- by pattern matching
|
||||
Pl => "mice" ;
|
||||
_ => "mouse" -- wildcard pattern
|
||||
}
|
||||
table {
|
||||
n => regn n "cat" -- variable pattern
|
||||
}
|
||||
table Num {...} -- table given with arg. type
|
||||
table ["ox"; "oxen"] -- table as course of values
|
||||
\\_ => "fish" -- same as table {_ => "fish"}
|
||||
\\p,q => t -- same as \\p => \\q => t
|
||||
|
||||
t ! p -- select p from table t
|
||||
case e of {...} -- same as table {...} ! e
|
||||
```
|
||||
Records
|
||||
```
|
||||
{s = "Liz"; g = Fem} -- record in full form
|
||||
{s,t = "et"} -- same as {s = "et";t= "et"}
|
||||
{s = "Liz"} ** -- record extension: same as
|
||||
{g = Fem} {s = "Liz" ; g = Fem}
|
||||
|
||||
<a,b,c> -- tuple, same as {p1=a;p2=b;p3=c}
|
||||
```
|
||||
Functions
|
||||
```
|
||||
\x -> t -- lambda abstract
|
||||
\x,y -> t -- same as \x -> \y -> t
|
||||
\x,_ -> t -- binding not in t
|
||||
```
|
||||
Local definitions
|
||||
```
|
||||
let x : A = d in t -- let definition
|
||||
let x = d in t -- let defin, type inferred
|
||||
let x=d ; y=e in t -- same as
|
||||
let x=d in let y=e in t
|
||||
let {...} in t -- same as let ... in t
|
||||
|
||||
t where {...} -- same as let ... in t
|
||||
```
|
||||
Free variation
|
||||
```
|
||||
variants {x ; y} -- both x and y possible
|
||||
variants {} -- nothing possible
|
||||
```
|
||||
Prefix-dependent choices
|
||||
```
|
||||
pre {"a" ; "an" / v} -- "an" before v, "a" otherw.
|
||||
strs {"a" ; "i" ;"o"}-- list of condition prefixes
|
||||
```
|
||||
Typed expression
|
||||
```
|
||||
<t:T> -- same as t, to help type inference
|
||||
```
|
||||
Accessing bound variables in ``lin``: use fields ``$1, $2, $3,...``.
|
||||
Example:
|
||||
```
|
||||
fun F : (A : Set) -> (El A -> Prop) -> Prop ;
|
||||
lin F A B = {s = ["for all"] ++ A.s ++ B.$1 ++ B.s}
|
||||
```
|
||||
|
||||
|
||||
===Pattern matching===
|
||||
|
||||
These patterns can be used in branches of ``table`` and
|
||||
``case`` expressions. Patterns are matched in the order in
|
||||
which they appear in the grammar.
|
||||
```
|
||||
C -- atomic param constructor
|
||||
C p q -- param constr. applied to patterns
|
||||
x -- variable, matches anything
|
||||
_ -- wildcard, matches anything
|
||||
"foo" -- string
|
||||
56 -- integer
|
||||
{s = p ; y = q} -- record, matches extensions too
|
||||
<p,q> -- tuple, same as {p1=p ; p2=q}
|
||||
p | q -- disjunction, binds to first match
|
||||
x@p -- binds x to what p matches
|
||||
- p -- negation
|
||||
p + "s" -- sequence of two string patterns
|
||||
p* -- repetition of a string pattern
|
||||
```
|
||||
|
||||
===Sample library functions===
|
||||
|
||||
```
|
||||
-- lib/prelude/Predef.gf
|
||||
drop : Int -> Tok -> Tok -- drop prefix of length
|
||||
take : Int -> Tok -> Tok -- take prefix of length
|
||||
tk : Int -> Tok -> Tok -- drop suffix of length
|
||||
dp : Int -> Tok -> Tok -- take suffix of length
|
||||
occur : Tok -> Tok -> PBool -- test if substring
|
||||
occurs : Tok -> Tok -> PBool -- test if any char occurs
|
||||
show : (P:Type) -> P ->Tok -- param to string
|
||||
read : (P:Type) -> Tok-> P -- string to param
|
||||
toStr : (L:Type) -> L ->Str -- find "first" string
|
||||
|
||||
-- lib/prelude/Prelude.gf
|
||||
param Bool = True | False
|
||||
oper
|
||||
SS : Type -- the type {s : Str}
|
||||
ss : Str -> SS -- construct SS
|
||||
cc2 : (_,_ : SS) -> SS -- concat SS's
|
||||
optStr : Str -> Str -- string or empty
|
||||
strOpt : Str -> Str -- empty or string
|
||||
bothWays : Str -> Str -> Str -- X++Y or Y++X
|
||||
init : Tok -> Tok -- all but last char
|
||||
last : Tok -> Tok -- last char
|
||||
prefixSS : Str -> SS -> SS
|
||||
postfixSS : Str -> SS -> SS
|
||||
infixSS : Str -> SS -> SS -> SS
|
||||
if_then_else : (A : Type) -> Bool -> A -> A -> A
|
||||
if_then_Str : Bool -> Str -> Str -> Str
|
||||
```
|
||||
|
||||
|
||||
===Flags===
|
||||
|
||||
Flags can appear, with growing priority,
|
||||
- in files, judgement ``flags`` and without dash (``-``)
|
||||
- as flags to ``gf`` when invoked, with dash
|
||||
- as flags to various GF commands, with dash
|
||||
|
||||
|
||||
Some common flags used in grammars:
|
||||
```
|
||||
startcat=cat use this category as default
|
||||
|
||||
lexer=literals int and string literals recognized
|
||||
lexer=code like program code
|
||||
lexer=text like text: spacing, capitals
|
||||
lexer=textlit text, unknowns as string lits
|
||||
|
||||
unlexer=code like program code
|
||||
unlexer=codelit code, remove string lit quotes
|
||||
unlexer=text like text: punctuation, capitals
|
||||
unlexer=textlit text, remove string lit quotes
|
||||
unlexer=concat remove all spaces
|
||||
unlexer=bind remove spaces around "&+"
|
||||
|
||||
optimize=all_subs best for almost any concrete
|
||||
optimize=values good for lexicon concrete
|
||||
optimize=all usually good for resource
|
||||
optimize=noexpand for resource, if =all too big
|
||||
```
|
||||
For the full set of values for ``FLAG``,
|
||||
use on-line ``h -FLAG``.
|
||||
|
||||
|
||||
|
||||
===File import search paths===
|
||||
|
||||
Colon-separated list of directories searched in the
|
||||
given order:
|
||||
```
|
||||
--# -path=.:../abstract:../common:prelude
|
||||
```
|
||||
This can be (in order of increasing priority), as
|
||||
first line in the file, as flag to ``gf``
|
||||
when invoked, or as flag to the ``i`` command.
|
||||
The prefix ``--#`` is used only in files.
|
||||
|
||||
GF attempts to satisfy an ``import`` command by searching for the
|
||||
import filename in the above search paths, initially qualified
|
||||
relative to the current working directory. If the file is not found in
|
||||
that initial expansion, the search paths are re-qualified relative to
|
||||
the directories given in the ``GF_LIB_PATH`` environment variable. If
|
||||
``GF_LIB_PATH`` is not defined, its default value is
|
||||
``/usr/local/share/gf-3.9/lib`` (assuming you have GF version 3.9).
|
||||
|
||||
If your GF resource grammar libraries are installed somewhere else,
|
||||
you will want to set ``GF_LIB_PATH`` to point there instead. In a
|
||||
pinch, you can point to the ``GF/lib/src/`` folder in your clone of
|
||||
the GF source code repository.
|
||||
|
||||
Developers of resource grammars may find it useful to define multiple
|
||||
directories, colon-separated, in ``GF_LIB_PATH``.
|
||||
|
||||
|
||||
===Alternative grammar formats===
|
||||
|
||||
**Old GF** (before GF 2.0):
|
||||
all judgements in any kinds of modules,
|
||||
division into files uses ``include``s.
|
||||
A file ``Foo.gf`` is recognized as the old format
|
||||
if it lacks a module header.
|
||||
|
||||
**Context-free** (file ``foo.cf``). The form of rules is e.g.
|
||||
```
|
||||
Fun. S ::= NP "is" AP ;
|
||||
```
|
||||
If ``Fun`` is omitted, it is generated automatically.
|
||||
Rules must be one per line. The RHS can be empty.
|
||||
|
||||
**Extended BNF** (file ``foo.ebnf``). The form of rules is e.g.
|
||||
```
|
||||
S ::= (NP+ ("is" | "was") AP | V NP*) ;
|
||||
```
|
||||
where the RHS is a regular expression of categories
|
||||
and quoted tokens: ``"foo", CAT, T U, T|U, T*, T+, T?``, or empty.
|
||||
Rule labels are generated automatically.
|
||||
|
||||
|
||||
**Probabilistic grammars** (not a separate format).
|
||||
You can set the probability of a function ``f`` (in its value category) by
|
||||
```
|
||||
--# prob f 0.009
|
||||
```
|
||||
These are put into a file given to GF using the ``probs=File`` flag
|
||||
on command line. This file can be the grammar file itself.
|
||||
|
||||
**Example-based grammars** (file ``foo.gfe``). Expressions of the form
|
||||
```
|
||||
in Cat "example string"
|
||||
```
|
||||
are preprocessed by using a parser given by the flag
|
||||
```
|
||||
--# -resource=File
|
||||
```
|
||||
and the result is written to ``foo.gf``.
|
||||
|
||||
|
||||
===References===
|
||||
|
||||
[GF Homepage http://www.grammaticalframework.org/]
|
||||
|
||||
A. Ranta, Grammatical Framework: A Type-Theoretical Grammar Formalism.
|
||||
//The Journal of Functional Programming//, vol. 14:2. 2004, pp. 145-189.
|
||||
|
||||
@@ -1,32 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>GF Language Reference Manual</TITLE>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||
<style>
|
||||
code {
|
||||
color: inherit;
|
||||
}
|
||||
center {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
</style>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<div class="container-fluid my-5" style="max-width:1200px">
|
||||
|
||||
<P ALIGN="center">
|
||||
<CENTER>
|
||||
<a href="..">
|
||||
<img src="Logos/gf1.svg" height="200px" class="mb-3" alt="GF Logo">
|
||||
</a>
|
||||
<H1>GF Language Reference Manual</H1>
|
||||
<TITLE>GF Language Reference Manual</TITLE>
|
||||
</HEAD><BODY BGCOLOR="white" TEXT="black">
|
||||
<P ALIGN="center"><CENTER><H1>GF Language Reference Manual</H1>
|
||||
<FONT SIZE="4">
|
||||
<I>Aarne Ranta</I>, <I>Krasimir Angelov</I><BR>June 2014, GF 3.6
|
||||
</FONT></CENTER>
|
||||
|
||||
<P></P>
|
||||
<HR NOSHADE SIZE=1>
|
||||
<P></P>
|
||||
<UL>
|
||||
<LI><A HREF="#toc1">Overview of GF</A>
|
||||
@@ -109,7 +92,7 @@
|
||||
</UL>
|
||||
|
||||
<P></P>
|
||||
<HR>
|
||||
<HR NOSHADE SIZE=1>
|
||||
<P></P>
|
||||
<P>
|
||||
|
||||
@@ -499,7 +482,7 @@ to reuse abstract and concrete modules as resources. The following table
|
||||
gives, for all module types, the possible module types of their <I>extends</I>
|
||||
and <I>opens</I>, as well as the forms of judgement legal in that module type.
|
||||
</P>
|
||||
<TABLE class="table">
|
||||
<TABLE ALIGN="center" CELLPADDING="4" BORDER="1">
|
||||
<TR>
|
||||
<TH>module type</TH>
|
||||
<TH>extends</TH>
|
||||
@@ -570,7 +553,7 @@ system, replacing modules by types and functions. This model could actually
|
||||
be developed towards treating modules in GF as first-class objects; so far,
|
||||
however, this step has not been motivated by any practical needs.
|
||||
</P>
|
||||
<TABLE class="table">
|
||||
<TABLE ALIGN="center" CELLPADDING="4" BORDER="1">
|
||||
<TR>
|
||||
<TH>module</TH>
|
||||
<TH COLSPAN="2">object and type</TH>
|
||||
@@ -935,7 +918,7 @@ The table moreover indicates whether the judgement has a default value, and
|
||||
whether it contributes to the <B>name base</B>, i.e. introduces a new
|
||||
name to the scope.
|
||||
</P>
|
||||
<TABLE class="table">
|
||||
<TABLE ALIGN="center" CELLPADDING="4" BORDER="1">
|
||||
<TR>
|
||||
<TH>judgement</TH>
|
||||
<TH>where</TH>
|
||||
@@ -1675,7 +1658,7 @@ inherited modules.
|
||||
<P>
|
||||
Here are some flags commonly included in grammars.
|
||||
</P>
|
||||
<TABLE class="table">
|
||||
<TABLE ALIGN="center" CELLPADDING="4" BORDER="1">
|
||||
<TR>
|
||||
<TH>flag</TH>
|
||||
<TH>value</TH>
|
||||
@@ -1738,7 +1721,7 @@ Type and other expressions have a system of <B>precedences</B>. The following ta
|
||||
summarizes all expression forms, from the highest to the lowest precedence.
|
||||
Some expressions are moreover left- or right-associative.
|
||||
</P>
|
||||
<TABLE class="table">
|
||||
<TABLE ALIGN="center" CELLPADDING="4" BORDER="1">
|
||||
<TR>
|
||||
<TH>prec</TH>
|
||||
<TH>expression example</TH>
|
||||
@@ -2145,7 +2128,7 @@ where
|
||||
GF provides three predefined categories for abstract syntax, with predefined
|
||||
expressions:
|
||||
</P>
|
||||
<TABLE class="table">
|
||||
<TABLE ALIGN="center" CELLPADDING="4" BORDER="1">
|
||||
<TR>
|
||||
<TH>category</TH>
|
||||
<TH COLSPAN="2">expressions</TH>
|
||||
@@ -2281,7 +2264,7 @@ Expressions of type <CODE>Str</CODE> have the following canonical forms:
|
||||
<LI><B>the empty token list</B>, <CODE>[]</CODE>
|
||||
<LI><B>concatenation</B>, <I>s</I> <CODE>++</CODE> <I>t</I>, where <I>s,t</I> : <CODE>Str</CODE>
|
||||
<LI><B>prefix-dependent choice</B>,
|
||||
<CODE>pre {p<sub>1</sub> => s<sub>1</sub> ; ... ; p<sub>n</sub> => s<sub>n</sub> ; _ => s }</CODE>, where
|
||||
<CODE>pre {p<sub>1</sub> => s<sub>1</sub> ; ... ; p<sub>n</sub> => s<sub>n</sub> ; _ => s }, where
|
||||
<UL>
|
||||
<LI><I>s</I>, <i>s</i><sub>1</sub>,...,<i>s</i><sub>n</sub>, <i>p</i><sub>1</sub>,...,<i>p</i><sub>n</sub> : <CODE>Str</CODE>
|
||||
</UL>
|
||||
@@ -3033,7 +3016,7 @@ The following predefined operations are defined in the resource module
|
||||
<CODE>prelude/Predef.gf</CODE>. Their implementations are defined as
|
||||
a part of the GF grammar compiler.
|
||||
</P>
|
||||
<TABLE class="table">
|
||||
<TABLE ALIGN="center" CELLPADDING="4" BORDER="1">
|
||||
<TR>
|
||||
<TH>operation</TH>
|
||||
<TH>type</TH>
|
||||
@@ -3137,44 +3120,23 @@ a part of the GF grammar compiler.
|
||||
<TR>
|
||||
<TD><CODE>nonExist</CODE></TD>
|
||||
<TD><CODE>Str</CODE></TD>
|
||||
<TD>a special token marking<BR/>
|
||||
<TD>this is a special token marking<BR/>
|
||||
non-existing morphological forms</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><CODE>BIND</CODE></TD>
|
||||
<TD><CODE>Str</CODE></TD>
|
||||
<TD>a special token marking<BR/>
|
||||
<TD>this is a special token marking<BR/>
|
||||
that the surrounding tokens should not<BR/>
|
||||
be separated by space</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><CODE>SOFT_BIND</CODE></TD>
|
||||
<TD><CODE>Str</CODE></TD>
|
||||
<TD>a special token marking<BR/>
|
||||
<TD>this is a special token marking<BR/>
|
||||
that the surrounding tokens may not<BR/>
|
||||
be separated by space</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><CODE>SOFT_SPACE</CODE></TD>
|
||||
<TD><CODE>Str</CODE></TD>
|
||||
<TD>a special token marking<BR/>
|
||||
that the space between the surrounding tokens<BR/>
|
||||
is optional</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><CODE>CAPIT</CODE></TD>
|
||||
<TD><CODE>Str</CODE></TD>
|
||||
<TD>a special token marking<BR/>
|
||||
that the first character in the next token<BR/>
|
||||
should be capitalized</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD><CODE>ALL_CAPIT</CODE></TD>
|
||||
<TD><CODE>Str</CODE></TD>
|
||||
<TD>a special token marking<BR/>
|
||||
that the next word should be<BR/>
|
||||
in all capital letters</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<P></P>
|
||||
@@ -3219,7 +3181,7 @@ the abstract syntax.
|
||||
<B>Compiler pragmas</B> are a special form of comments prefixed with <CODE>--#</CODE>.
|
||||
Currently GF interprets the following pragmas.
|
||||
</P>
|
||||
<TABLE class="table">
|
||||
<TABLE CELLPADDING="4" BORDER="1">
|
||||
<TR>
|
||||
<TH>pragma</TH>
|
||||
<TH COLSPAN="2">explanation</TH>
|
||||
@@ -3317,7 +3279,7 @@ The rules have the form
|
||||
where an <I>RHS</I> can be any regular expression
|
||||
built from quoted strings and category symbols, in the following ways:
|
||||
</P>
|
||||
<TABLE class="table">
|
||||
<TABLE ALIGN="center" CELLPADDING="4" BORDER="1">
|
||||
<TR>
|
||||
<TH>RHS item</TH>
|
||||
<TH COLSPAN="2">explanation</TH>
|
||||
@@ -4617,6 +4579,6 @@ All other symbols are terminals.
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
</div>
|
||||
</BODY>
|
||||
</HTML>
|
||||
<P></P>
|
||||
|
||||
</BODY></HTML>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
The GF Software System
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!options(html): --toc
|
||||
%!options(html): --toc-level=4
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
%!postproc(html): "#VSPACE" "<hr>"
|
||||
%!postproc(html): "#NORMAL" ""
|
||||
%!postproc(html): "#TINY" ""
|
||||
@@ -10,7 +13,7 @@ The GF Software System
|
||||
|
||||
The GF software system implements the GF programming language. Its
|
||||
components are
|
||||
- the //compiler//,
|
||||
- the //compiler//,
|
||||
translating ``.gf`` source files to ``.gfo`` object files, to
|
||||
``.pgf`` run-time grammars, and to various other formats
|
||||
- the //run-time system//,
|
||||
@@ -40,7 +43,7 @@ The shell maintains a //state//, to which belong
|
||||
|
||||
|
||||
Unless file arguments are provided to the ``gf`` command, the shell starts in an
|
||||
empty state, with no grammars and no history.
|
||||
empty state, with no grammars and no history.
|
||||
|
||||
In the shell, a set of commands
|
||||
is available. Some of these commands may change the grammars in the state. The general
|
||||
@@ -56,7 +59,7 @@ syntax of commands is given by the following BNF grammar:
|
||||
ARGUMENT ::= QUOTED_STRING | TREE
|
||||
VALUE ::= IDENT | QUOTED_STRING
|
||||
```
|
||||
A command pipe is a sequence of commands interpreted in such a way
|
||||
A command pipe is a sequence of commands interpreted in such a way
|
||||
that the output of each command
|
||||
is send as input to the next. The option ``-tr`` causes GF to show a trace,
|
||||
i.e. the intermediate result of the command to which it is attached.
|
||||
@@ -66,7 +69,7 @@ executed one by one, in the order of appearance.
|
||||
|
||||
===GF shell commands===
|
||||
|
||||
The full set of GF shell commands is listed below with explanations.
|
||||
The full set of GF shell commands is listed below with explanations.
|
||||
This list can also be obtained in the GF shell by the command ``help -full``.
|
||||
|
||||
%!include: gf-help-full.txt
|
||||
@@ -74,14 +77,14 @@ This list can also be obtained in the GF shell by the command ``help -full``.
|
||||
==The GF batch compiler==
|
||||
|
||||
With the option ``-batch``, GF can be invoked in batch mode, i.e.
|
||||
without opening the shell, to compile files from ``.gf`` to ``.gfo``.
|
||||
The ``-s`` option ("silent") eliminates all messages except errors.
|
||||
without opening the shell, to compile files from ``.gf`` to ``.gfo``.
|
||||
The ``-s`` option ("silent") eliminates all messages except errors.
|
||||
```
|
||||
$ gf -batch -s LangIta.gf
|
||||
```
|
||||
With the option ``-make``, and as a set of
|
||||
top-level grammar files (with the same abstract syntax) as arguments,
|
||||
GF produces a ``.pgf`` file. The flag ``-optimize-pgf`` minimizes
|
||||
GF produces a ``.pgf`` file. The flag ``-optimize-pgf`` minimizes
|
||||
the size of the ``.pgf`` file, and is recommended for grammars to be shipped.
|
||||
```
|
||||
$ gf -make -optimize-pgf LangIta.gf LangEng.gf LangGer.gf
|
||||
@@ -104,3 +107,5 @@ To run GF from a //script//, redirection of standard input can be used:
|
||||
```
|
||||
The file ``script.gfs`` should then contain a sequence of GF commands, one per line.
|
||||
Unrecognized command lines are skipped without terminating GF.
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ December 2010 for GF 3.2
|
||||
% txt2tags --toc -ttex gf-tutorial.txt
|
||||
|
||||
%!target:html
|
||||
%!encoding: utf-8
|
||||
%!encoding: iso-8859-1
|
||||
%!options: --toc
|
||||
|
||||
%!postproc(tex) : "\\subsection\*" "\\newslide"
|
||||
@@ -836,8 +836,8 @@ Finnish and an Italian concrete syntaxes:
|
||||
lin
|
||||
Hello recip = {s = "terve" ++ recip.s} ;
|
||||
World = {s = "maailma"} ;
|
||||
Mum = {s = "äiti"} ;
|
||||
Friends = {s = "ystävät"} ;
|
||||
Mum = {s = "äiti"} ;
|
||||
Friends = {s = "ystävät"} ;
|
||||
}
|
||||
|
||||
concrete HelloIta of Hello = {
|
||||
@@ -925,7 +925,7 @@ Default of the language flag (``-lang``): the last-imported concrete syntax.
|
||||
**Multilingual generation**:
|
||||
```
|
||||
> parse -lang=HelloEng "hello friends" | linearize
|
||||
terve ystävät
|
||||
terve ystävät
|
||||
ciao amici
|
||||
hello friends
|
||||
```
|
||||
@@ -1335,7 +1335,7 @@ Just (?) replace English words with their dictionary equivalents:
|
||||
Phrase, Item, Kind, Quality = {s : Str} ;
|
||||
|
||||
lin
|
||||
Is item quality = {s = item.s ++ "è" ++ quality.s} ;
|
||||
Is item quality = {s = item.s ++ "č" ++ quality.s} ;
|
||||
This kind = {s = "questo" ++ kind.s} ;
|
||||
That kind = {s = "quel" ++ kind.s} ;
|
||||
QKind quality kind = {s = kind.s ++ quality.s} ;
|
||||
@@ -1446,11 +1446,11 @@ linearizations in different languages:
|
||||
> gr -number=2 | l -treebank
|
||||
|
||||
Is (That Cheese) (Very Boring)
|
||||
quel formaggio è molto noioso
|
||||
quel formaggio č molto noioso
|
||||
that cheese is very boring
|
||||
|
||||
Is (That Cheese) Fresh
|
||||
quel formaggio è fresco
|
||||
quel formaggio č fresco
|
||||
that cheese is fresh
|
||||
```
|
||||
|
||||
@@ -1472,14 +1472,14 @@ answer given in another language.
|
||||
You can interrupt the quiz by entering a line consisting of a dot ('.').
|
||||
|
||||
this fish is warm
|
||||
questo pesce è caldo
|
||||
questo pesce č caldo
|
||||
> Yes.
|
||||
Score 1/1
|
||||
|
||||
this cheese is Italian
|
||||
questo formaggio è noioso
|
||||
> No, not questo formaggio è noioso, but
|
||||
questo formaggio è italiano
|
||||
questo formaggio č noioso
|
||||
> No, not questo formaggio č noioso, but
|
||||
questo formaggio č italiano
|
||||
|
||||
Score 1/2
|
||||
this fish is expensive
|
||||
@@ -1756,7 +1756,7 @@ Simultaneous extension and opening:
|
||||
lincat
|
||||
Question = SS ;
|
||||
lin
|
||||
QIs item quality = ss (item.s ++ "è" ++ quality.s) ;
|
||||
QIs item quality = ss (item.s ++ "č" ++ quality.s) ;
|
||||
Pizza = ss "pizza" ;
|
||||
}
|
||||
```
|
||||
@@ -2364,10 +2364,10 @@ in English, with special care taken of variations with the suffix
|
||||
|
||||
+ Implement the German **Umlaut** operation on word stems.
|
||||
The operation changes the vowel of the stressed stem syllable as follows:
|
||||
//a// to //ä//, //au// to //äu//, //o// to //ö//, and //u// to //ü//. You
|
||||
//a// to //ä//, //au// to //äu//, //o// to //ö//, and //u// to //ü//. You
|
||||
can assume that the operation only takes syllables as arguments. Test the
|
||||
operation to see whether it correctly changes //Arzt// to //Ärzt//,
|
||||
//Baum// to //Bäum//, //Topf// to //Töpf//, and //Kuh// to //Küh//.
|
||||
operation to see whether it correctly changes //Arzt// to //Ärzt//,
|
||||
//Baum// to //Bäum//, //Topf// to //Töpf//, and //Kuh// to //Küh//.
|
||||
|
||||
|
||||
|
||||
@@ -2480,10 +2480,10 @@ The command ``morpho_quiz = mq`` generates inflection exercises.
|
||||
Welcome to GF Morphology Quiz.
|
||||
...
|
||||
|
||||
réapparaître : VFin VCondit Pl P2
|
||||
réapparaitriez
|
||||
> No, not réapparaitriez, but
|
||||
réapparaîtriez
|
||||
réapparaître : VFin VCondit Pl P2
|
||||
réapparaitriez
|
||||
> No, not réapparaitriez, but
|
||||
réapparaîtriez
|
||||
Score 0/1
|
||||
```
|
||||
To create a list for later use, use the command ``morpho_list = ml``
|
||||
@@ -2563,7 +2563,7 @@ We need only number variation for the copula.
|
||||
```
|
||||
copula : Number -> Str =
|
||||
\n -> case n of {
|
||||
Sg => "è" ;
|
||||
Sg => "č" ;
|
||||
Pl => "sono"
|
||||
} ;
|
||||
```
|
||||
@@ -3305,13 +3305,13 @@ we can write a **functor instantiation**,
|
||||
oper
|
||||
wine_N = mkN "Wein" ;
|
||||
pizza_N = mkN "Pizza" "Pizzen" feminine ;
|
||||
cheese_N = mkN "Käse" "Käsen" masculine ;
|
||||
cheese_N = mkN "Käse" "Käsen" masculine ;
|
||||
fish_N = mkN "Fisch" ;
|
||||
fresh_A = mkA "frisch" ;
|
||||
warm_A = mkA "warm" "wärmer" "wärmste" ;
|
||||
warm_A = mkA "warm" "wärmer" "wärmste" ;
|
||||
italian_A = mkA "italienisch" ;
|
||||
expensive_A = mkA "teuer" ;
|
||||
delicious_A = mkA "köstlich" ;
|
||||
delicious_A = mkA "köstlich" ;
|
||||
boring_A = mkA "langweilig" ;
|
||||
}
|
||||
```
|
||||
@@ -3362,11 +3362,11 @@ Lexicon instance
|
||||
cheese_N = mkN "juusto" ;
|
||||
fish_N = mkN "kala" ;
|
||||
fresh_A = mkA "tuore" ;
|
||||
warm_A = mkA "lämmin" ;
|
||||
warm_A = mkA "lämmin" ;
|
||||
italian_A = mkA "italialainen" ;
|
||||
expensive_A = mkA "kallis" ;
|
||||
delicious_A = mkA "herkullinen" ;
|
||||
boring_A = mkA "tylsä" ;
|
||||
boring_A = mkA "tylsä" ;
|
||||
}
|
||||
```
|
||||
Functor instantiation
|
||||
@@ -3626,7 +3626,7 @@ Goals:
|
||||
- semantic definitions
|
||||
|
||||
These concepts are inherited from **type theory** (more precisely:
|
||||
constructive type theory, or Martin-Löf type theory).
|
||||
constructive type theory, or Martin-Löf type theory).
|
||||
|
||||
Type theory is the basis **logical frameworks**.
|
||||
|
||||
@@ -4639,7 +4639,7 @@ output. Therefore it can be a part of a pipe and read and write files.
|
||||
The simplest way to translate is to ``echo`` input to the program:
|
||||
```
|
||||
% echo "this wine is delicious" | ./trans Food.pgf
|
||||
questo vino è delizioso
|
||||
questo vino č delizioso
|
||||
```
|
||||
The result is given in all languages except the input language.
|
||||
|
||||
|
||||
13
doc/txt2html.sh
Normal file
13
doc/txt2html.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
FILES="darcs.txt transfer-reference.txt transfer-tutorial.txt \
|
||||
transfer.txt"
|
||||
|
||||
for f in $FILES; do
|
||||
h=`basename "$f" ".txt"`.html
|
||||
if [ "$f" -nt "$h" ]; then
|
||||
txt2tags $f
|
||||
else
|
||||
echo "$h is newer than $f, skipping"
|
||||
fi
|
||||
done
|
||||
@@ -1,6 +1,10 @@
|
||||
GF character encoding changes
|
||||
Thomas Hallgren
|
||||
2013-12-18
|
||||
%%mtime(%F)
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TITLE> <meta charset="UTF-8"><meta name = "viewport" content = "width = device-width"> <TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
==Changes to character encodings in GF grammar files ==
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ GF 3.1.6 released 23 April 2010.
|
||||
- Windows (zipped executable):
|
||||
[``gf-3.1.6-bin-i486-windows.zip`` gf-3.1.6-bin-i486-windows.zip]
|
||||
(1.6 MB)
|
||||
- Ubuntu Linux (gzipped executable):
|
||||
- Ubuntu Linux (gzipped executable):
|
||||
[``gf-3.1.6-bin-i486-linux.gz`` gf-3.1.6-bin-i486-linux.gz]
|
||||
(1.7 MB)
|
||||
- compiled library package:
|
||||
@@ -25,7 +25,7 @@ GF 3.1.6 released 23 April 2010.
|
||||
- full source package (GF system, libraries, examples, documentation):
|
||||
[``gf-3.1.6-src.tar.gz`` gf-3.1.6-src.tar.gz]
|
||||
(11 MB)
|
||||
|
||||
|
||||
GF is also on [Hackage http://hackage.haskell.org/package/gf]
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ What's new? See the [release notes release-3.1.6.html].
|
||||
==Installation instructions==
|
||||
|
||||
|
||||
The Windows package is installed by just unpacking it anywhere.
|
||||
The Windows package is installed by just unpacking it anywhere.
|
||||
It finds the libraries relative to the ``.exe`` file.
|
||||
|
||||
To install a binary package for MacOS X or Linux: uncompress the executable and
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TD><B> <TH>
|
||||
%!postproc(html): </B></TD> </TH>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
**GF 3.2.9** source-only snapshot was released on 12 September 2011.
|
||||
|
||||
What's new? Faster grammar compilation!
|
||||
@@ -72,3 +77,9 @@ The above notes for installing from source apply also in this case.
|
||||
- [GF 3.2 index-3.2.html] (December 2011).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TD><B> <TH>
|
||||
%!postproc(html): </B></TD> </TH>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
**GF 3.2** was released on 23 December 2010.
|
||||
|
||||
What's new? See the [Release notes release-3.2.html].
|
||||
@@ -22,7 +27,7 @@ More packages might be added later.
|
||||
|
||||
===Notes===
|
||||
|
||||
The Windows package is installed by just unpacking it anywhere.
|
||||
The Windows package is installed by just unpacking it anywhere.
|
||||
It finds the libraries relative to the ``.exe`` file.
|
||||
|
||||
The ``.deb`` packages work on Ubuntu 10.04 and 10.10.
|
||||
@@ -100,3 +105,8 @@ Subsequently:
|
||||
```
|
||||
|
||||
The above notes for installing from source apply also in this case.
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <TD><B> <TH>
|
||||
%!postproc(html): </B></TD> </TH>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
**GF 3.3.3** was released on 3 March 2012.
|
||||
|
||||
What's new? See the [Release notes release-3.3.3.html].
|
||||
@@ -18,7 +24,7 @@ What's new? See the [Release notes release-3.3.3.html].
|
||||
|
||||
===Notes===
|
||||
|
||||
The Windows package is installed by just unpacking it anywhere.
|
||||
The Windows package is installed by just unpacking it anywhere.
|
||||
It finds the libraries relative to the ``.exe`` file.
|
||||
|
||||
%The ``.deb`` packages work on Ubuntu 10.04 and 10.10.
|
||||
@@ -121,3 +127,9 @@ For more info, see the [GF Developers Guide ../doc/gf-developers.html].
|
||||
- [GF 3.2 index-3.2.html] (December 2010).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TD><B> <TH>
|
||||
%!postproc(html): </B></TD> </TH>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
**GF 3.3** was released on 27 October 2011.
|
||||
|
||||
What's new? See the [Release notes release-3.3.html].
|
||||
@@ -22,7 +27,7 @@ More packages might be added later.
|
||||
|
||||
===Notes===
|
||||
|
||||
The Windows package is installed by just unpacking it anywhere.
|
||||
The Windows package is installed by just unpacking it anywhere.
|
||||
It finds the libraries relative to the ``.exe`` file.
|
||||
|
||||
%The ``.deb`` packages work on Ubuntu 10.04 and 10.10.
|
||||
@@ -110,3 +115,9 @@ The above notes for installing from source apply also in this case.
|
||||
- [GF 3.2 index-3.2.html] (December 2010).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): </HEAD> <STYLE>body { color: #333; } li>code,p>code,pre { color: #730; }</STYLE></HEAD>
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <TD><B> <TH>
|
||||
%!postproc(html): </B></TD> </TH>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
**GF 3.4** was released on 31 January 2013.
|
||||
|
||||
What's new? See the [Release notes release-3.4.html].
|
||||
@@ -13,11 +20,14 @@ What's new? See the [Release notes release-3.4.html].
|
||||
| Fedora (32-bit) | [Fedora RPMs /~hallgren/tmp/Fedora/] | ``sudo rpm -i ...``
|
||||
| Ubuntu (32-bit) | [gf_3.4-1_i386.deb gf_3.4-1_i386.deb] | ``sudo dpkg -i gf_3.4-1_i386.deb``
|
||||
| Ubuntu (64-bit) | [gf_3.4-1_amd64.deb gf_3.4-1_amd64.deb] | ``sudo dpkg -i gf_3.4-1_amd64.deb``
|
||||
| Windows | [gf-3.4-bin-windows.zip gf-3.4-bin-windows.zip] | -
|
||||
| Windows | [gf-3.4-bin-windows.zip gf-3.4-bin-windows.zip] |
|
||||
%| ... | ... | ...
|
||||
|
||||
%More binary packages might be added later.
|
||||
|
||||
===Notes===
|
||||
|
||||
%The Windows package is installed by just unpacking it anywhere.
|
||||
%The Windows package is installed by just unpacking it anywhere.
|
||||
%It finds the libraries relative to the ``.exe`` file.
|
||||
|
||||
The ``.deb`` packages work on Ubuntu 12.04, 12.10 and 13.04.
|
||||
@@ -143,3 +153,8 @@ For more info on working with the GF source code, see the
|
||||
- [GF 3.2 index-3.2.html] (December 2010).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): </HEAD> <STYLE>body { color: #333; } li>code,p>code,pre { color: #730; }</STYLE></HEAD>
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <TD><B> <TH>
|
||||
%!postproc(html): </B></TD> </TH>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
**GF 3.5** was released on 6 August 2013.
|
||||
|
||||
What's new? See the [Release notes release-3.5.html].
|
||||
@@ -150,3 +157,8 @@ For more info on working with the GF source code, see the
|
||||
- [GF 3.2 index-3.2.html] (December 2010).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): </HEAD> <STYLE>body { color: #333; } li>code,p>code,pre { color: #730; }</STYLE></HEAD>
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
%!postproc(html): <TD><I> <TD><small>
|
||||
%!postproc(html): </I></TD> </small></TD>
|
||||
|
||||
**GF 3.6** was released on 23 June 2014.
|
||||
|
||||
What's new? See the [Release notes release-3.6.html].
|
||||
@@ -170,3 +177,8 @@ For more info on working with the GF source code, see the
|
||||
- [GF 3.2 index-3.2.html] (December 2010).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/notes.css
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
%!postproc(html): <TD><I> <TD><small>
|
||||
%!postproc(html): </I></TD> </small></TD>
|
||||
|
||||
**GF 3.7.1** was released on 2 October 2015.
|
||||
|
||||
What's new? See the [Release notes release-3.7.1.html].
|
||||
@@ -40,7 +46,7 @@ The ``.deb`` packages work on Ubuntu 12.04, 14.04 and 15.04.
|
||||
|
||||
The packages for Mac OS X should work on at least 10.9, 10.10 and 10.11 (Mavericks, Yosemite and El Capitan).
|
||||
|
||||
(*) **Note** that for compatibility with OS X 10.11,
|
||||
(*) **Note** that for compatibility with OS X 10.11,
|
||||
``gf-3.7.1.pkg`` will install the ``gf`` executable in ``/usr/local/bin``
|
||||
instead of ``/usr/bin``, so make sure ``/usr/local/bin`` is in your ``$PATH``.
|
||||
Also, if you still have an older version of GF installed in ``/usr/bin``,
|
||||
@@ -174,3 +180,8 @@ For more info on working with the GF source code, see the
|
||||
- [GF 3.2 index-3.2.html] (December 2010).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): </HEAD> <STYLE>body { color: #333; } li>code,p>code,pre { color: #730; }</STYLE></HEAD>
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
%!postproc(html): <TD><I> <TD><small>
|
||||
%!postproc(html): </I></TD> </small></TD>
|
||||
|
||||
**GF 3.7** was released on 25 June 2015.
|
||||
|
||||
What's new? See the [Release notes release-3.7.html].
|
||||
@@ -166,3 +173,8 @@ For more info on working with the GF source code, see the
|
||||
- [GF 3.2 index-3.2.html] (December 2010).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/notes.css
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
%!postproc(html): <TD><I> <TD><small>
|
||||
%!postproc(html): </I></TD> </small></TD>
|
||||
|
||||
**GF 3.8** was released on 22 June 2016.
|
||||
|
||||
What's new? See the [Release notes release-3.8.html].
|
||||
@@ -43,7 +49,7 @@ Linux distributions.
|
||||
|
||||
The packages for Mac OS X should work on at least 10.9, 10.10 and 10.11 (Mavericks, Yosemite and El Capitan).
|
||||
|
||||
(*) **Note** that for compatibility with OS X 10.11,
|
||||
(*) **Note** that for compatibility with OS X 10.11,
|
||||
``gf-3.8.pkg`` will install the ``gf`` executable in ``/usr/local/bin``
|
||||
instead of ``/usr/bin``, so make sure ``/usr/local/bin`` is in your ``$PATH``.
|
||||
Also, if you still have an older version of GF installed in ``/usr/bin``,
|
||||
@@ -165,3 +171,8 @@ For more info on working with the GF source code, see the
|
||||
- [GF 3.2 index-3.2.html] (December 2010).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,184 +0,0 @@
|
||||
---
|
||||
title: Grammatical Framework Download and Installation
|
||||
...
|
||||
|
||||
**GF 3.10** was released on 2 December 2018.
|
||||
It is the first version of GF which _does not include the RGL_.
|
||||
|
||||
What's new? See the [release notes](release-3.10.html).
|
||||
|
||||
## Binary packages
|
||||
|
||||
| Platform | Download | Features | How to install |
|
||||
|:----------------|:---------------------------------------------------|:---------------|:-----------------------------------|
|
||||
| macOS | [gf-3.10.pkg](gf-3.10.pkg) | GF, S, C, J, P | Double-click on the package icon |
|
||||
| Ubuntu (64-bit) | [gf\_3.10-1\_amd64.deb](gf_3.10-1_amd64.deb) | GF, S, C, J, P | `sudo dpkg -i gf_3.10-1_amd64.deb` |
|
||||
| Windows | [gf-3.10-bin-windows.zip](gf-3.10-bin-windows.zip) | GF, S | `unzip gf-3.10-bin-windows.zip` |
|
||||
|
||||
<!--
|
||||
| macOS | [gf-3.10-bin-intel-mac.tar.gz](gf-3.10-bin-intel-mac.tar.gz) | GF,S,C,J,P | `sudo tar -C /usr/local -zxf gf-3.10-bin-intel-mac.tar.gz` |
|
||||
| Raspbian 9.1 | [gf\_3.10-1\_armhf.deb](gf_3.10-1_armhf.deb) | GF,S,C,J,P | `sudo dpkg -i gf_3.10-1_armhf.deb` |
|
||||
| Ubuntu (32-bit) | [gf\_3.10-1\_i386.deb](gf_3.10-1_i386.deb) | GF,S,C,J,P | `sudo dpkg -i gf_3.10-1_i386.deb` |
|
||||
-->
|
||||
|
||||
**Features**
|
||||
|
||||
- GF = GF shell and grammar compiler
|
||||
- S = `gf -server` mode
|
||||
- C = C run-time system
|
||||
- J/P = Java/Python binding to the C run-time system
|
||||
|
||||
### Notes
|
||||
|
||||
The Windows package is installed by just unpacking it anywhere. You will
|
||||
probably need to set the `PATH` and `GF_LIB_PATH` environment variables,
|
||||
see Inari's notes on [Installing GF on Windows](http://www.grammaticalframework.org/~inari/gf-windows.html#toc3).
|
||||
|
||||
The Ubuntu `.deb` packages should work on Ubuntu 16.04 and 18.04 and
|
||||
similar Linux distributions.
|
||||
|
||||
<!-- The Raspbian `.deb` package was created on a Raspberry Pi 3 and will
|
||||
probably work on other ARM-based systems running Debian 9 (stretch) or
|
||||
similar Linux distributions. -->
|
||||
|
||||
The packages for macOS (Mac OS X) should work on at least 10.13 and
|
||||
10.14 (High Sierra and Mojave)
|
||||
|
||||
<!-- The Mac OS and Linux `.tar.gz` packages are designed to be installed in
|
||||
`/usr/local`. You can install them in other locations, but then you need
|
||||
to set the `GF_LIB_PATH` environment variable:
|
||||
|
||||
```
|
||||
export GF_LIB_PATH=/usr/local/share/gf-3.10/lib
|
||||
```
|
||||
|
||||
where `/usr/local` should be replaced with the path to the location
|
||||
where you unpacked the package. -->
|
||||
|
||||
## Installing the latest release from source
|
||||
|
||||
[GF is on Hackage](http://hackage.haskell.org/package/gf), so under
|
||||
normal circumstances the procedure is fairly simple:
|
||||
|
||||
1. Install a recent version of the [Haskell
|
||||
Platform](http://hackage.haskell.org/platform) (see note below)
|
||||
2. `cabal update`
|
||||
3. On Linux: install some C libraries from your Linux distribution (see note below)
|
||||
4. `cabal install gf`
|
||||
|
||||
Note that this installs GF _without_ the RGL.
|
||||
|
||||
You can also download full source packages from GitHub at the following links:
|
||||
|
||||
- [GF releases](https://github.com/GrammaticalFramework/gf-core/releases)
|
||||
- [RGL releases](https://github.com/GrammaticalFramework/gf-rgl/releases)
|
||||
|
||||
### Notes
|
||||
|
||||
**Installation location**
|
||||
|
||||
The above steps installs GF for a single user. The executables are put
|
||||
in `$HOME/.cabal/bin` (or, with recent versions of the Haskell platform
|
||||
on Mac OS X, in `$HOME/Library/Haskell/bin`), so it is a good idea to
|
||||
put a line in your `.bash_profile` or `.profile` to add that directory
|
||||
to you path:
|
||||
|
||||
```
|
||||
PATH=$HOME/.cabal/bin:$PATH
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
PATH=$HOME/Library/Haskell/bin:$PATH
|
||||
```
|
||||
|
||||
**Build tools**
|
||||
|
||||
In order to compile GF you need the build tools **Alex** and **Happy**.
|
||||
These can be installed via Cabal, e.g.:
|
||||
|
||||
```
|
||||
cabal install alex happy
|
||||
```
|
||||
|
||||
or obtained by other means, depending on your OS.
|
||||
|
||||
**Haskeline**
|
||||
|
||||
GF uses [`haskeline`](http://hackage.haskell.org/package/haskeline), which
|
||||
on Linux depends on some non-Haskell libraries that won't be installed
|
||||
automatically by cabal, and therefore need to be installed manually.
|
||||
Here is one way to do this:
|
||||
|
||||
- On Ubuntu: `sudo apt-get install libghc-haskeline-dev`
|
||||
- On Fedora: `sudo yum install ghc-haskeline-devel`
|
||||
|
||||
**GHC version**
|
||||
|
||||
The GF source code has been updated to compile with GHC 8.4.
|
||||
Using older versions of GHC (e.g. 8.2, 8.0 and 7.10) should still work too.
|
||||
|
||||
## Installing from the latest developer source code
|
||||
|
||||
If you haven't already, clone the repository with:
|
||||
|
||||
```
|
||||
git clone https://github.com/GrammaticalFramework/gf-core.git
|
||||
```
|
||||
|
||||
If you've already cloned the repository previously, update with:
|
||||
|
||||
```
|
||||
git pull
|
||||
```
|
||||
|
||||
Then install with:
|
||||
|
||||
```
|
||||
cabal install
|
||||
```
|
||||
|
||||
or, if you're a Stack user:
|
||||
|
||||
```
|
||||
stack install
|
||||
```
|
||||
|
||||
The above notes for installing from source apply also in these cases.
|
||||
For more info on working with the GF source code, see the
|
||||
[GF Developers Guide](../doc/gf-developers.html).
|
||||
|
||||
## Installing the RGL from source
|
||||
|
||||
To install the RGL from source,
|
||||
you can download a release from [GitHub](https://github.com/GrammaticalFramework/gf-rgl/releases)
|
||||
or get the latest version by cloning the repository:
|
||||
|
||||
```
|
||||
git clone https://github.com/GrammaticalFramework/gf-rgl.git
|
||||
```
|
||||
|
||||
In both cases, once you have the RGL sources you can install them by running:
|
||||
|
||||
```
|
||||
make
|
||||
```
|
||||
|
||||
in the RGL folder.
|
||||
For more details about building the RGL, see the [RGL README](https://github.com/GrammaticalFramework/gf-rgl/blob/master/README.md).
|
||||
|
||||
## Older releases
|
||||
|
||||
- [GF 3.9](index-3.9.html) (August 2017)
|
||||
- [GF 3.8](index-3.8.html) (June 2016)
|
||||
- [GF 3.7.1](index-3.7.1.html) (October 2015)
|
||||
- [GF 3.7](index-3.7.html) (June 2015)
|
||||
- [GF 3.6](index-3.6.html) (June 2014)
|
||||
- [GF 3.5](index-3.5.html) (August 2013)
|
||||
- [GF 3.4](index-3.4.html) (January 2013)
|
||||
- [GF 3.3.3](index-3.3.3.html) (March 2012)
|
||||
- [GF 3.3](index-3.3.html) (October 2011)
|
||||
- [GF 3.2.9](index-3.2.9.html) source-only snapshot (September 2011)
|
||||
- [GF 3.2](index-3.2.html) (December 2010)
|
||||
- [GF 3.1.6](index-3.1.6.html) (April 2010)
|
||||
@@ -1,6 +1,12 @@
|
||||
Grammatical Framework Download and Installation
|
||||
|
||||
|
||||
%!style:../css/notes.css
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
%!postproc(html): <TD><I> <TD><small>
|
||||
%!postproc(html): </I></TD> </small></TD>
|
||||
|
||||
**GF 3.9** was released on 11 August 2017.
|
||||
|
||||
What's new? See the [Release notes release-3.9.html].
|
||||
@@ -12,11 +18,10 @@ What's new? See the [Release notes release-3.9.html].
|
||||
| macOS | [gf-3.9.pkg gf-3.9.pkg] | //GF+S+C+J+P// | Double-click on the package icon
|
||||
| macOS | [gf-3.9-bin-intel-mac.tar.gz gf-3.9-bin-intel-mac.tar.gz] | //GF+S+C+J+P// | ``sudo tar -C /usr/local -zxf gf-3.9-bin-intel-mac.tar.gz``
|
||||
%| Fedora (32-bit) | [Fedora RPMs /~hallgren/tmp/Fedora/] | //GF+S+C+J+P// | ``sudo rpm -i ...``
|
||||
| Raspbian 9.1 | [gf_3.9-1_armhf.deb gf_3.9-1_armhf.deb] | //GF+S+C+J+P// | ``sudo dpkg -i gf_3.9-1_armhf.deb``
|
||||
| Raspian 9.1 | [gf_3.9-1_armhf.deb gf_3.9-1_armhf.deb] | //GF+S+C+J+P// | ``sudo dpkg -i gf_3.9-1_armhf.deb``
|
||||
| Ubuntu (32-bit) | [gf_3.9-1_i386.deb gf_3.9-1_i386.deb] | //GF+S+C+J+P// | ``sudo dpkg -i gf_3.9-1_i386.deb``
|
||||
| Ubuntu (64-bit) | [gf_3.9-1_amd64.deb gf_3.9-1_amd64.deb] | //GF+S+C+J+P// | ``sudo dpkg -i gf_3.9-1_amd64.deb``
|
||||
| Windows | [gf-3.9-bin-windows.zip gf-3.9-bin-windows.zip] | //GF+S// | ``unzip gf-3.9-bin-windows.zip``
|
||||
|
||||
%| MINGW | [gf-3.9-bin-i686-MINGW32_NT-6.1.tar.gz gf-3.9-bin-i686-MINGW32_NT-6.1.tar.gz] | //GF+S+C// | ``tar -C / gf-3.9-bin-i686-MINGW32_NT-6.1.tar.gz``
|
||||
%| ... | ... | ... | ...
|
||||
|
||||
@@ -171,11 +176,6 @@ The above notes for installing from source apply also in these cases.
|
||||
For more info on working with the GF source code, see the
|
||||
[GF Developers Guide ../doc/gf-developers.html].
|
||||
|
||||
==Using Stack==
|
||||
|
||||
You can also use [Stack https://www.haskellstack.org] to compile GF, just replace ``cabal install`` above
|
||||
with ``stack install`` (assuming you already have Stack set up).
|
||||
|
||||
==Older releases==
|
||||
|
||||
- [GF 3.8 index-3.8.html] (June 2016)
|
||||
@@ -190,3 +190,8 @@ with ``stack install`` (assuming you already have Stack set up).
|
||||
- [GF 3.2 index-3.2.html] (December 2010).
|
||||
- [GF 3.1.6 index-3.1.6.html] (April 2010).
|
||||
- [GF 3.1 old-index.html] (December 2009).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
@@ -5,13 +5,13 @@ GF Version 3.1.6 Release Notes
|
||||
=Installation=
|
||||
|
||||
The binaries now work out of the box for each platform and support
|
||||
completions (file names and parsing), because readline has been
|
||||
completions (file names and parsing), because readline has been
|
||||
changed to haskeline.
|
||||
|
||||
To compile from source, GHC 6.12 is now required. But GHC is not needed
|
||||
if the binary executables are used.
|
||||
|
||||
Binaries (``.gfo`` and ``.pgf`` files) compiled with GF 3.1 are incompatible
|
||||
Binaries (``.gfo`` and ``.pgf`` files) compiled with GF 3.1 are incompatible
|
||||
with 3.1.6 and must either be removed; alternatively, the ``-src`` flag can be
|
||||
used when compiling.
|
||||
|
||||
@@ -24,8 +24,8 @@ Grammar language
|
||||
- improved support for dependent types (see ``SUMO``, ``nqueens`` in ``examples``)
|
||||
|
||||
|
||||
Shell commands and options (see ``help`` in GF for more information)
|
||||
- ``eb``: example-based grammar file conversion
|
||||
Shell commands and options (see ``help`` in GF for more information)
|
||||
- ``eb``: example-based grammar file conversion
|
||||
(see ``examples/animals/QuestionI.gf``)
|
||||
- ``vd = visualize_dependency``: show dependency tree
|
||||
- ``vp = visualize_parse``: show parse tree
|
||||
@@ -57,3 +57,8 @@ Internal
|
||||
|
||||
Javascript generation is not updated to the new PGF format.
|
||||
[GF 3.1 old-index.html] should still be used for building Javascript applications.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
---
|
||||
title: GF 3.10 Release Notes
|
||||
date: 2 December 2018
|
||||
...
|
||||
|
||||
## Installation
|
||||
|
||||
See the [download page](index.html).
|
||||
|
||||
## What's new
|
||||
|
||||
- In this release, the GF "core" (compiler and runtimes) have been split from the RGL.
|
||||
|
||||
### Other
|
||||
|
||||
- A lot of repository cleanup
|
||||
@@ -1,6 +1,9 @@
|
||||
GF Version 3.2 Release Notes
|
||||
December 2010
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <H1> <H1><IMG src="../doc/Logos/gf0.png">
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
@@ -31,3 +34,8 @@ See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
|
||||
- GF compiler: GPL
|
||||
- Run-time libraries and Resource Grammar Library: LGPL + BSD
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
GF Version 3.3.3 Release Notes
|
||||
March 2012
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <H1> <H1><IMG src="../doc/Logos/gf0.png">
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
@@ -21,3 +25,8 @@ See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
- Fix for a bug that prevented the shell commands ``abstract_info``,
|
||||
``generate_random`` and ``generate_trees`` from working properly.
|
||||
- Various other small improvements and bug fixes.
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
GF Version 3.3 Release Notes
|
||||
October 2011
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TITLE> <meta name = "viewport" content = "width = device-width"><TITLE>
|
||||
%!postproc(html): <H1> <H1><IMG src="../doc/Logos/gf0.png">
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
|
||||
==New features==
|
||||
|
||||
- Source language extension: it is now possible to override the oper definitions in an interface, by using the
|
||||
- Source language extension: it is now possible to override the oper definitions in an interface, by using the
|
||||
header syntax ``instance Foo of Bar - [f,g,h]``.
|
||||
- New functionalities in GF shell commands (more information with ``help`` command-name).
|
||||
- ``aw`` = ``align_words`` option ``-giza`` prints word alignments in Giza++ format.
|
||||
@@ -25,3 +29,8 @@ See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
and the web-based grammar editor.
|
||||
- Faster grammar compilation (also included in the GF 3.2.9 source-only
|
||||
snapshot).
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
GF Version 3.4 Release Notes
|
||||
January 2013
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TITLE> <meta charset="UTF-8"><meta name = "viewport" content = "width = device-width"> <TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
@@ -42,3 +46,8 @@ See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
- Some new functionality in the web-based grammar editor, e.g. preliminary
|
||||
support for public grammars.
|
||||
- Various other small improvements and bug fixes.
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
GF 3.5 Release Notes
|
||||
August 2013
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TITLE> <meta charset="UTF-8"><meta name = "viewport" content = "width = device-width"> <TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
@@ -66,3 +70,7 @@ of GF 3.4.
|
||||
[``network-2.4.1.1`` https://github.com/haskell/network/commit/f2168b1f8978b4ad9c504e545755f0795ac869ce].
|
||||
- Various other small improvements and bug fixes.
|
||||
%- [...]
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
GF 3.6 Release Notes
|
||||
June 2014
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TITLE> <meta charset="UTF-8"><meta name = "viewport" content = "width = device-width"> <TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
@@ -22,7 +26,7 @@ Closed [issues http://code.google.com/p/grammatical-framework/issues/list]:
|
||||
as ``--# -coding=``//enc//, instead of ``flags coding=``//enc//.
|
||||
See the separate document
|
||||
[GF character encoding changes encoding-change.html] for more details.
|
||||
- Record update: in record objects (but not types) of form ``r ** s``, the values assigned
|
||||
- Record update: in record objects (but not types) of form ``r ** s``, the values assigned
|
||||
in ``s`` now overwrite those in ``r``. In previous versions, record extensions with
|
||||
overlapping assignments in ``r`` and ``s`` were not supported, and their behaviour was
|
||||
unpredictable.
|
||||
@@ -103,3 +107,8 @@ Closed [issues http://code.google.com/p/grammatical-framework/issues/list]:
|
||||
- ``c-wordforword``: this works as ``c-translate`` but does a
|
||||
word-for-word lookup to create a (potentially very low quality)
|
||||
translation that can be used if all else fails.
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
GF 3.7.1 Release Notes
|
||||
October 2015
|
||||
|
||||
%!style:../css/notes.css
|
||||
%!postproc(html): <TITLE> <meta charset="UTF-8"><meta name = "viewport" content = "width = device-width"> <TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
@@ -14,10 +18,10 @@ Over 170 changes have been pushed to the source repository since
|
||||
|
||||
====New features and notable changes====
|
||||
|
||||
- GF shell: ``cc -trace`` (preliminary): you can now do things like
|
||||
|
||||
- GF shell: ``cc -trace`` (preliminary): you can now do things like
|
||||
|
||||
``cc -trace mkV "debug"``
|
||||
|
||||
|
||||
to see a trace of all opers with their arguments and results during the
|
||||
computation of ``mkV "debug"``.
|
||||
|
||||
@@ -25,7 +29,7 @@ Over 170 changes have been pushed to the source repository since
|
||||
from the GF shell by starting GF with ``gf -cshell`` or ``gf -crun``.
|
||||
Only limited functionality is available when running the shell in these
|
||||
modes (use the ``help`` command in the shell for details):
|
||||
|
||||
|
||||
- You can only import ``.pgf`` files, not source files.
|
||||
- The ``-retain`` flag can not be used and the commands that require it to
|
||||
work are not available.
|
||||
@@ -73,3 +77,8 @@ Over 170 changes have been pushed to the source repository since
|
||||
you can leave ``&+`` uninterpreted instead of gluing the adjacent tokens.
|
||||
This means that the output is left in a format that can be parsed in
|
||||
a subsequent request.
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
GF 3.7 Release Notes
|
||||
June 2015
|
||||
|
||||
%!style:../css/style.css
|
||||
%!postproc(html): <TITLE> <meta charset="UTF-8"><meta name = "viewport" content = "width = device-width"> <TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
@@ -36,7 +40,7 @@ Over 800 changes have been pushed to the source repository since
|
||||
``BIND``, ``SOFT_BIND``, ``SOFT_SPACE``, ``CAPIT``, ``ALL_CAPIT`` and
|
||||
``nonExist``.
|
||||
- It is now possible to define callbacks for literals from the Haskell
|
||||
binding to the C runtime. This is used for instance in
|
||||
binding to the C runtime. This is used for instance in
|
||||
the Wide Coverage translator on the Web.
|
||||
|
||||
|
||||
@@ -99,3 +103,8 @@ Over 800 changes have been pushed to the source repository since
|
||||
unused for 24 hours, to keep memory use down in long running servers.
|
||||
- PGF service: limit the number of parallel calls to the C run-time parse
|
||||
function to 4 by default. The limit can be changed with the ``-j`` flag.
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
GF 3.8 Release Notes
|
||||
June 2016
|
||||
|
||||
%!style:../css/notes.css
|
||||
%!postproc(html): <TITLE> <meta charset="UTF-8"><meta name = "viewport" content = "width = device-width"> <TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
@@ -21,7 +25,7 @@ Roughly 400 changes have been pushed to the source repository since
|
||||
[universal dependency http://universaldependencies.org/] diagrams
|
||||
in various formats, see ``help vd``.
|
||||
- The C runtime now includes an experimental library for managing
|
||||
and querying ontologies built on top of the abstract syntax of
|
||||
and querying ontologies built on top of the abstract syntax of
|
||||
a grammar. Since the ontology is based on an abstract syntax,
|
||||
it is language independent by design. For now the library is
|
||||
only used in the GF Offline Translator. The library uses
|
||||
@@ -96,3 +100,7 @@ Roughly 400 changes have been pushed to the source repository since
|
||||
translations in the domain they cover.
|
||||
You can change the order in which the selected grammars are tried
|
||||
by dragging them up and down in the list.
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
GF 3.9 Release Notes
|
||||
August 2017
|
||||
|
||||
%!style:../css/notes.css
|
||||
%!postproc(html): <TITLE> <meta charset="UTF-8"><meta name = "viewport" content = "width = device-width"> <TITLE>
|
||||
%!postproc(html): <H1> <H1><a href="../"><IMG src="../doc/Logos/gf0.png"></a>
|
||||
|
||||
==Installation==
|
||||
|
||||
See the [download page http://www.grammaticalframework.org/download/index.html].
|
||||
@@ -32,7 +36,7 @@ very innefficient for some grammars.
|
||||
|
||||
- A new .NET binding for the GF runtime is available.
|
||||
|
||||
- The API in the Java binding is extended and it covers more from
|
||||
- The API in the Java binding is extended and it covers more from
|
||||
the full functionality of the C runtime.
|
||||
|
||||
|
||||
@@ -62,3 +66,8 @@ the full functionality of the C runtime.
|
||||
|
||||
- PGF service: support for language-specific depencency configurations in
|
||||
``command=deptree``.
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
[www.grammaticalframework.org http://www.grammaticalframework.org]
|
||||
|
||||
BIN
favicon.ico
BIN
favicon.ico
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
32
gf.cabal
32
gf.cabal
@@ -1,5 +1,5 @@
|
||||
name: gf
|
||||
version: 3.10
|
||||
version: 3.9-git
|
||||
|
||||
cabal-version: >= 1.22
|
||||
build-type: Custom
|
||||
@@ -11,7 +11,7 @@ description: GF, Grammatical Framework, is a programming language for multilingu
|
||||
homepage: http://www.grammaticalframework.org/
|
||||
bug-reports: https://github.com/GrammaticalFramework/gf-core/issues
|
||||
maintainer: Thomas Hallgren
|
||||
tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.3
|
||||
tested-with: GHC==7.6.3, GHC==7.8.3, GHC==7.10.3, GHC==8.0.2
|
||||
|
||||
data-dir: src
|
||||
data-files:
|
||||
@@ -42,7 +42,7 @@ data-files:
|
||||
custom-setup
|
||||
setup-depends:
|
||||
base,
|
||||
Cabal >=1.22.0.0,
|
||||
Cabal >=1.4.0.0,
|
||||
directory,
|
||||
filepath,
|
||||
process >=1.0.1.1
|
||||
@@ -67,6 +67,11 @@ flag network-uri
|
||||
-- Description: Make -new-comp the default
|
||||
-- Default: True
|
||||
|
||||
flag custom-binary
|
||||
Description: Use a customised version of the binary package
|
||||
Default: True
|
||||
Manual: True
|
||||
|
||||
flag c-runtime
|
||||
Description: Include functionality from the C run-time library (which must be installed already)
|
||||
Default: False
|
||||
@@ -84,14 +89,17 @@ Library
|
||||
exceptions
|
||||
hs-source-dirs: src/runtime/haskell
|
||||
|
||||
other-modules:
|
||||
-- not really part of GF but I have changed the original binary library
|
||||
-- and we have to keep the copy for now.
|
||||
Data.Binary
|
||||
Data.Binary.Put
|
||||
Data.Binary.Get
|
||||
Data.Binary.Builder
|
||||
Data.Binary.IEEE754
|
||||
if flag(custom-binary)
|
||||
other-modules:
|
||||
-- not really part of GF but I have changed the original binary library
|
||||
-- and we have to keep the copy for now.
|
||||
Data.Binary
|
||||
Data.Binary.Put
|
||||
Data.Binary.Get
|
||||
Data.Binary.Builder
|
||||
Data.Binary.IEEE754
|
||||
else
|
||||
build-depends: binary, data-binary-ieee754
|
||||
|
||||
--ghc-options: -fwarn-unused-imports
|
||||
--if impl(ghc>=7.8)
|
||||
@@ -141,7 +149,7 @@ Library
|
||||
|
||||
---- GF compiler as a library:
|
||||
|
||||
build-depends: filepath, directory, time, time-compat,
|
||||
build-depends: filepath, directory, time, time-compat, old-locale,
|
||||
process, haskeline, parallel>=3
|
||||
|
||||
hs-source-dirs: src/compiler
|
||||
|
||||
698
index.html
698
index.html
@@ -1,379 +1,418 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<!DOCTYPE html>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>GF - Grammatical Framework</TITLE>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="css/newstyle.css" title="GF">
|
||||
<link rel="alternate" href="https://github.com/GrammaticalFramework/gf-core/" title="GF GitHub repository">
|
||||
<meta name = "viewport" content = "width = device-width">
|
||||
<script type="text/javascript">
|
||||
function sitesearch() {
|
||||
var q=document.forms[0].q.value;
|
||||
var site=" site:www.grammaticalframework.org";
|
||||
var search=encodeURIComponent(q+site)
|
||||
document.location.href="http://www.google.com/search?q="+search
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
<meta name="keywords" content="machine translation">
|
||||
</HEAD>
|
||||
|
||||
<title>GF - Grammatical Framework</title>
|
||||
<meta name="keywords" content="machine translation">
|
||||
<body class=new>
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.2/css/all.css" integrity="sha384-/rXc/GQVaYpyDdyxK+ecHPVYJSN9bmVFBvjA/9eOB+pb3F2w2N6fc5qB9Ew5yIns" crossorigin="anonymous">
|
||||
|
||||
<link rel="alternate" href="https://github.com/GrammaticalFramework/gf-core/" title="GF GitHub repository">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container-fluid my-5" style="max-width:1200px">
|
||||
|
||||
<div class="text-center">
|
||||
<img style="height:250px" src="doc/Logos/gf1.svg" alt="GF Logo">
|
||||
<h1 class="display-4" style="text-shadow: 1px 1px 5px #999;">Grammatical Framework</h1>
|
||||
<h4 class="text-black-50">A programming language for multilingual grammar applications</h4>
|
||||
<div class="header sky blue">
|
||||
<img class="gflogo" src="doc/Logos/gf1.svg" alt="">
|
||||
<H1>Grammatical Framework</H1>
|
||||
<small class=tagline>A programming language for multilingual grammar applications</small>
|
||||
</div>
|
||||
|
||||
<div class="row my-4">
|
||||
<div class=menu>
|
||||
|
||||
<div class="col-sm-6 col-md-3">
|
||||
<h3>Get started</h3>
|
||||
<ul>
|
||||
<li><a href="https://www.youtube.com/watch?v=x1LFbDQhbso">Google Tech Talk</a></li>
|
||||
<li>
|
||||
<a href="http://cloud.grammaticalframework.org/">
|
||||
GF Cloud
|
||||
<img src="http://www.grammaticalframework.org/src/www/P/gf-cloud.png" style="height:30px" class="ml-2">
|
||||
</a>
|
||||
</li>
|
||||
<li><a href="doc/tutorial/gf-tutorial.html">Tutorial</a></li>
|
||||
</ul>
|
||||
<div class=links>
|
||||
<h4>Use GF</h4>
|
||||
<ul>
|
||||
<li><a href="http://cloud.grammaticalframework.org/">GF Cloud<img class=right src="src/www/P/gf-cloud.png" alt="GF Cloud Service" title="GF Cloud Service"></a>
|
||||
<li><A HREF="demos/index.html">Other Demos</A>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><A HREF="http://www.grammaticalframework.org/download/index.html"><b>Download GF</b></A>
|
||||
<li><a href="doc/gf-editor-modes.html">GF Editor Modes</a>
|
||||
</ul>
|
||||
|
||||
<a href="download/index.html" class="btn btn-primary ml-3">
|
||||
<i class="fas fa-download mr-1"></i>
|
||||
Download GF
|
||||
</a>
|
||||
</div>
|
||||
<ul>
|
||||
<li><A HREF="http://groups.google.com/group/gf-dev">User Group</A>
|
||||
<li><a href="https://github.com/GrammaticalFramework/gf-core/issues">Bug Reports</a>
|
||||
(<a href="http://code.google.com/p/grammatical-framework/issues/list">old</a>)
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6 col-md-3">
|
||||
<h3>Learn more</h3>
|
||||
<div class=links>
|
||||
<h4>Learn GF</h4>
|
||||
<ul>
|
||||
<li><a href="https://www.youtube.com/watch?v=x1LFbDQhbso">Google Tech Talk</a>
|
||||
<li><A HREF="doc/gf-quickstart.html">QuickStart</A>
|
||||
<li><A HREF="doc/gf-reference.html">QuickRefCard</A>
|
||||
<li><A HREF="doc/gf-shell-reference.html">GF Shell Reference</A>
|
||||
<li><a href="http://school.grammaticalframework.org/"><b>GF Summer School</b></a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><A HREF="gf-book">The GF Book</A>
|
||||
<li><A HREF="doc/tutorial/gf-tutorial.html">GF Tutorial</A>
|
||||
<li><A HREF="doc/gf-refman.html">Reference Manual</A>
|
||||
<li><A HREF="http://www.molto-project.eu/sites/default/files/MOLTO_D2.3.pdf">Best Practices</A> <small>[PDF]</small>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><A HREF="lib/doc/synopsis.html">Library Synopsis</A>
|
||||
<li><A HREF="doc/gf-lrec-2010.pdf">Library Tutorial</A> <small>[PDF]</small>
|
||||
<li><A HREF="http://www.postcrashgames.com/gf_world/">Coverage Map</A>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li><a href="gf-book">The GF Book</a></li>
|
||||
<li><a href="doc/gf-refman.html">Reference Manual</a></li>
|
||||
<li><a href="doc/gf-shell-reference.html">Shell Reference</a></li>
|
||||
<li><a href="http://www.molto-project.eu/sites/default/files/MOLTO_D2.3.pdf">Best Practices</a> <small>[PDF]</small></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class=links>
|
||||
<h4>Develop GF</h4>
|
||||
<ul>
|
||||
<li><a href="doc/gf-developers.html">GF Developers Guide</a>
|
||||
<li><A HREF="https://github.com/GrammaticalFramework/">GF on GitHub</A>
|
||||
<li><a href="/~hallgren/gf-experiment/browse/">Browse Source Code</a>
|
||||
<li><A HREF="doc/gf-people.html">Authors</A>
|
||||
</ul>
|
||||
<h4>Develop Applications</h4>
|
||||
<ul>
|
||||
<li><a href="http://hackage.haskell.org/package/gf-3.9/docs/PGF.html">PGF library API (Old Runtime)</a>
|
||||
<li><a href="doc/runtime-api.html">PGF library API (New Runtime)</a>
|
||||
<li><a href="src/ui/android/README">GF on Android (new)</a>
|
||||
<li><A HREF="/android/">GF on Android (old) </A>
|
||||
</ul>
|
||||
</div>
|
||||
<div class=links>
|
||||
<h4>Related to GF</h4>
|
||||
<ul>
|
||||
<li><A HREF="doc/gf-bibliography.html">Publications</A>
|
||||
<li><A HREF="http://remu.grammaticalframework.org/">The REMU Project</A>
|
||||
<li><A HREF="http://www.molto-project.eu">The MOLTO Project</A>
|
||||
<li><a href="http://en.wikipedia.org/wiki/Grammatical_Framework">GF on Wikipedia</a>
|
||||
<li><p><a href="Http://www.digitalgrammars.com/">Digital Grammars AB</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="lib/doc/synopsis/index.html" class="btn btn-primary ml-3">
|
||||
<i class="fab fa-readme mr-1"></i>
|
||||
RGL Synopsis
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6 col-md-3">
|
||||
<h3>Develop</h3>
|
||||
<ul>
|
||||
<li><a href="doc/gf-developers.html">Developers Guide</a></li>
|
||||
<!-- <li><a href="/~hallgren/gf-experiment/browse/">Browse Source Code</a></li> -->
|
||||
<li><a href="http://hackage.haskell.org/package/gf/docs/PGF.html">PGF library API (Haskell runtime)</a></li>
|
||||
<li><a href="doc/runtime-api.html">PGF library API (C runtime)</a></li>
|
||||
<li><a href="http://hackage.haskell.org/package/gf/docs/GF.html">GF compiler API</a></li>
|
||||
<!-- <li><a href="src/ui/android/README">GF on Android (new)</a></li>
|
||||
<li><a href="/android/">GF on Android (old) </a></li> -->
|
||||
<li><a href="doc/gf-editor-modes.html">Text Editor Support</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
document.write('<div style="float: right; margin-top: 3ex;"> <form onsubmit="return sitesearch()" method=get action="http://www.google.com/search"> <input type=search name="q" placeholder="site search"> <input type=submit value="Search"> </form></div>')
|
||||
</script>
|
||||
|
||||
<div class="col-sm-6 col-md-3">
|
||||
<h3>Contribute</h3>
|
||||
<ul>
|
||||
<li><a href="http://groups.google.com/group/gf-dev">Mailing List</a></li>
|
||||
<li><a href="https://github.com/GrammaticalFramework/gf-core/issues">Issue Tracker</a></li>
|
||||
<li><a href="doc/gf-people.html">Authors</a></li>
|
||||
<li><a href="http://school.grammaticalframework.org/2018/">Summer School</a></li>
|
||||
</ul>
|
||||
<a href="https://github.com/GrammaticalFramework/" class="btn btn-primary ml-3">
|
||||
<i class="fab fa-github mr-1"></i>
|
||||
GF on GitHub
|
||||
</a>
|
||||
</div>
|
||||
<H2 class=noclear>News</H2>
|
||||
|
||||
<div class=news2>
|
||||
|
||||
<table class=news>
|
||||
<tr><td>2018-07-25:<td>The GF repository has been split in two:
|
||||
<a href="https://github.com/GrammaticalFramework/gf-core">gf-core</a> and
|
||||
<a href="https://github.com/GrammaticalFramework/gf-rgl">gf-rgl</a>.
|
||||
The original <a href="https://github.com/GrammaticalFramework/GF">GF</a> repository is now archived.
|
||||
<tr><td>2017-08-11:<td><strong>GF 3.9 released!</strong>
|
||||
<a href="download/release-3.9.html">Release notes</a>.
|
||||
<tr><td>2017-06-29:<td>GF is moving to <a href="https://github.com/GrammaticalFramework/GF/">GitHub</a>!
|
||||
<tr><td>2017-03-13:<td><strong>GF Summer School in Riga (Latvia), 14-25 August 2017</strong>
|
||||
<a href="http://school.grammaticalframework.org/2017/">Summer
|
||||
School web page</a>.
|
||||
<tr><td>2016-09-07:<td><strong>Google Tech Talk on GF</strong> <a
|
||||
href="https://www.youtube.com/watch?v=x1LFbDQhbso">on Youtube</a>.
|
||||
<tr><td>2016-07-05:<td>GitHub mirror temporarily not updated, due to server migration.
|
||||
<tr><td>2016-06-22:<td><strong>GF 3.8 released!</strong>
|
||||
<a href="download/release-3.8.html">Release notes</a>.
|
||||
<tr><td>2015-06-21:<td><strong>Summer School in Rule-Based Machine
|
||||
Translation in Alacant/Alicante (Spain), 11-21 July 2016</strong>
|
||||
featuring GF, Apertium, Matxin, and TectoMT.
|
||||
<a href="http://xixona.dlsi.ua.es/rbmt-summer-school/2016/">Summer
|
||||
School web page</a>.
|
||||
<tr><td>2016-06-14:<td>New resource grammar language: Nynorsk.
|
||||
<tr><td>2015-10-02:<td><strong>GF 3.7.1 released!</strong>
|
||||
<a href="download/release-3.7.1.html">Release notes</a>.
|
||||
<tr><td>2015-06-25:<td><strong>GF 3.7 released!</strong>
|
||||
<a href="download/release-3.7.html">Release notes</a>.
|
||||
<tr><td>2015-03-13:<td>New resource grammar language: Mongolian.
|
||||
See <a href="lib/doc/synopsis.html">library synopsis</a>.
|
||||
<tr><td>2015-02-09:<td><strong>GF Summer School in Gozo (Malta), 13-24 July 2015</strong>
|
||||
<a href="http://school.grammaticalframework.org/2015/">Summer
|
||||
School web page</a>.
|
||||
<tr><td>2014-06-23:<td><strong>GF 3.6 released!</strong>
|
||||
<a href="download/release-3.6.html">Release notes</a>.
|
||||
<tr><td>2014-03-11:
|
||||
<td>A company for commercial applications of GF has been founded:
|
||||
<a href="http://www.digitalgrammars.com/">Digital Grammars</a>.
|
||||
<tr><td>2013-11-25:
|
||||
<td>The default character encoding in GF grammar files will be changed
|
||||
from Latin-1 to UTF-8. See
|
||||
<a href="download/encoding-change.html">GF character encoding changes</a>
|
||||
for details.
|
||||
<tr><td>2013-10-18:<td>New resource grammar language: Estonian.
|
||||
See <a href="lib/doc/synopsis.html">library synopsis</a>.
|
||||
<tr><td>2013-09-18:<td>New <a href="https://github.com/GrammaticalFramework/gf-contrib">GF contributions repository</a>, hosted on GitHub.
|
||||
<tr><td>2013-08-06:<td><strong>GF 3.5 released!</strong>
|
||||
<a href="download/release-3.5.html">Release notes</a>.
|
||||
<tr><td>2013-07-26:<td>Started a page with <A HREF="lib/doc/rgl-publications.html">RGL Documentation and Publications</A>.
|
||||
<tr><td>2013-06-24:<td>We are now running the IRC channel <a href="https://webchat.freenode.net/?channels=gf"><strong><code>#gf</code></strong></a> on the Freenode network.
|
||||
<tr><td>2013-06-19:<td>New resource grammar language: Maltese.
|
||||
See <a href="lib/doc/synopsis.html">library synopsis</a>.
|
||||
<tr><td>2013-04-25:<td>New resource grammar language: Greek.
|
||||
See <a href="lib/doc/synopsis.html">library synopsis</a>.
|
||||
<tr><td>2013-01-31:<td><strong>GF 3.4 released!</strong>
|
||||
<a href="download/release-3.4.html">Release notes</a>.
|
||||
<tr><td>2012-12-10:<td>
|
||||
<a href="http://www.postcrashgames.com/gf_world/">Resource Grammar Library
|
||||
coverage map</a>, created by Tommi Nieminen.
|
||||
<!--
|
||||
<tr><td>2012-11-18:<td>
|
||||
<A HREF="http://school.grammaticalframework.org/2013">GF Summer School</A>
|
||||
in Frauenchiemsee, 18-30 August 2013.
|
||||
<tr><td>2012-11-18:<td>New resource grammar language: Chinese.
|
||||
See <a href="lib/doc/synopsis.html">library synopsis</a>.
|
||||
Complete but not yet perfect.
|
||||
<tr><td>2012-06-29:<td>GF sources now mirrored in GitHub, with change
|
||||
statistics and other browsing features.
|
||||
See <a href="https://github.com/GrammaticalFramework/GF/"><tt>github.com/GrammaticalFramework/GF</tt></a>
|
||||
<tr><td>2012-05-07:<td>New resource grammar language: Japanese.
|
||||
See <a href="lib/doc/synopsis.html">library synopsis</a>.
|
||||
<tr><td>2012-03-23:<td>There will be a
|
||||
<a href="gf-tutorial-icfp-2012/">GF tutorial at ICFP 2012</a>
|
||||
in Copenhagen.
|
||||
<tr><td>2012-03-03:<td><strong>GF 3.3.3 released!</strong>
|
||||
<a href="download/release-3.3.3.html">Release notes</a>.
|
||||
<tr><td>2012-02-24:<td>New resource grammar languages: Hindi, Sindhi.
|
||||
See <a href="lib/doc/synopsis.html">library synopsis</a>.
|
||||
<tr><td>2011-12-29:<td>New resource grammar languages: Latvian, Thai.
|
||||
See <a href="lib/doc/synopsis.html">library synopsis</a>.
|
||||
<tr><td>2011-10-27:<td><strong>GF 3.3 released!</strong>
|
||||
<a href="download/release-3.3.html">Release notes</a>.
|
||||
<tr><td>2011-09-20:<td>There is now a page collecting
|
||||
<a href="doc/gf-editor-modes.html">editor modes for GF</a>.
|
||||
Contributions are welcome!
|
||||
<tr><td>2011-09-12:<td><strong>GF 3.2.9</strong> source snapshot with faster grammar compilation available. See <a href="download/index.html">Downloads</a>.
|
||||
<tr><td>2011-04-22:<td><a href="android/tutorial/">JPGF Android Tutorial</a> added.
|
||||
<tr><td>2011-04-15:<td>The <a href="gf-book">GF Book</a> is available.
|
||||
<tr><td>2011-01-13:<td><a href="http://www.molto-project.eu/node/1177">Phrasedroid
|
||||
available on the Android Market</a>.
|
||||
<tr><td>2011-01-04:<td>GF is part of the
|
||||
<a href="http://www.clt.gu.se/clt-toolkit">CLT Toolkit</a>.
|
||||
<tr><td>2010-12-23:<td><strong>GF 3.2 released!</strong>
|
||||
<a href="download/release-3.2.html">Release notes</a>.
|
||||
-->
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<h2>What is GF?</h2>
|
||||
<p>
|
||||
<H2>What is GF</H2>
|
||||
<P>
|
||||
GF, Grammatical Framework, is a programming language for
|
||||
<strong>multilingual grammar applications</strong>. It is
|
||||
</p>
|
||||
<ul>
|
||||
<li>a <strong>special-purpose language for grammars</strong>, like
|
||||
<B>multilingual grammar applications</B>. It is
|
||||
</P>
|
||||
<UL>
|
||||
<LI>a <B>special-purpose language for grammars</B>, like
|
||||
<a href="http://dinosaur.compilertools.net/yacc/">YACC</a>,
|
||||
<a href="http://www.gnu.org/software/bison/">Bison</a>,
|
||||
<a href="http://www.haskell.org/happy/">Happy</a>,
|
||||
<a href="http://bnfc.digitalgrammars.com/">BNFC</a>,
|
||||
but not restricted to programming languages
|
||||
</li>
|
||||
<li>a <strong>functional programming language</strong>, like
|
||||
<LI>a <B>functional programming language</B>, like
|
||||
<a href="http://www.haskell.org/">Haskell</a>,
|
||||
<a href="http://en.wikipedia.org/wiki/Lisp_(programming_language)">Lisp</a>,
|
||||
<a href="http://ocaml.org/">OCaml</a>,
|
||||
<a href="http://www.smlnj.org/">SML</a>,
|
||||
<a href="http://schemers.org/">Scheme</a>,
|
||||
but specialized to grammar writing
|
||||
</li>
|
||||
<li>a <strong>development platform for natural language grammars</strong>, like
|
||||
<LI>a <B>development platform for natural language grammars</B>, like
|
||||
<a href="http://moin.delph-in.net/LkbTop">LKB</a>,
|
||||
<a href="http://www2.parc.com/isl/groups/nltt/xle/">XLE</a>,
|
||||
<a href="http://www.issco.unige.ch/en/research/projects/regulus/news.shtml">Regulus</a>,
|
||||
but based on functional programming and type theory
|
||||
</li>
|
||||
<li>a <strong>categorial grammar formalism</strong>, like
|
||||
<LI>a <B>categorial grammar formalism</B>, like
|
||||
<a href="http://www.loria.fr/equipes/calligramme/acg/">ACG</a>,
|
||||
<a href="http://openccg.sourceforge.net/">CCG</a>,
|
||||
but specialized for multilingual grammars,
|
||||
</li>
|
||||
<li>a <strong>logical framework</strong>, like
|
||||
<LI>a <B>logical framework</B>, like
|
||||
<a href="http://wiki.portal.chalmers.se/agda/pmwiki.php">Agda</a>,
|
||||
<a href="http://coq.inria.fr/">Coq</a>,
|
||||
<a href="http://www.cl.cam.ac.uk/research/hvg/Isabelle/">Isabelle</a>,
|
||||
but equipped with concrete syntax in addition to logic
|
||||
</li>
|
||||
<li>a <strong>platform for machine translation</strong>, like
|
||||
<li>a <b>platform for machine translation</b>, like
|
||||
<a href="http://www.statmt.org/moses/">Moses</a>,
|
||||
<a href="http://www.apertium.org/">Apertium</a>,
|
||||
but based on deep structural analysis (and usually applied for
|
||||
limited fragments of language).
|
||||
</li>
|
||||
</ul>
|
||||
</UL>
|
||||
|
||||
<p>
|
||||
<P>
|
||||
Don't worry if you don't know most of the references above - but if you do know at
|
||||
least one, it may help you to get a first idea of what GF is.
|
||||
</P>
|
||||
<H2>Applications</H2>
|
||||
<P>
|
||||
GF can be used for building
|
||||
</P>
|
||||
<UL>
|
||||
<LI><A HREF="http://cloud.grammaticalframework.org/translator/">translation systems</A>
|
||||
<LI><A HREF="http://cloud.grammaticalframework.org/minibar/minibar.html">multilingual web gadgets</A>
|
||||
<LI><A HREF="http://www.cs.chalmers.se/~hallgren/Alfa/Tutorial/GFplugin.html">natural-language interfaces</A>
|
||||
<LI><A HREF="http://www.youtube.com/watch?v=1bfaYHWS6zU">dialogue systems</A>
|
||||
<LI><A HREF="lib/doc/synopsis.html">natural language resources</A>
|
||||
</UL>
|
||||
|
||||
<H2>Availability</H2>
|
||||
<P>
|
||||
GF is <B>open-source</B>, licensed under <A HREF="LICENSE">GPL</A> (the program) and
|
||||
<A HREF="./LICENSE">LGPL</A> and <A HREF="./LICENSE">BSD</A> (the libraries). It
|
||||
is available for
|
||||
</P>
|
||||
<UL>
|
||||
<LI>Linux
|
||||
<LI>Mac OS X
|
||||
<LI>Windows
|
||||
<li>Android mobile platform (via Java; runtime)
|
||||
<LI>via compilation to JavaScript, almost any platform that has a web browser (runtime)
|
||||
</UL>
|
||||
|
||||
<H2>Projects</H2>
|
||||
<P>
|
||||
GF was first created in 1998 at
|
||||
<A HREF="http://www.xrce.xerox.com/">Xerox Research Centre Europe</A>,
|
||||
Grenoble, in the project
|
||||
Multilingual Document Authoring. At Xerox, it was used for prototypes including
|
||||
a restaurant phrase book,
|
||||
a database query system,
|
||||
a formalization of an alarm system instructions with translations to 5 languages, and
|
||||
an authoring system for medical drug descriptions.
|
||||
</P>
|
||||
<P>
|
||||
Later projects using GF and involving third parties include, in chronological order,
|
||||
</P>
|
||||
<UL>
|
||||
<LI><A HREF="http://www.cs.chalmers.se/~hallgren/Alfa/Tutorial/GFplugin.html">GF-Alfa</A>:
|
||||
natural language interface to formal proofs
|
||||
<LI><A HREF="http://efficient.citi.tudor.lu/index_noframe.html">Efficient</A>:
|
||||
authoring tool for business models.
|
||||
<LI><A HREF="http://www.key-project.org/">GF-KeY</A>:
|
||||
authoring and translation of software specifications
|
||||
<LI><A HREF="http://www.talk-project.org">TALK</A>:
|
||||
multilingual and multimodal spoken dialogue systems
|
||||
<LI><A HREF="http://webalt.math.helsinki.fi/">WebALT</A>:
|
||||
multilingual generation of mathematical exercises (commercial project)
|
||||
<LI><A HREF="http://spraakbanken.gu.se/sal/">SALDO</A>:
|
||||
Swedish morphological dictionary based on rules developed for GF and
|
||||
<A HREF="http://www.cse.chalmers.se/alumni/markus/FM/">Functional Morphology</A>
|
||||
<LI><a href="http://www.molto-project.eu">MOLTO</a>:
|
||||
multilingual online translation
|
||||
<LI><a href="http://remu.grammaticalframework.org">REMU</a>:
|
||||
reliable multilingual digital communication.
|
||||
</UL>
|
||||
<p>
|
||||
Here is a <a
|
||||
href="http://videos.xrce.xerox.com/index.php/videos/index/618">talk
|
||||
about GF at XRCE</a>,
|
||||
14 years later.
|
||||
|
||||
<P>
|
||||
Academically, GF has been used in at least ten PhD theses and resulted
|
||||
in more than a hundred
|
||||
scientific publications (see <A HREF="doc/gf-bibliography.html">GF publication list</A>).
|
||||
</P>
|
||||
<H2>Programming in GF</H2>
|
||||
<P>
|
||||
GF is easy to learn by following the <A HREF="doc/tutorial/gf-tutorial.html">tutorial</A>.
|
||||
You can write your first translator in 15 minutes.
|
||||
</P>
|
||||
<P>
|
||||
GF has an interactive command interpreter, as well as a batch compiler.
|
||||
Grammars can be compiled to parser and translator code in many different
|
||||
formats. These components can then be embedded in applications written
|
||||
in other programming languages. The formats currently supported are:
|
||||
</P>
|
||||
<UL>
|
||||
<LI>Haskell
|
||||
<li>Java, in particular the Android platform
|
||||
<LI>JavaScript
|
||||
<LI>Speech recognition: HTK/ATK, Nuance, JSGF
|
||||
</UL>
|
||||
|
||||
<P>
|
||||
The GF programming language is high-level and advanced, featuring
|
||||
</P>
|
||||
<UL>
|
||||
<LI>static type checking
|
||||
<LI>higher-order functions
|
||||
<LI>dependent types
|
||||
<LI>pattern matching with data constructors and regular expressions
|
||||
<LI>module system with multiple inheritance and parametrized modules
|
||||
</UL>
|
||||
|
||||
<h3>Getting help</h3>
|
||||
<p>
|
||||
If you need some help with GF, the first places to start are the <a href="doc/tutorial/gf-tutorial.html">Tutorial</a> and <a href="doc/gf-refman.html">Reference</a> pages.
|
||||
The printed <a href="gf-book">book</a> contains all the material in the tutorial and some extra bits, and is the recommended reference for GF.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
<p>
|
||||
We run the IRC channel <strong><code>#gf</code></strong> on the Freenode network, where you are welcome to look for help with small questions or just start a general discussion.
|
||||
IRC logs (in raw format) are available <a href="irc/">here</a>.
|
||||
If you have a larger question which the community may benefit from, we recommend you ask it on the <a href="http://groups.google.com/group/gf-dev">mailing list</a>.
|
||||
</p>
|
||||
|
||||
<div class="row">
|
||||
<H2>Libraries</H2>
|
||||
<P>
|
||||
Libraries are at the heart of modern software engineering. In natural language
|
||||
applications, libraries are a way to cope with thousands of details involved in
|
||||
syntax, lexicon, and inflection. The
|
||||
<A HREF="lib/doc/synopsis.html">GF resource grammar library</A> has
|
||||
support for an increasing number of languages, currently including
|
||||
</P>
|
||||
<ol class=languages>
|
||||
<LI>Afrikaans
|
||||
<LI>Amharic (partial)
|
||||
<LI>Arabic (partial)
|
||||
<LI>Bulgarian
|
||||
<LI>Catalan
|
||||
<LI>Chinese
|
||||
<LI>Danish
|
||||
<LI>Dutch
|
||||
<LI>English
|
||||
<LI>Estonian
|
||||
<LI>Finnish
|
||||
<LI>French
|
||||
<LI>German
|
||||
<li>Greek ancient (partial)
|
||||
<li>Greek modern
|
||||
<li>Hebrew (fragments)
|
||||
<LI>Hindi
|
||||
<LI><A HREF="http://www.interlingua.com/">Interlingua</A>
|
||||
<LI>Japanese
|
||||
<LI>Italian
|
||||
<LI>Latin (fragments)
|
||||
<LI>Latvian
|
||||
<li>Maltese
|
||||
<li>Mongolian
|
||||
<LI>Nepali
|
||||
<LI>Norwegian bokmål
|
||||
<LI>Norwegian nynorsk
|
||||
<LI>Persian
|
||||
<LI>Polish
|
||||
<li>Punjabi
|
||||
<LI>Romanian
|
||||
<LI>Russian
|
||||
<LI>Sindhi
|
||||
<LI>Slovene (partial)
|
||||
<LI>Spanish
|
||||
<li>Swahili (fragments)
|
||||
<LI>Swedish
|
||||
<LI>Thai
|
||||
<LI>Turkish (fragments)
|
||||
<LI>Urdu
|
||||
</ol>
|
||||
|
||||
<div class="col-md-6">
|
||||
<h2>Applications & Availability</h2>
|
||||
<p>
|
||||
GF can be used for building
|
||||
<a href="http://cloud.grammaticalframework.org/translator/">translation systems</a>,
|
||||
<a href="http://cloud.grammaticalframework.org/minibar/minibar.html">multilingual web gadgets</a>,
|
||||
<a href="http://www.cs.chalmers.se/~hallgren/Alfa/Tutorial/GFplugin.html">natural-language interfaces</a>,
|
||||
<a href="http://www.youtube.com/watch?v=1bfaYHWS6zU">dialogue systems</a>, and
|
||||
<a href="lib/doc/synopsis/index.html">natural language resources</a>.
|
||||
</p>
|
||||
<P>
|
||||
Adding a language to the resource library takes 3 to 9
|
||||
months - contributions
|
||||
are welcome! You can start with the <A HREF="doc/gf-lrec-2010.pdf">resource grammarian's tutorial</A>.
|
||||
|
||||
<p>
|
||||
GF is <strong>open-source</strong>, licensed under <a href="LICENSE">GPL</a> (the program) and
|
||||
<a href="LICENSE">LGPL</a> and <a href="LICENSE">BSD</a> (the libraries). It
|
||||
is available for
|
||||
</p>
|
||||
<ul>
|
||||
<li>Linux</li>
|
||||
<li>macOS</li>
|
||||
<li>Windows</li>
|
||||
<li>Android mobile platform (via Java; runtime)</li>
|
||||
<li>via compilation to JavaScript, almost any platform that has a web browser (runtime)</li>
|
||||
</ul>
|
||||
|
||||
<h2>Programming in GF</h2>
|
||||
<p>
|
||||
GF is easy to learn by following the <a href="doc/tutorial/gf-tutorial.html">tutorial</a>.
|
||||
You can write your first translator in 15 minutes.
|
||||
</p>
|
||||
<p>
|
||||
GF has an interactive command interpreter, as well as a batch compiler.
|
||||
Grammars can be compiled to parser and translator code in many different
|
||||
formats. These components can then be embedded in applications written
|
||||
in other programming languages. The formats currently supported are:
|
||||
</p>
|
||||
<ul>
|
||||
<li>Haskell</li>
|
||||
<li>Java, in particular the Android platform</li>
|
||||
<li>JavaScript</li>
|
||||
<li>Speech recognition: HTK/ATK, Nuance, JSGF</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
The GF programming language is high-level and advanced, featuring:
|
||||
</p>
|
||||
<ul>
|
||||
<li>static type checking</li>
|
||||
<li>higher-order functions</li>
|
||||
<li>dependent types</li>
|
||||
<li>pattern matching with data constructors and regular expressions</li>
|
||||
<li>module system with multiple inheritance and parametrized modules</li>
|
||||
</ul>
|
||||
|
||||
<h3>Getting help</h3>
|
||||
<p>
|
||||
If you need some help with GF, the first places to start are the <a href="doc/tutorial/gf-tutorial.html">Tutorial</a> and <a href="doc/gf-refman.html">Reference</a> pages.
|
||||
The printed <a href="gf-book">book</a> contains all the material in the tutorial and some extra bits, and is the recommended reference for GF.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
We run the IRC channel <strong><code>#gf</code></strong> on the Freenode network, where you are welcome to look for help with small questions or just start a general discussion.
|
||||
IRC logs (in raw format) are available <a href="http://www.grammaticalframework.org/irc/">here</a>.
|
||||
If you have a larger question which the community may benefit from, we recommend you ask it on the <a href="http://groups.google.com/group/gf-dev">mailing list</a>.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<h2>News</h2>
|
||||
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3 text-center text-nowrap">2018-12-03</dt>
|
||||
<dd class="col-sm-9">
|
||||
<a href="http://school.grammaticalframework.org/2018/">Sixth GF Summer School</a> in Stellenbosch (South Africa), 3–14 December 2018
|
||||
</dd>
|
||||
<dt class="col-sm-3 text-center text-nowrap">2018-12-02</dt>
|
||||
<dd class="col-sm-9">
|
||||
<strong>GF 3.10 released.</strong>
|
||||
<!-- <a href="download/release-3.10.html">Release notes</a> -->
|
||||
</dd>
|
||||
<dt class="col-sm-3 text-center text-nowrap">2018-07-25</dt>
|
||||
<dd class="col-sm-9">
|
||||
The GF repository has been split in two:
|
||||
<a href="https://github.com/GrammaticalFramework/gf-core">gf-core</a> and
|
||||
<a href="https://github.com/GrammaticalFramework/gf-rgl">gf-rgl</a>.
|
||||
The original <a href="https://github.com/GrammaticalFramework/GF">GF</a> repository is now archived.
|
||||
</dd>
|
||||
<dt class="col-sm-3 text-center text-nowrap">2017-08-11</dt>
|
||||
<dd class="col-sm-9">
|
||||
<strong>GF 3.9 released.</strong>
|
||||
<a href="download/release-3.9.html">Release notes</a>
|
||||
</dd>
|
||||
<dt class="col-sm-3 text-center text-nowrap">2017-06-29</dt>
|
||||
<dd class="col-sm-9">
|
||||
GF is moving to <a href="https://github.com/GrammaticalFramework/GF/">GitHub</a>.</dd>
|
||||
<dt class="col-sm-3 text-center text-nowrap">2017-03-13</dt>
|
||||
<dd class="col-sm-9">
|
||||
<a href="http://school.grammaticalframework.org/2017/">GF Summer School</a> in Riga (Latvia), 14-25 August 2017
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h2>Projects</h2>
|
||||
<p>
|
||||
GF was first created in 1998 at
|
||||
<a href="http://www.xrce.xerox.com/">Xerox Research Centre Europe</a>,
|
||||
Grenoble, in the project
|
||||
Multilingual Document Authoring. At Xerox, it was used for prototypes including
|
||||
a restaurant phrase book,
|
||||
a database query system,
|
||||
a formalization of an alarm system instructions with translations to 5 languages, and
|
||||
an authoring system for medical drug descriptions.
|
||||
</p>
|
||||
<p>
|
||||
Later projects using GF and involving third parties include, in chronological order:
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="http://www.cs.chalmers.se/~hallgren/Alfa/Tutorial/GFplugin.html">GF-Alfa</a>:
|
||||
natural language interface to formal proofs
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://efficient.citi.tudor.lu/index_noframe.html">Efficient</a>:
|
||||
authoring tool for business models.
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://www.key-project.org/">GF-KeY</a>:
|
||||
authoring and translation of software specifications
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://www.talk-project.org">TALK</a>:
|
||||
multilingual and multimodal spoken dialogue systems
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://webalt.math.helsinki.fi/">WebALT</a>:
|
||||
multilingual generation of mathematical exercises (commercial project)
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://spraakbanken.gu.se/sal/">SALDO</a>:
|
||||
Swedish morphological dictionary based on rules developed for GF and
|
||||
<a href="http://www.cse.chalmers.se/alumni/markus/FM/">Functional Morphology</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://www.molto-project.eu">MOLTO</a>:
|
||||
multilingual online translation
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://remu.grammaticalframework.org">REMU</a>:
|
||||
reliable multilingual digital communication
|
||||
</li>
|
||||
</ul>
|
||||
<!-- <p>
|
||||
Here is a <a
|
||||
href="http://videos.xrce.xerox.com/index.php/videos/index/618">talk
|
||||
about GF at XRCE</a>,
|
||||
14 years later.
|
||||
</p> -->
|
||||
|
||||
<p>
|
||||
Academically, GF has been used in at least ten PhD theses and resulted
|
||||
in more than a hundred scientific publications.
|
||||
<!-- (see <a href="doc/gf-bibliography.html">GF publication list</a>). -->
|
||||
</p>
|
||||
|
||||
<h2>Libraries</h2>
|
||||
<p>
|
||||
Libraries are at the heart of modern software engineering. In natural language
|
||||
applications, libraries are a way to cope with thousands of details involved in
|
||||
syntax, lexicon, and inflection. The
|
||||
<a href="lib/doc/synopsis/index.html">GF resource grammar library</a> has
|
||||
support for an increasing number of languages, currently including
|
||||
Afrikaans,
|
||||
Amharic (partial),
|
||||
Arabic (partial),
|
||||
Bulgarian,
|
||||
Catalan,
|
||||
Chinese,
|
||||
Danish,
|
||||
Dutch,
|
||||
English,
|
||||
Estonian,
|
||||
Finnish,
|
||||
French,
|
||||
German,
|
||||
Greek ancient (partial),
|
||||
Greek modern,
|
||||
Hebrew (fragments),
|
||||
Hindi,
|
||||
Interlingua,
|
||||
Japanese,
|
||||
Italian,
|
||||
Latin (fragments),
|
||||
Latvian,
|
||||
Maltese,
|
||||
Mongolian,
|
||||
Nepali,
|
||||
Norwegian bokmål,
|
||||
Norwegian nynorsk,
|
||||
Persian,
|
||||
Polish,
|
||||
Punjabi,
|
||||
Romanian,
|
||||
Russian,
|
||||
Sindhi,
|
||||
Slovene (partial),
|
||||
Spanish,
|
||||
Swahili (fragments),
|
||||
Swedish,
|
||||
Thai,
|
||||
Turkish (fragments),
|
||||
Urdu
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Adding a language to the resource library takes 3 to 9
|
||||
months - contributions
|
||||
are welcome! You can start with the <a href="doc/gf-lrec-2010.pdf">resource grammarian's tutorial</a>.
|
||||
</p>
|
||||
|
||||
</div><!-- .col-6 -->
|
||||
|
||||
</div><!-- .row -->
|
||||
|
||||
</div><!-- .container -->
|
||||
|
||||
<footer class="bg-light mt-5 py-5">
|
||||
<div class="container mb-5">
|
||||
<div class="row">
|
||||
<div>
|
||||
<div>
|
||||
</footer>
|
||||
|
||||
<script type="text/javascript">
|
||||
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
||||
@@ -384,6 +423,5 @@ try {
|
||||
var pageTracker = _gat._getTracker("UA-7811807-3");
|
||||
pageTracker._trackPageview();
|
||||
} catch(err) {}</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
||||
@@ -723,7 +723,7 @@ pgfCommands = Map.fromList [
|
||||
case toExprs arg of
|
||||
[EFun id] -> case Map.lookup id (funs (abstract pgf)) of
|
||||
Just fd -> do putStrLn $ render (ppFun id fd)
|
||||
let (_,_,_,prob) = fd
|
||||
let (_,_,_,_,prob) = fd
|
||||
putStrLn ("Probability: "++show prob)
|
||||
return void
|
||||
Nothing -> case Map.lookup id (cats (abstract pgf)) of
|
||||
@@ -732,7 +732,7 @@ pgfCommands = Map.fromList [
|
||||
if null (functionsToCat pgf id)
|
||||
then empty
|
||||
else ' ' $$
|
||||
vcat [ppFun fid (ty,0,Just ([],[]),0) | (fid,ty) <- functionsToCat pgf id] $$
|
||||
vcat [ppFun fid (ty,[],0,Just ([],[]),0) | (fid,ty) <- functionsToCat pgf id] $$
|
||||
' ')
|
||||
let (_,_,prob) = cd
|
||||
putStrLn ("Probability: "++show prob)
|
||||
@@ -909,7 +909,7 @@ pgfCommands = Map.fromList [
|
||||
| otherwise = do fmt <- readOutputFormat (valStrOpts "printer" "pgf_pretty" opts)
|
||||
return $ fromString $ concatMap snd $ exportPGF noOptions fmt pgf
|
||||
|
||||
funsigs pgf = [(f,ty) | (f,(ty,_,_,_)) <- Map.assocs (funs (abstract pgf))]
|
||||
funsigs pgf = [(f,ty) | (f,(ty,_,_,_,_)) <- Map.assocs (funs (abstract pgf))]
|
||||
showFun (f,ty) = showCId f ++ " : " ++ showType [] ty ++ " ;"
|
||||
|
||||
morphos (Env pgf mos) opts s =
|
||||
|
||||
@@ -35,7 +35,7 @@ cf2abstr cfg = Abstr aflags afuns acats
|
||||
| (cat,rules) <- (Map.toList . Map.fromListWith (++))
|
||||
[(cat2id cat, catRules cfg cat) |
|
||||
cat <- allCats' cfg]]
|
||||
afuns = Map.fromList [(mkRuleName rule, (cftype [cat2id c | NonTerminal c <- ruleRhs rule] (cat2id (ruleLhs rule)), 0, Nothing, 0))
|
||||
afuns = Map.fromList [(mkRuleName rule, (cftype [cat2id c | NonTerminal c <- ruleRhs rule] (cat2id (ruleLhs rule)), [], 0, Nothing, 0))
|
||||
| rule <- allRules cfg]
|
||||
|
||||
cat2id = mkCId . fst
|
||||
@@ -56,7 +56,7 @@ cf2concr cfg = Concr Map.empty Map.empty
|
||||
map mkSequence rules)
|
||||
sequences = listArray (0,Set.size sequences0-1) (Set.toList sequences0)
|
||||
|
||||
idFun = CncFun wildCId (listArray (0,0) [seqid])
|
||||
idFun = CncFun [wildCId] (listArray (0,0) [seqid])
|
||||
where
|
||||
seq = listArray (0,0) [SymCat 0 0]
|
||||
seqid = binSearch seq sequences (bounds sequences)
|
||||
@@ -77,7 +77,7 @@ cf2concr cfg = Concr Map.empty Map.empty
|
||||
let args = [PArg [] (cat2arg c) | NonTerminal c <- ruleRhs rule]
|
||||
prod = PApply funid args
|
||||
seqid = binSearch (mkSequence rule) sequences (bounds sequences)
|
||||
fun = CncFun (mkRuleName rule) (listArray (0,0) [seqid])
|
||||
fun = CncFun [mkRuleName rule] (listArray (0,0) [seqid])
|
||||
funid' = funid+1
|
||||
in funid' `seq` ((funid',fun:funs),let (c,ps) = ruleLhs rule in [(cat2fid c p, prod) | p <- ps])
|
||||
|
||||
|
||||
@@ -6,18 +6,15 @@ import GF.Compile.GeneratePMCFG
|
||||
import GF.Compile.GenerateBC
|
||||
|
||||
import PGF(CId,mkCId,utf8CId)
|
||||
import PGF.Internal(fidInt,fidFloat,fidString,fidVar)
|
||||
import PGF.Internal(fidInt,fidFloat,fidString,fidVar,DepPragma(..))
|
||||
import PGF.Internal(updateProductionIndices)
|
||||
--import qualified PGF.Macros as CM
|
||||
import qualified PGF.Internal as C
|
||||
import qualified PGF.Internal as D
|
||||
import GF.Grammar.Predef
|
||||
--import GF.Grammar.Printer
|
||||
import GF.Grammar.Grammar
|
||||
import qualified GF.Grammar.Lookup as Look
|
||||
import qualified GF.Grammar as A
|
||||
import qualified GF.Grammar.Macros as GM
|
||||
--import GF.Compile.GeneratePMCFG
|
||||
|
||||
import GF.Infra.Ident
|
||||
import GF.Infra.Option
|
||||
@@ -25,20 +22,24 @@ import GF.Infra.UseIO (IOE)
|
||||
import GF.Data.Operations
|
||||
|
||||
import Data.List
|
||||
import Data.Maybe (fromMaybe)
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.IntMap as IntMap
|
||||
import Data.Array.IArray
|
||||
|
||||
mkCanon2pgf :: Options -> SourceGrammar -> ModuleName -> IOE D.PGF
|
||||
mkCanon2pgf :: Options -> SourceGrammar -> ModuleName -> IOE C.PGF
|
||||
mkCanon2pgf opts gr am = do
|
||||
(an,abs) <- mkAbstr am
|
||||
depconf <- case flag optLabelsFile opts of
|
||||
Nothing -> return Map.empty
|
||||
Just fpath -> readDepConfig fpath
|
||||
(an,abs) <- mkAbstr am depconf
|
||||
cncs <- mapM mkConcr (allConcretes gr am)
|
||||
return $ updateProductionIndices (D.PGF Map.empty an abs (Map.fromList cncs))
|
||||
return $ updateProductionIndices (C.PGF Map.empty an abs (Map.fromList cncs))
|
||||
where
|
||||
cenv = resourceValues opts gr
|
||||
|
||||
mkAbstr am = return (mi2i am, D.Abstr flags funs cats)
|
||||
mkAbstr am depconf = return (mi2i am, C.Abstr flags funs cats)
|
||||
where
|
||||
aflags = err (const noOptions) mflags (lookupModule gr am)
|
||||
|
||||
@@ -48,7 +49,7 @@ mkCanon2pgf opts gr am = do
|
||||
|
||||
flags = Map.fromList [(mkCId f,x) | (f,x) <- optionsPGF aflags]
|
||||
|
||||
funs = Map.fromList [(i2i f, (mkType [] ty, arity, mkDef gr arity mdef, 0)) |
|
||||
funs = Map.fromList [(i2i f, (mkType [] ty, fromMaybe [] (Map.lookup (i2i f) depconf), arity, mkDef gr arity mdef, 0)) |
|
||||
((m,f),AbsFun (Just (L _ ty)) ma mdef _) <- adefs,
|
||||
let arity = mkArity ma mdef ty]
|
||||
|
||||
@@ -78,7 +79,7 @@ mkCanon2pgf opts gr am = do
|
||||
= genCncFuns gr am cm ex_seqs_arr seqs cdefs fid_cnt1 cnccats
|
||||
|
||||
printnames = genPrintNames cdefs
|
||||
return (mi2i cm, D.Concr flags
|
||||
return (mi2i cm, C.Concr flags
|
||||
printnames
|
||||
cncfuns
|
||||
lindefs
|
||||
@@ -189,54 +190,80 @@ genCncFuns :: Grammar
|
||||
-> Array SeqId Sequence
|
||||
-> [(QIdent, Info)]
|
||||
-> FId
|
||||
-> Map.Map CId D.CncCat
|
||||
-> Map.Map CId C.CncCat
|
||||
-> (FId,
|
||||
IntMap.IntMap (Set.Set D.Production),
|
||||
IntMap.IntMap (Set.Set C.Production),
|
||||
IntMap.IntMap [FunId],
|
||||
IntMap.IntMap [FunId],
|
||||
Array FunId D.CncFun)
|
||||
Array FunId C.CncFun)
|
||||
genCncFuns gr am cm ex_seqs seqs cdefs fid_cnt cnccats =
|
||||
let (fid_cnt1,funs_cnt1,funs1,lindefs,linrefs) = mkCncCats cdefs fid_cnt 0 [] IntMap.empty IntMap.empty
|
||||
(fid_cnt2,funs_cnt2,funs2,prods) = mkCncFuns cdefs fid_cnt1 funs_cnt1 funs1 lindefs Map.empty IntMap.empty
|
||||
in (fid_cnt2,prods,lindefs,linrefs,array (0,funs_cnt2-1) funs2)
|
||||
let (fid_cnt1,lindefs,linrefs,fun_st1) = mkCncCats cdefs fid_cnt IntMap.empty IntMap.empty Map.empty
|
||||
((fid_cnt2,crc,prods),fun_st2) = mkCncFuns cdefs lindefs ((fid_cnt1,Map.empty,IntMap.empty),fun_st1)
|
||||
in (fid_cnt2,prods,lindefs,linrefs,array (0,Map.size fun_st2-1) (Map.elems fun_st2))
|
||||
where
|
||||
mkCncCats [] fid_cnt funs_cnt funs lindefs linrefs =
|
||||
(fid_cnt,funs_cnt,funs,lindefs,linrefs)
|
||||
mkCncCats (((m,id),CncCat _ _ _ _ (Just (PMCFG prods0 funs0))):cdefs) fid_cnt funs_cnt funs lindefs linrefs =
|
||||
let !funs_cnt' = let (s_funid, e_funid) = bounds funs0
|
||||
in funs_cnt+(e_funid-s_funid+1)
|
||||
lindefs' = foldl' (toLinDef (am,id) funs_cnt) lindefs prods0
|
||||
linrefs' = foldl' (toLinRef (am,id) funs_cnt) linrefs prods0
|
||||
funs' = foldl' (toCncFun funs_cnt (m,mkLinDefId id)) funs (assocs funs0)
|
||||
in mkCncCats cdefs fid_cnt funs_cnt' funs' lindefs' linrefs'
|
||||
mkCncCats (_ :cdefs) fid_cnt funs_cnt funs lindefs linrefs =
|
||||
mkCncCats cdefs fid_cnt funs_cnt funs lindefs linrefs
|
||||
mkCncCats [] fid_cnt lindefs linrefs fun_st =
|
||||
(fid_cnt,lindefs,linrefs,fun_st)
|
||||
mkCncCats (((m,id),CncCat _ _ _ _ (Just (PMCFG prods0 funs0))):cdefs) fid_cnt lindefs linrefs fun_st =
|
||||
let mseqs = case lookupModule gr m of
|
||||
Ok (ModInfo{mseqs=Just mseqs}) -> mseqs
|
||||
_ -> ex_seqs
|
||||
(lindefs',fun_st1) = foldl' (toLinDef (m,id) funs0 mseqs) (lindefs,fun_st ) prods0
|
||||
(linrefs',fun_st2) = foldl' (toLinRef (m,id) funs0 mseqs) (linrefs,fun_st1) prods0
|
||||
in mkCncCats cdefs fid_cnt lindefs' linrefs' fun_st2
|
||||
mkCncCats (_ :cdefs) fid_cnt lindefs linrefs fun_st =
|
||||
mkCncCats cdefs fid_cnt lindefs linrefs fun_st
|
||||
|
||||
mkCncFuns [] fid_cnt funs_cnt funs lindefs crc prods =
|
||||
(fid_cnt,funs_cnt,funs,prods)
|
||||
mkCncFuns (((m,id),CncFun _ _ _ (Just (PMCFG prods0 funs0))):cdefs) fid_cnt funs_cnt funs lindefs crc prods =
|
||||
let ---Ok ty_C = fmap GM.typeForm (Look.lookupFunType gr am id)
|
||||
ty_C = err error (\x -> x) $ fmap GM.typeForm (Look.lookupFunType gr am id)
|
||||
!funs_cnt' = let (s_funid, e_funid) = bounds funs0
|
||||
in funs_cnt+(e_funid-s_funid+1)
|
||||
!(fid_cnt',crc',prods')
|
||||
= foldl' (toProd lindefs ty_C funs_cnt)
|
||||
(fid_cnt,crc,prods) prods0
|
||||
funs' = foldl' (toCncFun funs_cnt (m,id)) funs (assocs funs0)
|
||||
in mkCncFuns cdefs fid_cnt' funs_cnt' funs' lindefs crc' prods'
|
||||
mkCncFuns (_ :cdefs) fid_cnt funs_cnt funs lindefs crc prods =
|
||||
mkCncFuns cdefs fid_cnt funs_cnt funs lindefs crc prods
|
||||
mkCncFuns [] lindefs st = st
|
||||
mkCncFuns (((m,id),CncFun _ _ _ (Just (PMCFG prods0 funs0))):cdefs) lindefs st =
|
||||
let ty_C = err error (\x -> x) $ fmap GM.typeForm (Look.lookupFunType gr am id)
|
||||
mseqs = case lookupModule gr m of
|
||||
Ok (ModInfo{mseqs=Just mseqs}) -> mseqs
|
||||
_ -> ex_seqs
|
||||
bundles = [([(args0,res0) | Production res0 funid0 args0 <- prods0, funid0==funid],lins) | (funid,lins) <- assocs funs0]
|
||||
!st' = foldl' (toProd id lindefs mseqs ty_C) st bundles
|
||||
in mkCncFuns cdefs lindefs st'
|
||||
mkCncFuns (_ :cdefs) lindefs st =
|
||||
mkCncFuns cdefs lindefs st
|
||||
|
||||
toProd lindefs (ctxt_C,res_C,_) offs st (Production fid0 funid0 args0) =
|
||||
let !((fid_cnt,crc,prods),args) = mapAccumL mkArg st (zip ctxt_C args0)
|
||||
set0 = Set.fromList (map (C.PApply (offs+funid0)) (sequence args))
|
||||
fid = mkFId res_C fid0
|
||||
!prods' = case IntMap.lookup fid prods of
|
||||
Just set -> IntMap.insert fid (Set.union set0 set) prods
|
||||
Nothing -> IntMap.insert fid set0 prods
|
||||
in (fid_cnt,crc,prods')
|
||||
toLinDef mid funs0 mseqs st@(lindefs,fun_st) (Production res0 funid0 [arg0])
|
||||
| arg0 == [fidVar] =
|
||||
let res = mkFId mid res0
|
||||
|
||||
lins = amap (newSeqId mseqs) (funs0 ! funid0)
|
||||
|
||||
!funid = Map.size fun_st
|
||||
!fun_st' = Map.insert ([([C.PArg [] fidVar],res)],lins) (funid, C.CncFun [] lins) fun_st
|
||||
|
||||
!lindefs' = IntMap.insertWith (++) res [funid] lindefs
|
||||
in (lindefs',fun_st')
|
||||
toLinDef res funs0 mseqs st _ = st
|
||||
|
||||
toLinRef mid funs0 mseqs st (Production res0 funid0 [arg0])
|
||||
| res0 == fidVar =
|
||||
let arg = map (mkFId mid) arg0
|
||||
|
||||
lins = amap (newSeqId mseqs) (funs0 ! funid0)
|
||||
|
||||
in foldr (\arg (linrefs,fun_st) ->
|
||||
let !funid = Map.size fun_st
|
||||
!fun_st' = Map.insert ([([C.PArg [] arg],fidVar)],lins) (funid, C.CncFun [] lins) fun_st
|
||||
|
||||
!linrefs' = IntMap.insertWith (++) arg [funid] linrefs
|
||||
in (linrefs',fun_st'))
|
||||
st arg
|
||||
toLinRef res funs0 mseqs st _ = st
|
||||
|
||||
toProd id lindefs mseqs (ctxt_C,res_C,_) (prod_st,fun_st) (sigs0,lins0) =
|
||||
let (prod_st',sigs) = mapAccumL mkCncSig prod_st sigs0
|
||||
lins = amap (newSeqId mseqs) lins0
|
||||
in addBundle id (prod_st',fun_st) (concat sigs,lins)
|
||||
where
|
||||
mkArg st@(fid_cnt,crc,prods) ((_,_,ty),fid0s ) =
|
||||
mkCncSig prod_st (args0,res0) =
|
||||
let !(prod_st',args) = mapAccumL mkArg prod_st (zip ctxt_C args0)
|
||||
res = mkFId res_C res0
|
||||
in (prod_st',[(args,res) | args <- sequence args])
|
||||
|
||||
mkArg st@(fid_cnt,crc,prods) ((_,_,ty),fid0s) =
|
||||
case fid0s of
|
||||
[fid0] -> (st,map (flip C.PArg (mkFId arg_C fid0)) ctxt)
|
||||
fid0s -> case Map.lookup fids crc of
|
||||
@@ -246,43 +273,16 @@ genCncFuns gr am cm ex_seqs seqs cdefs fid_cnt cnccats =
|
||||
in ((fid_cnt+1,crc',prods'),map (flip C.PArg fid_cnt) ctxt)
|
||||
where
|
||||
(hargs_C,arg_C) = GM.catSkeleton ty
|
||||
ctxt = mapM (mkCtxt lindefs) hargs_C
|
||||
ctxt = mapM mkCtxt hargs_C
|
||||
fids = map (mkFId arg_C) fid0s
|
||||
|
||||
mkLinDefId id = prefixIdent "lindef " id
|
||||
mkCtxt (_,cat) =
|
||||
case Map.lookup (i2i cat) cnccats of
|
||||
Just (C.CncCat s e _) -> [(C.fidVar,fid) | fid <- [s..e], Just _ <- [IntMap.lookup fid lindefs]]
|
||||
Nothing -> error "GrammarToPGF.mkCtxt failed"
|
||||
|
||||
toLinDef res offs lindefs (Production fid0 funid0 args) =
|
||||
if args == [[fidVar]]
|
||||
then IntMap.insertWith (++) fid [offs+funid0] lindefs
|
||||
else lindefs
|
||||
newSeqId mseqs i = binSearch (mseqs ! i) seqs (bounds seqs)
|
||||
where
|
||||
fid = mkFId res fid0
|
||||
|
||||
toLinRef res offs linrefs (Production fid0 funid0 [fargs]) =
|
||||
if fid0 == fidVar
|
||||
then foldr (\fid -> IntMap.insertWith (++) fid [offs+funid0]) linrefs fids
|
||||
else linrefs
|
||||
where
|
||||
fids = map (mkFId res) fargs
|
||||
|
||||
mkFId (_,cat) fid0 =
|
||||
case Map.lookup (i2i cat) cnccats of
|
||||
Just (C.CncCat s e _) -> s+fid0
|
||||
Nothing -> error ("GrammarToPGF.mkFId: missing category "++showIdent cat)
|
||||
|
||||
mkCtxt lindefs (_,cat) =
|
||||
case Map.lookup (i2i cat) cnccats of
|
||||
Just (C.CncCat s e _) -> [(C.fidVar,fid) | fid <- [s..e], Just _ <- [IntMap.lookup fid lindefs]]
|
||||
Nothing -> error "GrammarToPGF.mkCtxt failed"
|
||||
|
||||
toCncFun offs (m,id) funs (funid0,lins0) =
|
||||
let mseqs = case lookupModule gr m of
|
||||
Ok (ModInfo{mseqs=Just mseqs}) -> mseqs
|
||||
_ -> ex_seqs
|
||||
in (offs+funid0,C.CncFun (i2i id) (amap (newIndex mseqs) lins0)):funs
|
||||
where
|
||||
newIndex mseqs i = binSearch (mseqs ! i) seqs (bounds seqs)
|
||||
|
||||
binSearch v arr (i,j)
|
||||
| i <= j = case compare v (arr ! k) of
|
||||
LT -> binSearch v arr (i,k-1)
|
||||
@@ -292,6 +292,24 @@ genCncFuns gr am cm ex_seqs seqs cdefs fid_cnt cnccats =
|
||||
where
|
||||
k = (i+j) `div` 2
|
||||
|
||||
addBundle id ((fid_cnt,crc,prods),fun_st) bundle@(sigs,lins) =
|
||||
case Map.lookup bundle fun_st of
|
||||
Just (funid, C.CncFun funs lins) ->
|
||||
let !fun_st' = Map.insert bundle (funid, C.CncFun (i2i id:funs) lins) fun_st
|
||||
!prods' = foldl' (\prods (args,res) -> IntMap.insert res (Set.singleton (C.PApply funid args)) prods) prods sigs
|
||||
in ((fid_cnt,crc,prods'),fun_st')
|
||||
Nothing ->
|
||||
let !funid = Map.size fun_st
|
||||
!fun_st' = Map.insert bundle (funid, C.CncFun [i2i id] lins) fun_st
|
||||
!prods' = foldl' (\prods (args,res) -> IntMap.insert res (Set.singleton (C.PApply funid args)) prods) prods sigs
|
||||
in ((fid_cnt,crc,prods'),fun_st')
|
||||
|
||||
mkFId (_,cat) fid0 =
|
||||
case Map.lookup (i2i cat) cnccats of
|
||||
Just (C.CncCat s e _) -> s+fid0
|
||||
Nothing -> error ("GrammarToPGF.mkFId: missing category "++showIdent cat)
|
||||
|
||||
|
||||
genPrintNames cdefs =
|
||||
Map.fromAscList [(i2i id, name) | ((m,id),info) <- cdefs, name <- prn info]
|
||||
where
|
||||
@@ -306,3 +324,29 @@ genPrintNames cdefs =
|
||||
--mkArray lst = listArray (0,length lst-1) lst
|
||||
mkMapArray map = array (0,Map.size map-1) [(v,k) | (k,v) <- Map.toList map]
|
||||
mkSetArray set = listArray (0,Set.size set-1) [v | v <- Set.toList set]
|
||||
|
||||
|
||||
|
||||
readDepConfig :: FilePath -> IO (Map.Map CId [DepPragma])
|
||||
readDepConfig fpath =
|
||||
fmap (Map.fromList . concatMap toEntry . lines) $ readFile fpath
|
||||
where
|
||||
toEntry l =
|
||||
case words l of
|
||||
[] -> []
|
||||
("--":_) -> []
|
||||
(fun:ws) -> [(mkCId fun,[toPragma w | w <- ws])]
|
||||
|
||||
toPragma "head" = Head 0 ""
|
||||
toPragma ('h':'e':'a':'d':':':cs) =
|
||||
case break (==':') cs of
|
||||
(lbl,[] ) -> Head 0 lbl
|
||||
(lbl,':':cs) -> Head (read cs) lbl
|
||||
toPragma "rel" = Rel 0
|
||||
toPragma ('r':'e':'l':':':cs) = Rel (read cs)
|
||||
toPragma "_" = Skip
|
||||
toPragma "anchor" = Anch
|
||||
toPragma s =
|
||||
case break (==':') s of
|
||||
(lbl,[] ) -> Mod 0 lbl
|
||||
(lbl,':':cs) -> Mod (read cs) lbl
|
||||
|
||||
@@ -273,7 +273,7 @@ hSkeleton gr =
|
||||
fns = groupBy valtypg (sortBy valtyps (map jty (Map.assocs (funs (abstract gr)))))
|
||||
valtyps (_, (_,x)) (_, (_,y)) = compare x y
|
||||
valtypg (_, (_,x)) (_, (_,y)) = x == y
|
||||
jty (f,(ty,_,_,_)) = (f,catSkeleton ty)
|
||||
jty (f,(ty,_,_,_,_)) = (f,catSkeleton ty)
|
||||
{-
|
||||
updateSkeleton :: OIdent -> HSkeleton -> (OIdent, [OIdent]) -> HSkeleton
|
||||
updateSkeleton cat skel rule =
|
||||
|
||||
@@ -32,8 +32,8 @@ pgf2js pgf =
|
||||
abstract2js :: String -> Abstr -> JS.Expr
|
||||
abstract2js start ds = new "GFAbstract" [JS.EStr start, JS.EObj $ map absdef2js (Map.assocs (funs ds))]
|
||||
|
||||
absdef2js :: (CId,(Type,Int,Maybe ([Equation],[[M.Instr]]),Double)) -> JS.Property
|
||||
absdef2js (f,(typ,_,_,_)) =
|
||||
absdef2js :: (CId,(Type,[DepPragma],Int,Maybe ([Equation],[[M.Instr]]),Double)) -> JS.Property
|
||||
absdef2js (f,(typ,_,_,_,_)) =
|
||||
let (args,cat) = M.catSkeleton typ in
|
||||
JS.Prop (JS.IdentPropName (JS.Ident (showCId f))) (new "Type" [JS.EArray [JS.EStr (showCId x) | x <- args], JS.EStr (showCId cat)])
|
||||
|
||||
@@ -78,7 +78,7 @@ frule2js (PCoerce arg) = new "Coerce" [JS.EInt arg]
|
||||
|
||||
farg2js (PArg hypos fid) = new "PArg" (map (JS.EInt . snd) hypos ++ [JS.EInt fid])
|
||||
|
||||
ffun2js (CncFun f lins) = new "CncFun" [JS.EStr (showCId f), JS.EArray (map JS.EInt (Array.elems lins))]
|
||||
ffun2js (CncFun fns lins) = new "CncFun" [JS.EArray (map (JS.EStr . showCId) fns), JS.EArray (map JS.EInt (Array.elems lins))]
|
||||
|
||||
seq2js :: Array.Array DotPos Symbol -> JS.Expr
|
||||
seq2js seq = JS.EArray [sym2js s | s <- Array.elems seq]
|
||||
|
||||
@@ -54,11 +54,11 @@ plAbstract name abs
|
||||
let args = reverse [EFun x | (_,x) <- subst]] ++++
|
||||
plFacts name "fun" 3 "(?Fun, ?Type, ?[X:Type,...])"
|
||||
[[plp fun, plType cat args, plHypos hypos] |
|
||||
(fun, (typ, _, _, _)) <- Map.assocs (funs abs),
|
||||
(fun, (typ, _, _, _, _)) <- Map.assocs (funs abs),
|
||||
let (_, DTyp hypos cat args) = alphaConvert emptyEnv typ] ++++
|
||||
plFacts name "def" 2 "(?Fun, ?Expr)"
|
||||
[[plp fun, plp expr] |
|
||||
(fun, (_, _, Just (eqs,_), _)) <- Map.assocs (funs abs),
|
||||
(fun, (_, _, _, Just (eqs,_), _)) <- Map.assocs (funs abs),
|
||||
let (_, expr) = alphaConvert emptyEnv eqs]
|
||||
)
|
||||
where plType cat args = plTerm (plp cat) (map plp args)
|
||||
|
||||
@@ -40,8 +40,8 @@ pgf2python pgf = ("# -*- coding: utf-8 -*-" ++++
|
||||
abs = abstract pgf
|
||||
cncs = concretes pgf
|
||||
|
||||
pyAbsdef :: (Type, Int, Maybe ([Equation], [[M.Instr]]), Double) -> String
|
||||
pyAbsdef (typ, _, _, _) = pyTuple 0 id [pyCId cat, pyList 0 pyCId args]
|
||||
pyAbsdef :: (Type, [DepPragma], Int, Maybe ([Equation], [[M.Instr]]), Double) -> String
|
||||
pyAbsdef (typ, _, _, _, _) = pyTuple 0 id [pyCId cat, pyList 0 pyCId args]
|
||||
where (args, cat) = M.catSkeleton typ
|
||||
|
||||
pyLiteral :: Literal -> String
|
||||
@@ -62,7 +62,7 @@ pyConcrete cnc = pyDict 3 pyStr id [
|
||||
]
|
||||
where pyProds prods = pyList 5 pyProduction (Set.toList prods)
|
||||
pyCncCat (CncCat start end _) = pyList 0 pyCat [start..end]
|
||||
pyCncFun (CncFun f lins) = pyTuple 0 id [pyList 0 pySeq (Array.elems lins), pyCId f]
|
||||
pyCncFun (CncFun fns lins) = pyTuple 0 id [pyList 0 pySeq (Array.elems lins), pyList 0 pyCId fns]
|
||||
pySymbols syms = pyList 0 pySymbol (Array.elems syms)
|
||||
|
||||
pyProduction :: Production -> String
|
||||
|
||||
@@ -157,6 +157,7 @@ data Flags = Flags {
|
||||
optDocumentRoot :: Maybe FilePath, -- For --server mode
|
||||
optRecomp :: Recomp,
|
||||
optProbsFile :: Maybe FilePath,
|
||||
optLabelsFile :: Maybe FilePath,
|
||||
optRetainResource :: Bool,
|
||||
optName :: Maybe String,
|
||||
optPreprocessors :: [String],
|
||||
@@ -268,6 +269,7 @@ defaultFlags = Flags {
|
||||
optDocumentRoot = Nothing,
|
||||
optRecomp = RecompIfNewer,
|
||||
optProbsFile = Nothing,
|
||||
optLabelsFile = Nothing,
|
||||
optRetainResource = False,
|
||||
|
||||
optName = Nothing,
|
||||
@@ -349,8 +351,9 @@ optDescr =
|
||||
Option [] ["gfo","no-recomp"] (NoArg (recomp NeverRecomp))
|
||||
"Never recompile from source, if there is already .gfo file.",
|
||||
Option [] ["retain"] (NoArg (set $ \o -> o { optRetainResource = True })) "Retain opers.",
|
||||
Option [] ["probs"] (ReqArg probsFile "file.probs") "Read probabilities from file.",
|
||||
Option ['n'] ["name"] (ReqArg name "NAME")
|
||||
Option [] ["probs"] (ReqArg probsFile "file.probs") "Read probabilities from a file.",
|
||||
Option [] ["depconf"] (ReqArg labelsFile "file.labels") "Read a configuration for generation of syntactic dependency graphs from a file.",
|
||||
Option ['n'] ["name"] (ReqArg name "NAME")
|
||||
(unlines ["Use NAME as the name of the output. This is used in the output file names, ",
|
||||
"with suffixes depending on the formats, and, when relevant, ",
|
||||
"internally in the output."]),
|
||||
@@ -373,6 +376,8 @@ optDescr =
|
||||
"Enable or disable global grammar optimization. This could significantly reduce the size of the final PGF file",
|
||||
Option [] ["split-pgf"] (NoArg (splitPGF True))
|
||||
"Split the PGF into one file per language. This allows the runtime to load only individual languages",
|
||||
Option [] ["stem"] (onOff (toggleOptimize OptStem) True) "Perform stem-suffix analysis (default on).",
|
||||
Option [] ["cse"] (onOff (toggleOptimize OptCSE) True) "Perform common sub-expression elimination (default on).",
|
||||
Option [] ["cfg"] (ReqArg cfgTransform "TRANS") "Enable or disable specific CFG transformations. TRANS = merge, no-merge, bottomup, no-bottomup, ...",
|
||||
Option [] ["heuristic_search_factor"] (ReqArg (readDouble (\d o -> o { optHeuristicFactor = Just d })) "FACTOR") "Set the heuristic search factor for statistical parsing",
|
||||
Option [] ["case_sensitive"] (onOff (\v -> set $ \o -> o{optCaseSensitive=v}) True) "Set the parser in case-sensitive/insensitive mode [sensitive by default]",
|
||||
@@ -426,6 +431,7 @@ optDescr =
|
||||
gfDocuRoot x = set $ \o -> o { optDocumentRoot = Just x }
|
||||
recomp x = set $ \o -> o { optRecomp = x }
|
||||
probsFile x = set $ \o -> o { optProbsFile = Just x }
|
||||
labelsFile x = set $ \o -> o { optLabelsFile = Just x }
|
||||
|
||||
name x = set $ \o -> o { optName = Just x }
|
||||
addLibDir x = set $ \o -> o { optLibraryPath = x:optLibraryPath o }
|
||||
@@ -446,6 +452,8 @@ optDescr =
|
||||
optimize_pgf x = set $ \o -> o { optOptimizePGF = x }
|
||||
splitPGF x = set $ \o -> o { optSplitPGF = x }
|
||||
|
||||
toggleOptimize x b = set $ setOptimization' x b
|
||||
|
||||
cfgTransform x = let (x', b) = case x of
|
||||
'n':'o':'-':rest -> (rest, False)
|
||||
_ -> (x, True)
|
||||
|
||||
@@ -23,7 +23,7 @@ import GF.System.Console (setConsoleEncoding)
|
||||
-- Run @gf --help@ for usage info.
|
||||
main :: IO ()
|
||||
main = do
|
||||
--setConsoleEncoding
|
||||
setConsoleEncoding
|
||||
uncurry mainOpts =<< getOptions
|
||||
|
||||
-- | Get and parse GF command line arguments. Fix relative paths.
|
||||
|
||||
@@ -57,7 +57,7 @@ pgfToCFG pgf lang = mkCFG (showCId (lookStartCat pgf)) extCats (startRules ++ co
|
||||
|
||||
topdownRules cat = f cat []
|
||||
where
|
||||
f cat rules = maybe rules (Set.foldr g rules) (IntMap.lookup cat (productions cnc))
|
||||
f cat rules = maybe rules (Set.fold g rules) (IntMap.lookup cat (productions cnc))
|
||||
|
||||
g (PApply funid args) rules = (cncfuns cnc ! funid,args) : rules
|
||||
g (PCoerce cat) rules = f cat rules
|
||||
@@ -74,12 +74,15 @@ pgfToCFG pgf lang = mkCFG (showCId (lookStartCat pgf)) extCats (startRules ++ co
|
||||
|
||||
ruleToCFRule :: (FId,Production) -> [CFRule]
|
||||
ruleToCFRule (c,PApply funid args) =
|
||||
[Rule (fcatToCat c l) (mkRhs row) (profilesToTerm [fixProfile row n | n <- [0..length args-1]])
|
||||
[Rule (fcatToCat c l) (mkRhs row) term
|
||||
| (l,seqid) <- Array.assocs rhs
|
||||
, let row = sequences cnc ! seqid
|
||||
, not (containsLiterals row)]
|
||||
, not (containsLiterals row)
|
||||
, f <- fns
|
||||
, let term = profilesToTerm f [fixProfile row n | n <- [0..length args-1]]
|
||||
]
|
||||
where
|
||||
CncFun f rhs = cncfuns cnc ! funid
|
||||
CncFun fns rhs = cncfuns cnc ! funid
|
||||
|
||||
mkRhs :: Array DotPos Symbol -> [CFSymbol]
|
||||
mkRhs = concatMap symbolToCFSymbol . Array.elems
|
||||
@@ -111,8 +114,8 @@ pgfToCFG pgf lang = mkCFG (showCId (lookStartCat pgf)) extCats (startRules ++ co
|
||||
getPos (SymLit j _) = [j]
|
||||
getPos _ = []
|
||||
|
||||
profilesToTerm :: [Profile] -> CFTerm
|
||||
profilesToTerm ps = CFObj f (zipWith profileToTerm argTypes ps)
|
||||
profilesToTerm :: CId -> [Profile] -> CFTerm
|
||||
profilesToTerm f ps = CFObj f (zipWith profileToTerm argTypes ps)
|
||||
where (argTypes,_) = catSkeleton $ lookType (abstract pgf) f
|
||||
|
||||
profileToTerm :: CId -> Profile -> CFTerm
|
||||
|
||||
489
src/pgf-binary/PGF/Data/Binary.hs
Normal file
489
src/pgf-binary/PGF/Data/Binary.hs
Normal file
@@ -0,0 +1,489 @@
|
||||
{-# LANGUAGE FlexibleInstances, FlexibleContexts #-}
|
||||
-- | This is a layer on top of "Data.Binary" with its own 'Binary' class
|
||||
-- and customised instances for 'Word', 'Int' and 'Double'.
|
||||
-- The 'Int' and 'Word' instance use a variable-length encoding to save space
|
||||
-- for small numbers. The 'Double' instance uses the standard IEEE754 encoding.
|
||||
module PGF.Data.Binary (
|
||||
|
||||
-- * The Binary class
|
||||
Binary(..)
|
||||
|
||||
-- * The Get and Put monads
|
||||
, Get , Put, runPut
|
||||
|
||||
-- * Useful helpers for writing instances
|
||||
, putWord8 , getWord8 , putWord16be , getWord16be
|
||||
|
||||
-- * Binary serialisation
|
||||
, encode , decode
|
||||
|
||||
-- * IO functions for serialisation
|
||||
, encodeFile , decodeFile
|
||||
|
||||
, encodeFile_ , decodeFile_
|
||||
|
||||
-- * Useful
|
||||
, Word8, Word16
|
||||
|
||||
) where
|
||||
|
||||
|
||||
import Data.Word
|
||||
|
||||
import qualified Data.Binary as Bin
|
||||
import Data.Binary.Put
|
||||
import Data.Binary.Get
|
||||
import Data.Binary.IEEE754 ( putFloat64be, getFloat64be)
|
||||
import Control.Monad
|
||||
import Control.Exception
|
||||
import Foreign
|
||||
import System.IO
|
||||
|
||||
import Data.ByteString.Lazy (ByteString)
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
|
||||
--import Data.Char (chr,ord)
|
||||
--import Data.List (unfoldr)
|
||||
|
||||
-- And needed for the instances:
|
||||
import qualified Data.ByteString as B
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.IntMap as IntMap
|
||||
import qualified Data.IntSet as IntSet
|
||||
--import qualified Data.Ratio as R
|
||||
|
||||
--import qualified Data.Tree as T
|
||||
|
||||
import Data.Array.Unboxed
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
-- | The @Binary@ class provides 'put' and 'get', methods to encode and
|
||||
-- decode a Haskell value to a lazy ByteString. It mirrors the Read and
|
||||
-- Show classes for textual representation of Haskell types, and is
|
||||
-- suitable for serialising Haskell values to disk, over the network.
|
||||
--
|
||||
-- For parsing and generating simple external binary formats (e.g. C
|
||||
-- structures), Binary may be used, but in general is not suitable
|
||||
-- for complex protocols. Instead use the Put and Get primitives
|
||||
-- directly.
|
||||
--
|
||||
-- Instances of Binary should satisfy the following property:
|
||||
--
|
||||
-- > decode . encode == id
|
||||
--
|
||||
-- That is, the 'get' and 'put' methods should be the inverse of each
|
||||
-- other. A range of instances are provided for basic Haskell types.
|
||||
--
|
||||
class Binary t where
|
||||
-- | Encode a value in the Put monad.
|
||||
put :: t -> Put
|
||||
-- | Decode a value in the Get monad
|
||||
get :: Get t
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- Wrappers to run the underlying monad
|
||||
|
||||
-- | Encode a value using binary serialisation to a lazy ByteString.
|
||||
--
|
||||
encode :: Binary a => a -> ByteString
|
||||
encode = runPut . put
|
||||
{-# INLINE encode #-}
|
||||
|
||||
-- | Decode a value from a lazy ByteString, reconstructing the original structure.
|
||||
--
|
||||
decode :: Binary a => ByteString -> a
|
||||
decode = runGet get
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- Convenience IO operations
|
||||
|
||||
-- | Lazily serialise a value to a file
|
||||
--
|
||||
-- This is just a convenience function, it's defined simply as:
|
||||
--
|
||||
-- > encodeFile f = B.writeFile f . encode
|
||||
--
|
||||
-- So for example if you wanted to compress as well, you could use:
|
||||
--
|
||||
-- > B.writeFile f . compress . encode
|
||||
--
|
||||
encodeFile :: Binary a => FilePath -> a -> IO ()
|
||||
encodeFile f v = L.writeFile f (encode v)
|
||||
|
||||
encodeFile_ :: FilePath -> Put -> IO ()
|
||||
encodeFile_ f m = L.writeFile f (runPut m)
|
||||
|
||||
-- | Lazily reconstruct a value previously written to a file.
|
||||
--
|
||||
-- This is just a convenience function, it's defined simply as:
|
||||
--
|
||||
-- > decodeFile f = return . decode =<< B.readFile f
|
||||
--
|
||||
-- So for example if you wanted to decompress as well, you could use:
|
||||
--
|
||||
-- > return . decode . decompress =<< B.readFile f
|
||||
--
|
||||
decodeFile :: Binary a => FilePath -> IO a
|
||||
decodeFile f = bracket (openBinaryFile f ReadMode) hClose $ \h -> do
|
||||
s <- L.hGetContents h
|
||||
evaluate $ runGet get s
|
||||
|
||||
decodeFile_ :: FilePath -> Get a -> IO a
|
||||
decodeFile_ f m = bracket (openBinaryFile f ReadMode) hClose $ \h -> do
|
||||
s <- L.hGetContents h
|
||||
evaluate $ runGet m s
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- For ground types, the standard instances can be reused,
|
||||
-- but for container types it would imply using
|
||||
-- the standard instances for all types of values in the container...
|
||||
|
||||
instance Binary () where put=Bin.put; get=Bin.get
|
||||
instance Binary Bool where put=Bin.put; get=Bin.get
|
||||
instance Binary Word8 where put=Bin.put; get=Bin.get
|
||||
instance Binary Word16 where put=Bin.put; get=Bin.get
|
||||
instance Binary Char where put=Bin.put; get=Bin.get
|
||||
|
||||
-- -- GF doesn't need these:
|
||||
--instance Binary Ordering where put=Bin.put; get=Bin.get
|
||||
--instance Binary Word32 where put=Bin.put; get=Bin.get
|
||||
--instance Binary Word64 where put=Bin.put; get=Bin.get
|
||||
--instance Binary Int8 where put=Bin.put; get=Bin.get
|
||||
--instance Binary Int16 where put=Bin.put; get=Bin.get
|
||||
--instance Binary Int32 where put=Bin.put; get=Bin.get
|
||||
|
||||
--instance Binary Int64 where put=Bin.put; get=Bin.get -- needed by instance Binary ByteString
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
-- Words are written as sequence of bytes. The last bit of each
|
||||
-- byte indicates whether there are more bytes to be read
|
||||
instance Binary Word where
|
||||
put i | i <= 0x7f = do put a
|
||||
| i <= 0x3fff = do put (a .|. 0x80)
|
||||
put b
|
||||
| i <= 0x1fffff = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put c
|
||||
| i <= 0xfffffff = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put (c .|. 0x80)
|
||||
put d
|
||||
-- -- #if WORD_SIZE_IN_BITS < 64
|
||||
| otherwise = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put (c .|. 0x80)
|
||||
put (d .|. 0x80)
|
||||
put e
|
||||
{-
|
||||
-- Restricted to 32 bits even on 64-bit systems, so that negative
|
||||
-- Ints are written as 5 bytes instead of 10 bytes (TH 2013-02-13)
|
||||
--#else
|
||||
| i <= 0x7ffffffff = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put (c .|. 0x80)
|
||||
put (d .|. 0x80)
|
||||
put e
|
||||
| i <= 0x3ffffffffff = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put (c .|. 0x80)
|
||||
put (d .|. 0x80)
|
||||
put (e .|. 0x80)
|
||||
put f
|
||||
| i <= 0x1ffffffffffff = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put (c .|. 0x80)
|
||||
put (d .|. 0x80)
|
||||
put (e .|. 0x80)
|
||||
put (f .|. 0x80)
|
||||
put g
|
||||
| i <= 0xffffffffffffff = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put (c .|. 0x80)
|
||||
put (d .|. 0x80)
|
||||
put (e .|. 0x80)
|
||||
put (f .|. 0x80)
|
||||
put (g .|. 0x80)
|
||||
put h
|
||||
| i <= 0xffffffffffffff = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put (c .|. 0x80)
|
||||
put (d .|. 0x80)
|
||||
put (e .|. 0x80)
|
||||
put (f .|. 0x80)
|
||||
put (g .|. 0x80)
|
||||
put h
|
||||
| i <= 0x7fffffffffffffff = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put (c .|. 0x80)
|
||||
put (d .|. 0x80)
|
||||
put (e .|. 0x80)
|
||||
put (f .|. 0x80)
|
||||
put (g .|. 0x80)
|
||||
put (h .|. 0x80)
|
||||
put j
|
||||
| otherwise = do put (a .|. 0x80)
|
||||
put (b .|. 0x80)
|
||||
put (c .|. 0x80)
|
||||
put (d .|. 0x80)
|
||||
put (e .|. 0x80)
|
||||
put (f .|. 0x80)
|
||||
put (g .|. 0x80)
|
||||
put (h .|. 0x80)
|
||||
put (j .|. 0x80)
|
||||
put k
|
||||
-- #endif
|
||||
-}
|
||||
where
|
||||
a = fromIntegral ( i .&. 0x7f) :: Word8
|
||||
b = fromIntegral (shiftR i 7 .&. 0x7f) :: Word8
|
||||
c = fromIntegral (shiftR i 14 .&. 0x7f) :: Word8
|
||||
d = fromIntegral (shiftR i 21 .&. 0x7f) :: Word8
|
||||
e = fromIntegral (shiftR i 28 .&. 0x7f) :: Word8
|
||||
{-
|
||||
f = fromIntegral (shiftR i 35 .&. 0x7f) :: Word8
|
||||
g = fromIntegral (shiftR i 42 .&. 0x7f) :: Word8
|
||||
h = fromIntegral (shiftR i 49 .&. 0x7f) :: Word8
|
||||
j = fromIntegral (shiftR i 56 .&. 0x7f) :: Word8
|
||||
k = fromIntegral (shiftR i 63 .&. 0x7f) :: Word8
|
||||
-}
|
||||
get = do i <- getWord8
|
||||
(if i <= 0x7f
|
||||
then return (fromIntegral i)
|
||||
else do n <- get
|
||||
return $ (n `shiftL` 7) .|. (fromIntegral (i .&. 0x7f)))
|
||||
|
||||
-- Int has the same representation as Word
|
||||
instance Binary Int where
|
||||
put i = put (fromIntegral i :: Word)
|
||||
get = liftM toInt32 (get :: Get Word)
|
||||
where
|
||||
-- restrict to 32 bits (for PGF portability, TH 2013-02-13)
|
||||
toInt32 w = fromIntegral (fromIntegral w::Int32)::Int
|
||||
|
||||
------------------------------------------------------------------------
|
||||
--
|
||||
-- Portable, and pretty efficient, serialisation of Integer
|
||||
--
|
||||
|
||||
-- Fixed-size type for a subset of Integer
|
||||
--type SmallInt = Int32
|
||||
|
||||
-- Integers are encoded in two ways: if they fit inside a SmallInt,
|
||||
-- they're written as a byte tag, and that value. If the Integer value
|
||||
-- is too large to fit in a SmallInt, it is written as a byte array,
|
||||
-- along with a sign and length field.
|
||||
{-
|
||||
instance Binary Integer where
|
||||
|
||||
{-# INLINE put #-}
|
||||
put n | n >= lo && n <= hi = do
|
||||
putWord8 0
|
||||
put (fromIntegral n :: SmallInt) -- fast path
|
||||
where
|
||||
lo = fromIntegral (minBound :: SmallInt) :: Integer
|
||||
hi = fromIntegral (maxBound :: SmallInt) :: Integer
|
||||
|
||||
put n = do
|
||||
putWord8 1
|
||||
put sign
|
||||
put (unroll (abs n)) -- unroll the bytes
|
||||
where
|
||||
sign = fromIntegral (signum n) :: Word8
|
||||
|
||||
{-# INLINE get #-}
|
||||
get = do
|
||||
tag <- get :: Get Word8
|
||||
case tag of
|
||||
0 -> liftM fromIntegral (get :: Get SmallInt)
|
||||
_ -> do sign <- get
|
||||
bytes <- get
|
||||
let v = roll bytes
|
||||
return $! if sign == (1 :: Word8) then v else - v
|
||||
|
||||
--
|
||||
-- Fold and unfold an Integer to and from a list of its bytes
|
||||
--
|
||||
unroll :: Integer -> [Word8]
|
||||
unroll = unfoldr step
|
||||
where
|
||||
step 0 = Nothing
|
||||
step i = Just (fromIntegral i, i `shiftR` 8)
|
||||
|
||||
roll :: [Word8] -> Integer
|
||||
roll = foldr unstep 0
|
||||
where
|
||||
unstep b a = a `shiftL` 8 .|. fromIntegral b
|
||||
|
||||
instance (Binary a,Integral a) => Binary (R.Ratio a) where
|
||||
put r = put (R.numerator r) >> put (R.denominator r)
|
||||
get = liftM2 (R.%) get get
|
||||
-}
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- Instances for the first few tuples
|
||||
|
||||
instance (Binary a, Binary b) => Binary (a,b) where
|
||||
put (a,b) = put a >> put b
|
||||
get = liftM2 (,) get get
|
||||
|
||||
instance (Binary a, Binary b, Binary c) => Binary (a,b,c) where
|
||||
put (a,b,c) = put a >> put b >> put c
|
||||
get = liftM3 (,,) get get get
|
||||
|
||||
instance (Binary a, Binary b, Binary c, Binary d) => Binary (a,b,c,d) where
|
||||
put (a,b,c,d) = put a >> put b >> put c >> put d
|
||||
get = liftM4 (,,,) get get get get
|
||||
|
||||
instance (Binary a, Binary b, Binary c, Binary d, Binary e) => Binary (a,b,c,d,e) where
|
||||
put (a,b,c,d,e) = put a >> put b >> put c >> put d >> put e
|
||||
get = liftM5 (,,,,) get get get get get
|
||||
|
||||
--
|
||||
-- and now just recurse:
|
||||
--
|
||||
|
||||
instance (Binary a, Binary b, Binary c, Binary d, Binary e, Binary f)
|
||||
=> Binary (a,b,c,d,e,f) where
|
||||
put (a,b,c,d,e,f) = put (a,(b,c,d,e,f))
|
||||
get = do (a,(b,c,d,e,f)) <- get ; return (a,b,c,d,e,f)
|
||||
|
||||
instance (Binary a, Binary b, Binary c, Binary d, Binary e, Binary f, Binary g)
|
||||
=> Binary (a,b,c,d,e,f,g) where
|
||||
put (a,b,c,d,e,f,g) = put (a,(b,c,d,e,f,g))
|
||||
get = do (a,(b,c,d,e,f,g)) <- get ; return (a,b,c,d,e,f,g)
|
||||
|
||||
instance (Binary a, Binary b, Binary c, Binary d, Binary e,
|
||||
Binary f, Binary g, Binary h)
|
||||
=> Binary (a,b,c,d,e,f,g,h) where
|
||||
put (a,b,c,d,e,f,g,h) = put (a,(b,c,d,e,f,g,h))
|
||||
get = do (a,(b,c,d,e,f,g,h)) <- get ; return (a,b,c,d,e,f,g,h)
|
||||
|
||||
instance (Binary a, Binary b, Binary c, Binary d, Binary e,
|
||||
Binary f, Binary g, Binary h, Binary i)
|
||||
=> Binary (a,b,c,d,e,f,g,h,i) where
|
||||
put (a,b,c,d,e,f,g,h,i) = put (a,(b,c,d,e,f,g,h,i))
|
||||
get = do (a,(b,c,d,e,f,g,h,i)) <- get ; return (a,b,c,d,e,f,g,h,i)
|
||||
|
||||
instance (Binary a, Binary b, Binary c, Binary d, Binary e,
|
||||
Binary f, Binary g, Binary h, Binary i, Binary j)
|
||||
=> Binary (a,b,c,d,e,f,g,h,i,j) where
|
||||
put (a,b,c,d,e,f,g,h,i,j) = put (a,(b,c,d,e,f,g,h,i,j))
|
||||
get = do (a,(b,c,d,e,f,g,h,i,j)) <- get ; return (a,b,c,d,e,f,g,h,i,j)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- Container types
|
||||
|
||||
instance Binary a => Binary [a] where
|
||||
put l = put (length l) >> mapM_ put l
|
||||
get = do n <- get :: Get Int
|
||||
xs <- replicateM n get
|
||||
return xs
|
||||
|
||||
instance (Binary a) => Binary (Maybe a) where
|
||||
put Nothing = putWord8 0
|
||||
put (Just x) = putWord8 1 >> put x
|
||||
get = do
|
||||
w <- getWord8
|
||||
case w of
|
||||
0 -> return Nothing
|
||||
_ -> liftM Just get
|
||||
|
||||
instance (Binary a, Binary b) => Binary (Either a b) where
|
||||
put (Left a) = putWord8 0 >> put a
|
||||
put (Right b) = putWord8 1 >> put b
|
||||
get = do
|
||||
w <- getWord8
|
||||
case w of
|
||||
0 -> liftM Left get
|
||||
_ -> liftM Right get
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- ByteStrings (have specially efficient instances)
|
||||
|
||||
instance Binary B.ByteString where
|
||||
put bs = do put (B.length bs)
|
||||
putByteString bs
|
||||
get = get >>= getByteString
|
||||
|
||||
--
|
||||
-- Using old versions of fps, this is a type synonym, and non portable
|
||||
--
|
||||
-- Requires 'flexible instances'
|
||||
--
|
||||
{-
|
||||
instance Binary ByteString where
|
||||
put bs = do put (fromIntegral (L.length bs) :: Int)
|
||||
putLazyByteString bs
|
||||
get = get >>= getLazyByteString
|
||||
-}
|
||||
------------------------------------------------------------------------
|
||||
-- Maps and Sets
|
||||
|
||||
instance (Ord a, Binary a) => Binary (Set.Set a) where
|
||||
put s = put (Set.size s) >> mapM_ put (Set.toAscList s)
|
||||
get = liftM Set.fromDistinctAscList get
|
||||
|
||||
instance (Ord k, Binary k, Binary e) => Binary (Map.Map k e) where
|
||||
put m = put (Map.size m) >> mapM_ put (Map.toAscList m)
|
||||
get = liftM Map.fromDistinctAscList get
|
||||
|
||||
instance Binary IntSet.IntSet where
|
||||
put s = put (IntSet.size s) >> mapM_ put (IntSet.toAscList s)
|
||||
get = liftM IntSet.fromDistinctAscList get
|
||||
|
||||
instance (Binary e) => Binary (IntMap.IntMap e) where
|
||||
put m = put (IntMap.size m) >> mapM_ put (IntMap.toAscList m)
|
||||
get = liftM IntMap.fromDistinctAscList get
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- Floating point
|
||||
|
||||
-- instance Binary Double where
|
||||
-- put d = put (decodeFloat d)
|
||||
-- get = liftM2 encodeFloat get get
|
||||
|
||||
instance Binary Double where
|
||||
put = putFloat64be
|
||||
get = getFloat64be
|
||||
{-
|
||||
instance Binary Float where
|
||||
put f = put (decodeFloat f)
|
||||
get = liftM2 encodeFloat get get
|
||||
-}
|
||||
------------------------------------------------------------------------
|
||||
-- Trees
|
||||
{-
|
||||
instance (Binary e) => Binary (T.Tree e) where
|
||||
put (T.Node r s) = put r >> put s
|
||||
get = liftM2 T.Node get get
|
||||
-}
|
||||
------------------------------------------------------------------------
|
||||
-- Arrays
|
||||
|
||||
instance (Binary i, Ix i, Binary e) => Binary (Array i e) where
|
||||
put a = do
|
||||
put (bounds a)
|
||||
put (rangeSize $ bounds a) -- write the length
|
||||
mapM_ put (elems a) -- now the elems.
|
||||
get = do
|
||||
bs <- get
|
||||
n <- get -- read the length
|
||||
xs <- replicateM n get -- now the elems.
|
||||
return (listArray bs xs)
|
||||
|
||||
--
|
||||
-- The IArray UArray e constraint is non portable. Requires flexible instances
|
||||
--
|
||||
instance (Binary i, Ix i, Binary e, IArray UArray e) => Binary (UArray i e) where
|
||||
put a = do
|
||||
put (bounds a)
|
||||
put (rangeSize $ bounds a) -- now write the length
|
||||
mapM_ put (elems a)
|
||||
get = do
|
||||
bs <- get
|
||||
n <- get
|
||||
xs <- replicateM n get
|
||||
return (listArray bs xs)
|
||||
27
src/pgf-binary/pgf-binary.cabal
Normal file
27
src/pgf-binary/pgf-binary.cabal
Normal file
@@ -0,0 +1,27 @@
|
||||
name: pgf-binary
|
||||
version: 0.5
|
||||
|
||||
cabal-version: >= 1.10
|
||||
build-type: Simple
|
||||
license: BSD3
|
||||
--license-file: LICENSE
|
||||
synopsis: Custom version of the binary-0.5 package for the PGF library
|
||||
homepage: http://www.grammaticalframework.org/
|
||||
--bug-reports: http://code.google.com/p/grammatical-framework/issues/list
|
||||
maintainer: Thomas Hallgren
|
||||
stability: provisional
|
||||
category: Data, Parsing
|
||||
tested-with: GHC==7.4.2, GHC==7.8.3
|
||||
|
||||
source-repository head
|
||||
type: darcs
|
||||
location: http://www.grammaticalframework.org/
|
||||
|
||||
Library
|
||||
default-language: Haskell2010
|
||||
build-depends: base >= 4.3 && <5, binary, data-binary-ieee754,
|
||||
containers, array, bytestring
|
||||
exposed-modules: PGF.Data.Binary
|
||||
|
||||
ghc-options: -fwarn-unused-imports -O2
|
||||
extensions: FlexibleInstances, FlexibleContexts
|
||||
@@ -76,9 +76,27 @@ typedef GuSeq PgfEquations;
|
||||
|
||||
typedef void *PgfFunction;
|
||||
|
||||
typedef enum {
|
||||
PGF_DEP_PRAGMA_HEAD,
|
||||
PGF_DEP_PRAGMA_MOD,
|
||||
PGF_DEP_PRAGMA_REL,
|
||||
PGF_DEP_PRAGMA_SKIP,
|
||||
PGF_DEP_PRAGMA_ANCH,
|
||||
PGF_DEP_PRAGMA_TAGS
|
||||
} PgfDepPragmaTag;
|
||||
|
||||
typedef struct {
|
||||
PgfDepPragmaTag tag;
|
||||
size_t index;
|
||||
GuString label;
|
||||
} PgfDepPragma;
|
||||
|
||||
typedef GuSeq PgfDepPragmas;
|
||||
|
||||
typedef struct {
|
||||
PgfCId name;
|
||||
PgfType* type;
|
||||
PgfDepPragmas* pragmas;
|
||||
int arity;
|
||||
PgfEquations* defns; // maybe null
|
||||
PgfExprProb ep;
|
||||
@@ -119,7 +137,6 @@ typedef struct {
|
||||
PgfFlags* aflags;
|
||||
PgfAbsFuns* funs;
|
||||
PgfAbsCats* cats;
|
||||
PgfAbsFun* abs_lin_fun;
|
||||
PgfEvalGates* eval_gates;
|
||||
} PgfAbstr;
|
||||
|
||||
@@ -262,8 +279,8 @@ typedef struct {
|
||||
typedef GuSeq PgfSequences;
|
||||
|
||||
typedef struct {
|
||||
PgfAbsFun* absfun;
|
||||
PgfExprProb *ep;
|
||||
GuSeq* absfuns;
|
||||
prob_t prob;
|
||||
int funid;
|
||||
size_t n_lins;
|
||||
PgfSequence* lins[];
|
||||
|
||||
@@ -413,3 +413,304 @@ pgf_graphviz_word_alignment(PgfConcr** concrs, size_t n_concrs, PgfExpr expr, Pg
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
PgfPGF* pgf;
|
||||
int next_fid;
|
||||
GuBuf* anchors;
|
||||
GuBuf* heads;
|
||||
GuPool* pool;
|
||||
} PgfDepGenState;
|
||||
|
||||
typedef struct {
|
||||
int fid;
|
||||
int visit;
|
||||
PgfExpr expr;
|
||||
GuBuf* edges;
|
||||
} PgfDepNode;
|
||||
|
||||
typedef struct {
|
||||
GuString label;
|
||||
PgfDepNode* node;
|
||||
} PgfDepEdge;
|
||||
|
||||
typedef struct {
|
||||
bool solved;
|
||||
size_t start;
|
||||
size_t end;
|
||||
GuString label;
|
||||
} PgfDepStackRange;
|
||||
|
||||
static void
|
||||
pgf_graphviz_dependency_graph_(PgfDepGenState* state,
|
||||
size_t parents_start,size_t parents_end,
|
||||
GuString head_label, GuString mod_label,
|
||||
PgfExpr expr);
|
||||
|
||||
static bool
|
||||
pgf_graphviz_dependency_graph_apply(PgfDepGenState* state,
|
||||
size_t parents_start,size_t parents_end,
|
||||
GuString head_label, GuString mod_label,
|
||||
GuBuf* args, GuSeq* pragmas)
|
||||
{
|
||||
size_t n_args = gu_buf_length(args);
|
||||
size_t n_pragmas = pragmas ? gu_seq_length(pragmas) : 0;
|
||||
|
||||
size_t n_count = (n_args <= n_pragmas) ? n_args : n_pragmas;
|
||||
PgfDepStackRange ranges[n_count+1];
|
||||
for (size_t i = 0; i <= n_count; i++) {
|
||||
ranges[i].solved = false;
|
||||
ranges[i].label =
|
||||
(i > 0) ? gu_seq_index(pragmas, PgfDepPragma, i-1)->label
|
||||
: NULL;
|
||||
}
|
||||
|
||||
ranges[0].start = gu_buf_length(state->heads);
|
||||
ranges[0].end = gu_buf_length(state->heads);
|
||||
|
||||
bool rel_solved = false;
|
||||
size_t n_solved = 0;
|
||||
size_t count = 0;
|
||||
while (n_solved < n_count) {
|
||||
if (!ranges[0].solved) {
|
||||
ranges[0].start = gu_buf_length(state->heads);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < n_count; i++) {
|
||||
if (ranges[i+1].solved)
|
||||
continue;
|
||||
|
||||
PgfExpr arg = gu_buf_get(args, PgfExpr, n_args-i-1);
|
||||
PgfDepPragma* pragma = gu_seq_index(pragmas, PgfDepPragma, i);
|
||||
|
||||
switch (pragma->tag) {
|
||||
case PGF_DEP_PRAGMA_MOD:
|
||||
assert(pragma->index <= n_count);
|
||||
if (ranges[0].solved && ranges[pragma->index].solved) {
|
||||
ranges[i+1].start = gu_buf_length(state->heads);
|
||||
pgf_graphviz_dependency_graph_(state,
|
||||
ranges[pragma->index].start, ranges[pragma->index].end,
|
||||
NULL, ranges[i+1].label,
|
||||
arg);
|
||||
ranges[i+1].end = gu_buf_length(state->heads);
|
||||
ranges[i+1].solved= true;
|
||||
n_solved++;
|
||||
}
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_REL:
|
||||
ranges[i+1].solved = true;
|
||||
ranges[i+1].start = 0;
|
||||
ranges[i+1].end = 0;
|
||||
n_solved++;
|
||||
|
||||
GuPool *tmp_pool = gu_local_pool();
|
||||
|
||||
GuStringBuf* sbuf =
|
||||
gu_new_string_buf(tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
GuExn* err = gu_new_exn(tmp_pool);
|
||||
|
||||
pgf_print_expr(arg, NULL, 0, out, err);
|
||||
|
||||
ranges[pragma->index].label =
|
||||
gu_string_buf_freeze(sbuf, state->pool);
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_SKIP:
|
||||
ranges[i+1].solved = true;
|
||||
n_solved++;
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_ANCH:
|
||||
if (ranges[0].solved) {
|
||||
ranges[i+1].start = gu_buf_length(state->heads);
|
||||
pgf_graphviz_dependency_graph_(state,0,0,"ROOT","ROOT",arg);
|
||||
ranges[i+1].end = gu_buf_length(state->heads);
|
||||
ranges[i+1].solved= true;
|
||||
n_solved++;
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_HEAD:
|
||||
if (!rel_solved)
|
||||
break;
|
||||
|
||||
if (!ranges[0].solved) {
|
||||
GuString new_head_label = head_label;
|
||||
GuString new_mod_label = mod_label;
|
||||
if (pragma->label != NULL && *pragma->label && pragma->index == 0) {
|
||||
new_head_label = pragma->label;
|
||||
new_mod_label = "ROOT";
|
||||
}
|
||||
if (ranges[0].label != NULL)
|
||||
new_mod_label = ranges[0].label;
|
||||
ranges[i+1].start = gu_buf_length(state->heads);
|
||||
pgf_graphviz_dependency_graph_(state,
|
||||
parents_start,parents_end,
|
||||
new_head_label, new_mod_label,
|
||||
arg);
|
||||
ranges[i+1].end = gu_buf_length(state->heads);
|
||||
if (pragma->index == 0) {
|
||||
ranges[i+1].solved = true;
|
||||
n_solved++;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (pragma->index != 0 && ranges[pragma->index].solved) {
|
||||
for (size_t j = ranges[pragma->index].start; j < ranges[pragma->index].end; j++) {
|
||||
PgfDepNode* parent = gu_buf_get(state->heads, PgfDepNode*, j);
|
||||
for (size_t k = ranges[i+1].start; k < ranges[i+1].end; k++) {
|
||||
PgfDepNode* child = gu_buf_get(state->heads, PgfDepNode*, k);
|
||||
PgfDepEdge* edge = gu_buf_extend(parent->edges);
|
||||
edge->label = pragma->label;
|
||||
edge->node = child;
|
||||
}
|
||||
}
|
||||
ranges[i+1].solved = true;
|
||||
n_solved++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
gu_impossible();
|
||||
}
|
||||
}
|
||||
|
||||
if (rel_solved) {
|
||||
if (!ranges[0].solved) {
|
||||
ranges[0].end = gu_buf_length(state->heads);
|
||||
ranges[0].solved = true;
|
||||
}
|
||||
} else {
|
||||
rel_solved = true;
|
||||
}
|
||||
}
|
||||
|
||||
gu_buf_trim_n(state->heads, gu_buf_length(state->heads)-ranges[0].end);
|
||||
|
||||
return (count > 0);
|
||||
}
|
||||
|
||||
static void
|
||||
pgf_graphviz_dependency_graph_(PgfDepGenState* state,
|
||||
size_t parents_start,size_t parents_end,
|
||||
GuString head_label, GuString mod_label,
|
||||
PgfExpr expr)
|
||||
{
|
||||
PgfExpr e = expr;
|
||||
GuBuf* args = gu_new_buf(PgfDepNode*, state->pool);
|
||||
|
||||
for (;;) {
|
||||
GuVariantInfo ei = gu_variant_open(e);
|
||||
switch (ei.tag) {
|
||||
case PGF_EXPR_APP: {
|
||||
PgfExprApp* app = ei.data;
|
||||
gu_buf_push(args, PgfExpr, app->arg);
|
||||
e = app->fun;
|
||||
break;
|
||||
}
|
||||
case PGF_EXPR_TYPED: {
|
||||
PgfExprTyped* typed = ei.data;
|
||||
e = typed->expr;
|
||||
break;
|
||||
}
|
||||
case PGF_EXPR_IMPL_ARG: {
|
||||
PgfExprImplArg* implarg = ei.data;
|
||||
e = implarg->expr;
|
||||
break;
|
||||
}
|
||||
case PGF_EXPR_FUN: {
|
||||
PgfExprFun* fun = ei.data;
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_binsearch(state->pgf->abstract.funs, pgf_absfun_order, PgfAbsFun, fun->fun);
|
||||
|
||||
if (pgf_graphviz_dependency_graph_apply(state,
|
||||
parents_start,parents_end,
|
||||
head_label,mod_label,
|
||||
args,absfun ? absfun->pragmas : NULL))
|
||||
return;
|
||||
// continue to default
|
||||
}
|
||||
default: {
|
||||
PgfDepNode* node = gu_new(PgfDepNode, state->pool);
|
||||
node->fid = state->next_fid++;
|
||||
node->visit = 0;
|
||||
node->expr = expr;
|
||||
node->edges = gu_new_buf(PgfDepEdge, state->pool);
|
||||
|
||||
for (size_t i = parents_start; i < parents_end; i++) {
|
||||
PgfDepNode* parent = gu_buf_get(state->heads, PgfDepNode*, i);
|
||||
if (head_label == NULL) {
|
||||
PgfDepEdge* edge = gu_buf_extend(parent->edges);
|
||||
edge->label = mod_label;
|
||||
edge->node = node;
|
||||
} else {
|
||||
PgfDepEdge* edge = gu_buf_extend(node->edges);
|
||||
edge->label = head_label;
|
||||
edge->node = parent;
|
||||
}
|
||||
}
|
||||
|
||||
gu_buf_push(state->heads, PgfDepNode*, node);
|
||||
if (head_label != NULL)
|
||||
gu_buf_push(state->anchors, PgfDepNode*, node);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pgf_graphviz_print_graph(PgfGraphvizOptions* opts, PgfDepNode* node,
|
||||
GuOut* out, GuExn* err)
|
||||
{
|
||||
if (node->visit++ > 0)
|
||||
return;
|
||||
|
||||
gu_printf(out, err, " n%d[label = \"", node->fid);
|
||||
pgf_print_expr(node->expr, NULL, 0, out, err);
|
||||
if (opts->nodeColor != NULL && *opts->nodeColor)
|
||||
gu_printf(out, err, ", fontcolor = \"%s\"", opts->nodeColor);
|
||||
if (opts->nodeFont != NULL && *opts->nodeFont)
|
||||
gu_printf(out, err, ", fontname = \"%s\"", opts->nodeFont);
|
||||
gu_puts("\"]\n", out, err);
|
||||
|
||||
size_t n_children = gu_buf_length(node->edges);
|
||||
for (size_t i = 0; i < n_children; i++) {
|
||||
PgfDepEdge* edge = gu_buf_index(node->edges, PgfDepEdge, n_children-i-1);
|
||||
gu_printf(out, err, " n%d -> n%d [label = \"%s\"",
|
||||
node->fid, edge->node->fid, edge->label);
|
||||
if (opts->nodeEdgeStyle != NULL && *opts->nodeEdgeStyle)
|
||||
gu_printf(out, err, ", style = \"%s\"", opts->nodeEdgeStyle);
|
||||
if (opts->nodeColor != NULL && *opts->nodeColor)
|
||||
gu_printf(out, err, ", color = \"%s\"", opts->nodeColor);
|
||||
gu_puts("]\n", out, err);
|
||||
|
||||
if (edge->node->fid > node->fid)
|
||||
pgf_graphviz_print_graph(opts, edge->node, out, err);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pgf_graphviz_dependency_graph(PgfPGF* pgf, PgfExpr expr,
|
||||
PgfGraphvizOptions* opts,
|
||||
GuOut* out, GuExn* err,
|
||||
GuPool* pool)
|
||||
{
|
||||
PgfDepGenState state;
|
||||
state.pgf = pgf;
|
||||
state.next_fid = 1;
|
||||
state.pool = pool;
|
||||
state.anchors = gu_new_buf(PgfDepNode*, pool);
|
||||
state.heads = gu_new_buf(PgfDepNode*, pool);
|
||||
|
||||
pgf_graphviz_dependency_graph_(&state, 0, 0, "ROOT", "ROOT", expr);
|
||||
|
||||
gu_puts("digraph {\n", out, err);
|
||||
size_t n_anchors = gu_buf_length(state.anchors);
|
||||
for (size_t i = 0; i < n_anchors; i++) {
|
||||
PgfDepNode* node = gu_buf_get(state.anchors, PgfDepNode*, i);
|
||||
pgf_graphviz_print_graph(opts,node,out,err);
|
||||
}
|
||||
gu_puts("}", out, err);
|
||||
}
|
||||
|
||||
@@ -40,15 +40,23 @@ pgf_lzr_index(PgfConcr* concr,
|
||||
switch (gu_variant_tag(prod)) {
|
||||
case PGF_PRODUCTION_APPLY: {
|
||||
PgfProductionApply* papply = data;
|
||||
PgfCncOverloadMap* overl_table =
|
||||
gu_map_get(concr->fun_indices, papply->fun->absfun->name,
|
||||
PgfCncOverloadMap*);
|
||||
if (!overl_table) {
|
||||
overl_table = gu_new_addr_map(PgfCCat*, GuBuf*, &gu_null_struct, pool);
|
||||
gu_map_put(concr->fun_indices,
|
||||
papply->fun->absfun->name, PgfCncOverloadMap*, overl_table);
|
||||
|
||||
size_t n_absfuns = gu_seq_length(papply->fun->absfuns);
|
||||
for (size_t i = 0; i < n_absfuns; i++) {
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_get(papply->fun->absfuns, PgfAbsFun*, i);
|
||||
|
||||
PgfCncOverloadMap* overl_table =
|
||||
gu_map_get(concr->fun_indices, absfun->name,
|
||||
PgfCncOverloadMap*);
|
||||
if (!overl_table) {
|
||||
overl_table = gu_new_addr_map(PgfCCat*, GuBuf*, &gu_null_struct, pool);
|
||||
gu_map_put(concr->fun_indices,
|
||||
absfun->name,
|
||||
PgfCncOverloadMap*, overl_table);
|
||||
}
|
||||
pgf_lzr_add_overl_entry(overl_table, ccat, papply, pool);
|
||||
}
|
||||
pgf_lzr_add_overl_entry(overl_table, ccat, papply, pool);
|
||||
break;
|
||||
}
|
||||
case PGF_PRODUCTION_COERCE: {
|
||||
@@ -148,7 +156,7 @@ pgf_cnc_resolve(PgfCnc* cnc,
|
||||
static PgfCncTree
|
||||
pgf_cnc_resolve_app(PgfCnc* cnc,
|
||||
size_t n_vars, PgfPrintContext* context,
|
||||
PgfCCat* ccat, GuBuf* buf, GuBuf* args,
|
||||
PgfCCat* ccat, PgfCId abs_id, GuBuf* buf, GuBuf* args,
|
||||
GuPool* pool)
|
||||
{
|
||||
GuChoiceMark mark = gu_choice_mark(cnc->ch);
|
||||
@@ -164,6 +172,7 @@ pgf_cnc_resolve_app(PgfCnc* cnc,
|
||||
capp->ccat = ccat;
|
||||
capp->n_vars = n_vars;
|
||||
capp->context = context;
|
||||
capp->abs_id = abs_id;
|
||||
|
||||
redo:;
|
||||
int index = gu_choice_next(cnc->ch, gu_buf_length(buf));
|
||||
@@ -175,7 +184,6 @@ redo:;
|
||||
gu_buf_get(buf, PgfProductionApply*, index);
|
||||
gu_assert(n_args == gu_seq_length(papply->args));
|
||||
|
||||
capp->abs_id = papply->fun->absfun->name;
|
||||
capp->fun = papply->fun;
|
||||
capp->fid = 0;
|
||||
capp->n_args = n_args;
|
||||
@@ -470,7 +478,7 @@ redo:;
|
||||
gu_map_iter(overl_table, &clo.fn, NULL);
|
||||
assert(clo.ccat != NULL && clo.buf != NULL);
|
||||
|
||||
ret = pgf_cnc_resolve_app(cnc, n_vars, context, clo.ccat, clo.buf, args, pool);
|
||||
ret = pgf_cnc_resolve_app(cnc, n_vars, context, clo.ccat, efun->fun, clo.buf, args, pool);
|
||||
if (gu_variant_is_null(ret)) {
|
||||
gu_choice_reset(cnc->ch, mark);
|
||||
if (gu_choice_advance(cnc->ch))
|
||||
@@ -483,7 +491,7 @@ redo:;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = pgf_cnc_resolve_app(cnc, n_vars, context, ccat, buf, args, pool);
|
||||
ret = pgf_cnc_resolve_app(cnc, n_vars, context, ccat, efun->fun, buf, args, pool);
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -803,7 +803,12 @@ pgf_lookup_ctree_to_expr(PgfCncTree ctree, PgfExprProb* ep,
|
||||
switch (cti.tag) {
|
||||
case PGF_CNC_TREE_APP: {
|
||||
PgfCncTreeApp* fapp = cti.data;
|
||||
*ep = fapp->fun->absfun->ep;
|
||||
if (gu_seq_length(fapp->fun->absfuns) > 0)
|
||||
*ep = gu_seq_get(fapp->fun->absfuns, PgfAbsFun*, 0)->ep;
|
||||
else {
|
||||
ep->expr = gu_null_variant;
|
||||
ep->prob = fapp->fun->prob;
|
||||
}
|
||||
n_args = fapp->n_args;
|
||||
args = fapp->args;
|
||||
break;
|
||||
@@ -923,8 +928,15 @@ pgf_lookup_sentence(PgfConcr* concr, PgfType* typ, GuString sentence, GuPool* po
|
||||
size_t n_cncfuns = gu_seq_length(concr->cncfuns);
|
||||
for (size_t i = 0; i < n_cncfuns; i++) {
|
||||
PgfCncFun* cncfun = gu_seq_get(concr->cncfuns, PgfCncFun*, i);
|
||||
for (size_t lin_idx = 0; lin_idx < cncfun->n_lins; lin_idx++) {
|
||||
pgf_lookup_index_syms(lexicon_idx, cncfun->lins[lin_idx]->syms, cncfun->absfun, pool);
|
||||
|
||||
size_t n_absfuns = gu_seq_length(cncfun->absfuns);
|
||||
for (size_t j = 0; j < n_absfuns; j++) {
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_get(cncfun->absfuns, PgfAbsFun*, j);
|
||||
|
||||
for (size_t lin_idx = 0; lin_idx < cncfun->n_lins; lin_idx++) {
|
||||
pgf_lookup_index_syms(lexicon_idx, cncfun->lins[lin_idx]->syms, absfun, pool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -710,8 +710,8 @@ pgf_new_item(PgfParsing* ps, PgfItemConts* conts, PgfProduction prod)
|
||||
case PGF_PRODUCTION_APPLY: {
|
||||
PgfProductionApply* papp = pi.data;
|
||||
item->args = papp->args;
|
||||
item->inside_prob = papp->fun->ep->prob;
|
||||
|
||||
item->inside_prob = papp->fun->prob;
|
||||
|
||||
int n_args = gu_seq_length(item->args);
|
||||
for (int i = 0; i < n_args; i++) {
|
||||
PgfPArg *arg = gu_seq_index(item->args, PgfPArg, i);
|
||||
@@ -1265,8 +1265,12 @@ pgf_parsing_add_transition(PgfParsing* ps, PgfToken tok, PgfItem* item)
|
||||
ps->tp = gu_new(PgfTokenProb, ps->out_pool);
|
||||
ps->tp->tok = tok;
|
||||
ps->tp->cat = item->conts->ccat->cnccat->abscat->name;
|
||||
ps->tp->fun = papp->fun->absfun->name;
|
||||
ps->tp->prob = item->inside_prob + item->conts->outside_prob;
|
||||
ps->tp->fun = "_";
|
||||
|
||||
if (gu_seq_length(papp->fun->absfuns) > 0)
|
||||
ps->tp->fun =
|
||||
gu_seq_get(papp->fun->absfuns, PgfAbsFun*, 0)->name;
|
||||
}
|
||||
} else {
|
||||
if (!ps->before->needs_bind && cmp_string(¤t, tok, ps->case_sensitive) == 0) {
|
||||
@@ -1794,19 +1798,25 @@ pgf_result_production(PgfParsing* ps,
|
||||
case PGF_PRODUCTION_APPLY: {
|
||||
PgfProductionApply* papp = pi.data;
|
||||
|
||||
PgfExprState *st = gu_new(PgfExprState, ps->pool);
|
||||
st->answers = answers;
|
||||
st->ep = *papp->fun->ep;
|
||||
st->args = papp->args;
|
||||
st->arg_idx = 0;
|
||||
size_t n_absfuns = gu_seq_length(papp->fun->absfuns);
|
||||
for (size_t i = 0; i < n_absfuns; i++) {
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_get(papp->fun->absfuns, PgfAbsFun*, i);
|
||||
|
||||
size_t n_args = gu_seq_length(st->args);
|
||||
for (size_t k = 0; k < n_args; k++) {
|
||||
PgfPArg* parg = gu_seq_index(st->args, PgfPArg, k);
|
||||
st->ep.prob += parg->ccat->viterbi_prob;
|
||||
PgfExprState *st = gu_new(PgfExprState, ps->pool);
|
||||
st->answers = answers;
|
||||
st->ep = absfun->ep;
|
||||
st->args = papp->args;
|
||||
st->arg_idx = 0;
|
||||
|
||||
size_t n_args = gu_seq_length(st->args);
|
||||
for (size_t k = 0; k < n_args; k++) {
|
||||
PgfPArg* parg = gu_seq_index(st->args, PgfPArg, k);
|
||||
st->ep.prob += parg->ccat->viterbi_prob;
|
||||
}
|
||||
|
||||
gu_buf_heap_push(ps->expr_queue, &pgf_expr_state_order, &st);
|
||||
}
|
||||
|
||||
gu_buf_heap_push(ps->expr_queue, &pgf_expr_state_order, &st);
|
||||
break;
|
||||
}
|
||||
case PGF_PRODUCTION_COERCE: {
|
||||
@@ -2355,15 +2365,20 @@ pgf_morpho_iter(PgfProductionIdx* idx,
|
||||
PgfProductionIdxEntry* entry =
|
||||
gu_buf_index(idx, PgfProductionIdxEntry, i);
|
||||
|
||||
PgfCId lemma = entry->papp->fun->absfun->name;
|
||||
GuString analysis = entry->ccat->cnccat->labels[entry->lin_idx];
|
||||
|
||||
prob_t prob = entry->ccat->cnccat->abscat->prob +
|
||||
entry->papp->fun->absfun->ep.prob;
|
||||
callback->callback(callback,
|
||||
lemma, analysis, prob, err);
|
||||
if (!gu_ok(err))
|
||||
return;
|
||||
size_t n_absfuns = gu_seq_length(entry->papp->fun->absfuns);
|
||||
for (size_t j = 0; j < n_absfuns; j++) {
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_get(entry->papp->fun->absfuns, PgfAbsFun*, j);
|
||||
PgfCId lemma = absfun->name;
|
||||
GuString analysis = entry->ccat->cnccat->labels[entry->lin_idx];
|
||||
|
||||
prob_t prob = entry->ccat->cnccat->abscat->prob +
|
||||
absfun->ep.prob;
|
||||
callback->callback(callback,
|
||||
lemma, analysis, prob, err);
|
||||
if (!gu_ok(err))
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2569,7 +2584,7 @@ pgf_ccat_set_viterbi_prob(PgfCCat* ccat) {
|
||||
return INFINITY;
|
||||
|
||||
prob_t viterbi_prob = INFINITY;
|
||||
|
||||
|
||||
size_t n_prods = gu_seq_length(ccat->prods);
|
||||
for (size_t i = 0; i < n_prods; i++) {
|
||||
PgfProduction prod =
|
||||
@@ -2581,7 +2596,7 @@ pgf_ccat_set_viterbi_prob(PgfCCat* ccat) {
|
||||
switch (inf.tag) {
|
||||
case PGF_PRODUCTION_APPLY: {
|
||||
PgfProductionApply* papp = inf.data;
|
||||
prob = papp->fun->ep->prob;
|
||||
prob = papp->fun->prob;
|
||||
|
||||
size_t n_args = gu_seq_length(papp->args);
|
||||
for (size_t j = 0; j < n_args; j++) {
|
||||
|
||||
@@ -60,7 +60,44 @@ pgf_print_absfuns(PgfAbsFuns* absfuns, GuOut *out, GuExn* err)
|
||||
pgf_print_cid(absfun->name, out, err);
|
||||
gu_puts(" : ", out, err);
|
||||
pgf_print_type(absfun->type, NULL, 0, out, err);
|
||||
gu_printf(out, err, " ; -- %f\n", absfun->ep.prob);
|
||||
gu_printf(out, err, " ; -- %f ", absfun->ep.prob);
|
||||
|
||||
size_t n_pragmas = gu_seq_length(absfun->pragmas);
|
||||
for (size_t i = 0; i < n_pragmas; i++) {
|
||||
PgfDepPragma* pragma =
|
||||
gu_seq_index(absfun->pragmas, PgfDepPragma, i);
|
||||
switch (pragma->tag) {
|
||||
case PGF_DEP_PRAGMA_HEAD:
|
||||
gu_puts("head",out,err);
|
||||
if (pragma->index > 0)
|
||||
gu_printf(out,err,":%d", pragma->index);
|
||||
if (pragma->label != NULL && *pragma->label != 0)
|
||||
gu_printf(out,err,":%s", pragma->label);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_MOD:
|
||||
gu_puts(pragma->label, out,err);
|
||||
if (pragma->index > 0)
|
||||
gu_printf(out,err,":%d", pragma->index);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_REL:
|
||||
gu_puts("rel",out,err);
|
||||
if (pragma->index > 0)
|
||||
gu_printf(out,err,":%d", pragma->index);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_SKIP:
|
||||
gu_puts("_",out,err);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_ANCH:
|
||||
gu_puts("anchor",out,err);
|
||||
break;
|
||||
default:
|
||||
gu_impossible();
|
||||
}
|
||||
|
||||
gu_putc(' ', out, err);
|
||||
}
|
||||
|
||||
gu_putc('\n', out, err);
|
||||
}
|
||||
}
|
||||
static void
|
||||
@@ -206,15 +243,17 @@ pgf_print_cncfun(PgfCncFun *cncfun, PgfSequences* sequences,
|
||||
gu_printf(out,err,"S%d", (seq - ((PgfSequence*) gu_seq_data(sequences))));
|
||||
}
|
||||
|
||||
gu_puts(")", out, err);
|
||||
|
||||
if (cncfun->absfun != NULL) {
|
||||
gu_puts(" [", out, err);
|
||||
pgf_print_cid(cncfun->absfun->name, out, err);
|
||||
gu_puts("]", out, err);
|
||||
gu_puts(") [", out, err);
|
||||
|
||||
size_t n_absfuns = gu_seq_length(cncfun->absfuns);
|
||||
for (size_t i = 0; i < n_absfuns; i++) {
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_get(cncfun->absfuns, PgfAbsFun*, i);
|
||||
|
||||
pgf_print_cid(absfun->name, out, err);
|
||||
}
|
||||
|
||||
gu_puts("\n", out, err);
|
||||
|
||||
gu_puts("]\n", out, err);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -407,6 +407,45 @@ pgf_read_patt(PgfReader* rdr)
|
||||
return patt;
|
||||
}
|
||||
|
||||
static PgfDepPragmas*
|
||||
pgf_read_deppragmas(PgfReader* rdr)
|
||||
{
|
||||
size_t n_pragmas = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
GuSeq* pragmas = gu_new_seq(PgfDepPragma, n_pragmas, rdr->opool);
|
||||
for (size_t i = 0; i < n_pragmas; i++) {
|
||||
PgfDepPragma* pragma = gu_seq_index(pragmas, PgfDepPragma, i);
|
||||
pragma->tag = pgf_read_tag(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
switch (pragma->tag) {
|
||||
case PGF_DEP_PRAGMA_HEAD:
|
||||
pragma->index = pgf_read_int(rdr);
|
||||
pragma->label = pgf_read_string(rdr);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_MOD:
|
||||
pragma->index = pgf_read_int(rdr);
|
||||
pragma->label = pgf_read_string(rdr);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_REL:
|
||||
pragma->index = pgf_read_int(rdr);
|
||||
pragma->label = NULL;
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_SKIP:
|
||||
pragma->index = 0;
|
||||
pragma->label = NULL;
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_ANCH:
|
||||
pragma->index = 0;
|
||||
pragma->label = NULL;
|
||||
break;
|
||||
default:
|
||||
pgf_read_tag_error(rdr);
|
||||
}
|
||||
}
|
||||
return pragmas;
|
||||
}
|
||||
|
||||
static PgfAbsFun*
|
||||
pgf_read_absfun(PgfReader* rdr, PgfAbstr* abstr, PgfAbsFun* absfun)
|
||||
{
|
||||
@@ -426,6 +465,9 @@ pgf_read_absfun(PgfReader* rdr, PgfAbstr* abstr, PgfAbsFun* absfun)
|
||||
absfun->type = pgf_read_type_(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
absfun->pragmas = pgf_read_deppragmas(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
absfun->arity = pgf_read_int(rdr);
|
||||
|
||||
uint8_t tag = pgf_read_tag(rdr);
|
||||
@@ -549,17 +591,6 @@ pgf_read_abstract(PgfReader* rdr, PgfAbstr* abstract)
|
||||
|
||||
abstract->cats = pgf_read_abscats(rdr, abstract);
|
||||
gu_return_on_exn(rdr->err, );
|
||||
|
||||
abstract->abs_lin_fun = gu_new(PgfAbsFun, rdr->opool);
|
||||
abstract->abs_lin_fun->name = "_";
|
||||
abstract->abs_lin_fun->type = gu_new(PgfType, rdr->opool);
|
||||
abstract->abs_lin_fun->type->hypos = NULL;
|
||||
abstract->abs_lin_fun->type->cid = "_";
|
||||
abstract->abs_lin_fun->type->n_exprs = 0;
|
||||
abstract->abs_lin_fun->arity = 0;
|
||||
abstract->abs_lin_fun->defns = NULL;
|
||||
abstract->abs_lin_fun->ep.prob = INFINITY;
|
||||
abstract->abs_lin_fun->ep.expr = gu_null_variant;
|
||||
}
|
||||
|
||||
static PgfCIdMap*
|
||||
@@ -776,22 +807,38 @@ pgf_read_sequences(PgfReader* rdr)
|
||||
static PgfCncFun*
|
||||
pgf_read_cncfun(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr, int funid)
|
||||
{
|
||||
PgfCId name = pgf_read_cid(rdr, rdr->tmp_pool);
|
||||
size_t n_absfuns = pgf_read_len(rdr);
|
||||
GuSeq* absfuns =
|
||||
gu_new_seq(PgfAbsFun*, n_absfuns, rdr->opool);
|
||||
prob_t prob;
|
||||
if (n_absfuns == 0)
|
||||
prob = 0;
|
||||
else {
|
||||
prob = INFINITY;
|
||||
for (size_t i = 0; i < n_absfuns; i++) {
|
||||
PgfCId name = pgf_read_cid(rdr, rdr->tmp_pool);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_binsearch(abstr->funs, pgf_absfun_order, PgfAbsFun, name);
|
||||
|
||||
if (prob > absfun->ep.prob)
|
||||
prob = absfun->ep.prob;
|
||||
|
||||
gu_seq_set(absfuns, PgfAbsFun*, i, absfun);
|
||||
}
|
||||
}
|
||||
|
||||
size_t n_lins = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
size_t len = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_binsearch(abstr->funs, pgf_absfun_order, PgfAbsFun, name);
|
||||
|
||||
PgfCncFun* cncfun = gu_new_flex(rdr->opool, PgfCncFun, lins, len);
|
||||
cncfun->absfun = absfun;
|
||||
cncfun->ep = (absfun == NULL) ? NULL : &absfun->ep;
|
||||
PgfCncFun* cncfun = gu_new_flex(rdr->opool, PgfCncFun, lins, n_lins);
|
||||
cncfun->absfuns = absfuns;
|
||||
cncfun->prob = prob;
|
||||
cncfun->funid = funid;
|
||||
cncfun->n_lins = len;
|
||||
cncfun->n_lins = n_lins;
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
for (size_t i = 0; i < n_lins; i++) {
|
||||
size_t seqid = pgf_read_int(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
@@ -878,7 +925,6 @@ pgf_read_lindefs(PgfReader* rdr, PgfConcr* concr)
|
||||
ccat->lindefs = gu_new_seq(PgfCncFun*, n_funs, rdr->opool);
|
||||
for (size_t j = 0; j < n_funs; j++) {
|
||||
PgfCncFun* fun = pgf_read_funid(rdr, concr);
|
||||
fun->absfun = concr->abstr->abs_lin_fun;
|
||||
gu_seq_set(ccat->lindefs, PgfCncFun*, j, fun);
|
||||
}
|
||||
}
|
||||
@@ -899,7 +945,6 @@ pgf_read_linrefs(PgfReader* rdr, PgfConcr* concr)
|
||||
ccat->linrefs = gu_new_seq(PgfCncFun*, n_funs, rdr->opool);
|
||||
for (size_t j = 0; j < n_funs; j++) {
|
||||
PgfCncFun* fun = pgf_read_funid(rdr, concr);
|
||||
fun->absfun = concr->abstr->abs_lin_fun;
|
||||
gu_seq_set(ccat->linrefs, PgfCncFun*, j, fun);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,6 +311,32 @@ pgf_write_absfun(PgfAbsFun* absfun, PgfWriter* wtr)
|
||||
|
||||
pgf_write_type_(absfun->type, wtr);
|
||||
gu_return_on_exn(wtr->err, );
|
||||
|
||||
size_t n_pragmas = gu_seq_length(absfun->pragmas);
|
||||
for (size_t i = 0; i < n_pragmas; i++) {
|
||||
PgfDepPragma* pragma =
|
||||
gu_seq_index(absfun->pragmas, PgfDepPragma, i);
|
||||
|
||||
pgf_write_tag(pragma->tag, wtr);
|
||||
switch (pragma->tag) {
|
||||
case PGF_DEP_PRAGMA_HEAD:
|
||||
pgf_write_int(pragma->index, wtr);
|
||||
pgf_write_string(pragma->label, wtr);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_MOD:
|
||||
pgf_write_int(pragma->index, wtr);
|
||||
pgf_write_string(pragma->label, wtr);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_REL:
|
||||
pgf_write_int(pragma->index, wtr);
|
||||
break;
|
||||
case PGF_DEP_PRAGMA_SKIP:
|
||||
case PGF_DEP_PRAGMA_ANCH:
|
||||
break;
|
||||
default:
|
||||
gu_impossible();
|
||||
}
|
||||
}
|
||||
|
||||
pgf_write_int(absfun->arity, wtr);
|
||||
|
||||
@@ -579,8 +605,15 @@ pgf_write_sequences(PgfSequences* seqs, PgfWriter* wtr)
|
||||
static void
|
||||
pgf_write_cncfun(PgfCncFun* cncfun, PgfConcr* concr, PgfWriter* wtr)
|
||||
{
|
||||
pgf_write_cid(cncfun->absfun->name, wtr);
|
||||
gu_return_on_exn(wtr->err, );
|
||||
size_t n_absfuns = gu_seq_length(cncfun->absfuns);
|
||||
pgf_write_len(n_absfuns, wtr);
|
||||
for (size_t i = 0; i < n_absfuns; i++) {
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_get(cncfun->absfuns, PgfAbsFun*, i);
|
||||
|
||||
pgf_write_cid(absfun->name, wtr);
|
||||
gu_return_on_exn(wtr->err, );
|
||||
}
|
||||
|
||||
pgf_write_len(cncfun->n_lins, wtr);
|
||||
gu_return_on_exn(wtr->err, );
|
||||
|
||||
@@ -1305,20 +1305,26 @@ sg_update_fts_index(SgSG* sg, PgfPGF* pgf, GuExn* err)
|
||||
for (size_t funid = 0; funid < n_funs; funid++) {
|
||||
PgfCncFun* cncfun = gu_seq_get(concr->cncfuns, PgfCncFun*, funid);
|
||||
|
||||
SgId key = 0;
|
||||
rc = find_function_rowid(sg, &ctxt, cncfun->absfun->name, &key, 1);
|
||||
if (rc != SQLITE_OK) {
|
||||
sg_raise_sqlite(rc, err);
|
||||
goto close;
|
||||
}
|
||||
size_t n_absfuns = gu_seq_length(cncfun->absfuns);
|
||||
for (size_t i = 0; i < n_absfuns; i++) {
|
||||
PgfAbsFun* absfun =
|
||||
gu_seq_get(cncfun->absfuns, PgfAbsFun*, i);
|
||||
|
||||
for (size_t lin_idx = 0; lin_idx < cncfun->n_lins; lin_idx++) {
|
||||
PgfSequence* seq = cncfun->lins[lin_idx];
|
||||
rc = insert_syms(sg, crsTokens, seq->syms, key);
|
||||
SgId key = 0;
|
||||
rc = find_function_rowid(sg, &ctxt, absfun->name, &key, 1);
|
||||
if (rc != SQLITE_OK) {
|
||||
sg_raise_sqlite(rc, err);
|
||||
goto close;
|
||||
}
|
||||
|
||||
for (size_t lin_idx = 0; lin_idx < cncfun->n_lins; lin_idx++) {
|
||||
PgfSequence* seq = cncfun->lins[lin_idx];
|
||||
rc = insert_syms(sg, crsTokens, seq->syms, key);
|
||||
if (rc != SQLITE_OK) {
|
||||
sg_raise_sqlite(rc, err);
|
||||
goto close;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ module PGF2 (-- * PGF
|
||||
MorphoAnalysis, lookupMorpho, fullFormLexicon,
|
||||
-- ** Visualizations
|
||||
GraphvizOptions(..), graphvizDefaults,
|
||||
graphvizAbstractTree, graphvizParseTree, graphvizWordAlignment,
|
||||
graphvizAbstractTree, graphvizParseTree, graphvizDependencyGraph, graphvizWordAlignment,
|
||||
|
||||
-- * Exceptions
|
||||
PGFError(..),
|
||||
@@ -140,14 +140,13 @@ readPGF fpath =
|
||||
|
||||
showPGF :: PGF -> String
|
||||
showPGF p =
|
||||
unsafePerformIO $
|
||||
withGuPool $ \tmpPl ->
|
||||
do (sb,out) <- newOut tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
pgf_print (pgf p) out exn
|
||||
touchPGF p
|
||||
s <- gu_string_buf_freeze sb tmpPl
|
||||
peekUtf8CString s
|
||||
unsafePerformIO $ do
|
||||
tmpPl <- gu_new_pool
|
||||
(sb,out) <- newOut tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
pgf_print (pgf p) out exn
|
||||
touchPGF p
|
||||
peekUtf8CStringBufResult sb tmpPl
|
||||
|
||||
-- | List of all languages available in the grammar.
|
||||
languages :: PGF -> Map.Map ConcName Concr
|
||||
@@ -411,41 +410,48 @@ graphvizDefaults = GraphvizOptions False False False True "" "" "" "" "" ""
|
||||
-- | Renders an abstract syntax tree in a Graphviz format.
|
||||
graphvizAbstractTree :: PGF -> GraphvizOptions -> Expr -> String
|
||||
graphvizAbstractTree p opts e =
|
||||
unsafePerformIO $
|
||||
withGuPool $ \tmpPl ->
|
||||
do (sb,out) <- newOut tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
c_opts <- newGraphvizOptions tmpPl opts
|
||||
pgf_graphviz_abstract_tree (pgf p) (expr e) c_opts out exn
|
||||
touchExpr e
|
||||
s <- gu_string_buf_freeze sb tmpPl
|
||||
peekUtf8CString s
|
||||
|
||||
unsafePerformIO $ do
|
||||
tmpPl <- gu_new_pool
|
||||
(sb,out) <- newOut tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
c_opts <- newGraphvizOptions tmpPl opts
|
||||
pgf_graphviz_abstract_tree (pgf p) (expr e) c_opts out exn
|
||||
touchExpr e
|
||||
peekUtf8CStringBufResult sb tmpPl
|
||||
|
||||
graphvizParseTree :: Concr -> GraphvizOptions -> Expr -> String
|
||||
graphvizParseTree c opts e =
|
||||
unsafePerformIO $
|
||||
withGuPool $ \tmpPl ->
|
||||
do (sb,out) <- newOut tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
c_opts <- newGraphvizOptions tmpPl opts
|
||||
pgf_graphviz_parse_tree (concr c) (expr e) c_opts out exn
|
||||
touchExpr e
|
||||
s <- gu_string_buf_freeze sb tmpPl
|
||||
peekUtf8CString s
|
||||
unsafePerformIO $ do
|
||||
tmpPl <- gu_new_pool
|
||||
(sb,out) <- newOut tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
c_opts <- newGraphvizOptions tmpPl opts
|
||||
pgf_graphviz_parse_tree (concr c) (expr e) c_opts out exn
|
||||
touchExpr e
|
||||
peekUtf8CStringBufResult sb tmpPl
|
||||
|
||||
graphvizDependencyGraph :: PGF -> GraphvizOptions -> Expr -> String
|
||||
graphvizDependencyGraph p opts e =
|
||||
unsafePerformIO $ do
|
||||
tmpPl <- gu_new_pool
|
||||
(sb,out) <- newOut tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
c_opts <- newGraphvizOptions tmpPl opts
|
||||
pgf_graphviz_dependency_graph (pgf p) (expr e) c_opts out exn tmpPl
|
||||
touchExpr e
|
||||
peekUtf8CStringBufResult sb tmpPl
|
||||
|
||||
graphvizWordAlignment :: [Concr] -> GraphvizOptions -> Expr -> String
|
||||
graphvizWordAlignment cs opts e =
|
||||
unsafePerformIO $
|
||||
withGuPool $ \tmpPl ->
|
||||
withArrayLen (map concr cs) $ \n_concrs ptr ->
|
||||
do (sb,out) <- newOut tmpPl
|
||||
do tmpPl <- gu_new_pool
|
||||
(sb,out) <- newOut tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
c_opts <- newGraphvizOptions tmpPl opts
|
||||
pgf_graphviz_word_alignment ptr (fromIntegral n_concrs) (expr e) c_opts out exn
|
||||
touchExpr e
|
||||
s <- gu_string_buf_freeze sb tmpPl
|
||||
peekUtf8CString s
|
||||
peekUtf8CStringBufResult sb tmpPl
|
||||
|
||||
newGraphvizOptions :: Ptr GuPool -> GraphvizOptions -> IO (Ptr PgfGraphvizOptions)
|
||||
newGraphvizOptions pool opts = do
|
||||
@@ -750,8 +756,7 @@ linearize lang e = unsafePerformIO $
|
||||
msg <- peekUtf8CString c_msg
|
||||
throwIO (PGFError msg)
|
||||
else throwIO (PGFError "The abstract tree cannot be linearized")
|
||||
else do lin <- gu_string_buf_freeze sb pl
|
||||
peekUtf8CString lin
|
||||
else do peekUtf8CStringBuf sb
|
||||
|
||||
-- | Generates all possible linearizations of an expression
|
||||
linearizeAll :: Concr -> Expr -> [String]
|
||||
@@ -780,8 +785,7 @@ linearizeAll lang e = unsafePerformIO $
|
||||
if is_nonexist
|
||||
then collect cts exn pl
|
||||
else throwExn exn pl
|
||||
else do lin <- gu_string_buf_freeze sb tmpPl
|
||||
s <- peekUtf8CString lin
|
||||
else do s <- peekUtf8CStringBuf sb
|
||||
ss <- collect cts exn pl
|
||||
return (s:ss)
|
||||
|
||||
@@ -841,8 +845,7 @@ tabularLinearizeAll lang e = unsafePerformIO $
|
||||
if is_nonexist
|
||||
then collectTable lang ctree (lin_idx+1) labels exn tmpPl
|
||||
else throwExn exn
|
||||
else do lin <- gu_string_buf_freeze sb tmpPl
|
||||
s <- peekUtf8CString lin
|
||||
else do s <- peekUtf8CStringBuf sb
|
||||
ss <- collectTable lang ctree (lin_idx+1) labels exn tmpPl
|
||||
return ((label,s):ss)
|
||||
|
||||
|
||||
@@ -252,15 +252,14 @@ foreign import ccall "wrapper"
|
||||
-- of binding.
|
||||
showExpr :: [CId] -> Expr -> String
|
||||
showExpr scope e =
|
||||
unsafePerformIO $
|
||||
withGuPool $ \tmpPl ->
|
||||
do (sb,out) <- newOut tmpPl
|
||||
printCtxt <- newPrintCtxt scope tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
pgf_print_expr (expr e) printCtxt 1 out exn
|
||||
touchExpr e
|
||||
s <- gu_string_buf_freeze sb tmpPl
|
||||
peekUtf8CString s
|
||||
unsafePerformIO $ do
|
||||
tmpPl <- gu_new_pool
|
||||
(sb,out) <- newOut tmpPl
|
||||
printCtxt <- newPrintCtxt scope tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
pgf_print_expr (expr e) printCtxt 1 out exn
|
||||
touchExpr e
|
||||
peekUtf8CStringBufResult sb tmpPl
|
||||
|
||||
newPrintCtxt :: [String] -> Ptr GuPool -> IO (Ptr PgfPrintContext)
|
||||
newPrintCtxt [] pool = return nullPtr
|
||||
|
||||
@@ -15,6 +15,7 @@ import Control.Exception
|
||||
import GHC.Ptr
|
||||
import Data.Int
|
||||
import Data.Word
|
||||
import System.IO.Unsafe
|
||||
|
||||
type Touch = IO ()
|
||||
|
||||
@@ -106,6 +107,12 @@ foreign import ccall unsafe "gu/enum.h gu_enum_next"
|
||||
foreign import ccall unsafe "gu/string.h gu_string_buf_freeze"
|
||||
gu_string_buf_freeze :: Ptr GuStringBuf -> Ptr GuPool -> IO CString
|
||||
|
||||
foreign import ccall unsafe "gu/string.h gu_string_buf_data"
|
||||
gu_string_buf_data :: Ptr GuStringBuf -> IO CString
|
||||
|
||||
foreign import ccall unsafe "gu/string.h gu_string_buf_length"
|
||||
gu_string_buf_length :: Ptr GuStringBuf -> IO CSizeT
|
||||
|
||||
foreign import ccall unsafe "gu/utf8.h gu_utf8_decode"
|
||||
gu_utf8_decode :: Ptr CString -> IO GuUCS
|
||||
|
||||
@@ -186,6 +193,29 @@ peekUtf8CStringLen ptr len =
|
||||
cs <- decode pptr end
|
||||
return (((toEnum . fromEnum) x) : cs)
|
||||
|
||||
peekUtf8CStringBuf :: Ptr GuStringBuf -> IO String
|
||||
peekUtf8CStringBuf sbuf = do
|
||||
ptr <- gu_string_buf_data sbuf
|
||||
len <- gu_string_buf_length sbuf
|
||||
peekUtf8CStringLen ptr (fromIntegral len)
|
||||
|
||||
peekUtf8CStringBufResult :: Ptr GuStringBuf -> Ptr GuPool -> IO String
|
||||
peekUtf8CStringBufResult sbuf pool = do
|
||||
fptr <- newForeignPtr gu_pool_finalizer pool
|
||||
ptr <- gu_string_buf_data sbuf
|
||||
len <- gu_string_buf_length sbuf
|
||||
pptr <- gu_malloc pool (#size GuString*)
|
||||
poke pptr ptr >> decode fptr pptr (ptr `plusPtr` fromIntegral len)
|
||||
where
|
||||
decode fptr pptr end = do
|
||||
ptr <- peek pptr
|
||||
if ptr >= end
|
||||
then return []
|
||||
else do x <- gu_utf8_decode pptr
|
||||
cs <- unsafeInterleaveIO (decode fptr pptr end)
|
||||
touchForeignPtr fptr
|
||||
return (((toEnum . fromEnum) x) : cs)
|
||||
|
||||
pokeUtf8CString :: String -> CString -> IO ()
|
||||
pokeUtf8CString s ptr =
|
||||
alloca $ \pptr ->
|
||||
@@ -518,6 +548,9 @@ foreign import ccall "pgf/graphviz.h pgf_graphviz_abstract_tree"
|
||||
|
||||
foreign import ccall "pgf/graphviz.h pgf_graphviz_parse_tree"
|
||||
pgf_graphviz_parse_tree :: Ptr PgfConcr -> PgfExpr -> Ptr PgfGraphvizOptions -> Ptr GuOut -> Ptr GuExn -> IO ()
|
||||
|
||||
foreign import ccall "pgf/graphviz.h pgf_graphviz_dependency_graph"
|
||||
pgf_graphviz_dependency_graph :: Ptr PgfPGF -> PgfExpr -> Ptr PgfGraphvizOptions -> Ptr GuOut -> Ptr GuExn -> Ptr GuPool -> IO ()
|
||||
|
||||
foreign import ccall "pgf/graphviz.h pgf_graphviz_word_alignment"
|
||||
pgf_graphviz_word_alignment :: Ptr (Ptr PgfConcr) -> CSizeT -> PgfExpr -> Ptr PgfGraphvizOptions -> Ptr GuOut -> Ptr GuExn -> IO ()
|
||||
|
||||
@@ -12,9 +12,6 @@ module PGF2.Internal(-- * Access the internal structures
|
||||
build, eAbs, eApp, eMeta, eFun, eVar, eTyped, eImplArg, dTyp, hypo,
|
||||
AbstrInfo, newAbstr, ConcrInfo, newConcr, newPGF,
|
||||
|
||||
-- * Expose PGF and Concr for FFI with C
|
||||
PGF(..), Concr(..),
|
||||
|
||||
-- * Write an in-memory PGF to a file
|
||||
writePGF
|
||||
) where
|
||||
@@ -197,21 +194,24 @@ concrTotalFuns c = unsafePerformIO $ do
|
||||
touchConcr c
|
||||
return (fromIntegral (c_len :: CSizeT))
|
||||
|
||||
concrFunction :: Concr -> FunId -> (Fun,[SeqId])
|
||||
concrFunction :: Concr -> FunId -> ([Fun],[SeqId])
|
||||
concrFunction c funid = unsafePerformIO $ do
|
||||
c_cncfuns <- (#peek PgfConcr, cncfuns) (concr c)
|
||||
c_cncfun <- peek (c_cncfuns `plusPtr` ((#offset GuSeq, data)+funid*(#size PgfCncFun*)))
|
||||
c_absfun <- (#peek PgfCncFun, absfun) c_cncfun
|
||||
c_name <- (#peek PgfAbsFun, name) c_absfun
|
||||
name <- peekUtf8CString c_name
|
||||
c_absfuns <- (#peek PgfCncFun, absfuns) c_cncfun
|
||||
names <- peekSequence peekAbsName (#size PgfAbsFun*) c_absfuns
|
||||
c_n_lins <- (#peek PgfCncFun, n_lins) c_cncfun
|
||||
arr <- peekArray (fromIntegral (c_n_lins :: CSizeT)) (c_cncfun `plusPtr` (#offset PgfCncFun, lins))
|
||||
seqs_seq <- (#peek PgfConcr, sequences) (concr c)
|
||||
touchConcr c
|
||||
let seqs = seqs_seq `plusPtr` (#offset GuSeq, data)
|
||||
return (name, map (toSeqId seqs) arr)
|
||||
return (names, map (toSeqId seqs) arr)
|
||||
where
|
||||
toSeqId seqs seq = minusPtr seq seqs `div` (#size PgfSequence)
|
||||
|
||||
peekAbsName c_absfun = do
|
||||
c_name <- (#peek PgfAbsFun, name) c_absfun
|
||||
peekUtf8CString c_name
|
||||
|
||||
concrTotalSeqs :: Concr -> SeqId
|
||||
concrTotalSeqs c = unsafePerformIO $ do
|
||||
@@ -448,7 +448,7 @@ newHypos hypos pool = do
|
||||
Implicit -> (#const PGF_BIND_TYPE_IMPLICIT)
|
||||
|
||||
|
||||
data AbstrInfo = AbstrInfo (Ptr GuSeq) (Ptr GuSeq) (Map.Map String (Ptr PgfAbsCat)) (Ptr GuSeq) (Map.Map String (Ptr PgfAbsFun)) (Ptr PgfAbsFun) (Ptr GuBuf) Touch
|
||||
data AbstrInfo = AbstrInfo (Ptr GuSeq) (Ptr GuSeq) (Map.Map String (Ptr PgfAbsCat)) (Ptr GuSeq) (Map.Map String (Ptr PgfAbsFun)) (Ptr GuBuf) Touch
|
||||
|
||||
newAbstr :: (?builder :: Builder s) => [(String,Literal)] ->
|
||||
[(Cat,[B s Hypo],Float)] ->
|
||||
@@ -458,9 +458,8 @@ newAbstr aflags cats funs = unsafePerformIO $ do
|
||||
c_aflags <- newFlags aflags pool
|
||||
(c_cats,abscats) <- newAbsCats (sortByFst3 cats) pool
|
||||
(c_funs,absfuns) <- newAbsFuns (sortByFst4 funs) pool
|
||||
c_abs_lin_fun <- newAbsLinFun
|
||||
c_non_lexical_buf <- gu_make_buf (#size PgfProductionIdxEntry) pool
|
||||
return (AbstrInfo c_aflags c_cats abscats c_funs absfuns c_abs_lin_fun c_non_lexical_buf touch)
|
||||
return (AbstrInfo c_aflags c_cats abscats c_funs absfuns c_non_lexical_buf touch)
|
||||
where
|
||||
(Builder pool touch) = ?builder
|
||||
|
||||
@@ -506,26 +505,6 @@ newAbstr aflags cats funs = unsafePerformIO $ do
|
||||
(#poke PgfAbsFun, ep.prob) ptr (realToFrac prob :: CFloat)
|
||||
return (Map.insert name ptr absfuns)
|
||||
|
||||
newAbsLinFun = do
|
||||
ptr <- gu_malloc_aligned pool
|
||||
(#size PgfAbsFun)
|
||||
(#const gu_alignof(PgfAbsFun))
|
||||
c_wild <- newUtf8CString "_" pool
|
||||
c_ty <- gu_malloc_aligned pool
|
||||
(#size PgfType)
|
||||
(#const gu_alignof(PgfType))
|
||||
(#poke PgfType, hypos) c_ty nullPtr
|
||||
(#poke PgfType, cid) c_ty c_wild
|
||||
(#poke PgfType, n_exprs) c_ty (0 :: CSizeT)
|
||||
(#poke PgfAbsFun, name) ptr c_wild
|
||||
(#poke PgfAbsFun, type) ptr c_ty
|
||||
(#poke PgfAbsFun, arity) ptr (0 :: CSizeT)
|
||||
(#poke PgfAbsFun, defns) ptr nullPtr
|
||||
(#poke PgfAbsFun, ep.prob) ptr (- log 0 :: CFloat)
|
||||
(#poke PgfAbsFun, ep.expr) ptr nullPtr
|
||||
return ptr
|
||||
|
||||
|
||||
data ConcrInfo = ConcrInfo (Ptr GuSeq) (Ptr GuMap) (Ptr GuMap) (Ptr GuSeq) (Ptr GuSeq) (Ptr GuMap) (Ptr PgfConcr -> Ptr GuPool -> IO ()) CInt
|
||||
|
||||
newConcr :: (?builder :: Builder s) => AbstrInfo ->
|
||||
@@ -534,12 +513,12 @@ newConcr :: (?builder :: Builder s) => AbstrInfo ->
|
||||
[(FId,[FunId])] -> -- ^ Lindefs
|
||||
[(FId,[FunId])] -> -- ^ Linrefs
|
||||
[(FId,[Production])] -> -- ^ Productions
|
||||
[(Fun,[SeqId])] -> -- ^ Concrete functions (must be sorted by Fun)
|
||||
[([Fun],[SeqId])] -> -- ^ Concrete functions (must be sorted by Fun)
|
||||
[[Symbol]] -> -- ^ Sequences (must be sorted)
|
||||
[(Cat,FId,FId,[String])] -> -- ^ Concrete categories
|
||||
FId -> -- ^ The total count of the categories
|
||||
ConcrInfo
|
||||
newConcr (AbstrInfo _ _ abscats _ absfuns c_abs_lin_fun c_non_lexical_buf _) cflags printnames lindefs linrefs prods cncfuns sequences cnccats total_cats = unsafePerformIO $ do
|
||||
newConcr (AbstrInfo _ _ abscats _ absfuns c_non_lexical_buf _) cflags printnames lindefs linrefs prods cncfuns sequences cnccats total_cats = unsafePerformIO $ do
|
||||
c_cflags <- newFlags cflags pool
|
||||
c_printname <- newMap (#size GuString) gu_string_hasher newUtf8CString
|
||||
(#size GuString) (pokeString pool)
|
||||
@@ -600,7 +579,6 @@ newConcr (AbstrInfo _ _ abscats _ absfuns c_abs_lin_fun c_non_lexical_buf _) cf
|
||||
|
||||
pokeRefDefFunId funs_ptr ptr funid = do
|
||||
let c_fun = funs_ptr `plusPtr` (funid * (#size PgfCncFun))
|
||||
(#poke PgfCncFun, absfun) c_fun c_abs_lin_fun
|
||||
poke ptr c_fun
|
||||
|
||||
pokeCncCat c_ccats ptr (name,start,end,labels) = do
|
||||
@@ -632,7 +610,7 @@ newPGF :: (?builder :: Builder s) => [(String,Literal)] ->
|
||||
AbstrInfo ->
|
||||
[(ConcName,ConcrInfo)] ->
|
||||
B s PGF
|
||||
newPGF gflags absname (AbstrInfo c_aflags c_cats _ c_funs _ c_abs_lin_fun _ _) concrs =
|
||||
newPGF gflags absname (AbstrInfo c_aflags c_cats _ c_funs _ _ _) concrs =
|
||||
unsafePerformIO $ do
|
||||
ptr <- gu_malloc_aligned pool
|
||||
(#size PgfPGF)
|
||||
@@ -648,7 +626,6 @@ newPGF gflags absname (AbstrInfo c_aflags c_cats _ c_funs _ c_abs_lin_fun _ _) c
|
||||
(#poke PgfPGF, abstract.aflags) ptr c_aflags
|
||||
(#poke PgfPGF, abstract.funs) ptr c_funs
|
||||
(#poke PgfPGF, abstract.cats) ptr c_cats
|
||||
(#poke PgfPGF, abstract.abs_lin_fun) ptr c_abs_lin_fun
|
||||
(#poke PgfPGF, concretes) ptr c_concrs
|
||||
(#poke PgfPGF, pool) ptr pool
|
||||
return (B (PGF ptr touch))
|
||||
@@ -754,19 +731,18 @@ newProduction c_ccats funs_ptr c_non_lexical_buf (PCoerce fid) pool =
|
||||
return (0,c_prod)
|
||||
|
||||
|
||||
newCncFun absfuns seqs_ptr (funid,(fun,seqids)) pool =
|
||||
do let c_absfun = fromMaybe nullPtr (Map.lookup fun absfuns)
|
||||
c_ep = if c_absfun == nullPtr
|
||||
then nullPtr
|
||||
else c_absfun `plusPtr` (#offset PgfAbsFun, ep)
|
||||
n_lins = fromIntegral (length seqids) :: CSizeT
|
||||
newCncFun absfuns seqs_ptr (funid,(funs,seqids)) pool =
|
||||
do let absfun_ptrs = [ptr | fun <- funs, Just ptr <- [Map.lookup fun absfuns]]
|
||||
n_lins = fromIntegral (length seqids) :: CSizeT
|
||||
ptr <- gu_malloc_aligned pool
|
||||
((#size PgfCncFun)+n_lins*(#size PgfSequence*))
|
||||
(#const gu_flex_alignof(PgfCncFun))
|
||||
(#poke PgfCncFun, absfun) ptr c_absfun
|
||||
(#poke PgfCncFun, ep) ptr c_ep
|
||||
(#poke PgfCncFun, funid) ptr (funid :: CInt)
|
||||
(#poke PgfCncFun, n_lins) ptr n_lins
|
||||
c_absfuns <- newSequence (#size PgfAbsFun*) poke absfun_ptrs pool
|
||||
c_prob <- fmap (minimum . (0:)) $ mapM (#peek PgfAbsFun, ep.prob) absfun_ptrs
|
||||
(#poke PgfCncFun, absfuns) ptr c_absfuns
|
||||
(#poke PgfCncFun, prob) ptr (c_prob :: CFloat)
|
||||
(#poke PgfCncFun, funid) ptr (funid :: CInt)
|
||||
(#poke PgfCncFun, n_lins) ptr n_lins
|
||||
pokeSequences seqs_ptr (ptr `plusPtr` (#offset PgfCncFun, lins)) seqids
|
||||
return ptr
|
||||
where
|
||||
@@ -775,6 +751,7 @@ newCncFun absfuns seqs_ptr (funid,(fun,seqids)) pool =
|
||||
poke ptr (seqs_ptr `plusPtr` (seqid * (#size PgfSequence)))
|
||||
pokeSequences seqs_ptr (ptr `plusPtr` (#size PgfSequence*)) seqids
|
||||
|
||||
|
||||
getCCat c_ccats fid pool =
|
||||
alloca $ \pfid -> do
|
||||
poke pfid (fromIntegral fid :: CInt)
|
||||
|
||||
@@ -45,15 +45,14 @@ readType str =
|
||||
-- of binding.
|
||||
showType :: [CId] -> Type -> String
|
||||
showType scope (Type ty touch) =
|
||||
unsafePerformIO $
|
||||
withGuPool $ \tmpPl ->
|
||||
do (sb,out) <- newOut tmpPl
|
||||
printCtxt <- newPrintCtxt scope tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
pgf_print_type ty printCtxt 0 out exn
|
||||
touch
|
||||
s <- gu_string_buf_freeze sb tmpPl
|
||||
peekUtf8CString s
|
||||
unsafePerformIO $ do
|
||||
tmpPl <- gu_new_pool
|
||||
(sb,out) <- newOut tmpPl
|
||||
printCtxt <- newPrintCtxt scope tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
pgf_print_type ty printCtxt 0 out exn
|
||||
touch
|
||||
peekUtf8CStringBufResult sb tmpPl
|
||||
|
||||
-- | creates a type from a list of hypothesises, a category and
|
||||
-- a list of arguments for the category. The operation
|
||||
@@ -129,13 +128,12 @@ unType (Type c_type touch) = unsafePerformIO $ do
|
||||
-- of binding.
|
||||
showContext :: [CId] -> [Hypo] -> String
|
||||
showContext scope hypos =
|
||||
unsafePerformIO $
|
||||
withGuPool $ \tmpPl ->
|
||||
do (sb,out) <- newOut tmpPl
|
||||
c_hypos <- newSequence (#size PgfHypo) (pokeHypo tmpPl) hypos tmpPl
|
||||
printCtxt <- newPrintCtxt scope tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
pgf_print_context c_hypos printCtxt out exn
|
||||
mapM_ touchHypo hypos
|
||||
s <- gu_string_buf_freeze sb tmpPl
|
||||
peekUtf8CString s
|
||||
unsafePerformIO $ do
|
||||
tmpPl <- gu_new_pool
|
||||
(sb,out) <- newOut tmpPl
|
||||
c_hypos <- newSequence (#size PgfHypo) (pokeHypo tmpPl) hypos tmpPl
|
||||
printCtxt <- newPrintCtxt scope tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
pgf_print_context c_hypos printCtxt out exn
|
||||
mapM_ touchHypo hypos
|
||||
peekUtf8CStringBufResult sb tmpPl
|
||||
|
||||
@@ -196,18 +196,17 @@ readTriple str =
|
||||
showTriple :: Expr -> Expr -> Expr -> String
|
||||
showTriple (Expr expr1 touch1) (Expr expr2 touch2) (Expr expr3 touch3) =
|
||||
unsafePerformIO $
|
||||
withGuPool $ \tmpPl ->
|
||||
withTriple $ \triple -> do
|
||||
(sb,out) <- newOut tmpPl
|
||||
let printCtxt = nullPtr
|
||||
exn <- gu_new_exn tmpPl
|
||||
pokeElemOff triple 0 expr1
|
||||
pokeElemOff triple 1 expr2
|
||||
pokeElemOff triple 2 expr3
|
||||
pgf_print_expr_tuple 3 triple printCtxt out exn
|
||||
touch1 >> touch2 >> touch3
|
||||
s <- gu_string_buf_freeze sb tmpPl
|
||||
peekUtf8CString s
|
||||
withTriple $ \triple -> do
|
||||
tmpPl <- gu_new_pool
|
||||
(sb,out) <- newOut tmpPl
|
||||
let printCtxt = nullPtr
|
||||
exn <- gu_new_exn tmpPl
|
||||
pokeElemOff triple 0 expr1
|
||||
pokeElemOff triple 1 expr2
|
||||
pokeElemOff triple 2 expr3
|
||||
pgf_print_expr_tuple 3 triple printCtxt out exn
|
||||
touch1 >> touch2 >> touch3
|
||||
peekUtf8CStringBufResult sb tmpPl
|
||||
|
||||
insertTriple :: SG -> Expr -> Expr -> Expr -> IO SgId
|
||||
insertTriple (SG sg) (Expr expr1 touch1) (Expr expr2 touch2) (Expr expr3 touch3) =
|
||||
|
||||
@@ -335,8 +335,8 @@ functionsByCat pgf cat =
|
||||
|
||||
functionType pgf fun =
|
||||
case Map.lookup fun (funs (abstract pgf)) of
|
||||
Just (ty,_,_,_) -> Just ty
|
||||
Nothing -> Nothing
|
||||
Just (ty,_,_,_,_) -> Just ty
|
||||
Nothing -> Nothing
|
||||
|
||||
-- | Converts an expression to normal form
|
||||
compute :: PGF -> Expr -> Expr
|
||||
@@ -363,20 +363,20 @@ browse :: PGF -> CId -> Maybe (String,[CId],[CId])
|
||||
browse pgf id = fmap (\def -> (def,producers,consumers)) definition
|
||||
where
|
||||
definition = case Map.lookup id (funs (abstract pgf)) of
|
||||
Just (ty,_,Just (eqs,_),_) -> Just $ render (text "fun" <+> ppCId id <+> colon <+> ppType 0 [] ty $$
|
||||
Just (ty,_,_,Just (eqs,_),_) -> Just $ render (text "fun" <+> ppCId id <+> colon <+> ppType 0 [] ty $$
|
||||
if null eqs
|
||||
then empty
|
||||
else text "def" <+> vcat [let scope = foldl pattScope [] patts
|
||||
ds = map (ppPatt 9 scope) patts
|
||||
in ppCId id <+> hsep ds <+> char '=' <+> ppExpr 0 scope res | Equ patts res <- eqs])
|
||||
Just (ty,_,Nothing,_) -> Just $ render (text "data" <+> ppCId id <+> colon <+> ppType 0 [] ty)
|
||||
Just (ty,_,_,Nothing,_) -> Just $ render (text "data" <+> ppCId id <+> colon <+> ppType 0 [] ty)
|
||||
Nothing -> case Map.lookup id (cats (abstract pgf)) of
|
||||
Just (hyps,_,_) -> Just $ render (text "cat" <+> ppCId id <+> hsep (snd (mapAccumL (ppHypo 4) [] hyps)))
|
||||
Nothing -> Nothing
|
||||
|
||||
(producers,consumers) = Map.foldrWithKey accum ([],[]) (funs (abstract pgf))
|
||||
(producers,consumers) = Map.foldWithKey accum ([],[]) (funs (abstract pgf))
|
||||
where
|
||||
accum f (ty,_,_,_) (plist,clist) =
|
||||
accum f (ty,_,_,_,_) (plist,clist) =
|
||||
let !plist' = if id `elem` ps then f : plist else plist
|
||||
!clist' = if id `elem` cs then f : clist else clist
|
||||
in (plist',clist')
|
||||
|
||||
@@ -47,13 +47,13 @@ instance Binary CId where
|
||||
|
||||
instance Binary Abstr where
|
||||
put abs = do put (aflags abs)
|
||||
put (Map.map (\(ty,arity,mb_eq,prob) -> (ty,arity,fmap fst mb_eq,prob)) (funs abs))
|
||||
put (Map.map (\(ty,ps,arity,mb_eq,prob) -> (ty,ps,arity,fmap fst mb_eq,prob)) (funs abs))
|
||||
put (cats abs)
|
||||
get = do aflags <- get
|
||||
funs <- get
|
||||
cats <- get
|
||||
return (Abstr{ aflags=aflags
|
||||
, funs=Map.map (\(ty,arity,mb_eq,prob) -> (ty,arity,fmap (\eq -> (eq,[])) mb_eq,prob)) funs
|
||||
, funs=Map.map (\(ty,ps,arity,mb_eq,prob) -> (ty,ps,arity,fmap (\eq -> (eq,[])) mb_eq,prob)) funs
|
||||
, cats=cats
|
||||
})
|
||||
|
||||
@@ -199,6 +199,26 @@ instance Binary BindType where
|
||||
1 -> return Implicit
|
||||
_ -> decodingError
|
||||
|
||||
instance Binary DepPragma where
|
||||
put (Head index lbl) = putWord8 0 >> put index >> put lbl
|
||||
put (Mod index lbl) = putWord8 1 >> put index >> put lbl
|
||||
put (Rel index) = putWord8 2 >> put index
|
||||
put Skip = putWord8 3
|
||||
put Anch = putWord8 4
|
||||
get = do
|
||||
tag <- getWord8
|
||||
case tag of
|
||||
0 -> do index <- get
|
||||
lbl <- get
|
||||
return (Head index lbl)
|
||||
1 -> do index <- get
|
||||
lbl <- get
|
||||
return (Mod index lbl)
|
||||
2 -> do index <- get
|
||||
return (Rel index)
|
||||
3 -> return Skip
|
||||
4 -> return Anch
|
||||
|
||||
instance Binary CncFun where
|
||||
put (CncFun fun lins) = put fun >> putArray lins
|
||||
get = liftM2 CncFun get getArray
|
||||
|
||||
@@ -28,7 +28,7 @@ data PGF = PGF {
|
||||
|
||||
data Abstr = Abstr {
|
||||
aflags :: Map.Map CId Literal, -- ^ value of a flag
|
||||
funs :: Map.Map CId (Type,Int,Maybe ([Equation],[[Instr]]),Double),-- ^ type, arrity and definition of function + probability
|
||||
funs :: Map.Map CId (Type,[DepPragma],Int,Maybe ([Equation],[[Instr]]),Double), -- ^ type, pragmas, arrity and definition of function + probability
|
||||
cats :: Map.Map CId ([Hypo],[(Double, CId)],Double) -- ^ 1. context of a category
|
||||
-- 2. functions of a category. The functions are stored
|
||||
-- in decreasing probability order.
|
||||
@@ -74,7 +74,7 @@ data Production
|
||||
deriving (Eq,Ord,Show)
|
||||
data PArg = PArg [(FId,FId)] {-# UNPACK #-} !FId deriving (Eq,Ord,Show)
|
||||
data CncCat = CncCat {-# UNPACK #-} !FId {-# UNPACK #-} !FId {-# UNPACK #-} !(Array LIndex String)
|
||||
data CncFun = CncFun CId {-# UNPACK #-} !(UArray LIndex SeqId) deriving (Eq,Ord,Show)
|
||||
data CncFun = CncFun [CId] {-# UNPACK #-} !(UArray LIndex SeqId) deriving (Eq,Ord,Show)
|
||||
type Sequence = Array DotPos Symbol
|
||||
type FunId = Int
|
||||
type SeqId = Int
|
||||
@@ -105,8 +105,8 @@ emptyPGF = PGF {
|
||||
haveSameFunsPGF :: PGF -> PGF -> Bool
|
||||
haveSameFunsPGF one two =
|
||||
let
|
||||
fsone = [(f,t) | (f,(t,_,_,_)) <- Map.toList (funs (abstract one))]
|
||||
fstwo = [(f,t) | (f,(t,_,_,_)) <- Map.toList (funs (abstract two))]
|
||||
fsone = [(f,t) | (f,(t,_,_,_,_)) <- Map.toList (funs (abstract one))]
|
||||
fstwo = [(f,t) | (f,(t,_,_,_,_)) <- Map.toList (funs (abstract two))]
|
||||
in fsone == fstwo
|
||||
|
||||
-- | This is just a 'CId' with the language name.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module PGF.Expr(Tree, BindType(..), Expr(..), Literal(..), Patt(..), Equation(..),
|
||||
module PGF.Expr(Tree, BindType(..), Expr(..), Literal(..), Patt(..), Equation(..), DepPragma(..),
|
||||
readExpr, showExpr, pExpr, pBinds, ppExpr, ppPatt, pattScope,
|
||||
|
||||
mkAbs, unAbs,
|
||||
@@ -77,6 +77,14 @@ data Equation =
|
||||
Equ [Patt] Expr
|
||||
deriving Show
|
||||
|
||||
data DepPragma
|
||||
= Head Int String
|
||||
| Mod Int String
|
||||
| Rel Int
|
||||
| Skip
|
||||
| Anch
|
||||
|
||||
|
||||
-- | parses 'String' as an expression
|
||||
readExpr :: String -> Maybe Expr
|
||||
readExpr s = case [x | (x,cs) <- RP.readP_to_S pExpr s, all isSpace cs] of
|
||||
@@ -319,15 +327,15 @@ data Value
|
||||
| VClosure Env Expr
|
||||
| VImplArg Value
|
||||
|
||||
type Sig = ( Map.Map CId (Type,Int,Maybe ([Equation],[[Instr]]),Double) -- type and def of a fun
|
||||
, Int -> Maybe Expr -- lookup for metavariables
|
||||
type Sig = ( Map.Map CId (Type,[DepPragma],Int,Maybe ([Equation],[[Instr]]),Double) -- type and def of a fun
|
||||
, Int -> Maybe Expr -- lookup for metavariables
|
||||
)
|
||||
type Env = [Value]
|
||||
|
||||
eval :: Sig -> Env -> Expr -> Value
|
||||
eval sig env (EVar i) = env !! i
|
||||
eval sig env (EFun f) = case Map.lookup f (fst sig) of
|
||||
Just (_,a,meqs,_) -> case meqs of
|
||||
Just (_,_,a,meqs,_) -> case meqs of
|
||||
Just (eqs,_)
|
||||
-> if a == 0
|
||||
then case eqs of
|
||||
@@ -349,12 +357,12 @@ apply :: Sig -> Env -> Expr -> [Value] -> Value
|
||||
apply sig env e [] = eval sig env e
|
||||
apply sig env (EVar i) vs = applyValue sig (env !! i) vs
|
||||
apply sig env (EFun f) vs = case Map.lookup f (fst sig) of
|
||||
Just (_,a,meqs,_) -> case meqs of
|
||||
Just (eqs,_) -> if a <= length vs
|
||||
then match sig f eqs vs
|
||||
else VApp f vs
|
||||
Nothing -> VApp f vs
|
||||
Nothing -> error ("unknown function "++showCId f)
|
||||
Just (_,_,a,meqs,_) -> case meqs of
|
||||
Just (eqs,_) -> if a <= length vs
|
||||
then match sig f eqs vs
|
||||
else VApp f vs
|
||||
Nothing -> VApp f vs
|
||||
Nothing -> error ("unknown function "++showCId f)
|
||||
apply sig env (EApp e1 e2) vs = apply sig env e1 (eval sig env e2 : vs)
|
||||
apply sig env (EAbs b x e) (v:vs) = case (b,v) of
|
||||
(Implicit,VImplArg v) -> apply sig (v:env) e vs
|
||||
|
||||
@@ -71,11 +71,11 @@ bracketedTokn dp f@(Forest abs cnc forest root) =
|
||||
in (ct,fid',fun,es,(map getVar hypos,lin))
|
||||
Nothing -> error ("wrong forest id " ++ show fid)
|
||||
where
|
||||
descend forest (PApply funid args) = let (CncFun fun _lins) = cncfuns cnc ! funid
|
||||
cat = case isLindefCId fun of
|
||||
Just cat -> cat
|
||||
Nothing -> case Map.lookup fun (funs abs) of
|
||||
Just (DTyp _ cat _,_,_,_) -> cat
|
||||
descend forest (PApply funid args) = let (CncFun pfuns _lins) = cncfuns cnc ! funid
|
||||
cat = case pfuns of
|
||||
[] -> wildCId
|
||||
(pfun:_) -> case Map.lookup pfun (funs abs) of
|
||||
Just (DTyp _ cat _,_,_,_,_) -> cat
|
||||
largs = map (render forest) args
|
||||
ltable = mkLinTable cnc isTrusted [] funid largs
|
||||
in ((cat,fid),0,wildCId,either (const []) id $ getAbsTrees f arg Nothing dp,ltable)
|
||||
@@ -103,14 +103,6 @@ bracketedTokn dp f@(Forest abs cnc forest root) =
|
||||
descend (PCoerce fid) = trustedSpots parents' (PArg [] fid)
|
||||
descend (PConst c e _) = IntSet.empty
|
||||
|
||||
isLindefCId id
|
||||
| take l s == lindef = Just (mkCId (drop l s))
|
||||
| otherwise = Nothing
|
||||
where
|
||||
s = showCId id
|
||||
lindef = "lindef "
|
||||
l = length lindef
|
||||
|
||||
-- | This function extracts the list of all completed parse trees
|
||||
-- that spans the whole input consumed so far. The trees are also
|
||||
-- limited by the category specified, which is usually
|
||||
@@ -132,13 +124,13 @@ getAbsTrees (Forest abs cnc forest root) arg@(PArg _ fid) ty dp =
|
||||
| otherwise = do fid0 <- get
|
||||
put fid
|
||||
x <- foldForest (\funid args trees ->
|
||||
do let CncFun fn _lins = cncfuns cnc ! funid
|
||||
case isLindefCId fn of
|
||||
Just _ -> do arg <- go (Set.insert fid rec_) scope mb_tty (head args)
|
||||
do let CncFun fns _lins = cncfuns cnc ! funid
|
||||
case fns of
|
||||
[] -> do arg <- go (Set.insert fid rec_) scope mb_tty (head args)
|
||||
return (mkAbs arg)
|
||||
Nothing -> do ty_fn <- lookupFunType fn
|
||||
fns -> do ty_fn <- lookupFunType (head fns)
|
||||
(e,tty0) <- foldM (\(e1,tty) arg -> goArg (Set.insert fid rec_) scope fid e1 arg tty)
|
||||
(EFun fn,TTyp [] ty_fn) args
|
||||
(EFun (head fns),TTyp [] ty_fn) args
|
||||
case mb_tty of
|
||||
Just tty -> do i <- newGuardedMeta e
|
||||
eqType scope (scopeSize scope) i tty tty0
|
||||
@@ -190,7 +182,7 @@ foldForest :: (FunId -> [PArg] -> b -> b) -> (Expr -> [String] -> b -> b) -> b -
|
||||
foldForest f g b fcat forest =
|
||||
case IntMap.lookup fcat forest of
|
||||
Nothing -> b
|
||||
Just set -> Set.foldr foldProd b set
|
||||
Just set -> Set.fold foldProd b set
|
||||
where
|
||||
foldProd (PCoerce fcat) b = foldForest f g b fcat forest
|
||||
foldProd (PApply funid args) b = f funid args b
|
||||
|
||||
@@ -109,7 +109,7 @@ linTree pgf cnc e = nub (map snd (lin Nothing 0 e [] [] e []))
|
||||
Nothing -> concat [toApp fid prod | (fid,set) <- IntMap.toList prods, prod <- Set.toList set]
|
||||
where
|
||||
toApp fid (PApply funid pargs) =
|
||||
let Just (ty,_,_,_) = Map.lookup f (funs (abstract pgf))
|
||||
let Just (ty,_,_,_,_) = Map.lookup f (funs (abstract pgf))
|
||||
(args,res) = catSkeleton ty
|
||||
in [(funid,(res,fid),zip args [fid | PArg _ fid <- pargs])]
|
||||
toApp _ (PCoerce fid) =
|
||||
|
||||
@@ -22,13 +22,13 @@ mapConcretes f pgf = pgf { concretes = Map.map f (concretes pgf) }
|
||||
lookType :: Abstr -> CId -> Type
|
||||
lookType abs f =
|
||||
case lookMap (error $ "lookType " ++ show f) f (funs abs) of
|
||||
(ty,_,_,_) -> ty
|
||||
(ty,_,_,_,_) -> ty
|
||||
|
||||
isData :: Abstr -> CId -> Bool
|
||||
isData abs f =
|
||||
case Map.lookup f (funs abs) of
|
||||
Just (_,_,Nothing,_) -> True -- the encoding of data constrs
|
||||
_ -> False
|
||||
Just (_,_,_,Nothing,_) -> True -- the encoding of data constrs
|
||||
_ -> False
|
||||
|
||||
lookValCat :: Abstr -> CId -> CId
|
||||
lookValCat abs = valCat . lookType abs
|
||||
@@ -61,7 +61,7 @@ lookConcrFlag pgf lang f = Map.lookup f $ cflags $ lookConcr pgf lang
|
||||
|
||||
functionsToCat :: PGF -> CId -> [(CId,Type)]
|
||||
functionsToCat pgf cat =
|
||||
[(f,ty) | (_,f) <- fs, Just (ty,_,_,_) <- [Map.lookup f $ funs $ abstract pgf]]
|
||||
[(f,ty) | (_,f) <- fs, Just (ty,_,_,_,_) <- [Map.lookup f $ funs $ abstract pgf]]
|
||||
where
|
||||
(_,fs,_) = lookMap ([],[],0) cat $ cats $ abstract pgf
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ collectWords pinfo = Map.fromListWith (++)
|
||||
[(t, [(fun,lbls ! l)]) | (CncCat s e lbls) <- Map.elems (cnccats pinfo)
|
||||
, fid <- [s..e]
|
||||
, PApply funid _ <- maybe [] Set.toList (IntMap.lookup fid (productions pinfo))
|
||||
, let CncFun fun lins = cncfuns pinfo ! funid
|
||||
, let CncFun funs lins = cncfuns pinfo ! funid
|
||||
, fun <- funs
|
||||
, (l,seqid) <- assocs lins
|
||||
, sym <- elems (sequences pinfo ! seqid)
|
||||
, t <- sym2tokns sym]
|
||||
|
||||
@@ -39,7 +39,7 @@ getAbstract =
|
||||
funs <- getMap getCId getFun
|
||||
cats <- getMap getCId getCat
|
||||
return (Abstr{ aflags=aflags
|
||||
, funs=fmap (\(w,x,y,z) -> (w,x,fmap (flip (,) []) y,z)) funs
|
||||
, funs=fmap (\(w,x,y,z) -> (w,[],x,fmap (flip (,) []) y,z)) funs
|
||||
, cats=fmap (\(x,y) -> (x,y,0)) cats
|
||||
})
|
||||
getFun :: Get (Type,Int,Maybe [Equation],Double)
|
||||
@@ -60,7 +60,7 @@ getConcr =
|
||||
cnccats <- getMap getCId getCncCat
|
||||
totalCats <- get
|
||||
let rseq = listToArray [SymCat 0 0]
|
||||
rfun = CncFun (mkCId "linref") (listToArray [scnt])
|
||||
rfun = CncFun [mkCId "linref"] (listToArray [scnt])
|
||||
linrefs = IntMap.fromList [(i,[fcnt])|i<-[0..totalCats-1]]
|
||||
return (Concr{ cflags=cflags, printnames=printnames
|
||||
, sequences=toArray (scnt+1,seqs++[rseq])
|
||||
@@ -110,7 +110,7 @@ getBindType =
|
||||
1 -> return Implicit
|
||||
_ -> decodingError "getBindType"
|
||||
|
||||
getCncFun = liftM2 CncFun getCId (getArray get)
|
||||
getCncFun = liftM2 CncFun (fmap (:[]) getCId) (getArray get)
|
||||
|
||||
getCncCat = liftM3 CncCat get get (getArray get)
|
||||
|
||||
|
||||
@@ -185,8 +185,8 @@ filterProductions prods0 prods
|
||||
| prods0 == prods1 = prods0
|
||||
| otherwise = filterProductions prods1 prods
|
||||
where
|
||||
prods1 = IntMap.foldrWithKey foldProdSet IntMap.empty prods
|
||||
hoc = IntMap.foldr (\set !hoc -> Set.foldr accumHOC hoc set) IntSet.empty prods
|
||||
prods1 = IntMap.foldWithKey foldProdSet IntMap.empty prods
|
||||
hoc = IntMap.fold (\set !hoc -> Set.fold accumHOC hoc set) IntSet.empty prods
|
||||
|
||||
foldProdSet fid set !prods
|
||||
| Set.null set1 = prods
|
||||
@@ -204,7 +204,7 @@ filterProductions prods0 prods
|
||||
accumHOC _ hoc = hoc
|
||||
|
||||
splitLexicalRules cnc p_prods =
|
||||
IntMap.foldrWithKey split (IntMap.empty,IntMap.empty) p_prods
|
||||
IntMap.foldWithKey split (IntMap.empty,IntMap.empty) p_prods
|
||||
where
|
||||
split fid set (lex,syn) =
|
||||
let (lex0,syn0) = Set.partition isLexical set
|
||||
@@ -253,7 +253,7 @@ updateConcrete abs cnc =
|
||||
, prod <- Set.toList prods
|
||||
, fun <- getFunctions prod]
|
||||
where
|
||||
getFunctions (PApply funid args) = let CncFun fun _ = cncfuns cnc ! funid in [fun]
|
||||
getFunctions (PApply funid args) = let CncFun funs _ = cncfuns cnc ! funid in funs
|
||||
getFunctions (PCoerce fid) = case IntMap.lookup fid productions of
|
||||
Nothing -> []
|
||||
Just prods -> [fun | prod <- Set.toList prods, fun <- getFunctions prod]
|
||||
|
||||
@@ -53,7 +53,7 @@ fromDef pgf t@(Fun f ts) = defDown t ++ defUp t where
|
||||
isClosed d || (length equs == 1 && isLinear d)]
|
||||
|
||||
equss = [(f,[(Fun f (map patt2tree ps), expr2tree d) | (Equ ps d) <- eqs]) |
|
||||
(f,(_,_,Just (eqs,_),_)) <- Map.assocs (funs (abstract pgf)), not (null eqs)]
|
||||
(f,(_,_,_,Just (eqs,_),_)) <- Map.assocs (funs (abstract pgf)), not (null eqs)]
|
||||
---- AR 14/12/2010: (expr2tree d) fails unless we send the variable list from ps in eqs;
|
||||
---- cf. PGF.Tree.expr2tree
|
||||
trequ s f e = True ----trace (s ++ ": " ++ show f ++ " " ++ show e) True
|
||||
|
||||
@@ -198,7 +198,7 @@ recoveryStates open_types (EState abs cnc chart) =
|
||||
Nothing -> []
|
||||
|
||||
complete open_fcats items ac =
|
||||
foldl (Set.foldr (\(Active j' ppos funid seqid args keyc) ->
|
||||
foldl (Set.fold (\(Active j' ppos funid seqid args keyc) ->
|
||||
(:) (Active j' (ppos+1) funid seqid args keyc)))
|
||||
items
|
||||
[set | fcat <- open_fcats, (set,_) <- lookupACByFCat fcat ac]
|
||||
@@ -363,7 +363,7 @@ process flit ftok cnc (item@(Active j ppos funid seqid args key0):items) acc cha
|
||||
|
||||
items2 = case lookupAC key0 ((active chart:actives chart) !! (k-j)) of
|
||||
Nothing -> items
|
||||
Just (set,sc) -> Set.foldr (\(Active j' ppos funid seqid args keyc) ->
|
||||
Just (set,sc) -> Set.fold (\(Active j' ppos funid seqid args keyc) ->
|
||||
let SymCat d _ = unsafeAt (unsafeAt (sequences cnc) seqid) ppos
|
||||
PArg hypos _ = args !! d
|
||||
in (:) (Active j' (ppos+1) funid seqid (updateAt d (PArg hypos fid) args) keyc)) items set
|
||||
@@ -395,7 +395,7 @@ process flit ftok cnc (item@(Active j ppos funid seqid args key0):items) acc cha
|
||||
predict flit ftok cnc forest key0 key@(AK fid lbl) k acc items =
|
||||
let (acc1,items1) = case IntMap.lookup fid forest of
|
||||
Nothing -> (acc,items)
|
||||
Just set -> Set.foldr foldProd (acc,items) set
|
||||
Just set -> Set.fold foldProd (acc,items) set
|
||||
|
||||
(acc2,items2) = case IntMap.lookup fid (lexicon cnc) >>= IntMap.lookup lbl of
|
||||
Just tmap -> let (mb_v,toks) = TrieMap.decompose (TrieMap.map (toItems key0 k) tmap)
|
||||
@@ -503,14 +503,14 @@ type Continuation = TrieMap.TrieMap Token ActiveSet
|
||||
-- | Return the Continuation of a Parsestate with exportable types
|
||||
-- Used by PGFService
|
||||
getContinuationInfo :: ParseState -> Map.Map [Token] [(FunId, CId, String)]
|
||||
getContinuationInfo pstate = Map.map (map f . Set.toList) contMap
|
||||
getContinuationInfo pstate = Map.map (concatMap f . Set.toList) contMap
|
||||
where
|
||||
PState _abstr concr _chart cont = pstate
|
||||
contMap = Map.fromList (TrieMap.toList cont) -- always get [([], _::ActiveSet)]
|
||||
f :: Active -> (FunId,CId,String)
|
||||
f (Active int dotpos funid seqid pargs ak) = (funid, cid, seq)
|
||||
f :: Active -> [(FunId,CId,String)]
|
||||
f (Active int dotpos funid seqid pargs ak) = [(funid, fn, seq) | fn <- fns]
|
||||
where
|
||||
CncFun cid _ = cncfuns concr ! funid
|
||||
CncFun fns _ = cncfuns concr ! funid
|
||||
seq = showSeq dotpos (sequences concr ! seqid)
|
||||
|
||||
showSeq :: DotPos -> Sequence -> String
|
||||
|
||||
@@ -31,15 +31,15 @@ ppFlag flag value = text "flag" <+> ppCId flag <+> char '=' <+> ppLit value <+>
|
||||
ppCat :: CId -> ([Hypo],[(Double,CId)],Double) -> Doc
|
||||
ppCat c (hyps,_,_) = text "cat" <+> ppCId c <+> hsep (snd (mapAccumL (ppHypo 4) [] hyps)) <+> char ';'
|
||||
|
||||
ppFun :: CId -> (Type,Int,Maybe ([Equation],[[Instr]]),Double) -> Doc
|
||||
ppFun f (t,_,Just (eqs,code),_) = text "fun" <+> ppCId f <+> colon <+> ppType 0 [] t <+> char ';' $$
|
||||
(if null eqs
|
||||
then empty
|
||||
else text "def" <+> vcat [let scope = foldl pattScope [] patts
|
||||
ds = map (ppPatt 9 scope) patts
|
||||
in ppCId f <+> hsep ds <+> char '=' <+> ppExpr 0 scope res <+> char ';' | Equ patts res <- eqs]) $$
|
||||
ppCode 0 code
|
||||
ppFun f (t,_,Nothing,_) = text "data" <+> ppCId f <+> colon <+> ppType 0 [] t <+> char ';'
|
||||
ppFun :: CId -> (Type,[DepPragma],Int,Maybe ([Equation],[[Instr]]),Double) -> Doc
|
||||
ppFun f (t,_,_,Just (eqs,code),_) = text "fun" <+> ppCId f <+> colon <+> ppType 0 [] t <+> char ';' $$
|
||||
(if null eqs
|
||||
then empty
|
||||
else text "def" <+> vcat [let scope = foldl pattScope [] patts
|
||||
ds = map (ppPatt 9 scope) patts
|
||||
in ppCId f <+> hsep ds <+> char '=' <+> ppExpr 0 scope res <+> char ';' | Equ patts res <- eqs]) $$
|
||||
ppCode 0 code
|
||||
ppFun f (t,_,_,Nothing,_) = text "data" <+> ppCId f <+> colon <+> ppType 0 [] t <+> char ';'
|
||||
|
||||
ppCnc :: Language -> Concr -> Doc
|
||||
ppCnc name cnc =
|
||||
@@ -73,8 +73,8 @@ ppProduction (fid,PCoerce arg) =
|
||||
ppProduction (fid,PConst _ _ ss) =
|
||||
ppFId fid <+> text "->" <+> ppStrs ss
|
||||
|
||||
ppCncFun (funid,CncFun fun arr) =
|
||||
ppFunId funid <+> text ":=" <+> parens (hcat (punctuate comma (map ppSeqId (elems arr)))) <+> brackets (ppCId fun)
|
||||
ppCncFun (funid,CncFun funs arr) =
|
||||
ppFunId funid <+> text ":=" <+> parens (hcat (punctuate comma (map ppSeqId (elems arr)))) <+> brackets (hsep (map ppCId funs))
|
||||
|
||||
ppLinDefs (fid,funids) =
|
||||
[ppFId fid <+> text "->" <+> ppFunId funid <> brackets (ppFId fidVar) | funid <- funids]
|
||||
|
||||
@@ -76,15 +76,15 @@ defaultProbabilities pgf = mkProbabilities pgf Map.empty
|
||||
|
||||
getProbabilities :: PGF -> Probabilities
|
||||
getProbabilities pgf = Probs {
|
||||
funProbs = Map.map (\(_,_,_,p) -> p ) (funs (abstract pgf)),
|
||||
catProbs = Map.map (\(_,fns,p) -> (p,fns)) (cats (abstract pgf))
|
||||
funProbs = Map.map (\(_,_,_,_,p) -> p ) (funs (abstract pgf)),
|
||||
catProbs = Map.map (\(_,fns,p) -> (p,fns)) (cats (abstract pgf))
|
||||
}
|
||||
|
||||
setProbabilities :: Probabilities -> PGF -> PGF
|
||||
setProbabilities probs pgf = pgf {
|
||||
abstract = (abstract pgf) {
|
||||
funs = mapUnionWith (\(ty,a,df,_) p -> (ty,a,df, p)) (funs (abstract pgf)) (funProbs probs),
|
||||
cats = mapUnionWith (\(hypos,_,_) (p,fns) -> (hypos,fns,p)) (cats (abstract pgf)) (catProbs probs)
|
||||
funs = mapUnionWith (\(ty,ps,a,df,_) p -> (ty,ps,a,df, p)) (funs (abstract pgf)) (funProbs probs),
|
||||
cats = mapUnionWith (\(hypos,_,_) (p,fns) -> (hypos,fns,p)) (cats (abstract pgf)) (catProbs probs)
|
||||
}}
|
||||
where
|
||||
mapUnionWith f map1 map2 =
|
||||
@@ -95,8 +95,8 @@ probTree :: PGF -> Expr -> Double
|
||||
probTree pgf t = case t of
|
||||
EApp f e -> probTree pgf f * probTree pgf e
|
||||
EFun f -> case Map.lookup f (funs (abstract pgf)) of
|
||||
Just (_,_,_,p) -> p
|
||||
Nothing -> 1
|
||||
Just (_,_,_,_,p) -> p
|
||||
Nothing -> 1
|
||||
_ -> 1
|
||||
|
||||
-- | rank from highest to lowest probability
|
||||
@@ -113,7 +113,7 @@ mkProbDefs pgf =
|
||||
hyps0
|
||||
[1..]
|
||||
fns = [(f,ty) | (_,f) <- fs,
|
||||
let Just (ty,_,_,_) = Map.lookup f (funs (abstract pgf))]
|
||||
let Just (ty,_,_,_,_) = Map.lookup f (funs (abstract pgf))]
|
||||
]
|
||||
((_,css),eqss) = mapAccumL (\(ngen,css) (c,hyps,fns) ->
|
||||
let st0 = (1,Map.empty)
|
||||
@@ -263,7 +263,7 @@ computeConstrs pgf st fns =
|
||||
where
|
||||
addArgs (cn,fns) = addArg (length args) cn [] fns
|
||||
where
|
||||
Just (DTyp args _ _es,_,_,_) = Map.lookup cn (funs (abstract pgf))
|
||||
Just (DTyp args _ _es,_,_,_,_) = Map.lookup cn (funs (abstract pgf))
|
||||
|
||||
addArg 0 cn ps fns = [(PApp cn (reverse ps),fns)]
|
||||
addArg n cn ps fns = concat [addArg (n-1) cn (arg:ps) fns' | (arg,fns') <- computeConstr fns]
|
||||
|
||||
@@ -38,7 +38,7 @@ showInOrder abs fset remset avset =
|
||||
isArg :: Abstr -> Map.Map CId CId -> Set.Set CId -> CId -> Maybe [CId]
|
||||
isArg abs mtypes scid cid =
|
||||
let p = Map.lookup cid $ funs abs
|
||||
(ty,_,_,_) = fromJust p
|
||||
(ty,_,_,_,_) = fromJust p
|
||||
args = arguments ty
|
||||
setargs = Set.fromList args
|
||||
cond = Set.null $ Set.difference setargs scid
|
||||
@@ -51,8 +51,8 @@ typesInterm :: Abstr -> Set.Set CId -> Map.Map CId CId
|
||||
typesInterm abs fset =
|
||||
let fs = funs abs
|
||||
fsetTypes = Set.map (\x ->
|
||||
let (DTyp _ c _,_,_,_)=fromJust $ Map.lookup x fs
|
||||
in (x,c)) fset
|
||||
let (DTyp _ c _,_,_,_,_)=fromJust $ Map.lookup x fs
|
||||
in (x,c)) fset
|
||||
in Map.fromList $ Set.toList fsetTypes
|
||||
|
||||
{-
|
||||
@@ -67,7 +67,7 @@ doesReturnCat (DTyp _ c _) cat = c == cat
|
||||
returnCat :: Abstr -> CId -> CId
|
||||
returnCat abs cid =
|
||||
let p = Map.lookup cid $ funs abs
|
||||
(DTyp _ c _,_,_,_) = fromJust p
|
||||
(DTyp _ c _,_,_,_,_) = fromJust p
|
||||
in if isNothing p then error $ "not found "++ show cid ++ " in abstract "
|
||||
else c
|
||||
|
||||
|
||||
@@ -79,12 +79,12 @@ unionsWith f = foldl (unionWith f) empty
|
||||
elems :: TrieMap k v -> [v]
|
||||
elems tr = collect tr []
|
||||
where
|
||||
collect (Tr mb_v m) xs = maybe id (:) mb_v (Map.foldr collect xs m)
|
||||
collect (Tr mb_v m) xs = maybe id (:) mb_v (Map.fold collect xs m)
|
||||
|
||||
toList :: TrieMap k v -> [([k],v)]
|
||||
toList tr = collect [] tr []
|
||||
where
|
||||
collect ks (Tr mb_v m) xs = maybe id (\v -> (:) (ks,v)) mb_v (Map.foldrWithKey (\k -> collect (k:ks)) xs m)
|
||||
collect ks (Tr mb_v m) xs = maybe id (\v -> (:) (ks,v)) mb_v (Map.foldWithKey (\k -> collect (k:ks)) xs m)
|
||||
|
||||
fromListWith :: Ord k => (v -> v -> v) -> [([k],v)] -> TrieMap k v
|
||||
fromListWith f xs = foldl' (\trie (ks,v) -> insertWith f ks v trie) empty xs
|
||||
|
||||
@@ -135,8 +135,8 @@ lookupCatHyps cat = TcM (\abstr k h ms -> case Map.lookup cat (cats abstr) of
|
||||
|
||||
lookupFunType :: CId -> TcM s Type
|
||||
lookupFunType fun = TcM (\abstr k h ms -> case Map.lookup fun (funs abstr) of
|
||||
Just (ty,_,_,_) -> k ty ms
|
||||
Nothing -> h (UnknownFun fun))
|
||||
Just (ty,_,_,_,_) -> k ty ms
|
||||
Nothing -> h (UnknownFun fun))
|
||||
|
||||
typeGenerators :: Scope -> CId -> TcM s [(Double,Expr,TType)]
|
||||
typeGenerators scope cat = fmap normalize (liftM2 (++) x y)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user