Terse Language for Triples

Turtle is a simple language for representing triples. It is one of the languages invented for the semantic web. It is one of the syntaxes used for the Resource Description Framework, or RDF, growing out of a similar language called Notation 3 or N3.

In Turtle and RDF everything - including individuals, classes, and properties - is a resource. A Uniform Resource Identifier (URI) is a unique name that can be used to identify anything. A URI is written within angle brackets, and it often has the form of a URL because URLs are unique. For example, http://aispace.org can be a URI. A "#" in a URI denotes an individual that is referred to in a web page. For example, http://cs.ubc.ca/poole/foaf.rdf#david denotes the individual david referred to in http://cs.ubc.ca/∼poole/foaf.rdf. The URI refers to the current document, so the URI #comp_2347 denotes an individual defined in the current document.

A triple is written simply as

Subject Verb Object.

where Subject and Verb are URIs, and Object is either a URI or a literal (string or number). Verb denotes a property. Object is the value of the property Verb for Subject.

Example 13.8: The triples of Example 13.7 are written in Turtle as follows:
#comp_2347⟩ ⟨#owned_by⟩ ⟨#fran⟩.
#comp_2347⟩ ⟨#managed_by⟩ ⟨#sam⟩.
#comp_2347⟩ ⟨#model⟩ ⟨#lemon_laptop_10000⟩.
#comp_2347⟩ ⟨#brand⟩ ⟨#lemon_computer⟩.
#comp_2347⟩ ⟨#has_logo⟩ ⟨#lemon_disc⟩.
#comp_2347⟩ ⟨#color⟩ ⟨#green⟩.
#comp_2347⟩ ⟨#color⟩ ⟨#yellow⟩.
#fran⟩ ⟨#has_office⟩ ⟨#r107⟩.
#r107⟩ ⟨#serves_building⟩ ⟨#comp_sci⟩.

The identifier "fran" does not tell us the name of the individual. If we wanted to say that the person's name is Fran, we would write

#fran⟩ ⟨#name⟩ "Fran".

There are some useful abbreviations used in Turtle. A comma is used to group objects with the same subject and verb. That is,

S V O1,O2.

is an abbreviation for

S V O1.
S V O2.

A semicolon is used to group verb-object pairs for the same subject. That is,

S V1 O1;V2 O2.

is an abbreviation for

S V1 O1.
S V2 O2.

Square brackets are to define an individual that is not given an identifier. This unnamed resource is used as the object of some triple, but otherwise cannot be referred to. Both commas and semicolons can be used to give this resource properties. Thus,

[V1 O1;V2 O2]

is an individual that has value O1 on property V1 and has value O2 on property V2. Such descriptions of unnamed individuals are sometimes called frames. The verbs are sometimes called slots and the objects are fillers.

Example 13.9: The Turtle sentence
#owned_by⟩ ⟨#fran⟩;
#color⟩ ⟨#green⟩,⟨#yellow⟩;
#managed_by⟩ [
#occupation⟩ ⟨#sys_admin⟩;
#serves_building⟩ ⟨#comp_sci⟩].

says that ⟨comp_3645⟩ is owned by ⟨#fran⟩, its color is green and yellow, and it is managed by a resource whose occupation is system administration and who serves the comp_sci building.

This is an abbreviation for the triples

comp_3645⟩ ⟨#owned_by⟩ ⟨#fran⟩.
comp_3645⟩ ⟨#color⟩ ⟨#green⟩.
comp_3645⟩ ⟨#color⟩ ⟨#yellow⟩.
comp_3645⟩ ⟨#managed_by⟩ ⟨i2134⟩.
i2134⟩ ⟨#occupation⟩ ⟨#sys_admin⟩.
i2134⟩ ⟨#serves_building⟩ ⟨#comp_sci⟩.

but where the made-up URI, ⟨i2134⟩, cannot be referred to elsewhere.

It is difficult for a reader to know what the authors mean by a particular URI such as #name and how the use of this term relates to other people's use of the same term. There are, however, people who have agreed on certain meaning for specific terms. For example, the property http://xmlns.com/foaf/0.1/#name has a standard definition as the name of an object. Thus, if we write

#fran⟩ ⟨http://xmlns.com/foaf/0.1/#name⟩ "Fran".

we mean the particular name property having that agreed-on definition.

It does not matter what is at the URL http://xmlns.com/foaf/0.1/, as long as those who use the URI http://xmlns.com/foaf/0.1/#name all mean the same property. That URL, at the time of writing, just redirects to a web page. However, the "friend of a friend" project (which is what "foaf" stands for) uses that name space to mean something. This works simply because people use it that way.

In Turtle, URIs can be abbreviated using a "name:" to replace a URL and the angle brackets, using an "@prefix" declaration. For example,

@prefix   foaf: ⟨http://xmlns.com/foaf/0.1/#

lets "foaf:name" be an abbreviation for http://xmlns.com/foaf/0.1/#name. Similarly,

@prefix   : ⟨#

lets us write ⟨#color⟩ as :color.

Turtle also allows for parentheses for arguments to functions that are not reified. It also uses the abbreviation "a" for "rdf:type", but we do not follow that convention.

Classes in Knowledge Bases and Object-Oriented Programming

The use of "individuals" and "classes" in knowledge-based systems is very similar to the use of "objects" and "classes" in object-oriented programming (OOP) languages such as Smalltalk or Java. This should not be too surprising because they have an interrelated history. There are important differences that tend to make the direct analogy often more confusing than helpful:

  • Objects in OOP are computational objects; they are data structures and associated programs. A "person" object in Java is not a person. However, individuals in a knowledge base (KB) are (typically) things in the real world. A "person" individual in a KB can be a real person. A "chair" individual can be a real chair you can actually sit in; it can hurt you if you bump into it. You can send a message to, and get answers from, a "chair" object in Java, whereas a chair in the real world tends to ignore what you tell it. A KB is not typically used to interact with a chair, but to reason about a chair. A real chair stays where it is unless it is moved by a physical agent.
  • In a KB, a representation of an object is only an approximation at one (or a few) levels of abstraction. Real objects tend to be much more complicated than what is represented. We typically do not represent the individual fibers in a chair. In an OOP system, there are only the represented properties of an object. The system can know everything about a Java object, but not about a real individual.
  • The class structure of Java is intended to represent designed objects. A systems analyst or a programmer gets to create a design. For example, in Java, an object is only a member of one lowest-level class. There is no multiple inheritance. Real objects are not so well behaved. The same person could be a football coach, a mathematician, and a mother.
  • A computer program cannot be uncertain about its data structures; it has to select particular data structures to use. However, we can be uncertain about the types of things in the world.
  • The representations in a KB do not actually do anything. In an OOP system, objects do computational work. In a KB, they just represent - that is, they just refer to objects in the world.
  • Whereas an object-oriented modeling language, like UML, may be used for representing KBs, it may not be the best choice. A good OO modeling tool has facilities to help build good designs. However, the world being modeled may not have a good design at all. Trying to force a good design paradigm on a messy world may not be productive.