examples of dialogue system grammars

This commit is contained in:
aarne
2006-05-16 13:07:41 +00:00
parent e1ea20277c
commit 6bbd4e423a
18 changed files with 304 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
abstract Agenda = Dialogue, Weekday ** {
fun
Day : Kind ;
Meeting : Kind ;
Add : Oper2 Meeting Day ;
Remove : Oper1 Meeting ;
Interrupt : Oper0 ;
day : WDay -> Object Day ;
}

View File

@@ -0,0 +1,15 @@
--# -path=.:present:prelude
concrete AgendaEng of Agenda =
DialogueEng, WeekdayEng ** open LangEng, ParadigmsEng in {
lin
Day = UseN (regN "day") ;
Meeting = UseN (regN "meeting") ;
Add = dirV3 (regV "add") (mkPreposition "on") ;
Remove = dirV2 (regV "remove") ;
Interrupt = regV "interrupt" ;
day = UsePN ;
}

View File

@@ -0,0 +1,16 @@
--# -path=.:present:prelude
concrete AgendaFre of Agenda =
DialogueFre, WeekdayFre ** open LangFre, ParadigmsFre, IrregFre in {
lin
Day = UseN (regN "jour") ;
Meeting = UseN (regN "réunion") ;
Add = dirdirV3 (regV "ajouter") ;
Remove = dirV2 (regV "ôter") ;
Interrupt = interrompre_V2 ;
day = UsePN ;
}

View File

@@ -0,0 +1,15 @@
--# -path=.:prelude
concrete AgendaGodis of Agenda =
DialogueGodis, WeekdayGodis ** open ResGodis, Prelude in {
lin
Day = ss "day" ;
Meeting = ss "meeting" ;
Add = ss "add" ;
Remove = ss "remove" ;
Interrupt = ss "interrupt" ;
day = apps "weekday" ;
}

View File

@@ -0,0 +1,16 @@
--# -path=.:present:prelude
concrete AgendaSwe of Agenda =
DialogueSwe, WeekdaySwe ** open LangSwe, ParadigmsSwe, IrregSwe in {
lin
Day = UseN (regN "dag") ;
Meeting = UseN (regGenN "möte" neutrum) ;
Add = dirV3 (partV lägga_V "till") (mkPreposition "på") ;
Remove = dirV2 (partV taga_V "bort") ;
Interrupt = avbryta_V ;
day = UsePN ;
}

View File

@@ -0,0 +1,27 @@
abstract Dialogue = {
cat
Move ;
Action ;
Kind ;
Object Kind ;
Oper0 ;
Oper1 Kind ;
Oper2 Kind Kind ;
fun
MRequest : Action -> Move ;
MAnswer : Action -> Move ;
MQuery : Kind -> Move ;
AOper0 : Oper0 -> Action ;
AOper1 : (k : Kind) -> Oper1 k -> Object k -> Action ;
AOper2 : (k,m : Kind) -> Oper2 k m -> Object k -> Object m -> Action ;
OAll : (k : Kind) -> Object k ;
OIndef : (k : Kind) -> Object k ;
ODef : (k : Kind) -> Object k ;
}

View File

@@ -0,0 +1,4 @@
--# -path=.:present:prelude
concrete DialogueEng of Dialogue = DialogueI with
(Lang = LangEng) ;

View File

@@ -0,0 +1,4 @@
--# -path=.:present:prelude
concrete DialogueFre of Dialogue = DialogueI with
(Lang = LangFre) ;

View File

@@ -0,0 +1,34 @@
--# -path=.:prelude
concrete DialogueGodis of Dialogue = open ResGodis, Prelude in {
flags lexer=codelit ; unlexer=code ;
lincat
Move = SS ;
Action = SS ;
Kind = SS ;
Object = SS ;
Oper0 = SS ;
Oper1 = SS ;
Oper2 = SS ;
lin
MRequest a = a ;
MAnswer a = a ; --- ??
MQuery k = ss (bracket (app1 "query" k.s)) ; ---
AOper0 op = ss (bracket (request op.s)) ;
AOper1 k op x = ss (req_ans op.s k.s x.s) ;
AOper2 k m op x y =
ss (bracket (request op.s ++ "," ++
answer (app1 k.s x.s) ++ "," ++ answer (app1 m.s y.s))) ;
OAll = apps "all" ;
OIndef = apps "indef" ;
ODef = apps "def" ;
}

View File

