
INSTALL

1. Using Your SFTB Kit

1.1 Creating and Invoking a Parser

     Figure 1.1 illustrates the development of a parser from beginning
to invocation.


Choose a grammar rule source    +-------+
                                |+-------+         +-------+
  SFTB_L1.dcg ~ SFTB_L12.dcg    ||+-------+  ===>  |  (1)  |
                                +||       |        |       |
                                 +|       |        +-------+
                                  +-------+


Choose a dictionary file        +-------+
                                |+-------+         +-------+
  LEX_L1.dcg ~ LEX_L12.dcg      ||+-------+  ===>  |  (2)  |
                                +||       |        |       |
                                 +|       |        +-------+
                                  +-------+


Choose another dictionary file  +-------+
                                |+-------+         +-------+
  WORDS_L1.dcg ~ WORDS_L12.dcg  ||+-------+  ===>  |  (3)  |
                                +||       |        |       |
                                 +|       |        +-------+
                                  +-------+


Create a dictionary or          +-------+
       dictionaries             |+-------+         +-------+
  User.dcg                      ||+-------+  ===>  |  (4)  |
                                +||       |        |       |
                                 +|       |        +-------+
                                  +-------+

Concatenate sources (1),(2),(3) and (4) to get a grammar source

                                                   +-------+
                                                   |  (5)  |
                                                   |       |
                                                   +-------+
                                                       |
Translate the grammar source into a parser (program)   |
                                                       V
                                                   +-------+
                                                   |  (6)  |
                      +----------------+-----------|       |
                      |                |           +-------+
Read in the program   |                |               |
                      V                V               V
                  +-------+        +-------+       +-------+
                  |       |        |       |       |       |
                  |       |        |       |       |       |
                  +-------+        +-------+       +-------+
                consult('(6)')   compile('(6)')  catalogue('(6)')

Issue the query to parse sentences

                            :- goal(sentence,.....,Ans).

                Figure 1.1    Parser Development Process


2.1.1 File Specification

     File specification has the form:

                 ``filename''_L``level''.``filetype''


    * ``filename'' identifies the file by the name under which the
                   contents of the file are cataloged.

    * ``level''    defines which level of the file is desired.  Level is
                   an integer from 1 to 12.

    * ``filetype'' describes the type of data in the file.


2.2 Creating a Parser

                    Table 1.1   Software Components
+---+------------------------------+-------------------------------------+
|   |             File             |                Description          |
+---+------------------------------+-------------------------------------+
| 1 | SFTB_L1.dcg ~ SFTB_L12.dcg   | Grammar rules (Non terminal rules)  |
| 2 | LEX_L1.dcg ~ LEX_L12.dcg     | Grammar rules (Terminal rules)      |
| 3 | EXTRA_L1.dcg ~ EXTRA_L12.dcg | Prolog program source               |
| 4 | CAT_L1.dcg ~ CAT_L12.dcg     | List of non terminal symbols        |
|   |                              | appearing in the grammar rules      |
| 5 | WORDS_L1.dcg ~ WORDS_L12.dcg | Dictionaries                        |
| 6 | TEXTS_L1.txt ~ TEXTS_L12.txt | Corpus                              |
| 7 | TEXTS_L1.TXT ~ TEXTS_L12.TXT | Corpus (List format)                |
+---+------------------------------+-------------------------------------+

     Concatenate files 1, 2, and 3 and place the result in a grammar
rule file, for example ``Grammar.dcg''.  You can create a parser which
translate the grammar rule file into horn clauses with a DCG
translator.  The parser, however, might not parse any sentences,
because no dictionary is included.  If you intend to perform the
exercises in ``SFTB / Grammar Rules Reference Manual'', you need file
5 on your parser.  Ultimately, you must concatenate files 1, 2, 3, and
5.  File 6 contains input tokens to be analyzed for testing the
parser.  Input lists of tokens are listed in file 7.

     Once you have chosen SFTB_L``N''.dcg, the other files that you
will need depend on the number ``N'', which identifies the file to be
used.  If you choose SFTB_L7.dcg, you need LEX_L7.dcg and
WORDS_L7.dcg.  The corpus file TEXTS_L7.txt or TEXTS_L7.TXT is
required to test the parser created by these files.

2.2.1 Translation

     The parser being created must be transformed by the DCG
translator.  Notice that the grammar rules provided from SFTB include
left recursive grammar rules.  This would cause a top-down parser,
which may be created from translating grammar rules using an ordinary
DCG translator, to go into an infinite loop.  To avoid this problem
you must use one as a translator that creates a bottom up parser that
can handle left recursive grammar rules.

     You can use a bottom up parser as one of the following
translators.

    * LINGUIST system   has its own original BUP translator.
    * LangLAB system    provides a BUP-XG translator that is more
                        powerful than the original BUP translator.
    * SAX system        has a translator based on the bottom up 
                        breadth-first strategy.

     The methods for translating a source of grammar rules depend on
the system.  See the User's Manuals for the systems listed above.

2.2.2 Selecting the Files for Your Working System

     The files needed in the translation performed by each system are
