16. RDF support¶
16.1. AIML triple file¶
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¶
16.2.1. Load Element¶
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>
16.2.4. Search¶
The select element is used to search RDF.
16.2.4.1. Simple Search¶
In the case of a simple search, if you specify subject, predicate, and object as the contents of the <q> element, the contents registered as matching results will be returned as a list.
<select>
<q><subj>dog</subj><pred>sound</pred><obj>woof</obj></q>
</select>
If you want to retrieve only one specific element, the following can be described.
<select>
<q><subj>dog</subj><pred>sound</pred><obj>?</obj></q>
</select>
16.2.4.2. Searching by Variable¶
<select>
<vars>?x ?y ?z</vars>
<q><subj>?x</subj><pred>?y</pred><obj>?z</obj></q>
</select>
<select>
<vars>?x ?y</vars>
<q><subj>?x</subj><pred>legs</pred><obj>?y</obj></q>
</select>
16.2.4.3. Complex Condition Search¶
<select>
<vars>?x ?y ?z</vars>
<q><subj>?x</subj><pred>legs</pred><obj>?y</obj></q>
<notq><subj>?z</subj><pred>legs</pred><obj>0</obj></notq>
</select>
16.2.4.4. Data Retrieval¶
<set var="tuples">
<select>
<vars>?x ?y</vars>
<q><subj>?x</subj><pred>sound</pred><obj>?y</obj></q>
</select>
</set>
To get the data generated from the ‘select’ element described above, use the ‘tuple’ element to get the ‘get’ tag as a child element.
<get var="?x">
<tuple>
<get var="tuples" />
</tuple>
</get>
<get var="?y">
<tuple>
<get var="tuples" />
</tuple>
</get>
Also, by using the first tag and rest tag for “tuples”, partial results can be obtained as follows.
<get var="?x">
<tuple>
<first><get var="tuples" /></first>
</tuple>
</get>
<get var="?y">
<tuple>
<rest><get var="tuples" /></rest>
</tuple>
</get>