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: ~phrase ~clause ~verbal
 
 

Often a subject, direct object or an indirect object is part of a phrase or clause.  Is it possible to use the ~phrase or ~clause concept/marker some how to get the phrase/clause that they are a part of?

Sample sentence: The wise teacher taught the unruly students about astronomy.

Can I use one of the markers to extract “the wise teacher”, “the unruly students”, or “about astronomy”?

I’m not sure what the ~verbal is but it was listed along with the other two concepts.

A related question is how to identify prepositional phrases that modify a subject, verb, direct object, indirect object.  So given a ~mainsubject it is possible to tell if a given ~phrase modifies it or perhaps ~subject2 or the ~mainobject instead?

Sample sentence: The wise teacher at the university taught the unruly students about astronomy.

Is there a way to extract “at the university” and know that it modifies “teacher”? 

If not, then how are ~phrase, ~clause, ~verbal to be used?

Thanks.

 

 
  [ # 1 ]

A complicated business….

1. ~phrase refers to a prepositional phrase. Usually you can find it on the preposition e.g. :prepare
“Think about the consequences”
and you will see “about” is marked ~phrase(2-4).
2. ^phrase(_0) can get a noun phrase or a preopositonal phrase at the location specified. So you could get “the wise teacher” and “the unruly students” using matches from the subject and object roles.  and you can take the preposition and use ^phrase() as one way to the get prepositional phrase (where you know what the prep is) whereas _~phrase will get you a phrase but you wont know anything about it without bursting it.
3. adverb phrases are generally also marked as one of: ~whenunit ~whereunit ~howunit ~whyunit
4. Not currently exposed in the language are reference links that would tell you what word a phrase binds to. You can see in the :prepare sentence data that the system actually has those links.  But the pos-parser is a background work in progress, and I have not decided how to integrate the information into cs visibility.

 

 
  [ # 2 ]

Thanks Bruce.

It is a complicated business. 

I am able to use the ~phrase, ~clause. and ~verbal in pattern matching.  I am unable to get ^phrase(_0) or ^phrase( _0 ) or ^phrase( ‘_0 ) to work with either the ~mainsubject as _0 or ~whenunit, ~whereunit, ~howunit or ~whyunit prepositions as _0.

sample code:
...
u: FIND_WHERE_UNIT( _~whereunit ) $$WHEREUNIT = ‘_0   $$WHEREUNITPHRASE = ^phrase( _0 )
u: FIND_WHY_UNIT( _~whyunit ) $$WHYUNIT = ‘_0       $$WHYUNITPHRASE = ^phrase( _0 )
u: FIND_WHEN_UNIT( _~whenunit ) $$WHENUNIT = ‘_0     $$WHENUNITPHRASE = ^phrase( _0 )
u: FIND_HOW_UNIT( _~howunit ) $$HOWUNIT = ‘_0       $$HOWUNITPHRASE = ^phrase( _0 )
...
u: ANALYZE_SENTENCE() ^keep() ^repeat()
    ...
    if ($$WHEREUNIT != NULL) {Where $$MAINVERB: $$WHEREUNIT / $$WHEREUNITPHRASE \n }
    if ($$WHYUNIT != NULL) {Why $$MAINVERB: $$WHYUNIT / $$WHYUNITPHRASE \n }
    if ($$WHENUNIT != NULL) {When $$MAINVERB: $$WHENUNIT/ $$WHENUNITPHRASE \n }
    if ($$HOWUNIT != NULL) {How $$MAINVERB: $$HOWUNIT / $$HOWUNITPHRASE \n }

Sample output:
> I went to bed in the evening.
Where went: to /

:prepare shows that “to bed” is correctly tagged as a phrase
Tagged POS 7 words: I (MAINSUBJECT Pronoun_subject)  went/go (MAINVERB Verb_past)  to ()  in ()  the/a (Determiner)  evening/even (OBJECT2 Noun_singular Phrase>)

I am using version 4.8.1 of Chatscript.

 

 

 
  [ # 3 ]

Had I adequately documented the routine, I could castigate you for failing to supply the 2nd argument:
noun, preposition, verbal, or adjective. But since I did not, I can not.

 

 
  [ # 4 ]

As you have said if all else fails just ask.  smile

So armed with the secret knowledge of the 2nd parameter I was able to make it all work.

Here is some sample code for those who might be interested that illustrates some of the chatscript parsing features.  In the following example I have foregone trying to find the direct object and indirect object but rather show the “main object” and the “main object2”.  The main object2 follows the main verb and may or may not be an indirect object.


concept: ~article (a an the)

topic: ~parsesentence ( parse sentence )

u: (parse [the next following] sentence) ^keep() repeat() Ok. Let’s parse a sentence.  Type a sentence to parse.

u: FIND_MAIN_SUBJECT( _~mainsubject ) ^keep() $$MAINSUBJECT = ‘_0 $MAINSUBJECTPHRASE = ^phrase( _0 noun)
u: FIND_MAIN_VERB( _~mainverb ) ^keep() $$MAINVERB = ‘_0
u: FIND_WHERE_UNIT( _~whereunit ) ^keep()  $$WHEREUNIT = ‘_0   $$WHEREUNITPHRASE = ^phrase( _0 preposition)
u: FIND_WHY_UNIT( _~whyunit ) ^keep()  $$WHYUNIT = ‘_0       $$WHYUNITPHRASE = ^phrase( _0 preposition)
u: FIND_WHEN_UNIT( _~whenunit ) ^keep()  $$WHENUNIT = ‘_0     $$WHENUNITPHRASE = ^phrase( _0 preposition)
u: FIND_HOW_UNIT( _~howunit ) ^keep()  $$HOWUNIT = ‘_0       $$HOWUNITPHRASE = ^phrase( _0 preposition)
u: FIND_MAIN_OBJECT( _~mainobject ) ^keep() $$MAINOBJECT = ‘_0 $$MAINOBJECTPHRASE = ^phrase( _0 noun)
# find first object2 following the main verb
u: FIND_MAIN_OBJECT2_A( ~mainverb * _~object2) ^keep() $$MAINOBJECT2 = ‘_0 $$MAINOBJECT2PHRASE = ^phrase( _0 noun)
# override with first object2 following the main object
u: FIND_MAIN_OBJECT2_B( ~mainobject * _~object2) ^keep() $$MAINOBJECT2 = ‘_0 $$MAINOBJECT2PHRASE = ^phrase( _0 noun)
# override with the indirect object if it exists
u: FIND_MAIN_OBJECT2_C( _~mainindirectobject ) ^keep() $$MAINOBJECT2 = ‘_0 $$MAINOBJECT2PHRASE = ^phrase( _0 noun)

u: FIND_CLAUSE1( _~clause )  ^keep() $$CLAUSE1 = ‘_0 ^unmark(~Clause _0)
u: FIND_CLAUSE2( _~clause )  ^keep() $$CLAUSE2 = ‘_0 ^unmark(~Clause _0)
u: FIND_CLAUSE3( _~clause )  ^keep() $$CLAUSE3 = ‘_0 ^unmark(~Clause _0)
u: FIND_PHRASE1( _~phrase )  ^keep() $$PHRASE1 = ‘_0 ^unmark(~Phrase _0)
u: FIND_PHRASE2( _~phrase )  ^keep() $$PHRASE2 = ‘_0 ^unmark(~Phrase _0)
u: FIND_PHRASE3( _~phrase )  ^keep() $$PHRASE3 = ‘_0 ^unmark(~Phrase _0)
u: FIND_VERBAL1( _~verbal )  ^keep() $$VERBAL1 = ‘_0 ^unmark(~Verbal _0)
u: FIND_VERBAL2( _~verbal )  ^keep() $$VERBAL2 = ‘_0 ^unmark(~Verbal _0)
u: FIND_VERBAL3( _~verbal )  ^keep() $$VERBAL3 = ‘_0 ^unmark(~Verbal _0)

u: ANALYZE_SENTENCE() ^keep() ^repeat()
    This sentence has %length words. \n
if (%sentence = 1) {This input seems like a sentence in the %tense tense using the %voice voice. \n }
if (%question = 1) {It seems to be a question. \n }
if (%command = 1) {It seems to be a command. \n }
if (%parsed = 1) {
Main subject: $$MAINSUBJECT \n
if ($$MAINSUBJECTPHRASE != NULL) {Main subject phrase: $$MAINSUBJECTPHRASE \n }
  Main verb: $$MAINVERB \n
  if ($$WHEREUNIT != NULL) {$$MAINVERB Where: $$WHEREUNITPHRASE \n }
  if ($$WHYUNIT != NULL) {$$MAINVERB Why: $$WHYUNITPHRASE \n }
  if ($$WHENUNIT != NULL) {$$MAINVERB When: $$WHENUNITPHRASE \n }
  if ($$HOWUNIT != NULL) {$$MAINVERB How: $$HOWUNITPHRASE \n }
  if ($$MAINOBJECT != NULL) {Main object: $$MAINOBJECT \n }
      if ($$MAINOBJECTPHRASE != NULL) {Main object phrase: $$MAINOBJECTPHRASE \n }
  if ($$MAINOBJECT2 != NULL) {Object2: $$MAINOBJECT2 \n }
    if ($$MAINOBJECT2PHRASE != NULL) {Main Object2 phrase: $$MAINOBJECT2PHRASE \n }
if ($$CLAUSE1 != NULL) {Clause1: $$CLAUSE1 \n }
if ($$CLAUSE2 != NULL) {Clause2: $$CLAUSE2 \n }
if ($$CLAUSE3 != NULL) {Clause3: $$CLAUSE3 \n }
if ($$PHRASE1 != NULL) {Phrase1: $$PHRASE1 \n }
if ($$PHRASE2 != NULL) {Phrase2: $$PHRASE2 \n }
if ($$PHRASE3 != NULL) {Phrase3: $$PHRASE3 \n }
if ($$VERBAL1 != NULL) {Verbal1: $$VERBAL1 \n }
if ($$VERBAL2 != NULL) {Verbal2: $$VERBAL2 \n }
if ($$VERBAL3 != NULL) {Verbal3: $$VERBAL3 \n }
}
  else
  {Unable to parse sentence.}

 

 
  [ # 5 ]

Sample Output from above code:

  >The small dog panting loudly that I adopted from the pound jumped over the tall fence in the backyard.
This sentence has 19 words.
This input seems like a sentence in the past tense using the active voice.
Main subject: dog
Main verb: jumped
jumped Where: from the pound
Object2: fence
Main Object2 phrase: the tall fence
Clause1: that I adopted from the pound
Phrase1: from the pound
Phrase2: over the tall fence
Phrase3: in the backyard
Verbal1: panting loudly

Now on to figuring out how to code the information as fact triples or as nested facts.

 

 
  [ # 6 ]

you could simply your code. eg.
u: FIND_CLAUSE1( _~clause )  ^keep() $$CLAUSE1 = ‘_0 ^unmark(~Clause _0)
could be
u: (_~clause) ^keep() createfact(‘_0 clause clause) retry(RULE)
and then you have a bunch of clause facts you can query and display

 

 
  login or register to react