Linguistics 482 - Computational Linguistics Prolog Notes A. C. Brett acbrett@uvic.ca
Department of Linguistics
University of Victoria
Clearihue C139
Last updated: 23 October 1999

Structures

Structures are compound word-like entities in Prolog that are constructed by combining other morpheme-like objects in the language according to the following schema:
   name(arg1, arg2, ..., argn)
wherein name is an atom, and the entities arg1, arg2, ..., argn, which are enclosed in parentheses and separated by commas, may be any Prolog terms. There can be no space between the atom name and the left parenthesis; but, there may be spaces between the terms within the parentheses.

The atom in the name position represents the name or principal functor of the structure. The terms inside the parentheses are called the arguments of the structure, and a given structure is identified by its name and by the number of its arguments, which is called the arity of the structure. Two structures with the same name, but with a different number of arguments, are different structures. The following lines illustrate structures:

   det(those)
   det(this, sg)
   det(these, pl)
   word(the, det, _)
   lex(them, pro, agr(3, pl, acc))
The first two lines show two structures with the same name, det, but with different numbers of arguments, 1 in the first instance, and 2 in the second. Since they have different arity, they are different structures. The third line shows another example of a structure with the name det and an arity of 2. Although the arguments of the structure in the third line differ from those of the structure in the second line, both structures have the same name and the same arity, and hence, they represent just two instances of the same structure.

The arguments of the structures in the first three lines are all atoms. The first two arguments of the structure in the fourth line, with the name word and arity 3, are also atoms; but, the third argument is a variable, the anonymous variable in this case (which acts as a place holder for what might be a number feature value). The last line shows another structure with arity 3, but with the name lex. In this example, the third argument is another structure, illustrating thereby that the arguments of structures can be other structures. The structure in this case has the name agr and an arity of 3, and its first argument illustrates that an argument of a structure can be a number.

The sentence-like constructs, or clauses of the Prolog language are composed of structures. Thus, the actual "words" of the Prolog language are structures. Other Prolog terms, such as variables and numbers, serve as the constituent morphemes that are combined to form these words. Atoms might be viewed as root-like morphemes, while the other terms, including strings and lists, although they may sometimes be described as "word-like," might more appropriately be seen as something like the affixes and infixes of a natural language morphology because they never appear except as the components of a structure.

The following lines represent examples of Prolog "sentences," or clauses:

   det(this, sg).
   noun(cat, sg).
   np(this, cat, Agr).
   np(X, Y, Num) :- det(X, Num), noun(Y, Num).
The first two lines illustrate clauses that can appear in Prolog programs as facts, one of the two varieties of clause that comprise the statements of a Prolog program. A fact is just a structure, followed by a period (because all Prolog clauses must end with a period).

Structures such as those in the first and second lines can also be goals. A goal is typed (at the Listener prompt) to pose a query or claim. For example, the structure det(this, sg) in the first line can be typed as a query that might be translated into English as "Is this a singular determiner?", or as the claim that "this is a determiner with the value sg on the number feature." To test this claim, or to answer the corresponding query, the Listener will attempt to prove the goal. In this example, if the program that has been consulted includes a fact consisting of the structure det(this, sg), the Listener will obtain a match with this fact, and succeed in proving the goal.

The structures det(this, sg) and noun(cat, sg) in the first and second lines in the example above might be called either facts (when they are in a program) or goals (when they are typed as queries or claims). The structure np(this, cat, Agr) in the third line could, technically, appear as a fact in a program. A structure such as this one, however, is more likely to appear as a goal that is typed to assert a claim such as "this and cat comprise a noun phrase with number feature value Agr" or perhaps to pose the query: "What is the number feature value of the noun phrase consisting of this cat?"

The Listener might begin the process of answering this question, testing the claim, by matching the goal structure np(this, cat, Agr) with a structure such as np(X, Y, Num) that begins the clause in the fourth line of the example above (assuming a program has been consulted that includes such a clause). The clause in the fourth line is a rule, the second of the two varieties of clause that comprise the statements of a Prolog program. The structure np(X, Y, Num) is the head of the rule. Following the neck symbol, :-, is the tail of the rule. The body of this rule consists of the two goal structures det(X, Num) and noun(Y, Num). The Listener will attempt to prove these goals as it completes the process of answering the query that was typed.

Linguistics 482 Prolog Introductory Notes Top of Page