Synopsis: include explanation in category titles

This commit is contained in:
bringert
2007-11-05 22:05:07 +00:00
parent 446d99c370
commit b241cc1309
2 changed files with 91 additions and 171 deletions

View File

@@ -2,6 +2,9 @@ import System
import Char
import List
type Cats = [(String,String,String)]
type Rules = [(String,String,String)]
main = do
xx <- getArgs
let isLatex = case xx of
@@ -36,10 +39,10 @@ main = do
space
link "Source:" structuralAPI
space
rs <- rulesTable False isLatex structuralAPI
rs <- rulesTable False isLatex cs structuralAPI
delimit rs
space
mapM_ (putParadigms isLatex) paradigmFiles
mapM_ (putParadigms isLatex cs) paradigmFiles
space
include "synopsis-browse.txt"
space
@@ -52,7 +55,7 @@ main = do
if isLatex then (system $ "pdflatex synopsis.tex") >> return () else return ()
getCats :: FilePath -> IO [(String, String, String)]
getCats :: FilePath -> IO Cats
getCats file = do
ss <- readFile file >>= return . lines
return $ getrs [] ss
@@ -66,13 +69,13 @@ getCats file = do
(expl,ex) = span (/="e.g.") exp
_ -> getrs rs ss2
rulesTable :: Bool -> Bool -> FilePath -> IO [String]
rulesTable hasEx isLatex file = do
rulesTable :: Bool -> Bool -> Cats -> FilePath -> IO [String]
rulesTable hasEx isLatex cs file = do
rs <- getRules file
return $ mkTable hasEx isLatex rs
return $ mkTable hasEx isLatex cs rs
getRules :: FilePath -> IO [(String,String,String)]
getRules :: FilePath -> IO Rules
getRules file = do
ss <- readFile file >>= return . lines
return $ getrs [] ss
@@ -97,12 +100,13 @@ getRules file = do
n:ws | last n == '.' && not (null (init n)) && all isDigit (init n) -> ws
_ -> e
putParadigms isLatex (lang,file) = do
putParadigms :: Bool -> Cats -> (String, FilePath) -> IO ()
putParadigms isLatex cs (lang,file) = do
title ("Paradigms for " ++ lang)
space
link "source" file
space
rs <- rulesTable False isLatex file
rs <- rulesTable False isLatex cs file
space
delimit rs
space
@@ -114,16 +118,16 @@ inChunks i f = concat . intersperse ["\n\n"] . map f . chunks i where
-- Makes one table per result category.
-- Adds a subsection header for each table.
mkSplitTables :: Bool -> Bool -> [(String,String,String)] -> [(String,String,String)] -> [String]
mkSplitTables :: Bool -> Bool -> Cats -> Rules -> [String]
mkSplitTables hasEx isLatex cs rs = concatMap t (sortRules rs)
where t xs = [subtitle c] ++ expl ++ mkTable hasEx isLatex xs
where t xs = [subtitle c expl] ++ mkTable hasEx isLatex cs xs
where c = resultCat (head xs)
expl = case [e | (n,e,_) <- cs, n == c] of
[] -> []
e:_ -> ["", e, ""]
[] -> ""
e:_ -> e
mkTable :: Bool -> Bool -> [(String,String,String)] -> [String]
mkTable hasEx isLatex = inChunks chsize (\rs -> header : map (unwords . row) rs)
mkTable :: Bool -> Bool -> Cats -> Rules -> [String]
mkTable hasEx isLatex cs = inChunks chsize (\rs -> header : map (unwords . row) rs)
where
chsize = if isLatex then 40 else 1000
header = if hasEx then "|| Function | Type | Example ||"
@@ -133,15 +137,15 @@ mkTable hasEx isLatex = inChunks chsize (\rs -> header : map (unwords . row) rs)
else ["|", name', "|", typ', "|"]
where
name' = ttf name
typ' = showTyp typ
typ' = showTyp cs typ
ex' = if null ex then "-" else itf ex
mkCatTable :: Bool -> [(String, String, String)] -> [String]
mkCatTable isLatex = inChunks chsize (\rs -> header ++ map mk1 rs)
mkCatTable :: Bool -> Cats -> [String]
mkCatTable isLatex cs = inChunks chsize (\rs -> header ++ map mk1 rs) cs
where
header = ["|| Category | Explanation | Example ||"]
chsize = if isLatex then 40 else 1000
mk1 (name,expl,ex) = unwords ["|", showCat name, "|", expl, "|", typo ex, "|"]
mk1 (name,expl,ex) = unwords ["|", showCat cs name, "|", expl, "|", typo ex, "|"]
typo ex = if take 1 ex == "\"" then itf (init (tail ex)) else ex
synopsis = "synopsis.txt"
@@ -176,12 +180,12 @@ itf s = "//" ++ s ++ "//"
-----------------
-- sort category synopsis by category, retain one table
sortCats :: [(String,String,String)] -> [(String,String,String)]
sortCats :: Cats -> Cats
sortCats = sortBy compareCat
where compareCat (n1,_,_) (n2,_,_) = compare n1 n2
-- sort function synopsis by category, into separate tables
sortRules :: [(String,String,String)] -> [[(String,String,String)]]
sortRules :: Rules -> [Rules]
sortRules = groupBy sameCat . sortBy compareRules
where sameCat r1 r2 = resultCat r1 == resultCat r2
compareRules r1@(n1,_,_) r2@(n2,_,_)
@@ -191,14 +195,17 @@ resultCat :: (String,String,String) -> String
resultCat (_,t,_) = last (words t)
subtitle cat = "==" ++ cat ++ "==" ++ "[" ++ cat ++ "]"
subtitle cat expl = "==" ++ cat ++ e ++ "==" ++ "[" ++ cat ++ "]"
where e = if null expl then "" else " - " ++ expl
showCat cat = "[" ++ cat ++ " #" ++ cat ++ "]"
showCat :: Cats -> String -> String
showCat cs cat = "[" ++ cat ++ " #" ++ cat ++ "]"
showTyp = unwords . map f . words
showTyp :: Cats -> String -> String
showTyp cs = unwords . map f . words
where f s | head s == '(' && last s == ')' && isCat c
= "(" ++ showCat c ++ ")"
| isCat s = showCat s
= "(" ++ showCat cs c ++ ")"
| isCat s = showCat cs s
| otherwise = ttf s
where c = init (tail s)
isCat cat = cat `notElem` ["Str","Int"]

