Example 2: the match() method

The method Wisdom.ask() does not necessarily require the question to be in the interrogative form. A question can also be declared as

from NLUlite import ServerProxy, Wisdom

server   = ServerProxy('localhost', 4001)
wisdom   = Wisdom(server)
wisdom.add('The chancellor is going to Berlin')
answer  = wisdom.ask('person that goes to Germany')

print answer.comment()
for item in answer.elements():
    print item.comment()

and the output is exactly as before:

the answer is a list

person: the chancellor
The chancellor is going to Berlin.

However, the method Wisdom.ask() always assumes the text to be a question, with or without a final ‘?’. If you need to distinguish between purely declarative and purely interrogative sentences you should use the method Wisdom.match(). With this method, only sentences that end with ‘?’ are parsed with an interrogative grammar.

Moreover, in the Wisdom.match() method the query: reply elements can be specified separately by tagging single words using #1, #2, #whatever, etc

from NLUlite import ServerProxy, Wisdom

server   = ServerProxy('localhost', 4001)
wisdom   = Wisdom(server)
wisdom.add('The chancellor is going to Berlin')
answer  = wisdom.ask('person#1 that goes to a place#2')

print answer.comment()
for item in answer.elements():
    print item.comment()

with output:

the answer is a list

person#1: the chancellor
place#2: Berlin
The chancellor is going to Berlin.

The query: reply pairs can be further refined by providing a string in answer.elements()

from NLUlite import ServerProxy, Wisdom

server   = ServerProxy('localhost', 4001)
wisdom   = Wisdom(server)
wisdom.add('The chancellor is going to Berlin')
answer  = wisdom.ask('person#1 that goes to a place#2')

print answer.comment()
for item in answer.elements('person#1'):
   print item.comment()

with output:

the answer is a list

person#1: the chancellor
The chancellor is going to Berlin.

In the next example we shall address inference and rules.