mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-06-23 02:06:14 -06:00
move gf.cabal and all compiler dependent files into src/compiler
This commit is contained in:
112
src/compiler/www/gfmorpho/GFMorpho.hs
Normal file
112
src/compiler/www/gfmorpho/GFMorpho.hs
Normal file
@@ -0,0 +1,112 @@
|
||||
import Network.HTTP.Base
|
||||
import Codec.Binary.UTF8.String
|
||||
import Data.Char
|
||||
import Data.List
|
||||
import System
|
||||
|
||||
main = do
|
||||
xs <- getArgs
|
||||
let xxoo = lexArgs (unwords xs)
|
||||
case pArgs xxoo of
|
||||
Just (oo,xx) -> do
|
||||
morpho oo xx
|
||||
_ -> do
|
||||
putStrLn $ "cannot read " ++ unwords xs ++ "."
|
||||
putStrLn "<p>"
|
||||
putStrLn usage
|
||||
|
||||
usage = "usage: gfmorpho LANG POS FORMS OPT*"
|
||||
|
||||
noParse xx = length xx < 3 ----
|
||||
|
||||
lexArgs = map (decodeString . urlDecode) . words . map unspec . drop 1 . dropWhile (/='=') where
|
||||
unspec c = case c of
|
||||
'=' -> ' '
|
||||
'+' -> ' '
|
||||
_ -> c
|
||||
|
||||
pArgs xxoo = do
|
||||
let (oo,xx) = partition isOption xxoo
|
||||
if length xx < 3 then Nothing else return (oo,xx)
|
||||
|
||||
morpho :: [String] -> [String] -> IO ()
|
||||
morpho oo xx = do
|
||||
writeFile tmpCommand (script xx)
|
||||
system $ command xx
|
||||
s <- readFile tmpFile
|
||||
putStrLn $ mkFile $ response oo s
|
||||
|
||||
script ("!":lang:rest) = "cc -table -unqual " ++ unwords rest
|
||||
script (lang: pos: forms) = "cc -table -unqual " ++ fun pos ++ quotes forms
|
||||
where
|
||||
fun pos = "mk" ++ pos
|
||||
|
||||
command ("!":args) = command args
|
||||
command (lang: pos: forms) =
|
||||
"/usr/local/bin/gf -run -retain -path=alltenses alltenses/Paradigms" ++ lang ++ ".gfo"
|
||||
++ " < " ++ tmpCommand
|
||||
++ " > " ++ tmpFile
|
||||
|
||||
quotes = unwords . map quote where
|
||||
quote s = case s of
|
||||
'_':tag -> tag
|
||||
_ -> "\"" ++ s ++ "\""
|
||||
|
||||
-- html response
|
||||
response oo =
|
||||
tag "table border=1" . unlines . map (tag "tr" . unwords) . map cleanTable . grep oo . map words . lines
|
||||
|
||||
cleanTable ws = [tag "td" (unwords param), tag "td" (tag "i" (unwords form))] where
|
||||
(param,form) = getOne (map cleant ws)
|
||||
cleant w = case w of
|
||||
"s" -> ""
|
||||
"." -> ""
|
||||
_ -> cleanw w
|
||||
cleanw = filter (flip notElem "()")
|
||||
getOne ws = let ww = filter (/= "=>") ws in (init ww, [last ww]) -- excludes multiwords
|
||||
|
||||
responsePlain oo =
|
||||
unlines . map unwords . grep oo . map cleanTablePlain . map words . lines
|
||||
|
||||
cleanTablePlain = map clean where
|
||||
clean w = case w of
|
||||
"=>" -> "\t"
|
||||
"s" -> ""
|
||||
"." -> ""
|
||||
_ -> cleanw w
|
||||
cleanw = filter (flip notElem "()")
|
||||
|
||||
grep oo wss = filter (\ws -> all (flip matchIn ws) oo) wss
|
||||
|
||||
matchIn p ws = quant (matchPol pol patt) ws where
|
||||
quant = if pol then any else all
|
||||
(pol,patt) = (head p == '-', tail p)
|
||||
matchPol True p w = match p w
|
||||
matchPol False p w = not (match p w)
|
||||
match p w = case (p,w) of
|
||||
('*':ps,_ ) -> any (match ps) [drop i w | i <- [0..length w]] ---
|
||||
(c:ps, d:ws) -> c == d && match ps ws
|
||||
_ -> p == w
|
||||
|
||||
tmpFile = "_gfmorpho.tmp"
|
||||
tmpCommand = "_gfcommand.tmp"
|
||||
|
||||
isOption = (flip elem "-~") . head
|
||||
|
||||
tag t s = "<" ++ t ++ ">" ++ s ++ "</" ++ t ++ ">"
|
||||
|
||||
|
||||
-- html file with UTF8
|
||||
|
||||
mkFile s = unlines $ [
|
||||
"<HTML>",
|
||||
"<HEAD>",
|
||||
"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">",
|
||||
"<TITLE>GF Smart Paradigm Output</TITLE>",
|
||||
"</HEAD>",
|
||||
"<BODY>",
|
||||
s,
|
||||
"</BODY>",
|
||||
"</HTML>"
|
||||
]
|
||||
|
||||
23
src/compiler/www/gfmorpho/README
Normal file
23
src/compiler/www/gfmorpho/README
Normal file
@@ -0,0 +1,23 @@
|
||||
A service for using smart paradigms on the web.
|
||||
|
||||
Works with a cgi script running a Haskell program that calls GF to interprete a query string as a "cc" command on a specified Paradigms file. For instance, if the
|
||||
user submits the query
|
||||
|
||||
Eng N baby
|
||||
|
||||
the program executes the command
|
||||
|
||||
cc -table -unqual ParadigmsEng.mkN "baby"
|
||||
|
||||
The resulting output is converted into an HTML table.
|
||||
|
||||
The file gfmorpho.html gives some more information. Open issues in addition to those mentioned there are:
|
||||
|
||||
- GFMorpho.hs creates the temporary files _gfcommand.tmp and _gfmorpho.tmp which need to be world-writable; they should be created more properly and removed after use
|
||||
- gfmorpho.cgi defines the variable GF_LIB_PATH to reside in /home/aarne, and must be edited for other environments
|
||||
- to work for all languages mentioned, one has to compile some incomplete GF grammars not standardly compiled:
|
||||
|
||||
GF/lib/src$ runghc Make alltenses lang langs=Amh,Ara,Lat,Mlt,Tur
|
||||
|
||||
(c) Aarne Ranta 2012 under LGPL/BSD.
|
||||
|
||||
7
src/compiler/www/gfmorpho/gfmorpho.cgi
Normal file
7
src/compiler/www/gfmorpho/gfmorpho.cgi
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Content-type: text/html";
|
||||
echo ""
|
||||
export LANG=en_US.UTF-8
|
||||
export GF_LIB_PATH=/home/aarne/GF/lib/
|
||||
/usr/local/bin/runghc GFMorpho "$QUERY_STRING"
|
||||
112
src/compiler/www/gfmorpho/gfmorpho.html
Normal file
112
src/compiler/www/gfmorpho/gfmorpho.html
Normal file
@@ -0,0 +1,112 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html> <head>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
|
||||
<title>Use GF Smart Paradigms</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Word inflection with smart paradigms</h1>
|
||||
|
||||
Give language, part of speech, and one or more word forms, to obtain
|
||||
the inflection table.
|
||||
<p>
|
||||
<form method=get action="cgi-bin/gfmorpho.cgi">
|
||||
<input name=args>
|
||||
<INPUT TYPE=SUBMIT VALUE="Submit">
|
||||
</form>
|
||||
Examples:
|
||||
<pre>
|
||||
Eng N baby
|
||||
Fin V odottaa odotti
|
||||
Fre V manger
|
||||
Ger N Soldat Soldaten _masculine
|
||||
Hin N बच्छा
|
||||
Jpn V 答える _Gr2
|
||||
Lat A vetus veteris
|
||||
</pre>
|
||||
Thus notice that strings are given without quotes, but features
|
||||
are prefixed with an underscore <tt>_</tt>.
|
||||
|
||||
|
||||
<h2>Languages and part of speech tags</h2>
|
||||
|
||||
The available languages are:
|
||||
<pre>
|
||||
Afr Amh Cat Dan Dut Eng Fin Fre Ger Hin Ina Ita Jpn Lat
|
||||
Lav Nep Nor Pes Pnb Ron Rus Snd Spa Swe Tha Tur Urd
|
||||
</pre>
|
||||
In addition, the library has the languages <tt>Ara Bul Pol</tt>, but they
|
||||
are not yet available in this way; you can however use the full form of
|
||||
paradigm applications prefixed by "!" as described below.
|
||||
|
||||
<p>
|
||||
|
||||
The parts of speech are: N (= noun), A (= adjective), V (= verb).
|
||||
|
||||
<p>
|
||||
|
||||
The way this works is that the program constructs the most probable
|
||||
inflection table from the forms given. For a vast majority of words in
|
||||
all languages, it is enough to give just one form. But sometimes more
|
||||
forms are needed to get the inflection table right.
|
||||
|
||||
<p>
|
||||
|
||||
This is a front end to the Paradigms modules in the GF Resource Grammar.
|
||||
See <a href=http://grammaticalframework.org/lib/doc/synopsis.html>RGL
|
||||
Synopsis</a> for more information on available languages and paradigms.
|
||||
|
||||
|
||||
|
||||
<h2>Filtering with patterns</h2>
|
||||
|
||||
You may not want to see the whole table.
|
||||
Then you can filter it with patterns, each of which works like
|
||||
"grep", using <tt>*</tt> to match any substring, either in the
|
||||
features or in the forms:
|
||||
<pre>
|
||||
Eng N baby -Gen
|
||||
Eng V die -dy*
|
||||
</pre>
|
||||
If several pattern are given, they are applied in conjunction.
|
||||
Patterns prefixed with a tilde <tt>~</tt> rather than a hyphen
|
||||
<tt>-</tt> are checked for <i>not</i> matching. Thus the search
|
||||
<pre>
|
||||
Eng N baby -Gen ~Pl
|
||||
</pre>
|
||||
selects the lines that contain <tt>Gen</tt> but not <tt>Pl</tt>.
|
||||
|
||||
|
||||
<h2>Using custom paradigms</h2>
|
||||
|
||||
(For GF experts.) If you want to use other paradigms than the smart
|
||||
<tt>mk</tt> paradigms, you can prefix your input with <tt>!</tt> and
|
||||
use the normal expression syntax of GF. For example:
|
||||
<pre>
|
||||
! Ara brkN "طير" "فَعل" "فُعُول" Masc NoHum
|
||||
! Bul mkN041 "птица"
|
||||
! Pol mkRegAdj "duży" "większy" "dużo" "więcej"
|
||||
</pre>
|
||||
This also allows you to use structured terms:
|
||||
<pre>
|
||||
! Ger prefixV "auf" (mkV "fassen")
|
||||
</pre>
|
||||
|
||||
|
||||
<h2>To do</h2>
|
||||
|
||||
<ul>
|
||||
<li> nicer input helped by menus
|
||||
<li> error handling and reporting when some language doesn't follow
|
||||
the format assumed here
|
||||
<li> better documentation of the paradigms
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
|
||||
Powered by <a href=http://grammaticalframework.org>GF</a>. Aarne Ranta 2012.
|
||||
|
||||
<hr>
|
||||
<address></address>
|
||||
<!-- hhmts start --> Last modified: Wed Sep 12 14:24:51 CEST 2012 <!-- hhmts end -->
|
||||
</body> </html>
|
||||
107
src/compiler/www/gfmorpho/index.html
Normal file
107
src/compiler/www/gfmorpho/index.html
Normal file
@@ -0,0 +1,107 @@
|
||||
<!DOCTYPE html>
|
||||
<html> <head>
|
||||
<title>Smart paradigms</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name = "viewport" content = "width = device-width">
|
||||
<link rel=stylesheet href="../cloud.css">
|
||||
<style>
|
||||
.morpho_output {
|
||||
background: white;
|
||||
padding: 1ex;
|
||||
margin: 1ex;
|
||||
box-shadow: 5px 5px 5px rgba(0,0,0,0.3);
|
||||
}
|
||||
th,td { vertical-align: baseline; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<h1><a href="/"><img class=nofloat src="../P/gf-cloud.png" alt=""></a> Word inflection with smart paradigms</h1>
|
||||
</header>
|
||||
<main>
|
||||
|
||||
Give language, part of speech, and one or more word forms, to obtain
|
||||
the inflection table.
|
||||
<p>
|
||||
<table>
|
||||
<tr><th>Examples:
|
||||
<td>
|
||||
<input onclick="submit_example(this)" type=button value="Eng N baby">
|
||||
<input onclick="submit_example(this)" type=button value="Fin V odottaa odotti">
|
||||
<input onclick="submit_example(this)" type=button value="Fre V manger">
|
||||
<input onclick="submit_example(this)" type=button value="Ger N Soldat Soldaten _masculine">
|
||||
<input onclick="submit_example(this)" type=button value="Hin N बच्छा">
|
||||
<input onclick="submit_example(this)" type=button value="Jpn V 答える _Gr2">
|
||||
<input onclick="submit_example(this)" type=button value="Lat A vetus veteris">
|
||||
</table>
|
||||
<p>
|
||||
Thus notice that word forms are given without quotes. In addition
|
||||
to word forms, in some languages it might be necessary to give
|
||||
an inherent feature (e.g. gender) and these
|
||||
are prefixed with an underscore <tt>_</tt>.
|
||||
<p>
|
||||
<form name=morpho method=get action="gfmorpho.cgi" onsubmit="submitmorpho();return false" onreset="resetmorpho()">
|
||||
Create your own example:
|
||||
<!--
|
||||
<select name=language><option value=Eng>English</option></select>
|
||||
<select name=category>
|
||||
<option value=N>Noun</option>
|
||||
<option value=A>Adjective</option>
|
||||
<option value=V>Verb</option>
|
||||
</select>
|
||||
-->
|
||||
<input size=40 name=args placeholder="Lang Cat word_forms">
|
||||
<input type=submit value="Submit">
|
||||
<input type=reset value="Clear">
|
||||
</form>
|
||||
|
||||
<pre id=morpho_output></pre>
|
||||
|
||||
|
||||
<h2>Language and part of speech</h2>
|
||||
|
||||
The available languages are:
|
||||
<blockquote><tt>
|
||||
Afr Amh Ara Bul Cat Chi Dan Dut Eng Est Eus Fin Fre Ger
|
||||
Grc Gre Heb Hin Ice Ina Ita Jpn Lat Lav Mlt Mon Nep Nno
|
||||
Nor Pes Pnb Pol Por Ron Rus Slv Snd Spa Swe Tha Tur Urd
|
||||
</tt></blockquote>
|
||||
|
||||
<!--
|
||||
In addition, the library has the languages <tt>Ara Bul Pol</tt>, but they
|
||||
are not yet available in this way; you can however use the full form of
|
||||
paradigm applications prefixed by "!" as described below.
|
||||
-->
|
||||
<p>
|
||||
|
||||
The parts of speech are: N (= noun), A (= adjective), V (= verb).
|
||||
|
||||
<p>
|
||||
|
||||
The way this works is that the program constructs the most probable
|
||||
inflection table from the forms given. For a vast majority of words in
|
||||
all languages, it is enough to give just one form. But sometimes more
|
||||
forms are needed to get the inflection table right.
|
||||
|
||||
<p>
|
||||
|
||||
This is a front-end to the Paradigms modules in the GF Resource Grammar.
|
||||
See <a href=http://www.grammaticalframework.org/lib/doc/synopsis.html>RGL
|
||||
Synopsis</a> for more information on available languages and paradigms.
|
||||
|
||||
|
||||
</main>
|
||||
<footer>
|
||||
<hr>
|
||||
<div class=modtime><small>
|
||||
<!-- hhmts start -->Last modified: Tue Dec 3 17:06:25 CET 2019 <!-- hhmts end -->
|
||||
</small></div>
|
||||
<address>Thomas H</address>
|
||||
Based on <a href="gfmorpho.html">GFMorpho</a> by Aarne Ranta 2012.
|
||||
</body>
|
||||
<script src="../js/support.js"></script>
|
||||
<script src="../js/localstorage.js"></script>
|
||||
<script src="../gfse/cloud2.js"></script>
|
||||
<script src="morpho.js"></script>
|
||||
</html>
|
||||
42
src/compiler/www/gfmorpho/morpho.js
Normal file
42
src/compiler/www/gfmorpho/morpho.js
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
var local=appLocalStorage("gf.morpho.")
|
||||
|
||||
function quote(s) {
|
||||
return s[0]=="_" ? s.substr(1) : '"'+s+'"'
|
||||
}
|
||||
|
||||
function show_output(output) {
|
||||
morpho_output.className=output ? "morpho_output" : ""
|
||||
replaceChildren(morpho_output,text(output))
|
||||
}
|
||||
|
||||
function submitmorpho() {
|
||||
clear(morpho_output)
|
||||
var args=morpho.args.value.split(/ +/)
|
||||
var lang=args[0]
|
||||
var cat=args[1]
|
||||
var wordforms=args.slice(2).map(quote).join(" ")
|
||||
//console.log("submitmorpho",lang,cat,wordforms)
|
||||
switch("") {
|
||||
case lang: show_output("No language"); break;
|
||||
case cat: show_output("No category"); break;
|
||||
case wordforms: show_output("No word forms"); break;
|
||||
default:
|
||||
gfshell("e",function() {
|
||||
gfshell("i -retain alltenses/Paradigms"+lang+".gfo",function() {
|
||||
gfshell("cc -table -unqual mk"+cat+wordforms,show_output)
|
||||
})
|
||||
})
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function resetmorpho() {
|
||||
show_output("")
|
||||
}
|
||||
|
||||
function submit_example(b) {
|
||||
//console.log("submit_example",b.value)
|
||||
morpho.args.value=b.value
|
||||
submitmorpho()
|
||||
}
|
||||
Reference in New Issue
Block a user