# -*- shell-script -*-
###############################################################################
# KNOWLEDGE BASE ##############################################################
###############################################################################


# RDF import / export
SEND\ ME\ RDF\ (KB|KNOWLEDGE\ BASE)\ BY\ (EMAIL|IM) >> RDF-EXPORT \2
RDF-EXPORT\s*(\w*) :: command 'kb_rdf_export' '\1'
GET\s+KB\s+FROM\s+(.*) :: command 'kb_rdf_extract' '\1'
#\<RDF\:RDF\ XMLNS\:RDF\=\"HTTP\:\/\/WWW\.LOGILAB\.ORG\/NAMESPACES\/NARVAL\/1\.2\#\"\>(.*)\<\/RDF\:RDF\> :: random 'got kb export'
(<\?XML.*<RDF:RDF.*) :: command 'kb_rdf_import' 'string' '\1'
(<RDF:RDF.*) :: command 'kb_rdf_import' 'string' '\1'
IMPORT\s+KB(.*) :: command 'kb_rdf_import' 'url' '\1'

# add statement to kb command
# (\S+)\s+IS\s+(.+)\. :: command 'kb_add_stmt' '\1' 'IS' '\2'
([^\s]+)\s+([^\s]+)\s+([^\s]+?)\s*\. >> ADD \1 \2 \3
ADD\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s* :: command 'kb_add_stmt' '\1' '\2' '\3'
(\S+)\s+IS\s+AN?\s+(.+)\. :: command 'kb_add_stmt' '\1' 'is_a' '\2'
(\S+)\s+EST\s+UNE?\s+(.+)\. :: command 'kb_add_stmt' '\1' 'is_a' '\2'
# add rule to kb 
RULE\s?:\s?(.*) :: command 'kb_add_rule' '\1'

WHO IS THE NARVAL OF ([^\s\?]+)\s*\?? >> WHO narval_of \1 ?

# RedLand
\^FIND\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s* :: command 'kb_search_stmts' '\1' '\2' '\3'
\^FETCH\s+(.*) :: command 'kb_foaf_import' '\1'
\^(SELECT\s+.*) :: command 'kb_rdql' '\1'

# FOAF
FOAF\s*:\s*(.*) :: command 'kb_foaf_import' 'url' '\1'
GET\s+FOAF\s+FROM\s+(.*) :: command 'kb_foaf_extract' '\1'
SHOW\s+MASTER\'S\s+FOAF :: command 'kb_foaf_export'
WHAT\'S\s+(.*?)\'S\s+NICK\s*\?? >> ^SELECT ?nick WHERE (?x foaf:name "\1") (?x foaf:nick ?nick) using foaf for <http://xmlns.com/foaf/0.1/>
WHO IS INTERESTED IN (.*?)\s*\?? >> ^SELECT ?name, ?nick WHERE (?x foaf:name ?name) (?x foaf:nick ?nick) (?x foaf:interest <\1>) using foaf for <http://xmlns.com/foaf/0.1/>
WHO DO I KNOW WHO IS INTERESTED IN (.*?)\s*\?? >> ^SELECT ?name, ?nick WHERE (?x foaf:name "${MYUSERNAME}") (?x foaf:knows ?y) (?y foaf:name ?name) (?y foaf:nick ?nick) (?y foaf:interest <\1>) using foaf for <http://xmlns.com/foaf/0.1/>
WHO DOES (.*?) KNOW WHO IS INTERESTED IN (.*?)\s*\?? >> ^SELECT ?name, ?nick WHERE (?x foaf:name "\1") (?x foaf:knows ?y) (?y foaf:name ?name) (?y foaf:nick ?nick) (?y foaf:interest <\2>) using foaf for <http://xmlns.com/foaf/0.1/>
# WHO DO I KNOW\s*\?? >> ^SELECT ?name, ?nick WHERE (?x foaf:name 'Adrien Di Mascio') (?x foaf:knows ?y) (?y foaf:name ?name) (?y foaf:nick ?nick) using foaf for <http://xmlns.com/foaf/0.1/>
WHO DO I KNOW\s*\?? >> ^SELECT ?name WHERE (?x foaf:name "${MYUSERNAME}") (?x foaf:knows ?y) (?y foaf:name ?name) using foaf for <http://xmlns.com/foaf/0.1/>
# WHO DOES (.*?) KNOW\s*\?? >> ^SELECT ?name, ?nick WHERE (?x foaf:name "\1") (?x foaf:knows ?y) (?y foaf:name ?name) (?y foaf:nick ?nick) using foaf for <http://xmlns.com/foaf/0.1/>
WHO DOES (.*?) KNOW\s*\?? >> ^SELECT ?name WHERE (?x foaf:name "\1") (?x foaf:knows ?y) (?y foaf:name ?name) using foaf for <http://xmlns.com/foaf/0.1/>
IN WHAT IS (.*?) INTERESTED\s*\?? >> ^SELECT ?t WHERE (?y foaf:name "\1") (?y foaf:interest ?t) using foaf for <http://xmlns.com/foaf/0.1/>
TELL\s+ME\s+MORE\s+ABOUT\s+(.*?) >> ^SELECT ?y,?z WHERE (?x ?y ?z) (?x foaf:name "\1")  using foaf for <http://xmlns.com/foaf/0.1/>


