From 3d7c4e80d7f24dc537e8b38ecd54a65e6d82c7cb Mon Sep 17 00:00:00 2001 From: aarne Date: Thu, 13 Apr 2006 14:19:27 +0000 Subject: [PATCH] extended unix grammars with character-based spelling --- doc/tutorial/gf-tutorial2.txt | 28 ++++++++--- examples/unix/Char.gf | 51 +++++++++++++++++++ examples/unix/CharEng.gf | 52 +++++++++++++++++++ examples/unix/CharUni.gf | 67 +++++++++++++++++++++++++ examples/unix/Unix.gf | 45 ++++++++++++----- examples/unix/UnixEng.gf | 19 +++++-- examples/unix/UnixUni.gf | 19 +++++-- lib/resource-1.0/english/CatEng.gf | 2 +- lib/resource-1.0/english/RelativeEng.gf | 18 +++++-- lib/resource-1.0/english/ResEng.gf | 1 + 10 files changed, 271 insertions(+), 31 deletions(-) create mode 100644 examples/unix/Char.gf create mode 100644 examples/unix/CharEng.gf create mode 100644 examples/unix/CharUni.gf diff --git a/doc/tutorial/gf-tutorial2.txt b/doc/tutorial/gf-tutorial2.txt index 43602d23b..a1226d7cd 100644 --- a/doc/tutorial/gf-tutorial2.txt +++ b/doc/tutorial/gf-tutorial2.txt @@ -1857,7 +1857,7 @@ they can be used as arguments. For example: -- e.g. (StreetAddress 10 "Downing Street") : Address ``` - +The linearization type is ``{s : Str}`` for all these categories. ==More concepts of abstract syntax== @@ -1922,16 +1922,30 @@ documents: However, to give a flavour of both using and writing resource grammars, we have created a miniature resource, which resides in the subdirectory [``resource`` resource]. Its API consists of the following -modules: -- [Syntax resource/Syntax.gf]: syntactic structures, language-independent -- [LexEng resource/LexEng.gf]: lexical paradigms, English -- [LexIta resource/LexIta.gf]: lexical paradigms, Italian +three modules: + +[Syntax resource/Syntax.gf] - syntactic structures, language-independent: +``` + +``` +[LexEng resource/LexEng.gf] - lexical paradigms, English: +``` + +``` +[LexIta resource/LexIta.gf] - lexical paradigms, Italian: +``` + +``` Only these three modules should be ``open``ed in applications. The implementations of the resource are given in the following four modules: -- [MorphoEng resource/MorphoEng.gf], - [MorphoIta resource/MorphoIta.gf]: low-level morphology + +[MorphoEng resource/MorphoEng.gf], +``` + +``` +[MorphoIta resource/MorphoIta.gf]: low-level morphology - [SyntaxEng resource/SyntaxEng.gf]. [SyntaxIta resource/SyntaxIta.gf]: definitions of syntactic structures diff --git a/examples/unix/Char.gf b/examples/unix/Char.gf new file mode 100644 index 000000000..f10284587 --- /dev/null +++ b/examples/unix/Char.gf @@ -0,0 +1,51 @@ +abstract Char = { + + cat + [Chr] {1} ; Chr ; Letter ; + + fun + C_dot : Chr ; + C_pipe : Chr ; + C_hyphen : Chr ; + CSmall : Letter -> Chr ; + CCap : Letter -> Chr ; + CC : Letter -> Chr ; + + CDig_0 : Chr ; + CDig_1 : Chr ; + CDig_2 : Chr ; + CDig_3 : Chr ; + CDig_4 : Chr ; + CDig_5 : Chr ; + CDig_6 : Chr ; + CDig_7 : Chr ; + CDig_8 : Chr ; + CDig_9 : Chr ; + + L_a : Letter ; + L_b : Letter ; + L_c : Letter ; + L_d : Letter ; + L_e : Letter ; + L_f : Letter ; + L_g : Letter ; + L_h : Letter ; + L_i : Letter ; + L_j : Letter ; + L_k : Letter ; + L_l : Letter ; + L_m : Letter ; + L_n : Letter ; + L_o : Letter ; + L_p : Letter ; + L_q : Letter ; + L_r : Letter ; + L_s : Letter ; + L_t : Letter ; + L_u : Letter ; + L_v : Letter ; + L_w : Letter ; + L_x : Letter ; + L_y : Letter ; + L_z : Letter ; +} diff --git a/examples/unix/CharEng.gf b/examples/unix/CharEng.gf new file mode 100644 index 000000000..39d9b9d16 --- /dev/null +++ b/examples/unix/CharEng.gf @@ -0,0 +1,52 @@ +concrete CharEng of Char = open Prelude in { + +lin + BaseChr c = c ; + ConsChr = infixSS "," ; + + C_dot = ss "dot" ; + C_pipe = ss "pipe" ; + C_hyphen = ss (variants {"dash" ; "hyphen" ; "minus"}) ; + CSmall = prefixSS "small" ; + CCap = prefixSS "capital" ; + CC c = c ; + + CDig_0 = ss "0" ; + CDig_1 = ss "1" ; + CDig_2 = ss "2" ; + CDig_3 = ss "3" ; + CDig_4 = ss "4" ; + CDig_5 = ss "5" ; + CDig_6 = ss "6" ; + CDig_7 = ss "7" ; + CDig_8 = ss "8" ; + CDig_9 = ss "9" ; + + L_a = ss "A" ; + L_b = ss "B" ; + L_c = ss "C" ; + L_d = ss "D" ; + L_e = ss "E" ; + L_f = ss "F" ; + L_g = ss "G" ; + L_h = ss "H" ; + L_i = ss "I" ; + L_j = ss "J" ; + L_k = ss "K" ; + L_l = ss "L" ; + L_m = ss "M" ; + L_n = ss "N" ; + L_o = ss "O" ; + L_p = ss "P" ; + L_q = ss "Q" ; + L_r = ss "R" ; + L_s = ss "S" ; + L_t = ss "T" ; + L_u = ss "U" ; + L_v = ss "V" ; + L_w = ss "W" ; + L_x = ss "X" ; + L_y = ss "Y" ; + L_z = ss "Z" ; + +} \ No newline at end of file diff --git a/examples/unix/CharUni.gf b/examples/unix/CharUni.gf new file mode 100644 index 000000000..0e6628657 --- /dev/null +++ b/examples/unix/CharUni.gf @@ -0,0 +1,67 @@ +concrete CharUni of Char = open Prelude in { + +param + LForm = LCap | LSma ; + +oper + chr : Str -> Str -> {s : LForm => Str} = \c,C -> { + s = table { + LCap => C ; + LSma => c + } + } ; + +lincat + Letter = {s : LForm => Str} ; + +lin + BaseChr c = c ; + ConsChr = infixSS "&+" ; + + C_dot = ss "." ; + C_pipe = ss "|" ; + C_hyphen = ss "-" ; + CSmall c = ss (c.s ! LSma) ; + CCap c = ss (c.s ! LCap) ; + CC c = ss (c.s ! LSma) ; + + CDig_0 = ss "0" ; + CDig_1 = ss "1" ; + CDig_2 = ss "2" ; + CDig_3 = ss "3" ; + CDig_4 = ss "4" ; + CDig_5 = ss "5" ; + CDig_6 = ss "6" ; + CDig_7 = ss "7" ; + CDig_8 = ss "8" ; + CDig_9 = ss "9" ; + + + L_a = chr "a" "A" ; + L_b = chr "b" "B" ; + L_c = chr "c" "C" ; + L_d = chr "d" "D" ; + L_e = chr "e" "E" ; + L_f = chr "f" "F" ; + L_g = chr "g" "G" ; + L_h = chr "h" "H" ; + L_i = chr "i" "I" ; + L_j = chr "j" "J" ; + L_k = chr "k" "K" ; + L_l = chr "l" "L" ; + L_m = chr "m" "M" ; + L_n = chr "n" "N" ; + L_o = chr "o" "O" ; + L_p = chr "p" "P" ; + L_q = chr "q" "Q" ; + L_r = chr "r" "R" ; + L_s = chr "s" "S" ; + L_t = chr "t" "T" ; + L_u = chr "u" "U" ; + L_v = chr "v" "V" ; + L_w = chr "w" "W" ; + L_x = chr "x" "X" ; + L_y = chr "y" "Y" ; + L_z = chr "z" "Z" ; + +} diff --git a/examples/unix/Unix.gf b/examples/unix/Unix.gf index c1ddd742b..ea5e2c2af 100644 --- a/examples/unix/Unix.gf +++ b/examples/unix/Unix.gf @@ -1,24 +1,43 @@ -abstract Unix = { +abstract Unix = Char ** { cat - S ; - Line ; - Command ; - File ; + S ; -- whole command line + Command ; -- one command + File ; -- file name + Word ; -- string e.g. in grep + [Word] {1} ; -- fun - Pipe : Command -> S -> S ; - Comm : Command -> S ; + +-- Catch-all: command dictated letter by letter. + + CommWords : [Word] -> Command ; + +-- General command-line structure. + + Redirect : S -> File -> S ; -- cs >f + Pipe : S -> Command -> S ; -- cs | c + Comm : Command -> S ; -- c + +--- This would be cool, but is it supported by speech recognition? +--- CommOpt : (c : Command) -> [Option c] -> S ; -- c -o -k WhatTime : Command ; WhatDate : Command ; WhereNow : Command ; - Remove : File -> Command ; - Copy : File -> File -> Command ; - Linecount : File -> Command ; - Wordcount : File -> Command ; + Remove : File -> Command ; + Copy : File -> File -> Command ; + Linecount : File -> Command ; + Wordcount : File -> Command ; + Grep : Word -> File -> Command ; + Cat : File -> Command ; - Name : String -> File ; - It : File ; + It : File ; -- no file name - contents received from pipe + + FileChars : [Chr] -> File ; + WordChars : [Chr] -> Word ; + + FileSuffix : Word -> File ; -- *suff + FilePrefix : Word -> File ; -- pref* } diff --git a/examples/unix/UnixEng.gf b/examples/unix/UnixEng.gf index 3bed08bc5..5b0ca944f 100644 --- a/examples/unix/UnixEng.gf +++ b/examples/unix/UnixEng.gf @@ -1,8 +1,8 @@ --# -path=.:prelude -concrete UnixEng of Unix = open Prelude in { +concrete UnixEng of Unix = CharEng ** open Prelude in { - flags unlexer=textlit ; lexer=textlit ; + flags lexer=text ; {- lincat @@ -13,6 +13,9 @@ concrete UnixEng of Unix = open Prelude in { -} lin + CommWords w = w ; + + Redirect = infixSS (optStr "and" ++ ["write the result to"]) ; Pipe = infixSS "then" ; Comm c = c ; @@ -23,8 +26,18 @@ concrete UnixEng of Unix = open Prelude in { Copy x y = ss ("copy" ++ x.s ++ "to" ++ y.s) ; Linecount = prefixSS ["how many lines has"] ; Wordcount = prefixSS ["how many words has"] ; + Grep x y = ss (["show the lines containing"] ++ x.s ++ "in" ++ y.s) ; + Cat = prefixSS ["show the contents of"] ; - Name x = x ; It = ss "it" ; + FileChars = prefixSS (optStr ["the file"]) ; + WordChars = prefixSS (optStr ["the word"]) ; + + FileSuffix = prefixSS ["all files ending with"] ; + FilePrefix = prefixSS ["all files beginning with"] ; + + BaseWord w = w ; + ConsWord = infixSS "space" ; + } diff --git a/examples/unix/UnixUni.gf b/examples/unix/UnixUni.gf index e0898853f..b1b220824 100644 --- a/examples/unix/UnixUni.gf +++ b/examples/unix/UnixUni.gf @@ -1,8 +1,8 @@ --# -path=.:prelude -concrete UnixUni of Unix = open Prelude in { +concrete UnixUni of Unix = CharUni ** open Prelude in { - flags unlexer=codelit ; lexer=codelit ; + flags unlexer=bind ; {- lincat @@ -13,6 +13,9 @@ concrete UnixUni of Unix = open Prelude in { -} lin + CommWords w = w ; + + Redirect = infixSS ">" ; Pipe = infixSS "|" ; Comm c = c ; @@ -23,8 +26,18 @@ concrete UnixUni of Unix = open Prelude in { Copy x y = ss ("cp" ++ x.s ++ y.s) ; Linecount = prefixSS ["wc -l"] ; Wordcount = prefixSS ["wc -w"] ; + Grep x y = ss ("grep" ++ x.s ++ y.s) ; + Cat = prefixSS "cat" ; - Name x = x ; It = ss [] ; + FileChars c = c ; + WordChars c = c ; + + FileSuffix = prefixSS ["* &+"] ; + FilePrefix = postfixSS ["&+ *"] ; + + BaseWord w = w ; + ConsWord = cc2 ; + } diff --git a/lib/resource-1.0/english/CatEng.gf b/lib/resource-1.0/english/CatEng.gf index a07865b63..91e5dfcc3 100644 --- a/lib/resource-1.0/english/CatEng.gf +++ b/lib/resource-1.0/english/CatEng.gf @@ -30,7 +30,7 @@ concrete CatEng of Cat = CommonX ** open ResEng, Prelude in { -- Relative RCl = {s : Tense => Anteriority => Polarity => Agr => Str} ; - RP = {s : Case => Str ; a : RAgr} ; + RP = {s : RCase => Str ; a : RAgr} ; -- Verb diff --git a/lib/resource-1.0/english/RelativeEng.gf b/lib/resource-1.0/english/RelativeEng.gf index c81b949b7..9b0b9b562 100644 --- a/lib/resource-1.0/english/RelativeEng.gf +++ b/lib/resource-1.0/english/RelativeEng.gf @@ -15,20 +15,30 @@ concrete RelativeEng of Relative = CatEng ** open ResEng in { RNoAg => ag ; RAg a => a } ; - cl = mkClause (rp.s ! Nom) agr vp + cl = mkClause (rp.s ! RC Nom) agr vp in cl.s ! t ! ant ! b ! ODir } ; +-- Preposition stranding: "that we are looking at". Pied-piping is +-- deferred to $ExtEng.gf$ ("at which we are looking"). + RelSlash rp slash = { - s = \\t,a,p,_ => slash.c2 ++ rp.s ! Acc ++ slash.s ! t ! a ! p ! ODir + s = \\t,a,p,_ => rp.s ! RC Acc ++ slash.s ! t ! a ! p ! ODir ++ slash.c2 } ; FunRP p np rp = { - s = \\c => np.s ! c ++ p.s ++ rp.s ! Acc ; + s = \\c => np.s ! Acc ++ p.s ++ rp.s ! RPrep ; a = RAg np.a } ; - IdRP = mkIP "which" "which" "whose" Sg ** {a = RNoAg} ; + IdRP = { + s = table { + RC Gen => "whose" ; + RC _ => "that" ; + RPrep => "which" + } ; + a = RNoAg + } ; } diff --git a/lib/resource-1.0/english/ResEng.gf b/lib/resource-1.0/english/ResEng.gf index df2dcc9a1..341db3641 100644 --- a/lib/resource-1.0/english/ResEng.gf +++ b/lib/resource-1.0/english/ResEng.gf @@ -62,6 +62,7 @@ resource ResEng = ParamX ** open Prelude in { --2 For $Relative$ RAgr = RNoAg | RAg {n : Number ; p : Person} ; + RCase = RPrep | RC Case ; --2 For $Numeral$