mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-25 02:38:55 -06:00
extended Synopsis with categories, structural, and an example
This commit is contained in:
@@ -143,29 +143,32 @@ two interfaces: the resource ``Syntax`` and an application lexicon.
|
|||||||
American = mkAP american_A ;
|
American = mkAP american_A ;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
The application lexicon ``MusicLex`` has an abstract syntax that extends
|
The application lexicon ``MusicLex`` is an interface
|
||||||
the resource category system ``Cat``.
|
opening the resource category system ``Cat``.
|
||||||
```
|
```
|
||||||
abstract MusicLex = Cat ** {
|
interface MusicLex = Cat ** {
|
||||||
|
oper
|
||||||
fun
|
|
||||||
song_N : N ;
|
song_N : N ;
|
||||||
american_A : A ;
|
american_A : A ;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
It could also be an abstract syntax that extends ``Cat``, but
|
||||||
|
this would limit the kind of constructions that are possible in
|
||||||
|
the interface
|
||||||
|
|
||||||
Each language has its own concrete syntax, which opens the
|
Each language has its own concrete syntax, which opens the
|
||||||
inflectional paradigms module for that language:
|
inflectional paradigms module for that language:
|
||||||
```
|
```
|
||||||
concrete MusicLexGer of MusicLex =
|
interface MusicLexGer of MusicLex =
|
||||||
CatGer ** open ParadigmsGer in {
|
CatGer ** open ParadigmsGer in {
|
||||||
lin
|
oper
|
||||||
song_N = mkN "Lied" "Lieder" neuter ;
|
song_N = mkN "Lied" "Lieder" neuter ;
|
||||||
american_A = mkA "amerikanisch" ;
|
american_A = mkA "amerikanisch" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
concrete MusicLexFre of MusicLex =
|
interface MusicLexFre of MusicLex =
|
||||||
CatFre ** open ParadigmsFre in {
|
CatFre ** open ParadigmsFre in {
|
||||||
lin
|
oper
|
||||||
song_N = mkN "chanson" feminine ;
|
song_N = mkN "chanson" feminine ;
|
||||||
american_A = mkA "américain" ;
|
american_A = mkA "américain" ;
|
||||||
}
|
}
|
||||||
@@ -195,9 +198,9 @@ instantiating ``Music``. The latter is
|
|||||||
completely trivial, whereas the former one involves the choice of correct
|
completely trivial, whereas the former one involves the choice of correct
|
||||||
vocabulary and inflectional paradigms. For instance, Finnish is added as follows:
|
vocabulary and inflectional paradigms. For instance, Finnish is added as follows:
|
||||||
```
|
```
|
||||||
concrete MusicLexFin of MusicLex =
|
instance MusicLexFin of MusicLex =
|
||||||
CatFin ** open ParadigmsFin in {
|
CatFin ** open ParadigmsFin in {
|
||||||
lin
|
oper
|
||||||
song_N = mkN "kappale" ;
|
song_N = mkN "kappale" ;
|
||||||
american_A = mkA "amerikkalainen" ;
|
american_A = mkA "amerikkalainen" ;
|
||||||
}
|
}
|
||||||
@@ -226,9 +229,9 @@ restricted inheritance of the functor:
|
|||||||
```
|
```
|
||||||
The lexicon is as expected:
|
The lexicon is as expected:
|
||||||
```
|
```
|
||||||
concrete MusicLexEng of MusicLex =
|
instance MusicLexEng of MusicLex =
|
||||||
CatEng ** open ParadigmsEng in {
|
CatEng ** open ParadigmsEng in {
|
||||||
lin
|
oper
|
||||||
song_N = mkN "song" ;
|
song_N = mkN "song" ;
|
||||||
american_A = mkA "American" ;
|
american_A = mkA "American" ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ abstract Common = {
|
|||||||
|
|
||||||
--2 Tense, polarity, and anteriority
|
--2 Tense, polarity, and anteriority
|
||||||
|
|
||||||
Tense ; -- tense: present, past, future, conditional
|
Tense ; -- tense e.g. present, past, future
|
||||||
Pol ; -- polarity: positive, negative
|
Pol ; -- polarity e.g. positive, negative
|
||||||
Ant ; -- anteriority: simultaneous, anterior
|
Ant ; -- anteriority e.g. simultaneous, anterior
|
||||||
|
|
||||||
fun
|
fun
|
||||||
PPos, PNeg : Pol ; -- I sleep/don't sleep
|
PPos, PNeg : Pol ; -- I sleep/don't sleep
|
||||||
|
|||||||
@@ -5,16 +5,51 @@ main = do
|
|||||||
writeFile synopsis "GF Resource Grammar Library: Synopsis"
|
writeFile synopsis "GF Resource Grammar Library: Synopsis"
|
||||||
append "Aarne Ranta"
|
append "Aarne Ranta"
|
||||||
space
|
space
|
||||||
title "Syntax"
|
title "Categories"
|
||||||
space
|
space
|
||||||
link "source" syntaxAPI
|
link "Source 1:" commonAPI
|
||||||
|
space
|
||||||
|
link "Source 2:" catAPI
|
||||||
|
space
|
||||||
|
cs1 <- getCats True commonAPI
|
||||||
|
cs2 <- getCats False catAPI
|
||||||
|
delimit $ cs1 ++ cs2
|
||||||
|
space
|
||||||
|
title "Syntax Rules"
|
||||||
|
space
|
||||||
|
link "Source:" syntaxAPI
|
||||||
space
|
space
|
||||||
rs <- getRules syntaxAPI
|
rs <- getRules syntaxAPI
|
||||||
delimit rs
|
delimit rs
|
||||||
space
|
space
|
||||||
|
title "Structural Words"
|
||||||
|
space
|
||||||
|
link "Source:" structuralAPI
|
||||||
|
space
|
||||||
|
rs <- getRules structuralAPI
|
||||||
|
delimit rs
|
||||||
|
space
|
||||||
mapM_ putParadigms paradigmFiles
|
mapM_ putParadigms paradigmFiles
|
||||||
|
space
|
||||||
|
title "Example Usage"
|
||||||
|
space
|
||||||
|
ss <- readFile "synopsis-example.txt" >>= return . lines
|
||||||
|
mapM_ append ss
|
||||||
|
space
|
||||||
system $ "txt2tags -thtml --toc " ++ synopsis
|
system $ "txt2tags -thtml --toc " ++ synopsis
|
||||||
|
|
||||||
|
getCats isBeg file = do
|
||||||
|
ss <- readFile file >>= return . lines
|
||||||
|
return $ mkCatTable isBeg $ getrs [] ss
|
||||||
|
where
|
||||||
|
getrs rs ss = case ss of
|
||||||
|
('-':'-':'.':_):_ -> reverse rs
|
||||||
|
[] -> reverse rs
|
||||||
|
('-':'-':_):ss2 -> getrs rs ss2
|
||||||
|
s:ss2 -> case words s of
|
||||||
|
cat:";":"--":exp -> getrs ((cat,unwords expl, unwords (tail ex)):rs) ss2 where
|
||||||
|
(expl,ex) = span (/="e.g.") exp
|
||||||
|
_ -> getrs rs ss2
|
||||||
|
|
||||||
getRules file = do
|
getRules file = do
|
||||||
ss <- readFile file >>= return . lines
|
ss <- readFile file >>= return . lines
|
||||||
@@ -28,6 +63,7 @@ getRules file = do
|
|||||||
_:_:"overload":_ -> getrs rs ss2
|
_:_:"overload":_ -> getrs rs ss2
|
||||||
_:":":_ -> getrs (layout s:rs) ss2
|
_:":":_ -> getrs (layout s:rs) ss2
|
||||||
_ -> getrs rs ss2
|
_ -> getrs rs ss2
|
||||||
|
layout s = " " ++ dropWhile isSpace s
|
||||||
|
|
||||||
putParadigms (lang,file) = do
|
putParadigms (lang,file) = do
|
||||||
title ("Paradigms for " ++ lang)
|
title ("Paradigms for " ++ lang)
|
||||||
@@ -39,8 +75,6 @@ putParadigms (lang,file) = do
|
|||||||
delimit rs
|
delimit rs
|
||||||
space
|
space
|
||||||
|
|
||||||
layout s = " " ++ dropWhile isSpace s
|
|
||||||
|
|
||||||
|
|
||||||
mkTable rs = "|| Function | Type | Example ||" : map (unwords . row . words) rs where
|
mkTable rs = "|| Function | Type | Example ||" : map (unwords . row . words) rs where
|
||||||
row ws = ["|", name, "|", typ, "|", ex, "|"] where
|
row ws = ["|", name, "|", typ, "|", ex, "|"] where
|
||||||
@@ -53,8 +87,17 @@ mkTable rs = "|| Function | Type | Example ||" : map (unwords . row . words)
|
|||||||
_ -> e
|
_ -> e
|
||||||
filtype = filter (/=";")
|
filtype = filter (/=";")
|
||||||
|
|
||||||
|
mkCatTable isBeg rs =
|
||||||
|
(if isBeg then ("|| Category | Explanation | Example ||" :) else id)
|
||||||
|
(map mk1 rs)
|
||||||
|
where
|
||||||
|
mk1 (name,typ,ex) = unwords ["|", ttf name, "|", typ, "|", ex, "|"]
|
||||||
|
|
||||||
synopsis = "synopsis.txt"
|
synopsis = "synopsis.txt"
|
||||||
|
commonAPI = "../abstract/Common.gf"
|
||||||
|
catAPI = "../abstract/Cat.gf"
|
||||||
syntaxAPI = "../api/Constructors.gf"
|
syntaxAPI = "../api/Constructors.gf"
|
||||||
|
structuralAPI = "../abstract/Structural.gf"
|
||||||
paradigmFiles = [
|
paradigmFiles = [
|
||||||
("Danish", "../danish/ParadigmsDan.gf"),
|
("Danish", "../danish/ParadigmsDan.gf"),
|
||||||
("English", "../english/ParadigmsEng.gf"),
|
("English", "../english/ParadigmsEng.gf"),
|
||||||
@@ -72,7 +115,8 @@ append s = appendFile synopsis ('\n':s)
|
|||||||
title s = append $ "=" ++ s ++ "="
|
title s = append $ "=" ++ s ++ "="
|
||||||
space = append "\n"
|
space = append "\n"
|
||||||
delimit ss = mapM_ append ss
|
delimit ss = mapM_ append ss
|
||||||
link s f = append $ "[" ++ s ++ " " ++ f ++ "]"
|
link s f = append $ s ++ " [``" ++ fa ++ "`` " ++ f ++ "]" where
|
||||||
|
fa = "http://www.cs.chalmers.se/~aarne/GF/lib/resource" ++ dropWhile (=='.') f
|
||||||
|
|
||||||
ttf s = "``" ++ s ++ "``"
|
ttf s = "``" ++ s ++ "``"
|
||||||
itf s = "//" ++ s ++ "//"
|
itf s = "//" ++ s ++ "//"
|
||||||
|
|||||||
49
lib/resource-1.0/doc/synopsis-example.txt
Normal file
49
lib/resource-1.0/doc/synopsis-example.txt
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
The standard way of building an application has the following modules.
|
||||||
|
|
||||||
|
An abstract syntax:
|
||||||
|
```
|
||||||
|
abstract Music = {
|
||||||
|
cat
|
||||||
|
Kind,
|
||||||
|
Property ;
|
||||||
|
fun
|
||||||
|
PropKind : Kind -> Property -> Kind ;
|
||||||
|
Song : Kind ;
|
||||||
|
American : Property ;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
A domain lexicon interface:
|
||||||
|
```
|
||||||
|
interface MusicLex = open Cat in {
|
||||||
|
oper
|
||||||
|
song_N : N ;
|
||||||
|
american_A : A ;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
A functor on ``Syntax`` and the domain lexicon interface:
|
||||||
|
```
|
||||||
|
incomplete concrete MusicI of Music = open Syntax, MusicLex in {
|
||||||
|
lincat
|
||||||
|
Kind = CN ;
|
||||||
|
Property = AP ;
|
||||||
|
lin
|
||||||
|
PropKind k p = mkCN p k ;
|
||||||
|
Song = mkCN song_N ;
|
||||||
|
American = mkAP american_A ;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
For each language, an instance of the domain lexicon:
|
||||||
|
```
|
||||||
|
instance MusicLexGer of MusicLex = CatGer ** open ParadigmsGer in {
|
||||||
|
oper
|
||||||
|
song_N = mkN "Lied" "Lieder" neuter ;
|
||||||
|
american_A = mkA "amerikanisch" ;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
For each language, an instantiation of the functor:
|
||||||
|
```
|
||||||
|
--# -path=.:present:prelude
|
||||||
|
concrete MusicGer of Music = MusicI with
|
||||||
|
(Syntax = SyntaxGer),
|
||||||
|
(MusicLex = MusicLexGer) ;
|
||||||
|
```
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user