# lookup kb command
QUI\s+EST\s+UNE?\s+(.+?)\s*\?? >> who is_a \1 ?
WHO\s+IS\s+AN?\s+(.+?)\s*\?? >> who is_a \1 ?
(QUI|QUOI|POURQUOI|WHO|WHY|WHICH|WHAT)\s+(\S+)\s+(.+?)\s*\? :: command 'kb_search_stmts' None '\2' '\3'
([^\s]+)\s+([^\s]+)\s+(WHO|WHY|WHICH|WHAT)\s*\? :: command 'kb_search_stmts' '\1' '\2' None
(QUI|QUOI|POURQUOI|WHO|WHY|WHICH|WHAT)\s+(\S+)\s*\? :: command 'kb_search_stmts' None '\2' None
(WHAT\s+LINKS)\s+([^\s]+)\s+AND\s+([^\s]+)\? :: command 'kb_search_stmts' '\2' None '\3' 
# WHO\s+DOES\s+([^\s]+)\s+KNOW\s*\? :: command 'kb_search_stmts' '\1' 'knows' None
#WHAT\s+IS\s+([^\s]+)\s+INTERESTED\s+IN\s*\? :: command 'kb_search_stmts' '\1' 'interest' None
WHAT\s+IS\s+([^\s]+)\'S\s+EMAIL\s*\? :: command 'kb_search_stmts' '\1' 'mbox' None
WHAT\s+IS\s+([^\s]+)\'S\s+([^\s]+)\s*\? :: command 'kb_search_stmts' '\1' '\2' None
(WHO|WHY|WHAT|WHICH)\s+DOES\s+(\S+)\s+(\S+)\s*\?? :: command 'kb_search_stmts' '\1' '\2' None

# ^SELECT ?nick WHERE (?x foaf:name "Adrien Di Mascio") (?x foaf:nick ?nick) using foaf for <http://xmlns.com/foaf/0.1/>

# turing test
ARE YOU A NARVAL\? :: command 'kb_state_you_are_a_narval'
# answer from human - FIXME if narval says NO he will be recorded as human
(NO|NON|(I\'M|I AM)\s+HUMAN) :: command 'kb_add_user_info' 'human'
(I\'M|I AM) A NARVAL :: command 'kb_add_user_info' 'narval'
(I\'M|I AM) THE NARVAL OF (\w+) :: command 'kb_add_user_info' 'narval' '\1'

# forward my messages to
# define a forwarding place
#  
# when the master does not want to use jabber anymore, he can tell to
# its narval where to forward its message. This destination must have 
# been defined previously
#I CAN BE REACHED VIA (.*)( AT (.*))?
