Skip to content

TRALE: Quick Start

TRALE is a programming language designed for defining and processing type-feature structure rules, commonly used in computational linguistics for constructing grammars. To build a functional grammar in TRALE, you need to define four core components: types, features, lexicons, and rules. Each of these components plays a crucial role in structuring how language elements (like words and phrases) combine and interact to form valid sentences. Let’s break down each part:

By combining these four components, you can build complex grammars that can accept well-formed sentences and reject ungrammatical ones.

Table of Contents

Open Table of Contents

1. Types

In TRALE, types are used to create hierarchical structures that represent different linguistic categories. Types can be broken down into subtypes, and each subtype inherits the characteristics of its supertype.

Syntax:

supertype sub [subtype1, subtype2, subtype3].

Example:

bot sub [cat, person].

Here, bot is the supertype, and cat (category) and person are subtypes. All other types in the grammar will be descendants of bot.

In TRALE, bot is a special supertype that stands for “bottom.” It represents the root or base of the type hierarchy tree. All types in your grammar ultimately trace their lineage back to bot. This makes it the foundation of any type structure in TRALE.

2. Features

Features are attributes or properties that further define a type. For instance, you might want to specify the person of a pronoun or the tense of a verb. Features help you capture these distinctions within your grammar.

Syntax:

type intro [
    feature_name_1:type_of_value_of_feature_1,
    feature_name_2:type_of_value_of_feature_2].

Example:

pn intro [pn_person:person].

In this example, the type pn (pronoun) introduces a feature called pn_person, which has the type person. This helps categorize pronouns according to their person (e.g., first, second, third).

3. Lexicons

Lexicons are where you define the actual words in your language and link them to their respective types and features. In TRALE, you use tokens to specify which word belongs to which type and what values its features should have.

Syntax:

token ---> (type, feature1:value1, feature2:value2).

Example:

i ---> (pn, pn_person:first).

This means that the word i is a pronoun (pn), and it refers to the first person (feature pn_person:first).

4. Rules

Rules are essential for defining how the elements of your grammar combine. They specify how different types (with their corresponding features) should appear together to form valid grammatical constructions.

Syntax:

rule_name rule
(product_type, feature:value) ===>
cat> (type1, feature1:value1),
cat> (type2, feature2:value2).

Example:

first_person rule
s ===>
cat> (pn, pn_person:first),
cat> (v, v_person:first).

This rule describes how a valid sentence (s) can be formed: a first-person pronoun (pn) must be followed by a verb that agrees in person (v_person:first).

5. Important Notes on TRALE Syntax

6. Your First Grammar

Now that you understand the basic components, let’s create a simple grammar that models subject-verb agreement based on person. This grammar will include the necessary types, features, lexicons, and rules.

% Type Feature Structure
bot sub [cat, person].
    cat sub [pn, v, s].
        pn intro [pn_person:person].
        v intro [v_person:person].
    person sub [first, second, third].

% Lexicon
i ---> (pn, pn_person:first).
you ---> (pn, pn_person:second).
he ---> (pn, pn_person:third).
she ---> (pn, pn_person:third).
sleep ---> (v, v_person:first).
sleep ---> (v, v_person:second).
sleeps ---> (v, v_person:third).

% Rules
first_person rule
s ===>
cat> (pn, pn_person:first),
cat> (v, v_person:first).

second_person rule
s ===>
cat> (pn, pn_person:second),
cat> (v, v_person:second).

third_person rule
s ===>
cat> (pn, pn_person:third),
cat> (v, v_person:third).

Type Feature Structure:

Lexicon: This lexicon defines first-, second-, and third-person pronouns and their corresponding verbs (with proper person agreement).

Rules: These rules ensure that:

7. Running Your Grammar

Once you’ve written your grammar, save it as a .pl file (e.g., your_first_grammar.pl) and use the following command to run it in TRALE:

trale -fusg -c your_first_grammar.pl

Getting the TRALE Prompt

After running the command, you’ll enter the TRALE prompt, which functions similarly to an interactive shell (like Python’s REPL). From here, you can test your grammar and validate sentences.

Commands at the Prompt:

Here’s what a sample session might look like:

| ? rec[i, sleep].
yes
| ? rec[you, sleeps].
no
| ? rec[he, sleeps].
yes
| ? rec[she, sleep].
no

By defining types, features, lexicons, and rules, you can build more complex grammars that reflect the syntax of any language you’re working on. This Quick Start guide covers the basics, but TRALE’s flexible framework allows you to extend your grammar to handle more intricate linguistic phenomena.