|
Answer class
Choosing the elements
An answer contains the results from calling Wisdom.ask() or
Wisdom.match():
answer = wisdom.ask('person that goes to Germany')
the list of elements from the answer is obtained by calling
Answer.elements():
for item in answer.elements():
print item.text
The type of elements in the list can be specified as an argument to
Answer.elements(); for example in
for item in answer.elements('person#1'):
print item.text
the list will only have elements that contain the string ‘person#1’ in
the query. This might be useful for example when calling:
answer = wisdom.match('person#1 that goes to a place#2')
in which case the list given by
answer.elements('person#1')
will only be about the people that have travelled, and will not
contain the places where they have been. In the same example the list
of places can be obtained by calling:
answer.elements('place#2')
Types of answer
An answer can be positive, negative or a list. The corresponding
methods are
-
Answer.is_positive()
The answer is positive to a yes/no question, or the answer is a list of possible matches.
-
Answer.is_negative()
The answer is negative to a yes/no question, or the answer does not contain any match to the question
-
Answer.is_list()
The answer is a list of possible matches
For example:
answer = wisdom.ask('does someone to Germany')
if answer.is_positive():
## Code here
or:
answer = wisdom.ask('who goes to Germany')
if answer.is_list():
## Code here
Notice that a list answer is positive by default, so the previous
code can be also written as:
answer = wisdom.ask('who goes to Germany')
if answer.is_positive():
## Code here
Auxiliary classes
The QPair class is a structure that contains two elements:
QPair.query, and Qpair.reply. Every answer item contains a list of
Qpair.
The Rule class is a structure that contains three elements:
Rule.text, Rule.description and Rule.weight.
AnswerElement
Each answer contains a list of AnswerElements, that can be retrieved
by using the method Answer.elements()
The AnswerElement class contains five main fields
-
AnswerElement.text
the sentence that matches the question
-
AnswerElement.link
the link related to the sentence that matches the question
-
AnswerElement.weight
the confidence in the answer.
-
AnswerElement.description
the confidence in the answer.
-
AnswerElement.pairs
a list of QPair. Each element contains a field “query” (like “what”
in “what is able to live beyond the tropic”) and “reply” (the
animal that a answer the previous question)
-
AnswerElement.rules
a list of Rules. When a question requires inference to be answered,
the list of rules that are used is stored in this list. Each
element of the list contains a field “text” (the text of the used
Rule) and a field “description” (the description associated to the
text that creates this Rule).
|