16. RDF support

RDF (Resource Descriptor Framework) is a W3C recommendation for describing meta-content based on XML.
The basic data structure of RDF is a set of 3 pieces of data called “triple”, each of which consists of a subject (subject), a predicate (predicate), and an object (object).
For more information, see RDF Concepts And Abstract .
The related AIML tags are addtriple, deletetriple, select, tuple, uniq.

16.1. AIML triple file

“triple” is a single line of text with the subject, predicate and object separated by a colon ‘:’. In this program, this line is referred to as an element.
Explain the RDF definition with an airplane example.
In this definition, “subject” is listed as “AIRPLANE” and a number of “predicate” describe each value (“object”).
AIRPLANE:hasPurpose:to transport us through the air
AIRPLANE:hasSize:9
AIRPLANE:hasSpeed:12
AIRPLANE:hasSyllables:1
AIRPLANE:isa:Aircraft
AIRPLANE:isa:Transportation
AIRPLANE:lifeArea:Physical

16.2. AIML RDF Tag

AIML defines creation, deletion, and search tags such as “addtriple”, “deletetriple”, “select”, and “uniq”.
You can also use tags like “set”, “get”, “first”, and “rest” to process search results.

16.2.1. Load Element

This program has a function to load pre-prepared files.
Reads the RDF definition file under the conditions set in rdf_storage of config.
client_type:
    storage:
        entities:
            rdf: file

        stores:
            file:
                type: file
                config:
                    rdf_storage:
                        dirs: ../storage/rdfs
                        subdirs: true
                        extension: txt

This section uses a definition file that describes the following.

ant:legs:6
ant:sound:scratch
bat:legs:2
bat:sound:eee
bear:legs:4
bear:sound:grrrrr
buffalo:legs:4
buffalo:sound:moo
cat:legs:4
cat:sound:meow
chicken:legs:2
chicken:sound:cluck cluck
dolphin:legs:0
dolphin:sound:meep meep
fish:legs:0
fish:sound:bubble bubble

16.2.2. Element Generation

A new “triple” can be dynamically added using not only loading data but also the addtriple element.

<addtriple>
  <subj>Subject</subj><pred>Predicate</pred><obj>Object</obj>
</addtriple>

An example of adding animal characteristics.

<addtriple>
  <subj>cow</subj><pred>sound</pred><obj>moo</obj>
</addtriple>
<addtriple>
  <subj>dog</subj><pred>sound</pred><obj>woof</obj>
</addtriple>

However, data added with addtriple is not persisted.

16.2.3. Delete Element

Any data including data added by the addtriple element or read from the file can be deleted using the deletetriple element. This includes not only elements added by addtriple, but also elements read from the file.

<deletetriple>
  <subj>cow</subj><pred>sound</pred><obj>moo</obj>
</deletetriple>
<deletetriple>
  <subj>ant</subj><pred>sound</pred><obj>scratch</obj>
</deletetriple>
If you specify three elements (subject, predicate, and object), only the elements that match all of them will be deleted.
If only subject and predicate are specified, matching elements are removed, regardless of the value of object.
If only subject is specified, all elements matching that subject are removed.