Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

pattern match for nlp

Project description






from pmnlp.word import build_sentence_word_dict
from pmnlp.sentence import SentenceTplTrie

# 初始化,用于记录用户配置的词槽,以及语句的模版匹配。
user_word_dict = {'num': ['一杯', '两杯'], 'coffee': [
    '拿铁', '拿铁咖啡'], 'common': [], 'phone': ['re\d+']}
sentent_intent_tpl = {
    'coffee': '[common:0-4][num][common:0-10][coffee]'

# 建立模型
sentence_word_dict = build_sentence_word_dict(word_dict=user_word_dict)
test_tree = SentenceTplTrie(word_dict=sentence_word_dict), common_key='common')

# 理解用户输入
_, intent, result = test_tree.sep('我要一杯热啊啊啊啊啊啊拿铁咖啡',common_key='common')
if isinstance(intent, str):
    print(intent, result)
    print(intent, result)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pmnlp, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size pmnlp-0.2.0.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page