shown in Table 1.2.


     Table 1.2    Planning the Arrangement of Files
+--------------------------+---------------+----------------+
| Files to be concatenated |     Corpus    |      System    |
+--------------------------+---------------+----------------+
|         1,2,3,5          |       6       |     LINGUIST   |
|         1,2,3,5          |       7       |     LangLAB    |
|         1,2,3,5          |       7       |       SAX      |
|         1,2,3,5          |       7       |Normal BUP(DCGs)|
|                          |               |   translator   |
+--------------------------+---------------+----------------+

2.2.3 Reading in Parser

     Before a translated grammar (a parser) can be invoked, you must
consult, compile or catalogue the grammar rules to produce an
executable image (i.e. a sequence of clauses).  To read in a parser
such as ``Grammar.dcg'', type ``consult'' predicate, followed by the
file name inside brackets:

        :- consult('Grammar.dcg').

     When you want to compile a parser, issue the predicate
``compile/1''.  When using the CESP interpreter, use the predicate
``catalogue/1'' to read in the parser.

2.3 Parsing

     The predicate ``goal'' initiates execution of a parser.  The
predicate has seven arguments:

    :- goal(Cat,SYN,X,REL,F,PRO,[ ..... ],[ ..... ] ).

2.3.1 Argument Specification in the goal predicate

     The first argument is the name of the syntactic category being
defined.  To parse sentences, you must specify the category.  This
must have already been found for the grammar rule to be invoked.
Normally ``sentence'' is used.  SYN is a list of arbitrary length
whose compound terms of elements each take one argument.  X is a
variable.  Note that you cannot unify the variable with any atom,
constant or compound term.  The seventh argument to ``goal'' is an
input list of tokens.  The last argument is constituted from whatever
part of the list is left over after the terminal or nonterminal has
been taken off the front of the lnput list.  When you use the systems
listed in Table 1.2, a default value is automatically provided.  The
default value is [ ](empty list).  Table 1.3 summarized the arguments
to the predicate ``goal''.


                    Table 1.3    Arguments to ``goal''
+---------+--------------+-------------+------------------------------------+
|Argument | Input/Output |  Data Type  |     Description                    |
+---------+--------------+-------------+------------------------------------+
|   Cat   |    Input     |     Atom    | Name of category                   |
|   SYN   |    Output    |     List    | Syntactic information obtained     |
|         |              |             | at step in parsing                 |
|    X    |    Output    |   Variable  | An index referring to the category |
|         |              |             | named `Cat'                        |
|   REL   |    Output    |     List    | Semantic information obtained at   |
|         |              |             | step in parsing                    |
|    F    |    Output    |([...],[...])| Subcategorized phrases found in    |
|         |              |             | parsing                            |
|   PRO   |    Output    |   Variable  | Not used (Reserved for extension)  |
| [.....] |    Input     |     List    | Input word list (Sentence you want |
|         |              |             | to parse)                          |
| [.....] |    Input     |     List    | Output word list (Normally [ ]     |
|         |              |             | (empty list) is  used)             |
+---------+--------------+-------------+------------------------------------+

2.2.3 Changing the Category Definition

     Once you have complete sentence parsing, you may want to change
the definition of the categories at parsing time.  The list of the
categories, including ``sentence'', that appears in SFTB_L``N''.dcg is
present in CAT_L``N''.dcg.  You can specify any category listed in the
file as the first argument to the ``goal'' predicate, as shown in the
following example:

    :- goal(renyoushi_2,SYN,X,REL,F,_,[.....],[ ]).

     The query tells the parser to parse a complement phrase.  For
example:

    :- goal(yougen_3,SYN,X,REL,F,_,[.....],[ ]).

     tells the parser to parse a verb phrase.  Any categories except
``sentence'' can be used preferably at parsing time.  This allow you
to parse sentences partially.

2.2.4 Using WORDS_L1.dcg ~ WORDS_L12.dcg

     WORDS_L1.dcg ~ WORDS_L12.dcg include lexical entries for testing
and checking grammar rules present in SFTB_L1.dcg ~ SFTB_L12.dcg.  You
can use corpus TEXTS_L1.txt ~ TEXTS_L12.txt and TEXTS_L1.TXT ~
TEXTS_L12.TXT as input tokens to test grammar rules that are used in
parsing.

     To use the lexical entries for corpus TEXTS_L1.txt ~
TEXTS_L12.txt and TEXTS_L1.TXT ~ TEXTS_L12.TXT, you must create a
parser including one of WORDS_L1.dcg ~ WORDS_L12.dcg and do the
following.


    1. Concatenate SFTB_L``N''.dcg, LEX_L``N''.dcg, WORDS_L``N''.dcg
       and put the result on a grammar file.
    2. Translate the grammar file into a parser (program).
    3. Run the Prolog interpreter.
    4. Read in the parser (program).
    5. Issue the query ``goal''. When you copy a sentence from the
       text file TEXTS_L``N''.txt or TEXTS_L``N''.TXT and locate it in
       the seventh argument to the predicate as an input list of
       tokens.
    6. The query will complete successfully.


% End of File
