This release is a pre-release and may not be stable for production use.
SimpleLabel
simplelabel 是一个使用 Python 编写的工具,它可以根据规则轻松地对文件进行标注,同时也支持根据规则快速生成 SQL 语句。
安装
首先,确保你已经安装了 Python 3.6 或更高版本(推荐Python 3.8及以上)。然后,你可以使用以下命令安装 simplelabel:
pip install simplelabel
命令行使用方法
显示版本信息
如果你想查看 simplelabel 的版本信息,可以使用以下命令:
simplelabel --version
快速完成数据标注
使用 --label 指令可以快速完成数据标注,该指令需要输入规则文件地址和原始待标注的数据文件地址,同时通过 -o 标识指定数据输出地址。示例如下:
simplelabel --label rule_file.csv data_file.csv -o output_labeled_data.csv
快速完成 SQL 语句生成
使用 --generate 指令可以快速完成 SQL 语句生成,该指令需要输入规则文件地址,同时通过 -o 标识指定 SQL 文件输出地址。示例如下:
simplelabel --generate rule_file.csv -o output_sql.txt
Python 使用方法
simplelabel 也提供了 Python API,你可以使用以下代码来完成数据标注和 SQL 语句生成:
from simplelabel import FieldMap, FieldsIdentifier
from simplelabel import DataLabelEngine, SQLGenerator
if __name__ == '__main__':
rule_file_path = 'data/rules_zfb.csv'
bill_file_path = 'data/bills_zfb.csv'
labeled_file_path = 'data/bills_zfb_labeled.csv'
sql_file_path = 'data/bills_zfb_sql.sql'
field_map = FieldMap(
field1='筛选字段1',
condition1='筛选条件1',
keyword1='关键字1',
logic='关联条件',
field2='(可选)筛选字段2',
condition2='(可选)筛选条件2',
keyword2='(可选)关键字2',
label='账单类别'
)
# 根据规则标注数据
label_engine = DataLabelEngine.init(rule_file_path, field_map)
label_engine.label(bill_file_path, labeled_file_path)
field_identifier = FieldsIdentifier({
'业务类型': 'yw_type',
'业务描述': 'yw_desc',
'备注': 'remark'
}).init()
# 根据规则生成 SQL 语句
sql_generator = SQLGenerator.init(rule_file_path, field_map)
sql_generator.generate(sql_file_path, field_identifier)
代码解读
FieldMap类用于定义规则文件中的列名映射关系,包括筛选字段、筛选条件、关键字、关联条件、筛选字段2、筛选条件2、关键字2和账单类别等。
# 默认列名映射关系
# DEFAULT_FIELD_MAP
field1='筛选字段1',
condition1='筛选条件1',
keyword1='关键字1',
logic='关联条件',
field2='(可选)筛选字段2',
condition2='(可选)筛选条件2',
keyword2='(可选)关键字2',
label='账单类别'
FieldsIdentifier类用于定义需标注数据的字段标识和字段名称的对应关系,包括业务类型、业务描述和备注等。DataLabelEngine类用于根据规则对数据进行标注,包括初始化规则、数据标注和输出标注结果等方法。SQLGenerator类用于根据规则生成 SQL 语句,包括初始化规则、生成SQL语句和输出SQL文件等方法。
在上述代码中,rule_file_path 是标注规则文件路径,bill_file_path 是原始待标注的数据文件路径,labeled_file_path 是标注后的数据文件路径,sql_file_path 是 SQL 语句文件路径。
我们首先实例化 FieldMap 对象,接着使用 DataLabelEngine 类根据标注规则对原始数据进行标注,输出标注结果文件,最后使用 SQLGenerator 类生成 SQL 语句,输出SQL文件。
Metadata
Release files for simplelabel 1.3.0b0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simplelabel-1.3.0b0-py3-none-any.whl | Python 3 | none | any | Details for simplelabel-1.3.0b0-py3-none-any.whl |
Release files / simplelabel-1.3.0b0-py3-none-any.whl
| Download URL | simplelabel-1.3.0b0-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9df7c5160cf2b5d38dc1edc69a3a0cff1e70107e245f82b815f213d9588bcf2c
|
|
BLAKE2b-256 checksum How to use checksums |
1371b228c9f6fce58d3a36fda4010a387e03c66187dceefab4c8bf6136664ab6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for simplelabel 1.3.0b0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.