Skip to content

Prolog in Tamgu

Claude Roux edited this page Oct 19, 2022 · 1 revision

Prolog

The triples in TREX are actually very close to the notion of a fact as defined in First Order Logic. There are programming languages that have been designed specifically for the manipulation of these facts. Prolog is certainly the best known of all (see Prolog 1).

Rules

The purpose of a Prolog program is to check the truth of an assertion defined as a predicate or a set of predicates. A Prolog program consists of a grammar of rules and a knowledge base. Evaluating a predicate consists either in applying a rule whose head corresponds to this predicate or in identifying in the knowledge base a corresponding fact.

When a rule applies, it builds an exploration tree, in order to evaluate all the possibilities offered by the grammar. Some operators such as "cut" allow to prune this tree to avoid an exponential explosion of the exploration.

Unification

The manipulation of variables in First Order Logic is done through unification. In a language like Prolog, we distinguish free variables from instantiated variables. A free variable has no value yet. When we associate a predicate with a fact or a rule head, the unification mechanism will allow the free variables to acquire a value. If the variable is already instantiated, the unification mechanism will check if the two variables are compatible or equal.

Tamgu

We decided to use Tamgu, an open-source language, which has the advantage of mixing in a single formalism an imperative language close to Python and a Prolog interpreter. Thus, the often complex work of transforming data into Prolog compatible objects is greatly simplified. Moreover, more prosaic Python-like functions can be called within the rules. All that is required is that the function returns "true" or "false" and they are treated as a "fact" by the Predicate Engine.

Fact extraction

In particular, we have been able to transform all sentences and triples into Prolog facts. It then became very easy to write rules to extract the elements we needed for training. The following rule, for example, checks that the arguments of TREX facts are present in the associated sentences:

alias ⊂(a,s) = a in s;

Check_into(?Key) :- TREX(?Key,?A1,?A2), SENTENCE(?Key,?S), ⊂(?A1,?S), ⊂(?A2,?S).

Note that Predicate variables are identified by the presence of a leading "?". The function "⊂" only checks whether the argument is present in the sentence. Triplets and sentences from TREX are all indexed on a particular key that identifies a particular type of predicate. We have systematically kept this key as the first argument for all facts extracted from TREX.

Biblio

@article{campbell1984implementation, title={Implementation of PROLOG}, author={Campbell, John A}, year={1984}, publisher={John Wiley and Sons, New York, NY} }

Clone this wiki locally