本文整理汇总了Python中adapt.engine.IntentDeterminationEngine.register_entity方法的典型用法代码示例。如果您正苦于以下问题:Python IntentDeterminationEngine.register_entity方法的具体用法?Python IntentDeterminationEngine.register_entity怎么用?Python IntentDeterminationEngine.register_entity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类adapt.engine.IntentDeterminationEngine
的用法示例。
在下文中一共展示了IntentDeterminationEngine.register_entity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ContextManagerIntegrationTest
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
class ContextManagerIntegrationTest(unittest.TestCase):
def setUp(self):
self.context_manager = ContextManager()
self.engine = IntentDeterminationEngine()
def testBasicContextualFollowup(self):
intent1 = IntentBuilder("TimeQueryIntent")\
.require("TimeQuery")\
.require("Location")\
.build()
intent2 = IntentBuilder("WeatherQueryIntent")\
.require("WeatherKeyword")\
.require("Location")\
.build()
self.engine.register_intent_parser(intent1)
self.engine.register_intent_parser(intent2)
self.engine.register_entity("what time is it", "TimeQuery")
self.engine.register_entity("seattle", "Location")
self.engine.register_entity("miami", "Location")
self.engine.register_entity("weather", "WeatherKeyword")
utterance1 = "what time is it in seattle"
intent = next(self.engine.determine_intent(utterance1, include_tags=True, context_manager=self.context_manager))
assert intent
assert intent['intent_type'] == 'TimeQueryIntent'
assert '__tags__' in intent
for tag in intent['__tags__']:
context_entity = tag.get('entities')[0]
self.context_manager.inject_context(context_entity)
utterance2 = "what's the weather like?"
intent = next(self.engine.determine_intent(utterance2, context_manager=self.context_manager))
assert intent
assert intent['intent_type'] == 'WeatherQueryIntent'
def testContextOnlyUsedOnce(self):
intent_parser = IntentBuilder("DummyIntent")\
.require("Foo")\
.optionally("Foo", "Foo2")\
.build()
context_entity = {'confidence': 1.0, 'data': [('foo', 'Foo')], 'match': 'foo', 'key': 'foo'}
self.context_manager.inject_context(context_entity)
self.engine.register_intent_parser(intent_parser)
self.engine.register_entity("foo", "Foo")
self.engine.register_entity("fop", "Foo")
intent = next(self.engine.determine_intent("foo", include_tags=True, context_manager=self.context_manager))
assert intent
assert intent['intent_type'] == "DummyIntent"
assert not (intent.get("Foo") and intent.get("Foo2"))
示例2: __init__
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
class input_engine:
"""Manages the intent engine and natural language input parser"""
def __init__(self):
self.engine = IntentDeterminationEngine()
def register_entity(self, keywords, name):
"""Registers an intenty to be found in an input"""
for k in keywords:
self.engine.register_entity(k, name)
def register_intent(self, intent):
"""Registers an intent that can be found in an input"""
self.engine.register_intent_parser(intent)
def get_intent(self, input_string):
"""Returns an intent from an input string if one is found"""
intent = self.engine.determine_intent(input_string)
for intent in self.engine.determine_intent(input_string):
if intent.get("confidence") > 0:
return intent
return None
示例3: IntentEngineTests
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
class IntentEngineTests(unittest.TestCase):
def setUp(self):
self.engine = IntentDeterminationEngine()
def testRegisterIntentParser(self):
assert len(self.engine.intent_parsers) == 0
try:
self.engine.register_intent_parser("NOTAPARSER")
assert "Did not fail to register invalid intent parser" and False
except ValueError as e:
pass
parser = IntentBuilder("Intent").build()
self.engine.register_intent_parser(parser)
assert len(self.engine.intent_parsers) == 1
def testRegisterRegexEntity(self):
assert len(self.engine._regex_strings) == 0
assert len(self.engine.regular_expressions_entities) == 0
self.engine.register_regex_entity(".*")
assert len(self.engine._regex_strings) == 1
assert len(self.engine.regular_expressions_entities) == 1
def testSelectBestIntent(self):
parser1 = IntentBuilder("Parser1").require("Entity1").build()
self.engine.register_intent_parser(parser1)
self.engine.register_entity("tree", "Entity1")
utterance = "go to the tree house"
intent = next(self.engine.determine_intent(utterance))
assert intent
assert intent['intent_type'] == 'Parser1'
parser2 = IntentBuilder("Parser2").require("Entity1").require("Entity2").build()
self.engine.register_intent_parser(parser2)
self.engine.register_entity("house", "Entity2")
intent = next(self.engine.determine_intent(utterance))
assert intent
assert intent['intent_type'] == 'Parser2'
示例4: get_intent
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
def get_intent(message):
engine = IntentDeterminationEngine()
keywords = [
'service',
'med',
'clinic',
'walk in',
]
for key in keywords:
engine.register_entity(key, "KeyWords")
print(os.getcwd())
with open(os.getcwd() + '/home/addresses.csv', 'rb') as csvfile:
records = csv.reader(csvfile, delimiter=',')
street_number = []
street_name = []
for row in records:
street_number.append(row[8])
street_name.append(row[11])
for key in street_number:
engine.register_entity(key, "StreetNumber")
for key in street_name:
engine.register_entity(key, "StreetName")
address_intent = IntentBuilder("AddressIntent")\
.require("KeyWords")\
.optionally("StreetNumber")\
.optionally("StreetName")\
.build()
engine.register_intent_parser(address_intent)
for intent in engine.determine_intent(''.join(message)):
return intent
示例5: EnglishTokenizer
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
tokenizer = EnglishTokenizer()
trie = Trie()
tagger = EntityTagger(trie, tokenizer)
parser = Parser(tokenizer, tagger)
engine = IntentDeterminationEngine()
# create and register weather vocabulary
error_keyword = [
"error",
"e",
"E"
]
for er in error_keyword:
engine.register_entity(er, "ErrorKeyword")
error_types = [
"E16",
"E17",
"E19",
"E30"
]
for et in error_types:
engine.register_entity(et, "ErrorType")
# create regex to parse out locations
#engine.register_regex_entity("in (?P<Location>.*)")
示例6: IntentService
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
#.........这里部分代码省略.........
Args:
utterances (list): list of utterances
lang (string): 4 letter ISO language code
Returns:
Intent structure, or None if no match was found.
"""
best_intent = None
for utterance in utterances:
try:
# normalize() changes "it's a boy" to "it is boy", etc.
best_intent = next(self.engine.determine_intent(
normalize(utterance, lang), 100,
include_tags=True,
context_manager=self.context_manager))
# TODO - Should Adapt handle this?
best_intent['utterance'] = utterance
except StopIteration:
# don't show error in log
continue
except Exception as e:
LOG.exception(e)
continue
if best_intent and best_intent.get('confidence', 0.0) > 0.0:
self.update_context(best_intent)
# update active skills
skill_id = best_intent['intent_type'].split(":")[0]
self.add_active_skill(skill_id)
# adapt doesn't handle context injection for one_of keywords
# correctly. Workaround this issue if possible.
try:
best_intent = workaround_one_of_context(best_intent)
except LookupError:
LOG.error('Error during workaround_one_of_context')
return best_intent
def handle_register_vocab(self, message):
start_concept = message.data.get('start')
end_concept = message.data.get('end')
regex_str = message.data.get('regex')
alias_of = message.data.get('alias_of')
if regex_str:
self.engine.register_regex_entity(regex_str)
else:
self.engine.register_entity(
start_concept, end_concept, alias_of=alias_of)
def handle_register_intent(self, message):
intent = open_intent_envelope(message)
self.engine.register_intent_parser(intent)
def handle_detach_intent(self, message):
intent_name = message.data.get('intent_name')
new_parsers = [
p for p in self.engine.intent_parsers if p.name != intent_name]
self.engine.intent_parsers = new_parsers
def handle_detach_skill(self, message):
skill_id = message.data.get('skill_id')
new_parsers = [
p for p in self.engine.intent_parsers if
not p.name.startswith(skill_id)]
self.engine.intent_parsers = new_parsers
def handle_add_context(self, message):
""" Add context
Args:
message: data contains the 'context' item to add
optionally can include 'word' to be injected as
an alias for the context item.
"""
entity = {'confidence': 1.0}
context = message.data.get('context')
word = message.data.get('word') or ''
origin = message.data.get('origin') or ''
# if not a string type try creating a string from it
if not isinstance(word, str):
word = str(word)
entity['data'] = [(word, context)]
entity['match'] = word
entity['key'] = word
entity['origin'] = origin
self.context_manager.inject_context(entity)
def handle_remove_context(self, message):
""" Remove specific context
Args:
message: data contains the 'context' item to remove
"""
context = message.data.get('context')
if context:
self.context_manager.remove_context(context)
def handle_clear_context(self, message):
""" Clears all keywords from context """
self.context_manager.clear_context()
示例7: IntentService
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
class IntentService(object):
def __init__(self, emitter):
self.engine = IntentDeterminationEngine()
self.emitter = emitter
self.emitter.on('register_vocab', self.handle_register_vocab)
self.emitter.on('register_intent', self.handle_register_intent)
self.emitter.on('recognizer_loop:utterance', self.handle_utterance)
self.emitter.on('detach_intent', self.handle_detach_intent)
self.emitter.on('detach_skill', self.handle_detach_skill)
def handle_utterance(self, message):
# Get language of the utterance
lang = message.data.get('lang', None)
if not lang:
lang = "en-us"
utterances = message.data.get('utterances', '')
best_intent = None
for utterance in utterances:
try:
# normalize() changes "it's a boy" to "it is boy", etc.
best_intent = next(self.engine.determine_intent(
normalize(utterance, lang), 100))
# TODO - Should Adapt handle this?
best_intent['utterance'] = utterance
except StopIteration as e:
logger.exception(e)
continue
if best_intent and best_intent.get('confidence', 0.0) > 0.0:
reply = message.reply(
best_intent.get('intent_type'), best_intent)
self.emitter.emit(reply)
elif len(utterances) == 1:
self.emitter.emit(Message("intent_failure", {
"utterance": utterances[0],
"lang": lang
}))
else:
self.emitter.emit(Message("multi_utterance_intent_failure", {
"utterances": utterances,
"lang": lang
}))
def handle_register_vocab(self, message):
start_concept = message.data.get('start')
end_concept = message.data.get('end')
regex_str = message.data.get('regex')
alias_of = message.data.get('alias_of')
if regex_str:
self.engine.register_regex_entity(regex_str)
else:
self.engine.register_entity(
start_concept, end_concept, alias_of=alias_of)
def handle_register_intent(self, message):
intent = open_intent_envelope(message)
self.engine.register_intent_parser(intent)
def handle_detach_intent(self, message):
intent_name = message.data.get('intent_name')
new_parsers = [
p for p in self.engine.intent_parsers if p.name != intent_name]
self.engine.intent_parsers = new_parsers
def handle_detach_skill(self, message):
skill_name = message.data.get('skill_name')
new_parsers = [
p for p in self.engine.intent_parsers if
not p.name.startswith(skill_name)]
self.engine.intent_parsers = new_parsers
示例8: IntentSkill
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
class IntentSkill(BoomerSkill):
def __init__(self):
BoomerSkill.__init__(self, name="IntentSkill")
self.engine = IntentDeterminationEngine()
def initialize(self):
self.emitter.on('register_vocab', self.handle_register_vocab)
self.emitter.on('register_intent', self.handle_register_intent)
self.emitter.on('recognizer_loop:utterance', self.handle_utterance)
self.emitter.on('detach_intent', self.handle_detach_intent)
def handle_utterance(self, message):
timer = Stopwatch()
timer.start()
metrics = MetricsAggregator()
utterances = message.data.get('utterances', '')
best_intent = None
for utterance in utterances:
metrics.increment("utterances.count")
for intent in self.engine.determine_intent(
utterance, num_results=100):
metrics.increment("intents.count")
intent['utterance'] = utterance
best_confidence = best_intent.get('confidence') \
if best_intent else 0.0
cur_confidence = intent.get('confidence', 0.0)
if best_confidence < cur_confidence:
best_intent = intent
if best_intent and best_intent.get('confidence', 0.0) > 0.0:
reply = message.reply(
best_intent.get('intent_type'), data=best_intent)
self.emitter.emit(reply)
elif len(utterances) == 1:
self.emitter.emit(
Message("intent_failure",
data={"utterance": utterances[0]}))
else:
self.emitter.emit(
Message("multi_utterance_intent_failure",
data={"utterances": utterances}))
metrics.timer("parse.time", timer.stop())
metrics.flush()
def handle_register_vocab(self, message):
start_concept = message.data.get('start')
end_concept = message.data.get('end')
regex_str = message.data.get('regex')
alias_of = message.data.get('alias_of')
if regex_str:
self.engine.register_regex_entity(regex_str)
else:
self.engine.register_entity(
start_concept, end_concept, alias_of=alias_of)
def handle_register_intent(self, message):
intent = open_intent_envelope(message)
self.engine.register_intent_parser(intent)
def handle_detach_intent(self, message):
intent_name = message.data.get('intent_name')
new_parsers = [
p for p in self.engine.intent_parsers if p.name != intent_name]
self.engine.intent_parsers = new_parsers
def stop(self):
pass
示例9: len
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
# If there's a second argument given, use that to insert an import path
# This enables users to use their own Adapt installation directories.
if len(sys.argv) > 2:
sys.path.insert(0, sys.argv[2])
from adapt.intent import IntentBuilder
from adapt.engine import IntentDeterminationEngine
engine = IntentDeterminationEngine()
schema = json.loads(sys.argv[1])
for entity in schema["entities"]:
if entity["type"] == "string":
for value in entity["values"]:
engine.register_entity(value, entity["name"])
elif entity["type"] == "regex":
engine.register_regex_entity(entity["pattern"])
for intent in schema["intents"]:
ib = IntentBuilder(intent["name"].encode("utf-8"))
for requirement in intent["requirements"]:
ib.require(requirement["entity"], requirement["attribute"])
for optional in intent["optionals"]:
ib.optionally(optional["entity"], optional["attribute"])
engine.register_intent_parser(ib.build())
if __name__ == "__main__":
while True:
line = sys.stdin.readline()
query = json.loads(line)
示例10: skyAdapt
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
def skyAdapt():
engine = IntentDeterminationEngine()
#dota vocabulary
dota_keywords = [ 'dota', 'dotes', 'dote']
for dk in dota_keywords:
engine.register_entity(dk, "DotaKeyword")
happening_keywords = [
'happening',
'anyone up for',
'when is',
'what time',
'tonight',
'this evening?',
'anyone about for',
'around',
'want to',
'fancy some',
'playing some',
'anyone playing'
]
for hk in happening_keywords:
engine.register_entity(hk, "HappeningKeyword")
dota_query_intent = IntentBuilder("DotaIntent")\
.require("DotaKeyword")\
.require("HappeningKeyword")\
.build()
stack_intent_words = [
'stack',
'stacked'
]
for sik in stack_intent_words:
engine.register_entity(hk, "StackKeyword")
stack_optionals = [
'are we',
'do we have a',
'how many',
'who\'s playing'
]
for osk in stack_optionals:
engine.register_entity(hk, "StackOptionalKeyword")
stack_intent = IntentBuilder("StackIntent")\
.require("StackKeyword")\
.optionally("StackOptionalKeyword")\
.build()
engine.register_regex_entity("at (?P<Time>.*)")
new_dota_intent = IntentBuilder("NewDotaIntent")\
.require("DotaKeyword")\
.require("Time")\
.build()
engine.register_intent_parser(dota_query_intent)
engine.register_intent_parser(stack_intent)
engine.register_intent_parser(new_dota_intent)
return engine
示例11: EnglishTokenizer
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
tokenizer = EnglishTokenizer()
trie = Trie()
tagger = EntityTagger(trie, tokenizer)
parser = Parser(tokenizer, tagger)
engine = IntentDeterminationEngine()
# create and register weather vocabulary
cartype_keyword = [
"rent",
"transfer"
]
for ck in cartype_keyword:
engine.register_entity(ck, "CarTypeKeyword")
months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
示例12: IntentService
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
#.........这里部分代码省略.........
# update timestamp, or there will be a timeout where
# intent stops conversing whether its being used or not
self.add_active_skill(skill[0])
return
# no skill wants to handle utterance
best_intent = None
for utterance in utterances:
try:
# normalize() changes "it's a boy" to "it is boy", etc.
best_intent = next(self.engine.determine_intent(
normalize(utterance, lang), 100,
include_tags=True,
context_manager=self.context_manager))
# TODO - Should Adapt handle this?
best_intent['utterance'] = utterance
except StopIteration:
# don't show error in log
continue
except e:
LOG.exception(e)
continue
if best_intent and best_intent.get('confidence', 0.0) > 0.0:
self.update_context(best_intent)
reply = message.reply(
best_intent.get('intent_type'), best_intent)
self.emitter.emit(reply)
# update active skills
skill_id = int(best_intent['intent_type'].split(":")[0])
self.add_active_skill(skill_id)
else:
self.emitter.emit(Message("intent_failure", {
"utterance": utterances[0],
"lang": lang
}))
def handle_register_vocab(self, message):
start_concept = message.data.get('start')
end_concept = message.data.get('end')
regex_str = message.data.get('regex')
alias_of = message.data.get('alias_of')
if regex_str:
self.engine.register_regex_entity(regex_str)
else:
self.engine.register_entity(
start_concept, end_concept, alias_of=alias_of)
def handle_register_intent(self, message):
print "Registering: " + str(message.data)
intent = open_intent_envelope(message)
self.engine.register_intent_parser(intent)
def handle_detach_intent(self, message):
intent_name = message.data.get('intent_name')
new_parsers = [
p for p in self.engine.intent_parsers if p.name != intent_name]
self.engine.intent_parsers = new_parsers
def handle_detach_skill(self, message):
skill_id = message.data.get('skill_id')
new_parsers = [
p for p in self.engine.intent_parsers if
not p.name.startswith(skill_id)]
self.engine.intent_parsers = new_parsers
def handle_add_context(self, message):
"""
Handles adding context from the message bus.
The data field must contain a context keyword and
may contain a word if a specific word should be injected
as a match for the provided context keyword.
"""
entity = {'confidence': 1.0}
context = message.data.get('context')
word = message.data.get('word') or ''
# if not a string type try creating a string from it
if not isinstance(word, basestring):
word = str(word)
entity['data'] = [(word, context)]
entity['match'] = word
entity['key'] = word
self.context_manager.inject_context(entity)
def handle_remove_context(self, message):
"""
Handles removing context from the message bus. The
data field must contain the 'context' to remove.
"""
context = message.data.get('context')
if context:
self.context_manager.remove_context(context)
def handle_clear_context(self, message):
"""
Clears all keywords from context.
"""
self.context_manager.clear_context()
示例13: EnglishTokenizer
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
from adapt.engine import IntentDeterminationEngine
tokenizer = EnglishTokenizer()
trie = Trie()
tagger = EntityTagger(trie, tokenizer)
parser = Parser(tokenizer, tagger)
engine = IntentDeterminationEngine()
# define vocabulary
weather_keyword = [
"weather"
]
for wk in weather_keyword:
engine.register_entity(wk, "WeatherKeyword")
weather_types = [
"snow",
"rain",
"wind",
"sleet",
"sun"
]
for wt in weather_types:
engine.register_entity(wt, "WeatherType")
locations = [
"Seattle",
"San Francisco",
示例14: IntentService
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
#.........这里部分代码省略.........
# intent stops conversing whether its being used or not
self.add_active_skill(skill[0])
return True
return False
def parse_utterances(self, utterances, lang):
"""
Parse the utteracne using adapt to find a matching intent.
Args:
utterances (list): list of utterances
lang (string): 4 letter ISO language code
Returns: Intent structure, or None if no match was found.
"""
best_intent = None
for utterance in utterances:
try:
# normalize() changes "it's a boy" to "it is boy", etc.
best_intent = next(self.engine.determine_intent(
normalize(utterance, lang), 100,
include_tags=True,
context_manager=self.context_manager))
# TODO - Should Adapt handle this?
best_intent['utterance'] = utterance
except StopIteration:
# don't show error in log
continue
except Exception as e:
LOG.exception(e)
continue
if best_intent and best_intent.get('confidence', 0.0) > 0.0:
self.update_context(best_intent)
# update active skills
skill_id = int(best_intent['intent_type'].split(":")[0])
self.add_active_skill(skill_id)
return best_intent
def handle_register_vocab(self, message):
start_concept = message.data.get('start')
end_concept = message.data.get('end')
regex_str = message.data.get('regex')
alias_of = message.data.get('alias_of')
if regex_str:
self.engine.register_regex_entity(regex_str)
else:
self.engine.register_entity(
start_concept, end_concept, alias_of=alias_of)
def handle_register_intent(self, message):
intent = open_intent_envelope(message)
self.engine.register_intent_parser(intent)
def handle_detach_intent(self, message):
intent_name = message.data.get('intent_name')
new_parsers = [
p for p in self.engine.intent_parsers if p.name != intent_name]
self.engine.intent_parsers = new_parsers
def handle_detach_skill(self, message):
skill_id = message.data.get('skill_id')
new_parsers = [
p for p in self.engine.intent_parsers if
not p.name.startswith(skill_id)]
self.engine.intent_parsers = new_parsers
def handle_add_context(self, message):
"""
Handles adding context from the message bus.
The data field must contain a context keyword and
may contain a word if a specific word should be injected
as a match for the provided context keyword.
"""
entity = {'confidence': 1.0}
context = message.data.get('context')
word = message.data.get('word') or ''
# if not a string type try creating a string from it
if not isinstance(word, basestring):
word = str(word)
entity['data'] = [(word, context)]
entity['match'] = word
entity['key'] = word
self.context_manager.inject_context(entity)
def handle_remove_context(self, message):
"""
Handles removing context from the message bus. The
data field must contain the 'context' to remove.
"""
context = message.data.get('context')
if context:
self.context_manager.remove_context(context)
def handle_clear_context(self, message):
"""
Clears all keywords from context.
"""
self.context_manager.clear_context()
示例15: IntentDeterminationEngine
# 需要导入模块: from adapt.engine import IntentDeterminationEngine [as 别名]
# 或者: from adapt.engine.IntentDeterminationEngine import register_entity [as 别名]
"""
import json
import sys
from adapt.intent import IntentBuilder
from adapt.engine import IntentDeterminationEngine
engine = IntentDeterminationEngine()
# create and register weather vocabulary
weather_keyword = [
"weather"
]
for wk in weather_keyword:
engine.register_entity(wk, "WeatherKeyword")
weather_types = [
"snow",
"rain",
"wind",
"sleet",
"sun"
]
for wt in weather_types:
engine.register_entity(wt, "WeatherType")
# create regex to parse out locations
engine.register_regex_entity("in (?P<Location>.*)")