You've already forked DataMate
init datamate
This commit is contained in:
6
runtime/ops/mapper/emoji_cleaner/__init__.py
Normal file
6
runtime/ops/mapper/emoji_cleaner/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datamate.core.base_op import OPERATORS
|
||||
|
||||
OPERATORS.register_module(module_name='EmojiCleaner',
|
||||
module_path="ops.mapper.emoji_cleaner.process")
|
||||
16
runtime/ops/mapper/emoji_cleaner/metadata.yml
Normal file
16
runtime/ops/mapper/emoji_cleaner/metadata.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
name: '文档表情去除'
|
||||
name_en: 'Emoticon Removal'
|
||||
description: '去除文档中表情字符或者emoji符号。'
|
||||
description_en: 'Removes emoticons or emojis from documents.'
|
||||
language: 'python'
|
||||
vendor: 'huawei'
|
||||
raw_id: 'EmojiCleaner'
|
||||
version: '1.0.0'
|
||||
types:
|
||||
- 'cleanse'
|
||||
modal: 'text'
|
||||
effect:
|
||||
before: '使用方式很简单,只需要将代码放入Markdown文本中即可,富文本格式可直接复制表情😀使用。'
|
||||
after: '使用方式很简单,只需要将代码放入Markdown文本中即可,富文本格式可直接复制表情使用。'
|
||||
inputs: 'text'
|
||||
outputs: 'text'
|
||||
27
runtime/ops/mapper/emoji_cleaner/process.py
Normal file
27
runtime/ops/mapper/emoji_cleaner/process.py
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
"""
|
||||
Description: 文档表情去除
|
||||
Create: 2023/12/7 15:43
|
||||
"""
|
||||
import time
|
||||
from typing import Dict, Any
|
||||
|
||||
import emoji
|
||||
from loguru import logger
|
||||
|
||||
from datamate.core.base_op import Mapper
|
||||
|
||||
|
||||
class EmojiCleaner(Mapper):
|
||||
@staticmethod
|
||||
def _emoji_filter(input_data: str):
|
||||
res = []
|
||||
for input_s in input_data.split('\n'):
|
||||
res.append(emoji.replace_emoji(input_s, replace=''))
|
||||
return '\n'.join(res)
|
||||
|
||||
def execute(self, sample: Dict[str, Any]) -> Dict[str, Any]:
|
||||
start = time.time()
|
||||
sample[self.text_key] = self._emoji_filter(sample[self.text_key])
|
||||
logger.info(f"fileName: {sample[self.filename_key]}, method: EmojiCleaner costs {time.time() - start:6f} s")
|
||||
return sample
|
||||
Reference in New Issue
Block a user