AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

POS Parser Question re: ~MainSubject
 
 

Bruce, in the documentation included with Chatscript in the document “ChatScript PosParser.pdf”
it mentions:

“Individual words serve roles, which are retrievable. These include
~mainsubject, ~mainverb, ~mainindirect, ~maindirect…”

When you have time could you please post an example of how they are retrievable? 

For example would it be possible to create a test topic where any input from a user is processed and the reply would be something like “I think the mainsubject is x”?  Does the chatscript pos parser actually identify what it thinks is the main subject of the user’s input?

Thanks.

 

 
  [ # 1 ]

u: (_~mainsubject) Main subject is ‘_0.

 

 
  [ # 2 ]

There is, of course, no guarantee that the user’s input is parseable… Though there is also a flag that the system uses to indicate it didnt think it parsed it completely. 

u: ( _~mainsubject * _~mainverb * _~mainobject) A simple sentence of subject verb and object

 

 
  [ # 3 ]

That is great.  This can be useful when interfacing with stored facts and performing queries.  Facts about the main subject can be queried for instance and responses selected based on knowledge from facts from other sources.

I was able to get the following code to work:

u: FINDMAINSUBJECT( _~mainsubject ) ^keep() ^repeat() $$MAINSUBJECT = _0 ^RETRY(FINDMAINVERB)

u: FINDMAINVERB( _~mainverb ) ^keep() ^repeat() $$MAINVERB = _0 ^RETRY(FINDMAINDIRECTOBJECT)

u: FINDMAINDIRECTOBJECT( _~mainobject ) ^keep() ^repeat() $$MAINDIRECTOBJECT = _0 ^RETRY(FINDMAININDIRECTOBJECT)

u: FINDMAININDIRECTOBJECT( _~object2 ) ^keep() ^repeat() $$MAININDIRECTOBJECT = _0 ^RETRY(ANALYZESENTENCE)

u: ANALYZESENTENCE( _* ) ^keep() ^repeat()
@1 = ^burst(‘_0)
    $sentencelength = ^length(@1)
    This sentence has $sentencelength words. \n
if (%parsed = 1) {
Main subject: $$MAINSUBJECT \n
Main verb: $$MAINVERB \n
Main direct object: $$MAINDIRECTOBJECT \n
Main indirect object: $$MAININDIRECTOBJECT \n }
else
{Unable to parse sentence.}


Sample Output:
>I hit the nail with the hammer.
This sentence has 7 words.
Main subject: I
Main verb: hit
Main direct object: nail
Main indirect object: hammer

  >The boy threw the ball.
This sentence has 5 words.
Main subject: boy
Main verb: throw
Main direct object: ball
Main indirect object:

  >The horse jumped over the gate.
This sentence has 6 words.
Main subject: horse
Main verb: jump
Main direct object:
Main indirect object: gate

(I was able to use concepts ~mainobject and ~object2 but was not successful trying ~maindirect and ~mainindirect.)

 

 
  [ # 4 ]

1.  why are you saying retry(xxx)?  the rules will automatically flow to the next one…
2. you don’t need repeat() on rules that do not generate output.
3. object2 is NOT an indirect object.
  I threw her the ball
“her” is the indirect object which is semi equivalent to I threw the ball to her.
But prepositional objects are NOT indirect objects per se.

 

 
  [ # 5 ]

Thanks Bruce.

I did not realize that pattern matching without output would continue processing the next “rule”...that has opened up many possibilities.  I have removed the repeat() from my code.  I see now that determining the “indirect object” is not that straight forward.  In the statement “I gave Mary a present” Mary is the indirect object.  In the statement “I gave a present to Mary” the prepositional phrase “to Mary” acts as an indirect object.  So in either case I would like to flag Mary as the indirect object.  I did not think that ~mainindirectobject was working so I had used ~object2.  Now I use ~object2 as the indirect object if it follows the main verb or the main object and ~mainindirectobject is not flagged.  I need to add more refined logic still.  I see that there can be many OBJECT2 nouns flagged so it would be possible to repeatedly test for each OBJECT2 and unmark it.  I found that I can temporarily mark a noun as an ~objectofphrase and then further test and capture patterns that would make up an indirect object phrase. 


u: CHECK_IF_OBJECT2_IS_INDIRECT_OBJECT_B( ~mainverb * _~object2) ^keep() $$MAININDIRECTOBJECT = ‘_0 ^mark(~objectofphrase _0)
u: CHECK_IF_OBJECT2_IS_INDIRECT_OBJECT_A( ~mainobject * _~object2) ^keep() $$MAININDIRECTOBJECT = ‘_0 ^mark(~objectofphrase _0)
u: FIND_MAIN_INDIRECT_OBJECT( _~mainindirectobject ) ^keep() $$MAININDIRECTOBJECT = ‘_0 ^mark(~objectofphrase _0)

u: FIND_MAIN_INDIRECT_OBJECT_PHRASE1( _~adjective _~objectofphrase ) ^keep() $$MAININDIRECTOBJECTPHRASE = ^JOIN(AUTOSPACE ‘_0 ‘_1)
u: FIND_MAIN_INDIRECT_OBJECT_PHRASE2( _~adjective _~adjective _~objectofphrase) ^keep() $$MAININDIRECTOBJECTPHRASE = ^JOIN(AUTOSPACE ‘_0 ‘_1 ‘_2)
u: FIND_MAIN_INDIRECT_OBJECT_PHRASE3( _~adverb _~adjective _~objectofphrase ) ^keep() $$MAININDIRECTOBJECTPHRASE = ^JOIN(AUTOSPACE ‘_0 ‘_1 ‘_2)

u: ( _~objectofphrase ) ^unmark(~objectofphrase _0)

This works for simple phrases and is in lieu of getting the ~phrase(_0) to work (see other post).  I am interested in possibly parsing and coding the semantics of entered sentences as facts so it is not a bad thing to have fixed patterns for the phrases as each pattern might need different coding depending on the number of adverbs adjectives etc.

Is there a way to ^unmark all words flagged with a specific flag?  I would like to be able to ^unmark(~objectofphrase) without specifying a second parameter and have it clear all words flagged with ~objectofphrase and leaving all other flags intact.

 

 

 
  [ # 6 ]

indirectobjects are tricky….
I walked my dog to my home- home is not a direct object
I threw my dog to the curb - curb is not a direct object
I threw my dog a bone -  clearly an indirect object
I threw a bone to my dog - your equivalent

basically you have to write script of the form u: (~mainsubject * ~mainverb * ~mainobject to * _~object2)
and decide which values of object2 are indirect objects and which are not.

—I’ll think on your unmark request….

 

 
  [ # 7 ]

next release (this weekend)  ^unmark(dog all) or ^unmark(~concept all)

 

 
  login or register to react