Meta-language for DSL implementation inspired by Xtext
Project description
textx_model
介绍
以textX为基础构建出可运行条件规则语句然后输出结果的模型
条件规则语句(例):"(current_medical_program = '白细胞计数') and (specimen_type = '全血') and "
"(medicine_projects in '[1,2,3]') and (time < 6)"
-
当里面变量是:"current_medical_program = '白细胞计数';specimen_type = '全血';medicine_projects = '2';time = 5;"
结果输出: True
-
当里面变量是:"current_medical_program = '白细胞计数';specimen_type = '全血';medicine_projects = '2';time = 8;"
结果输出: False
功能介绍
包含两个模型:通用模型(general_model)和 case when 专用模型(cs_model),它们处理的条件规则语句不同。
包含一个工具:字典转字符串工具(dict_to_str)
-
通用模型
能处理的条件规则语句(例):"(current_medical_program = '白细胞计数') and (specimen_type = '全血') and "
"(medicine_projects in '[1,2,3]') and (time < 6)"使用通用模型: from textx_model import general_model
-
case when 专用模型
能处理的条件规则语句(例):"case when (current_medical_program = '白细胞计数') and (specimen_type = '全血') and "
"(medicine_projects in '[1,2,3]') and (time < 6) then '提醒消息:白细胞计数的消息' else ''"使用case when 专用模型
from textx_model import cs_model
-
字典转字符串工具
from textx_tools import dict_to_str
安装教程
- pip install textx-model
使用说明
-
通用模型
from textx_model import general_model
rule = "(current_medical_program = '白细胞计数') and (specimen_type = '全血') and "
"(medicine_projects in '[1,2,3]') and (time < 6)"true_example = "current_medical_program = '白细胞计数';specimen_type = '全血';medicine_projects = '2';time = 5;"
false_example = "current_medical_program = '白细胞计数';specimen_type = '全血';medicine_projects = '2';time = 8;"
gm = general_model(true_example, rule)
print(gm.run()) # 预期结果:True
gm = general_model(false_example, rule)
print(gm.run()) # 预期结果:False
-
case when 专用模型
from textx_model import cs_model
rule = "case when (current_medical_program = '白细胞计数') and (specimen_type = '全血') and "
"(medicine_projects in '[1,2,3]') and (time < 6) then '提醒消息:白细胞计数的消息' else ''"true_example = "current_medical_program = '白细胞计数';specimen_type = '全血';medicine_projects = '2';time = 5;"
false_example = "current_medical_program = '白细胞计数';specimen_type = '全血';medicine_projects = '2';time = 8;"
cs = cs_model(true_example, rule)
print(cs.run()) # 预期结果:提醒消息:白细胞计数的消息
cs = cs_model(false_example, rule)
print(cs.run()) # 预期结果:''
-
字典转字符串工具
from textx_tools import dict_to_str
data_dict = { 'current_medical_program': '白细胞计数', 'specimen_type': '全血', 'medicine_projects': '2', 'time': 8, '_list': [1, 2, 3] }
""" 预期结果: "current_medical_program = '白细胞计数';specimen_type = '全血';medicine_projects = '2';time = 8;_list = '[1,2,3]';" """
print(dict_to_str(data_dict))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file textx-model-0.0.5.tar.gz
.
File metadata
- Download URL: textx-model-0.0.5.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfacb21984f8cb6cfd94b3fe5396ff885bf012f12699ed60477172e2b3986775 |
|
MD5 | d423b4cd00dbee2364174b61082b809c |
|
BLAKE2b-256 | 795e1683dc24fc92cc1b12f738986c2d66a6ea4cf1984323d3f845a05a58a210 |