1
0
forked from GitHub/gf-core

Working on with new resource API.

This commit is contained in:
aarne
2003-11-21 15:28:25 +00:00
parent 6d99debdff
commit 9cd2c273a2
12 changed files with 726 additions and 220 deletions

View File

@@ -0,0 +1,210 @@
--# -path=.:../nabstract:../../prelude
--1 The Top-Level Swedish Resource Grammar: Combination Rules
--
-- Aarne Ranta 2002 -- 2003
--
-- This is the Swedish concrete syntax of the multilingual resource
-- grammar. Most of the work is done in the file $SyntaxSwe.gf$.
-- However, for the purpose of documentation, we make here explicit the
-- linearization types of each category, so that their structures and
-- dependencies can be seen.
-- Another substantial part are the linearization rules of some
-- structural words.
--
-- The users of the resource grammar should not look at this file for the
-- linearization rules, which are in fact hidden in the document version.
-- They should use $resource.Abs.gf$ to access the syntactic rules.
-- This file can be consulted in those, hopefully rare, occasions in which
-- one has to know how the syntactic categories are
-- implemented. The parameter types are defined in $TypesSwe.gf$.
concrete CombinationsSwe of Combinations = open Prelude, SyntaxSwe in {
flags
startcat=Phr ;
lexer=text ;
unlexer=text ;
lincat
CN = {s : Number => SpeciesP => Case => Str ; g : Gender ; x : Sex ;
p : IsComplexCN} ;
N = CommNoun ;
-- = {s : Number => Species => Case => Str ; g : Gender ; x : Sex} ;
NP = NounPhrase ;
-- = {s : NPForm => Str ; g : Gender ; n : Number} ;
PN = {s : Case => Str ; g : Gender ; x : Sex} ;
Det = {s : Gender => Sex => Str ; n : Number ; b : SpeciesP} ;
Fun = Function ;
-- = CommNoun ** {s2 : Preposition} ;
Fun2 = Function ** {s3 : Preposition} ;
Num = {s : Case => Str} ;
Prep = {s : Str} ;
Adj1 = Adjective ;
-- = {s : AdjFormPos => Case => Str} ;
Adj2 = Adjective ** {s2 : Preposition} ;
AdjDeg = {s : AdjForm => Str} ;
AP = Adjective ** {p : IsPostfixAdj} ;
V = Verb ;
-- = {s : VForm => Str} ;
VG = Verb ** {s2 : Bool => Str ; s3 : Gender => Number => Str} ;
VP = Verb ** {s2 : Str ; s3 : Gender => Number => Str} ;
TV = TransVerb ;
-- = Verb ** {s2 : Preposition} ;
V3 = TransVerb ** {s3 : Preposition} ;
VS = Verb ;
VV = Verb ** {isAux : Bool} ;
AdV = {s : Str ; isPost : Bool} ;
S = Sentence ;
-- = {s : Order => Str} ;
Slash = Sentence ** {s2 : Preposition} ;
RP = {s : RelCase => GenNum => Str ; g : RelGender} ;
RC = {s : GenNum => Str} ;
IP = NounPhrase ;
Qu = {s : QuestForm => Str} ;
Imp = {s : Number => Str} ;
Phr = {s : Str} ;
Conj = {s : Str ; n : Number} ;
ConjD = {s1 : Str ; s2 : Str ; n : Number} ;
ListS = {s1,s2 : Order => Str} ;
ListAP = {s1,s2 : AdjFormPos => Case => Str ; p : Bool} ;
ListNP = {s1,s2 : NPForm => Str ; g : Gender ; n : Number} ;
--.
lin
UseN = noun2CommNounPhrase ;
ModAdj = modCommNounPhrase ;
ModGenOne = npGenDet singular noNum ;
ModGenMany = npGenDet plural ;
UsePN = nameNounPhrase ;
UseFun = funAsCommNounPhrase ;
AppFun = appFunComm ;
AppFun2 = appFun2 ;
AdjP1 = adj2adjPhrase ;
ComplAdj = complAdj ;
PositAdjP = positAdjPhrase ;
ComparAdjP = comparAdjPhrase ;
SuperlNP = superlNounPhrase ;
DetNP = detNounPhrase ;
IndefOneNP = indefNounPhrase singular ;
IndefManyNP = indefNounPhraseNum plural ;
DefOneNP = defNounPhrase singular ;
DefManyNP = defNounPhraseNum plural ;
MassNP = detNounPhrase (mkDeterminerSg (detSgInvar []) IndefP) ;
UseInt i = {s = table {Nom => i.s ; Gen => i.s ++ "s"}} ; ---
NoNum = noNum ;
CNthatS = nounThatSentence ;
PredVP = predVerbPhrase ;
PosVG = predVerbGroup True ;
NegVG = predVerbGroup False ;
PredV = predVerb ;
PredAP = predAdjective ;
PredCN = predCommNoun ;
PredTV = complTransVerb ;
PredV3 = complDitransVerb ;
PredPassV = passVerb ;
PredNP = predNounPhrase ;
PredAdV = predAdverb ;
PredVS = complSentVerb ;
PredVV = complVerbVerb ;
VTrans = transAsVerb ;
AdjAdv a = advPost (a.s ! adverbForm ! Nom) ;
PrepNP p = prepPhrase p.s ; ---
AdvVP = adVerbPhrase ;
AdvCN = advCommNounPhrase ;
AdvAP = advAdjPhrase ;
ThereIsCN A = predVerbPhrase npDet
(predVerbGroup True
(complTransVerb (mkDirectVerb verbFinnas)
(indefNounPhrase singular A))) ;
ThereAreCN n A = predVerbPhrase npDet
(predVerbGroup True
(complTransVerb (mkDirectVerb verbFinnas)
(indefNounPhraseNum plural n A))) ;
PosSlashTV = slashTransVerb True ;
NegSlashTV = slashTransVerb False ;
OneVP = predVerbPhrase npMan ;
IdRP = identRelPron ;
FunRP = funRelPron ;
RelVP = relVerbPhrase ;
RelSlash = relSlash ;
ModRC = modRelClause ;
RelSuch = relSuch ;
WhoOne = intPronWho singular ;
WhoMany = intPronWho plural ;
WhatOne = intPronWhat singular ;
WhatMany = intPronWhat plural ;
FunIP = funIntPron ;
NounIPOne = nounIntPron singular ;
NounIPMany = nounIntPron plural ;
QuestVP = questVerbPhrase ;
IntVP = intVerbPhrase ;
IntSlash = intSlash ;
QuestAdv = questAdverbial ;
IsThereCN A = questVerbPhrase npDet
(predVerbGroup True
(complTransVerb (mkDirectVerb verbFinnas)
(indefNounPhrase singular A))) ;
AreThereCN n A = questVerbPhrase npDet
(predVerbGroup True
(complTransVerb (mkDirectVerb verbFinnas)
(indefNounPhraseNum plural n A))) ;
ImperVP = imperVerbPhrase ;
IndicPhrase = indicUtt ;
QuestPhrase = interrogUtt ;
ImperOne = imperUtterance singular ;
ImperMany = imperUtterance plural ;
AdvS = advSentence ;
TwoS = twoSentence ;
ConsS = consSentence ;
ConjS = conjunctSentence ;
ConjDS = conjunctDistrSentence ;
TwoAP = twoAdjPhrase ;
ConsAP = consAdjPhrase ;
ConjAP = conjunctAdjPhrase ;
ConjDAP = conjunctDistrAdjPhrase ;
TwoNP = twoNounPhrase ;
ConsNP = consNounPhrase ;
ConjNP = conjunctNounPhrase ;
ConjDNP = conjunctDistrNounPhrase ;
SubjS = subjunctSentence ;
SubjImper = subjunctImperative ;
SubjQu = subjunctQuestion ;
SubjVP = subjunctVerbPhrase ;
PhrNP = useNounPhrase ;
PhrOneCN = useCommonNounPhrase singular ;
PhrManyCN = useCommonNounPhrase plural ;
PhrIP ip = ip ;
PhrIAdv ia = ia ;
OnePhr p = p ;
ConsPhr = cc2 ;
} ;

