You've already forked DataMate
init datamate
This commit is contained in:
6
runtime/ops/mapper/traditional_chinese/__init__.py
Normal file
6
runtime/ops/mapper/traditional_chinese/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datamate.core.base_op import OPERATORS
|
||||
|
||||
OPERATORS.register_module(module_name='TraditionalChineseCleaner',
|
||||
module_path="ops.mapper.traditional_chinese.process")
|
||||
16
runtime/ops/mapper/traditional_chinese/metadata.yml
Normal file
16
runtime/ops/mapper/traditional_chinese/metadata.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
name: '繁体转简体'
|
||||
name_en: 'Traditional-Simplified Chinese Conversion'
|
||||
description: '将繁体转换为简体。'
|
||||
description_en: 'Converts traditional Chinese characters to simplified Chinese characters.'
|
||||
language: 'python'
|
||||
vendor: 'huawei'
|
||||
raw_id: 'TraditionalChineseCleaner'
|
||||
version: '1.0.0'
|
||||
types:
|
||||
- 'cleanse'
|
||||
modal: 'text'
|
||||
effect:
|
||||
before: '華為的業務涵蓋了從通信設備到智能手機、企業網絡解決方案以及雲計算等多個領域。'
|
||||
after: '华为的业务涵盖了从通信设备到智能手机、企业网络解决方案以及云计算等多个领域。'
|
||||
inputs: 'text'
|
||||
outputs: 'text'
|
||||
33
runtime/ops/mapper/traditional_chinese/process.py
Normal file
33
runtime/ops/mapper/traditional_chinese/process.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/user/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Description: 繁体转简体
|
||||
Create: 2025/01/15
|
||||
"""
|
||||
import time
|
||||
from typing import Dict, Any
|
||||
|
||||
from zhconv import convert
|
||||
from loguru import logger
|
||||
|
||||
from datamate.core.base_op import Mapper
|
||||
|
||||
|
||||
class TraditionalChineseCleaner(Mapper):
|
||||
"""繁体转简体过滤插件"""
|
||||
|
||||
@staticmethod
|
||||
def _traditional_chinese_filter(input_data: str):
|
||||
""" 繁体转简体"""
|
||||
res = []
|
||||
for input_str in input_data.split('\n'):
|
||||
res.append(convert(input_str, 'zh-hans'))
|
||||
return '\n'.join(res)
|
||||
|
||||
def execute(self, sample: Dict[str, Any]) -> Dict[str, Any]:
|
||||
start = time.time()
|
||||
sample[self.text_key] = self._traditional_chinese_filter(sample[self.text_key])
|
||||
logger.info(
|
||||
f"fileName: {sample[self.filename_key]}, method: TraditionalChinese costs {time.time() - start:6f} s")
|
||||
return sample
|
||||
Reference in New Issue
Block a user