View File

@@ -20,44 +20,44 @@
</UL>
<LI><A HREF="#toc4">Syntax Rules</A>
<UL>
<LI><A HREF="#AP">AP</A>
<LI><A HREF="#AdN">AdN</A>
<LI><A HREF="#Adv">Adv</A>
<LI><A HREF="#Ant">Ant</A>
<LI><A HREF="#CN">CN</A>
<LI><A HREF="#Cl">Cl</A>
<LI><A HREF="#Det">Det</A>
<LI><A HREF="#IAdv">IAdv</A>
<LI><A HREF="#IP">IP</A>
<LI><A HREF="#Imp">Imp</A>
<LI><A HREF="#AP">AP - adjectival phrase</A>
<LI><A HREF="#AdN">AdN - numeral-modifying adverb</A>
<LI><A HREF="#Adv">Adv - verb-phrase-modifying adverb</A>
<LI><A HREF="#Ant">Ant - anteriority</A>
<LI><A HREF="#CN">CN - common noun (without determiner)</A>
<LI><A HREF="#Cl">Cl - declarative clause, with all tenses</A>
<LI><A HREF="#Det">Det - determiner phrase</A>
<LI><A HREF="#IAdv">IAdv - interrogative adverb</A>
<LI><A HREF="#IP">IP - interrogative pronoun</A>
<LI><A HREF="#Imp">Imp - imperative</A>
<LI><A HREF="#ImpForm">ImpForm</A>
<LI><A HREF="#ListAP">ListAP</A>
<LI><A HREF="#ListAdv">ListAdv</A>
<LI><A HREF="#ListNP">ListNP</A>
<LI><A HREF="#ListS">ListS</A>
<LI><A HREF="#NP">NP</A>
<LI><A HREF="#Num">Num</A>
<LI><A HREF="#NP">NP - noun phrase (subject or object)</A>
<LI><A HREF="#Num">Num - cardinal number (used with QuantPl)</A>
<LI><A HREF="#Numeral">Numeral</A>
<LI><A HREF="#Ord">Ord</A>
<LI><A HREF="#PConj">PConj</A>
<LI><A HREF="#Phr">Phr</A>
<LI><A HREF="#Pol">Pol</A>
<LI><A HREF="#Ord">Ord - ordinal number (used in Det)</A>
<LI><A HREF="#PConj">PConj - phrase-beginning conjunction</A>
<LI><A HREF="#Phr">Phr - phrase in a text</A>
<LI><A HREF="#Pol">Pol - polarity</A>
<LI><A HREF="#Punct">Punct</A>
<LI><A HREF="#QCl">QCl</A>
<LI><A HREF="#QS">QS</A>
<LI><A HREF="#Quant">Quant</A>
<LI><A HREF="#QCl">QCl - question clause, with all tenses</A>
<LI><A HREF="#QS">QS - question</A>
<LI><A HREF="#Quant">Quant - quantifier with both sg and pl</A>
<LI><A HREF="#QuantPl">QuantPl</A>
<LI><A HREF="#QuantSg">QuantSg</A>
<LI><A HREF="#RCl">RCl</A>
<LI><A HREF="#RP">RP</A>
<LI><A HREF="#RS">RS</A>
<LI><A HREF="#S">S</A>
<LI><A HREF="#Slash">Slash</A>
<LI><A HREF="#Tense">Tense</A>
<LI><A HREF="#Text">Text</A>
<LI><A HREF="#Utt">Utt</A>
<LI><A HREF="#VP">VP</A>
<LI><A HREF="#Voc">Voc</A>
<LI><A HREF="#RCl">RCl - relative clause, with all tenses</A>
<LI><A HREF="#RP">RP - relative pronoun</A>
<LI><A HREF="#RS">RS - relative</A>
<LI><A HREF="#S">S - declarative sentence</A>
<LI><A HREF="#Slash">Slash - clause missing NP (S/NP in GPSG)</A>
<LI><A HREF="#Tense">Tense - tense</A>
<LI><A HREF="#Text">Text - text consisting of several phrases</A>
<LI><A HREF="#Utt">Utt - sentence, question, word...</A>
<LI><A HREF="#VP">VP - verb phrase</A>
<LI><A HREF="#Voc">Voc - vocative or "please"</A>
</UL>
<LI><A HREF="#toc43">Structural Words</A>
<LI><A HREF="#toc44">Paradigms for Danish</A>
@@ -422,10 +422,7 @@ also in the <CODE>Paradigms</CODE> modules.
Source: <A HREF="../api/Constructors.gf"><CODE>http://www.cs.chalmers.se/~aarne/GF/lib/resource/api/Constructors.gf</CODE></A>
</P>
<A NAME="AP"></A>
<H2>AP</H2>
<P>
adjectival phrase
</P>
<H2>AP - adjectival phrase</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -500,10 +497,7 @@ adjectival phrase
</TABLE>
<A NAME="AdN"></A>
<H2>AdN</H2>
<P>
numeral-modifying adverb
</P>
<H2>AdN - numeral-modifying adverb</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -518,10 +512,7 @@ numeral-modifying adverb
</TABLE>
<A NAME="Adv"></A>
<H2>Adv</H2>
<P>
verb-phrase-modifying adverb
</P>
<H2>Adv - verb-phrase-modifying adverb</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -581,10 +572,7 @@ verb-phrase-modifying adverb
</TABLE>
<A NAME="Ant"></A>
<H2>Ant</H2>
<P>
anteriority
</P>
<H2>Ant - anteriority</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -604,10 +592,7 @@ anteriority
</TABLE>
<A NAME="CN"></A>
<H2>CN</H2>
<P>
common noun (without determiner)
</P>
<H2>CN - common noun (without determiner)</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -707,10 +692,7 @@ common noun (without determiner)
</TABLE>
<A NAME="Cl"></A>
<H2>Cl</H2>
<P>
declarative clause, with all tenses
</P>
<H2>Cl - declarative clause, with all tenses</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -845,10 +827,7 @@ declarative clause, with all tenses
</TABLE>
<A NAME="Det"></A>
<H2>Det</H2>
<P>
determiner phrase
</P>
<H2>Det - determiner phrase</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -928,10 +907,7 @@ determiner phrase
</TABLE>
<A NAME="IAdv"></A>
<H2>IAdv</H2>
<P>
interrogative adverb
</P>
<H2>IAdv - interrogative adverb</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -946,10 +922,7 @@ interrogative adverb
</TABLE>
<A NAME="IP"></A>
<H2>IP</H2>
<P>
interrogative pronoun
</P>
<H2>IP - interrogative pronoun</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -974,10 +947,7 @@ interrogative pronoun
</TABLE>
<A NAME="Imp"></A>
<H2>Imp</H2>
<P>
imperative
</P>
<H2>Imp - imperative</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1107,10 +1077,7 @@ imperative
</TABLE>
<A NAME="NP"></A>
<H2>NP</H2>
<P>
noun phrase (subject or object)
</P>
<H2>NP - noun phrase (subject or object)</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1235,10 +1202,7 @@ noun phrase (subject or object)
</TABLE>
<A NAME="Num"></A>
<H2>Num</H2>
<P>
cardinal number (used with QuantPl)
</P>
<H2>Num - cardinal number (used with QuantPl)</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1338,10 +1302,7 @@ cardinal number (used with QuantPl)
</TABLE>
<A NAME="Ord"></A>
<H2>Ord</H2>
<P>
ordinal number (used in Det)
</P>
<H2>Ord - ordinal number (used in Det)</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1366,10 +1327,7 @@ ordinal number (used in Det)
</TABLE>
<A NAME="PConj"></A>
<H2>PConj</H2>
<P>
phrase-beginning conjunction
</P>
<H2>PConj - phrase-beginning conjunction</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1384,10 +1342,7 @@ phrase-beginning conjunction
</TABLE>
<A NAME="Phr"></A>
<H2>Phr</H2>
<P>
phrase in a text
</P>
<H2>Phr - phrase in a text</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1427,10 +1382,7 @@ phrase in a text
</TABLE>
<A NAME="Pol"></A>
<H2>Pol</H2>
<P>
polarity
</P>
<H2>Pol - polarity</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1475,10 +1427,7 @@ polarity
</TABLE>
<A NAME="QCl"></A>
<H2>QCl</H2>
<P>
question clause, with all tenses
</P>
<H2>QCl - question clause, with all tenses</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1528,10 +1477,7 @@ question clause, with all tenses
</TABLE>
<A NAME="QS"></A>
<H2>QS</H2>
<P>
question
</P>
<H2>QS - question</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1556,10 +1502,7 @@ question
</TABLE>
<A NAME="Quant"></A>
<H2>Quant</H2>
<P>
quantifier with both sg and pl
</P>
<H2>Quant - quantifier with both sg and pl</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1654,10 +1597,7 @@ quantifier with both sg and pl
</TABLE>
<A NAME="RCl"></A>
<H2>RCl</H2>
<P>
relative clause, with all tenses
</P>
<H2>RCl - relative clause, with all tenses</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1687,10 +1627,7 @@ relative clause, with all tenses
</TABLE>
<A NAME="RP"></A>
<H2>RP</H2>
<P>
relative pronoun
</P>
<H2>RP - relative pronoun</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1710,10 +1647,7 @@ relative pronoun
</TABLE>
<A NAME="RS"></A>
<H2>RS</H2>
<P>
relative
</P>
<H2>RS - relative</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1733,10 +1667,7 @@ relative
</TABLE>
<A NAME="S"></A>
<H2>S</H2>
<P>
declarative sentence
</P>
<H2>S - declarative sentence</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1781,10 +1712,7 @@ declarative sentence
</TABLE>
<A NAME="Slash"></A>
<H2>Slash</H2>
<P>
clause missing NP (S/NP in GPSG)
</P>
<H2>Slash - clause missing NP (S/NP in GPSG)</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1814,10 +1742,7 @@ clause missing NP (S/NP in GPSG)
</TABLE>
<A NAME="Tense"></A>
<H2>Tense</H2>
<P>
tense
</P>
<H2>Tense - tense</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1847,10 +1772,7 @@ tense
</TABLE>
<A NAME="Text"></A>
<H2>Text</H2>
<P>
text consisting of several phrases
</P>
<H2>Text - text consisting of several phrases</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1900,10 +1822,7 @@ text consisting of several phrases
</TABLE>
<A NAME="Utt"></A>
<H2>Utt</H2>
<P>
sentence, question, word...
</P>
<H2>Utt - sentence, question, word...</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -1968,10 +1887,7 @@ sentence, question, word...
</TABLE>
<A NAME="VP"></A>
<H2>VP</H2>
<P>
verb phrase
</P>
<H2>VP - verb phrase</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>
@@ -2091,10 +2007,7 @@ verb phrase
</TABLE>
<A NAME="Voc"></A>
<H2>Voc</H2>
<P>
vocative or "please"
</P>
<H2>Voc - vocative or "please"</H2>
<TABLE CELLPADDING="4" BORDER="1">
<TR>
<TH>Function</TH>