View File

@@ -0,0 +1,115 @@
--# -path=.:../nabstract:../../prelude
--1 The Top-Level English Resource Grammar: Structural Words
--
-- Aarne Ranta 2002 -- 2003
--
concrete StructuralSwe of Structural =
CombinationsSwe ** open Prelude, SyntaxSwe in {
lin
INP = pronNounPhrase jag_32 ;
ThouNP = pronNounPhrase du_33 ;
HeNP = pronNounPhrase han_34 ;
SheNP = pronNounPhrase hon_35 ;
ItNP = pronNounPhrase det_40 ; ----
WeNP n = pronNounPhrase (pronWithNum vi_36 n) ;
YeNP n = pronNounPhrase (pronWithNum ni_37 n) ;
TheyNP = pronNounPhrase de_38 ;
YouNP = let {ni = pronNounPhrase ni_37 } in {s = ni.s ; g = ni.g ; n = Sg} ;
EveryDet = varjeDet ;
AllsDet = mkDeterminerPlNum "alla" IndefP ;
WhichDet = vilkenDet ;
MostDet = flestaDet ;
HowIAdv = ss "hur" ;
WhenIAdv = ss "när" ;
WhereIAdv = ss "var" ;
WhyIAdv = ss "varför" ;
AndConj = ss "och" ** {n = Pl} ;
OrConj = ss "eller" ** {n = Sg} ;
BothAnd = sd2 "både" "och" ** {n = Pl} ;
EitherOr = sd2 "antingen" "eller" ** {n = Sg} ;
NeitherNor = sd2 "varken" "eller" ** {n = Sg} ;
IfSubj = ss "om" ;
WhenSubj = ss "när" ;
PhrYes = ss ["Ja ."] ;
PhrNo = ss ["Nej ."] ;
VeryAdv = ss "mycket" ;
TooAdv = ss "för" ;
OtherwiseAdv = ss "annars" ;
ThereforeAdv = ss "därför" ;
{-
EveryDet = everyDet ;
AllDet = mkDeterminer Sg "all" ; --- all the missing
AllsDet = mkDeterminerNum Pl "all" ;
WhichDet = whichDet ;
WhichsDet = mkDeterminerNum Pl "which" ;
MostsDet = mostDet ;
MostDet = mkDeterminer Sg "most" ;
SomeDet = mkDeterminer Sg "some" ;
SomesDet = mkDeterminerNum Pl "some" ;
AnyDet = mkDeterminer Sg "any" ;
AnysDet = mkDeterminerNum Pl "any" ;
NoDet = mkDeterminer Sg "no" ;
NosDet = mkDeterminerNum Pl "no" ;
ManyDet = mkDeterminer Sg "many" ;
MuchDet = mkDeterminer Sg ["a lot of"] ; ---
ThisDet = mkDeterminer Sg "this" ;
TheseDet = mkDeterminerNum Pl "these" ;
ThatDet = mkDeterminer Sg "that" ;
ThoseDet = mkDeterminerNum Pl "those" ;
ThisNP = nameNounPhrase (nameReg "this") ;
ThatNP = nameNounPhrase (nameReg "that") ;
TheseNP n = nameNounPhrase {s = \\c => "these" ++ n.s ! c} ;
ThoseNP n = nameNounPhrase {s = \\c => "those" ++ n.s ! c} ;
-}
EverybodyNP = nameNounPhrase (mkProperName "alleman" Utr Masc) ;
SomebodyNP = nameNounPhrase (mkProperName "någon" Utr Masc) ;
NobodyNP = nameNounPhrase (mkProperName "ingen" Utr Masc) ;
EverythingNP = nameNounPhrase (mkProperName "allting" Neutr NoMasc) ;
SomethingNP = nameNounPhrase (mkProperName "någonting" Neutr NoMasc) ;
NothingNP = nameNounPhrase (mkProperName "ingenting" Neutr NoMasc) ;
CanVV = mkVerb "kunna" "kan" "kunn" ** {isAux = True} ; ---
CanKnowVV = mkVerb "kunna" "kan" "kunn" ** {isAux = True} ; ---
MustVV = mkVerb "få" "måste" "få" ** {isAux = True} ; ---
WantVV = mkVerb "vilja" "vill" "vilj" ** {isAux = True} ; ---
EverywhereNP = advPost "varstans" ;
SomewhereNP = advPost "någonstans" ;
NowhereNP = advPost "ingenstans" ;
AlthoughSubj = ss "fast" ;
AlmostAdv = ss "nästan" ;
QuiteAdv = ss "ganska" ;
InPrep = ss "i" ;
OnPrep = ss "på" ;
ToPrep = ss "till" ;
ThroughPrep = ss "genom" ;
AbovePrep = ss "ovanför" ;
UnderPrep = ss "under" ;
InFrontPrep = ss "framför" ;
BehindPrep = ss "bakom" ;
BetweenPrep = ss "mellan" ;
FromPrep = ss "från" ;
BeforePrep = ss "före" ;
DuringPrep = ss "under" ;
AfterPrep = ss "efter" ;
WithPrep = ss "med" ;
WithoutPrep = ss "utan" ;
ByMeansPrep = ss "med" ;
PartPrep = ss "av" ;
AgentPrep = ss "av" ;
}

