-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
26 lines (22 loc) · 911 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from lango.matcher import match_rules
from mycroft.skills.common_query_skill import CommonQuerySkill, CQSMatchLevel
from nlquery.nlquery import NLQueryEngine
from nlquery.utils import first
class WikidataSkill(CommonQuerySkill):
def __init__(self):
super().__init__()
self.engine = NLQueryEngine('localhost', 9000)
self.engine.logger = self.log
def CQS_match_query_phrase(self, utt):
sent = self.engine.preprocess(utt)
tree = self.engine.parser.parse(sent)
if len(tree) == 0:
return
ans = first([
match_rules(tree, self.engine.find_entity_rules, self.engine.find_entity_query),
match_rules(tree, self.engine.subject_prop_rules, self.engine.subject_query),
])
if ans and ans.data:
return (utt, CQSMatchLevel.GENERAL, ans.to_plain())
def create_skill():
return WikidataSkill()