@@ -0,0 +1,68 @@
incomplete concrete DialogueI of Dialogue = open Lang, Prelude in {
lincat
Move = Phr ;
Action = {s : ActType => Str} ;
Kind = CN ;
Object = NP ;
Oper0 = V ;
Oper1 = V2 ;
Oper2 = V3 ;
lin
MRequest a = ss (a.s ! ARequest) ;
MAnswer a = ss (a.s ! AAnswer) ;
MQuery k =
PhrUtt NoPConj (UttQS (UseQCl TPres ASimul PPos
(ExistIP (IDetCN whichPl_IDet NoNum NoOrd k)))) NoVoc ;
AOper0 op = mkAction (UseV op) ;
AOper1 _ op x = mkAction (ComplV2 op x) ;
AOper2 _ _ op x y = mkAction (ComplV3 op x y) ;
OAll k = PredetNP all_Predet (DetCN (DetPl (PlQuant IndefArt) NoNum NoOrd) k) ;
OIndef k = DetCN (DetSg (SgQuant IndefArt) NoOrd) k ;
ODef k = DetCN (DetSg (SgQuant DefArt) NoOrd) k ;
param
ActType = ARequest | AAnswer ; -- and some others
oper
-- this should perhaps be language dependent - but at least these
-- variants seem to make sense in all languages
mkAction : VP -> {s : ActType => Str} = \vp -> {
s = table {
ARequest => variants {
aImp vp ;
aImpPlease vp ;
aWant vp ;
aCanYou vp
} ;
AAnswer => variants {
aInf vp
}
}
} ;
aImp : VP -> Str = \vp ->
(PhrUtt NoPConj (UttImpPl PPos (ImpVP vp)) NoVoc).s ;
aImpPlease : VP -> Str = \vp ->
(PhrUtt NoPConj (UttImpPl PPos (ImpVP vp)) please_Voc).s ;
aWant : VP -> Str = \vp ->
(PhrUtt NoPConj (UttS (UseCl TPres ASimul PPos (PredVP (UsePron i_Pron)
(ComplVV want_VV vp)))) NoVoc).s ;
aCanYou : VP -> Str = \vp ->
(PhrUtt NoPConj (UttQS (UseQCl TPres ASimul PPos (QuestCl (PredVP
(UsePron youSg_Pron) (ComplVV can_VV vp))))) NoVoc).s ;
aInf : VP -> Str = \vp ->
(PhrUtt NoPConj (UttVP vp) NoVoc).s ;
}

View File

@@ -0,0 +1,4 @@
--# -path=.:present:prelude
concrete DialogueSwe of Dialogue = DialogueI with
(Lang = LangSwe) ;

23
examples/dialogue/README Normal file
View File

@@ -0,0 +1,23 @@
Dialogue system grammar examples.
Files (for X = Eng, Fre, Godis, Swe):
Dialogue.gf -- base dialogue grammar
DialogueX.gf -- implementation instance
DialogueI.gf -- implementation functor
ResGodis.gf -- help constructs for Prolog terms
Weekday.gf -- untility grammar with weekdays
WeekdayX.gf
Agenda.gf -- application grammar for agenda
AgendaX.gf
To build a new application for domain Dom, you need
Dom.gf -- introduce fun's in Kind, Object, Oper0, Oper1, Oper2
DomX.gf -- concrete syntax of the new fun's for language X

View File

@@ -0,0 +1,18 @@
resource ResGodis = open Prelude in {
oper
bracket : Str -> Str = \s -> "[" ++ s ++ "]" ;
app1 : Str -> Str -> Str = \f,x -> f ++ paren x ;
apps : Str -> SS -> SS = \f,x -> ss (app1 f x.s) ;
request : Str -> Str = app1 "request" ;
answer : Str -> Str = app1 "answer" ;
req_ans : Str -> Str -> Str -> Str = \f,t,k ->
bracket (request f ++ "," ++ answer (app1 t k)) ;
}
-- [request(add_event), answer(event_to_store(meeting))]

View File

@@ -0,0 +1,8 @@
abstract Weekday = {
cat
WDay ;
fun
Mon, Tue : WDay ;
}

View File

@@ -0,0 +1,10 @@
concrete WeekdayEng of Weekday = open LangEng, ParadigmsEng in {
lincat
WDay = PN ;
lin
Mon = regPN "Monday" nonhuman ;
Tue = regPN "Tuesday" nonhuman ;
}

View File

@@ -0,0 +1,10 @@
concrete WeekdayFre of Weekday = open LangFre, ParadigmsFre in {
lincat
WDay = PN ;
lin
Mon = mkPN "lundi" masculine ;
Tue = mkPN "mardi" masculine ;
}

View File

@@ -0,0 +1,10 @@
concrete WeekdayGodis of Weekday = open ResGodis, Prelude in {
lincat
WDay = SS ;
lin
Mon = ss "monday" ;
Tue = ss "tuesday" ;
}

View File

@@ -0,0 +1,10 @@
concrete WeekdaySwe of Weekday = open LangSwe, ParadigmsSwe in {
lincat
WDay = PN ;
lin
Mon = regPN "måndag" utrum ;
Tue = regPN "tisdag" utrum ;
}