diff --git a/doc/gf-history.html b/doc/gf-history.html index 1e5555c11..c6de42c03 100644 --- a/doc/gf-history.html +++ b/doc/gf-history.html @@ -18,7 +18,7 @@ Changes in functionality since May 17, 2005, release of GF Version 2.2 grammar writing by examples. Files of this format are first converted to .gf files by the command
-  gf -makeconcrete File.gfe
+  gf -examples File.gfe
 
See ../lib/resource/doc/examples/QuestionsI.gfe diff --git a/lib/resource/doc/example/QuestionsI.gf b/lib/resource/doc/example/QuestionsI.gf index 18174443f..0e09af13f 100644 --- a/lib/resource/doc/example/QuestionsI.gf +++ b/lib/resource/doc/example/QuestionsI.gf @@ -1,6 +1,6 @@ --# -resource=../../english/LangEng.gf --- to compile: gf -makeconcrete QuestionsI.gfe +-- to compile: gf -examples QuestionsI.gfe incomplete concrete QuestionsI of Questions = open Resource in { lincat diff --git a/lib/resource/doc/example/QuestionsI.gfe b/lib/resource/doc/example/QuestionsI.gfe index 557afe259..71110475b 100644 --- a/lib/resource/doc/example/QuestionsI.gfe +++ b/lib/resource/doc/example/QuestionsI.gfe @@ -1,6 +1,6 @@ --# -resource=../../english/LangEng.gf --- to compile: gf -makeconcrete QuestionsI.gfe +-- to compile: gf -examples QuestionsI.gfe incomplete concrete QuestionsI of Questions = open Resource in { lincat diff --git a/lib/resource/doc/gf-resource.html b/lib/resource/doc/gf-resource.html index 580d424f8..f761d7972 100644 --- a/lib/resource/doc/gf-resource.html +++ b/lib/resource/doc/gf-resource.html @@ -710,7 +710,7 @@ generates QuestionsI.gf, when you execute the command
-  gf -makeconcrete QuestionsI.gfe
+  gf -examples QuestionsI.gfe
 
Of course, the grammar of any language can be created by parsing any language, as long as they have a common resource API. @@ -718,6 +718,74 @@ The use of English resource is generally recommended, because it is smaller and faster to parse than the other languages. + +

Constants and variables in examples

+ +The file QuestionsI.gfe uses +as resource LangEng, which contains all resource syntax and +a lexicon of ca. 300 words. A linearization rule, such as +
+  lin Who love_V2 man_N = in Phr "who loves men ?" ;
+
+uses as argument variables constants for words that can be found in +the lexicon. It is due to this that the example can be parsed. +When the resulting rule, +
+  lin Who love_V2 man_N =
+    QuestPhrase (UseQCl (PosTP TPresent ASimul)
+      (QPredV2 who8one_IP love_V2 (IndefNumNP NoNum (UseN man_N)))) ;
+
+is read by the GF compiler, the identifiers love_V2 and +man_N are not treated as constants, but, following +the normal binding rules of functional languages, as bound variables. +This is what gives the example method the generality that is needed. + +

+ +To write linearization rules by examples one thus has to know at +least one abstract syntax constant for each category for which +one needs a variable. + + + + +

Extending the lexicon on the fly

+ +The greatest limitation of the example method is that the lexicon +may lack many of the words that are needed in examples. If parsing +fails because of this, the compiler gives a list of unknown words +in its error message. An obvious solution is, +of course, to extend the resource lexicon and try again. +A more light-weight solution is to add a substitution to +the example. For instance, if you want the example "the pope" +but the lexicon does not have the word "pope", you can write +
+  lin Pope = in NP "the man" {man_N = regN "pope"} ;
+
+The resulting linearization rule is initially +
+  lin Pope = DefOneNP (UseN man_N) ;
+
+but the substitution changes this to +
+  lin Pope = DefOneNP (UseN (regN "pope")) ;
+
+In this way, you do not have to extend the resource lexicon, but you +need to open the Paradigms module to compile the resulting term. + +

+ +Of course, the substituted expressions may come from another language +than the main language of the example: +

+  lin Pope = in NP "the man" {man_N = regN "pape" masculine} ;
+
+If many substitutions are needed, semicolons are used as separators: +
+  {man_N = regN "pope" ; walk_N = regV "pray"} ;
+
+ +

Implementation details: the structure of low-level files

diff --git a/src/GF.hs b/src/GF.hs index 2b7b6880d..96cf33661 100644 --- a/src/GF.hs +++ b/src/GF.hs @@ -5,9 +5,9 @@ -- Stability : (stability) -- Portability : (portability) -- --- > CVS $Date: 2005/06/02 17:31:56 $ +-- > CVS $Date: 2005/06/03 21:51:58 $ -- > CVS $Author: aarne $ --- > CVS $Revision: 1.26 $ +-- > CVS $Revision: 1.27 $ -- -- The Main module of GF program. ----------------------------------------------------------------------------- @@ -60,7 +60,7 @@ main = do _ -> putStrLnFlush "expecting exactly one gf file to compile" _ | opt makeConcrete -> do - mapM_ mkConcrete fs + mkConcretes fs _ | opt doBatch -> do if opt beSilent then return () else putStrLnFlush "" @@ -85,7 +85,7 @@ helpMsg = unlines [ " -noemit do not emit code when compiling", " -v be verbose when compiling", " -batch structure session by XML tags (use > to send into a file)", - " -makeconcrete batch-compile .gfe file to concrete syntax using parser", + " -examples batch-compile .gfe file by parsing examples", " -help show this message", "To use the GUI: jgf