PetaveseParser (Embodiment)

From OpenCog
Jump to: navigation, search

In the following it helps to know that Petavese is a subset of English, whereas Predavese is a predicate-logic version of Petavese, into which Petavese is mapped.

The current PetaveseParser (PP) is used in the following way:

  • In initialization, we define the transformation rules for expression patterns, and terminal patterns. Each terminal pattern will be associated with an action.
  • When the parse(string) method is called, these rules are applied recursively so as to identify the ways in which the original string can be mapped into terminal patterns. The set of terminal patterns that were found, as well as the associated actions, will be returned by the parser.

Each transformation rule is a mapping from one pattern to another pattern. Each pattern is defined as a sequence of c-elements, separated by whitespace. A c-element can be one of:

  1. String
  2. Predavese::Atom

Predavese::Atom is an object with an ID and an outgoing vector of c-elements. The Atom.ID can be one of a predefined set of primitive element types. The current list of types (as of July 25, 2007) is:

Elem              

Relation          
Relation_obj      
Relation_subj     
Relation_obj2     
Relation_poss     
Relation_subj_r   
Relation_to       
Relation_to_do    

Term              

BasicTerm
Verb              
GeneralWord

Name              
ProperName
TrickName
PetName

Adj               
Pron              
Poss              

QualifiedBasicTerm

// A Verb that launches a pre-programmed 
// metacognitive action. Eg. "learn".
KeyVerb

(These are defined by using prime numbers so as to enable rapid determination of inheritance relationships of each element type.)

Typically the outgoing vectors for Atoms are not used in the transformation rules. However, once a rule is applied, the original pattern that the transformation rule was applied to is stored as an "annotation" in the outgoing vector of the corresponding new pattern element. Eg. there is a rule { "Bad", [Petname] } -> { "You", "are", "a", "bad", [Petname] }. When the parser sees the expression "Bad dog", it converts this into { "You", "are", "a", "bad", [Petname] }. The [Petname] here denotes an atom with the ID Petname, and it will be accompanied with an outgoing vector which contains the string "dog".

Multiple successive transformations may be applied to a pattern or to a single element. Eg. "dog" may be successively casted into Petname, Name, BasicTerm, Term, and Elem, in the order of type inheritance. This will create a parse tree in which the outgoing vector of the Atom with id=Petname contains Atom with id=Name, the outgoing vector of which contains Atom with id=BasicTerm, etc.

In addition to basic English expressions, the Predavese expressions of the form _obj(a,b) are also supported. These are currently simply mapped into the form "_obj a b" and then treated as special cases of the more generic parser, and they simply require their own set of rules in the same parser context as the basic English equivalents.

Currently supported Predavese logic operators are

_obj(verb,N1)        indicating that N is the object of V,
                "verb N1"
                "verb N1 N2"
_subj(V, N)        indicating that N is the subject of V,
                "Term verb"
// indicating that N is the secondary object of V (used for ditransitive verbs).
_obj2(verb,N2)
                "verb N1 N2"
_poss(O,Name)    indicating the possessive form of N
                "Name's O"
                "O of Name"
_subj-r(ADV, X)    indicating that ADV modifies X,
                ???
_to(V,O)        "V to O"
_to-do(V1, V2)
                indicating an instruction to do V to N.
                "V1 V2[-1]-ing"

Support will later be added for:

_subj-a(ADJ, N)    indicating that ADJ modifies N
                "Term Term"

Examples of statements that the parser can correctly map into corresponding actions or declarative predicate formats include:

_obj(fetch, stick)
_subj(fetch, stick)
_obj2(fetch, stick)
_poss(Ben)
_subj_r(good, stick);
_to_do(fetch, enjoy)

a dog
I a dog
good ben
I am a dog
I am a Ben
wow
boy is your dog
Your boy is a dog

good boy
boy is a dog
good dog
bad pet


bad dog
You fnorble
You fnorble bob

Jump
Walk
GetJiggyWithIt
Do wow

Fetch the ball
Kick the man.
Fnorble the red ball!
Give Fred the ball.

Give her the ball

learn fnorble
learn to fnorble
stop learning to fnorble
stop fetch

I fetch
done fetch

Correct parsing here also implies some level of type-checking: eg. "Learn walk" (walk is Verb) is accepted, but "Learn Ben" (Ben is name) is not accepted.

Support will be added later for:

  • nested Predavese logic-style expressions
  • hash maps to replace common STL maps
  • Potentially parsing a wider variety of basic English expressions, or connecting an existing parser such as RelEx to do the parsing into Predavese logic forms.

Specific commands

There are some commands which are exclusively used on specifics agent modes. For example, when the agent is switched to the Scavenger Hunt mode, the following commands are evaluated before sent to Predavese Actions Step:

I (RED|BLUE) TEAM
GO (FIND|AFTER) TREASURES <agentName>
FOLLOW ME <agentName>
FOLLOW ME COLLECT <agentName>
COME HERE <agentName>
EXPLORE AREA <areaNumber> <agentName>
WAIT <agentName>
REGROUP TEAM (RED|BLUE)
SPY <targetAgentName> <agentName>

All these commands can only be given to an agent by its owner, otherwise they will be discarded before processed as a Predavese Action.

-- Main.AriHeljakka - 26 Jul 2007 -- Main.SamirAraujo - 29 Apr 2009