View File

@@ -129,10 +129,10 @@ oper
mkDeterminerSg : DetSg -> SpeciesP -> Determiner = \en, b ->
{s = en ; n = Sg ; b = b} ;
mkDeterminerPl : DetPl -> SpeciesP -> Determiner = \alla ->
mkDeterminerPlNum alla noNum ;
mkDeterminerPl : DetPl -> SpeciesP -> Determiner = \alla,b ->
mkDeterminerPlNum alla b noNum ;
mkDeterminerPlNum : DetPl -> Numeral -> SpeciesP -> Determiner = \alla,n,b ->
mkDeterminerPlNum : DetPl -> SpeciesP -> Numeral -> Determiner = \alla,b,n ->
{s = \\_,_ => alla ++ n.s ! Nom ;
n = Pl ;
b = b
@@ -202,7 +202,7 @@ oper
detNounPhrase
(mkDeterminerSgGender (table {g => artDef ! cn.p ! ASg g}) (DefP Def)) cn ;
deDet : Numeral -> CommNounPhrase -> NounPhrase = \n,cn ->
detNounPhrase (mkDeterminerPlNum (artDef ! cn.p ! APl) n (DefP Def)) cn ;
detNounPhrase (mkDeterminerPlNum (artDef ! cn.p ! APl) (DefP Def) n) cn ;
-- It is useful to have macros for indefinite and definite, singular and plural
-- noun-phrase-like syncategorematic expressions.
@@ -447,50 +447,53 @@ oper
-- to account for word order variations.
VerbPhrase : Type = Verb ** {s2 : Str ; s3 : Gender => Number => Str} ;
VerbGroup : Type = Verb ** {s2 : Bool => Str ; s3 : Gender => Number => Str} ;
predVerbGroup : Bool -> VerbGroup -> VerbPhrase = \b,vg -> {
s = vg.s ;
s2 = vg.s2 ! b ;
s3 = vg.s3
} ;
-- A simple verb can be made into a verb phrase with an empty complement.
-- There are two versions, depending on if we want to negate the verb.
-- N.B. negation is *not* a function applicable to a verb phrase, since
-- double negations with "inte" are not grammatical.
predVerb : Bool -> Verb -> VerbPhrase = \b,se ->
predVerb : Verb -> VerbGroup = \se ->
se ** {
s2 = negation b ;
s2 = negation ;
s3 = \\_,_ => []
} ;
negation : Bool -> Str = \b -> if_then_else Str b [] "inte" ;
-- Sometimes we want to extract the verb part of a verb phrase.
verbOfPhrase : VerbPhrase -> Verb = \v -> {s = v.s} ;
negation : Bool => Str = \\b => if_then_Str b [] "inte" ;
-- Verb phrases can also be formed from adjectives ("är snäll"),
-- common nouns ("är en man"), and noun phrases ("är den yngste mannen").
-- The third rule is overgenerating: "är varje man" has to be ruled out
-- on semantic grounds.
predAdjective : Bool -> Adjective -> VerbPhrase = \b,arg ->
predAdjective : Adjective -> VerbGroup = \arg ->
verbVara ** {
s2 = negation b ;
s2 = negation ;
s3 = \\g,n => arg.s ! mkAdjForm Indef n g NoMasc ! Nom
} ;
predCommNoun : Bool -> CommNounPhrase -> VerbPhrase = \b,man ->
predCommNoun : CommNounPhrase -> VerbGroup = \man ->
verbVara ** {
s2 = negation b ;
s2 = negation ;
s3 = \\_,n => indefNoun n man
} ;
predNounPhrase : Bool -> NounPhrase -> VerbPhrase = \b,john ->
predNounPhrase : NounPhrase -> VerbGroup = \john ->
verbVara ** {
s2 = negation b ;
s2 = negation ;
s3 = \\_,_ => john.s ! PNom
} ;
predAdverb : Bool -> Adverb -> VerbPhrase = \b,ute ->
predAdverb : Adverb -> VerbGroup = \ute ->
verbVara ** {
s2 = negation b ;
s2 = negation ;
s3 = \\_,_ => ute.s
} ;
@@ -517,9 +520,9 @@ oper
-- The rule for using transitive verbs is the complementization rule:
complTransVerb : Bool -> TransVerb -> NounPhrase -> VerbPhrase = \b,se,dig ->
complTransVerb : TransVerb -> NounPhrase -> VerbGroup = \se,dig ->
{s = se.s ;
s2 = negation b ;
s2 = negation ;
s3 = \\_,_ => se.s2 ++ dig.s ! PAcc
} ;
@@ -529,9 +532,9 @@ oper
-- The syntax is the same as for active verbs, with the choice of the
-- "s" passive form.
passVerb : Bool -> Verb -> VerbPhrase = \b,se -> ---- passive not yet
passVerb : Verb -> VerbGroup = \se -> ---- passive not yet
{s = table {VPres m _ => se.s ! VPres m Pass} ;
s2 = negation b ;
s2 = negation ;
s3 = \\_,_ => []
} ;
@@ -552,10 +555,9 @@ oper
v ** {s2 = p1 ; s3 = p2} ;
complDitransVerb :
Bool -> DitransVerb -> NounPhrase -> NounPhrase -> VerbPhrase =
\b,ge,dig,vin ->
DitransVerb -> NounPhrase -> NounPhrase -> VerbGroup = \ge,dig,vin ->
{s = ge.s ;
s2 = negation b ;
s2 = negation ;
s3 = \\_,_ => ge.s2 ++ dig.s ! PAcc ++ ge.s3 ++ vin.s ! PAcc
} ;
@@ -635,10 +637,6 @@ oper
}
} ;
-- This is a macro for simultaneous predication and complementation.
predTransVerb : Bool -> NounPhrase -> TransVerb -> NounPhrase -> Sentence =
\b,jag,ser,dig -> predVerbPhrase jag (complTransVerb b ser dig) ;
--3 Sentence-complement verbs
--
@@ -646,9 +644,27 @@ oper
SentenceVerb : Type = Verb ;
complSentVerb : Bool -> SentenceVerb -> Sentence -> VerbPhrase = \b,se,duler ->
{s = se.s ; s2 = negation b ; s3 = \\_,_ => optStr "att" ++ duler.s ! Main} ;
complSentVerb : SentenceVerb -> Sentence -> VerbGroup = \se,duler ->
{s = se.s ;
s2 = negation ;
s3 = \\_,_ => optStr "att" ++ duler.s ! Main
} ;
--3 Verb-complement verbs
--
-- Sentence-complement verbs take verb phrases as complements.
-- They can be auxiliaries ("kan", "måste") or ordinary verbs
-- ("försöka"); this distinction cannot be done in the multilingual
-- API and leads to some anomalies in Swedish, but less so than in English.
VerbVerb : Type = Verb ** {isAux : Bool} ;
complVerbVerb : VerbVerb -> VerbGroup -> VerbGroup = \vilja, simma ->
{s = vilja.s ;
s2 = negation ;
s3 = \\g,n => if_then_Str vilja.isAux [] "att" ++
simma.s ! VPres Infinit Act ++ simma.s2 ! True ++ simma.s3 ! g ! n
} ;
--2 Sentences missing noun phrases
@@ -668,7 +684,7 @@ oper
let {
jag = Jag.s ! PNom ;
ser = se.s ! VPres Indicat Act ;
inte = negation b
inte = negation ! b
} in
{s = table {
Main => jag ++ ser ++ inte ;

View File

@@ -0,0 +1,46 @@
--# -path=.:../nabstract:../../prelude
concrete TestResourceSwe of TestResource = StructuralSwe ** open SyntaxSwe in {
flags startcat=Phr ; lexer=text ; unlexer=text ;
-- a random sample from the lexicon
lin
Big = stor_25 ;
Small = liten_1146 ;
Old = gammal_16 ;
Young = ung_29 ;
American = extAdjective (aFin "amerikansk") ;
Finnish = extAdjective (aFin "finsk") ;
Married = extAdjective (aAbstrakt "gift") ** {s2 = "med"} ;
Man = extCommNoun Masc man_1144 ;
Woman = extCommNoun NoMasc (sApa "kvinn") ;
Car = extCommNoun NoMasc (sBil "bil") ;
House = extCommNoun NoMasc (sHus "hus") ;
Light = extCommNoun NoMasc (sHus "ljus") ;
Walk = extVerb Act gå_1174 ;
Run = extVerb Act (vFinna "spring" "sprang" "sprung") ;
Love = extTransVerb (vTala "älsk") [] ;
Send = extTransVerb (vTala "skick") [] ;
Wait = extTransVerb (vTala "vänt") "på" ;
Give = extTransVerb (vFinna "giv" "gav" "giv") [] ** {s3 = "till"} ; --- ge
Prefer = extTransVerb (vFinna "föredrag" "föredrog" "föredrag") [] **
{s3 = "framför"} ; --- föredra
Say = extVerb Act (vLeka "säg") ; --- works in present tense...
Prove = extVerb Act (vTala "bevis") ;
SwitchOn = extTransVerb (vVända "tän") [] ;
SwitchOff = extTransVerb (vLeka "släck") [] ;
Mother = mkFun (extCommNoun NoMasc mor_1) "till" ;
Uncle = mkFun (extCommNoun Masc farbror_8) "till" ;
Connection = mkFun (extCommNoun NoMasc (sVarelse "förbindelse")) "från" **
{s3 = "till"} ;
Always = advPre "alltid" ;
Well = advPost "bra" ;
John = mkProperName "Johan" Utr Masc ;
Mary = mkProperName "Maria" Utr NoMasc ;
} ;