Writer class

The Writer class writes out the answer in English. For example, this class is used by the method Answer.comment() to provide feedback on the answer. At this stage of development this documentation is just a placeholder for the future versions of the framework: the Writer has to be a separated class because in the future you will be able to decide the writing style of the answer.

In NLUlite an answer is given in terms of different elements - like ‘text’, ‘query’, ‘reply’. You might want to write out the sentence in a human language. For example, you might want an answer in terms of ‘Yes’, ‘No, or a short summary of what the answer is

from NLUlite import ServerProxy, Wisdom, Writer

server  = ServerProxy('localhost', 4001)
wisdom  = Wisdom(server)
wisdom.add('The chancellor had planned to go to Berlin January 10, 2102.')
answer   = wisdom.ask('is someone going to Germany?')

# Print a comment to all the answers
writer= Writer(wisdom)
print writer.write(answer)

and the output will be:

Yes

Another use of the Writer class allows you to write out in English the answer elements as they were understood by the NLUlite server: If the answer is a list, each item of the answer can be written separately, as in the the following example:

from NLUlite import ServerProxy, Wisdom, Writer

server    = ServerProxy('localhost', 4001)
wisdom   = Wisdom(server)
wisdom.add('The chancellor had planned to go to Berlin January 10, 2102.')
answer = wisdom.ask('Who goes to Germany')

for item in answer.elements():
    print item.text, item.link, item.weight
    print writer.write(item)
    for pair in item.pairs:
        print pair.query + ': ' + pair.reply

In which case the output would be:

the chancellor goes to Berlin on 10 January 2102