123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import os # 操作系统特定函数,用于文件路径和环境变量操作
- import sys # 系统特定参数和函数,用于访问系统变量和函数
- import shutil # 高级文件操作,用于文件和目录的复制、移动和删除
- import logging # 日志系统,用于记录程序运行中的日志信息
- # import threading # 基于线程的并行处理,用于多线程编程
- import uuid # 通用唯一标识符,用于生成唯一的标识符
- import re # 正则表达式操作,用于字符串的模式匹配和替换
- import json # JSON编码器和解码器,用于JSON数据的处理
- import time # 时间相关函数,用于时间和日期的处理
- import warnings # 警告控制,用于显示或隐藏警告信息
- from time import sleep # 时间相关函数中的睡眠函数,用于线程的暂停
- import numpy as np # 数值计算库,用于科学计算和数据分析
- import platform # 平台信息,用于获取当前运行平台的信息
- import subprocess # 子进程管理,用于在Python中执行外部命令
- import tempfile # 临时文件管理,用于创建和管理临时文件
- import pandas as pd # 数据分析库,用于数据处理和分析
- import logger # 自定义日志库,用于记录程序的日志信息
- import pika # RabbitMQ客户端库,用于消息队列的处理
- import traceback # 异常跟踪库,用于获取异常的跟踪信息
- import random
- # 第三方模块
- import cv2 # 计算机视觉库,用于图像和视频处理
- from PIL import Image # Python图像库,用于图像处理和操作
- from datetime import timedelta, datetime, timezone # 日期和时间类,用于日期和时间的处理
- from io import BytesIO # 二进制流,用于在内存中处理二进制数据
- import markdown # Markdown解析,用于将Markdown文本转换为HTML
- # from paddleocr import PaddleOCR # Paddle OCR用于文本识别,用于图像中的文本识别
- from requests import RequestException # 请求异常处理,用于处理HTTP请求中的异常
- import requests # HTTP请求库,用于发送HTTP请求
- from scipy import interpolate # 插值库,用于数据的插值和拟合
- import PyPDF2 # PDF处理库,用于PDF文件的读取和写入
- import fitz
- # 增加 了 spacy
- """
- ps
- 1 安装 框架
- pip install spacy
- 2 下载 语言
- python -m spacy download en_core_web_sm
- 3 测试代码
- import spacy
- import re
- nlp_zh = spacy.load('zh_core_web_sm')
- def process_mixed_text(text):
- doc = nlp_zh(re.sub(re.compile("\t|\n"), '', str(text)))
- for token in doc.sents:
- if len(token) > 10:
- print(token.text,'\r\n')
- """
- import spacy
- """
- import nltk
- # 下载所有 NLTK 资源
- # def download_all_resources():
- # 使用代理下载 总包 3 G 左右
- # nltk.set_proxy('http://127.0.0.1:7890/')
- # nltk.download('all')
- def tokenize_english(text):
- # 句子分割
- sentences = nltk.sent_tokenize(text)
- # 单词分割
- words = [nltk.word_tokenize(sentence) for sentence in sentences]
- return sentences, words
- sentences, words = tokenize_english(txt)
- for x in sentences:
- if re.match(r'^[a-zA-Z]', x):
- if len(x.split()) > 10:
- print("英文句子分割结果:", x, '\r\n')
- elif re.match(r'^[\u4e00-\u9fa5]', x):
- if len(x) >= 10:
- print("中文句子分割结果:", x, '\r\n')
- """
- import nltk
- logger = logging.getLogger(__name__)
- formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s')
- ch = logging.StreamHandler()
- ch.setFormatter(formatter)
- logger.addHandler(ch)
- # # 创建一个日志记录器
- # logger = logging.getLogger(__name__)
- # # 设置日志级别
- # logger.setLevel(logging.DEBUG)
- # # 配置日志文件
- # try:
- # file_handler = logging.FileHandler('e:/log.txt')
- # file_handler.setLevel(logging.DEBUG)
- # file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s'))
- # logger.addHandler(file_handler)
- # except PermissionError:
- # print("Permission denied: 'e:\\log.txt'")
-
- # if 'Paddle_OCR' not in locals():
- # # Paddle_OCR = PaddleOCR(use_angle_cls=True, lang="ch", use_gpu=False, det_db_thresh=0.3, det_db_box_thresh=0.3)
- # Paddle_OCR= []
- __all__ = [
- 'cv2', 'os', 'sys', 'shutil', 'logging', 'uuid',
- 're', 'json', 'time', 'BytesIO', 'warnings',
- 'timedelta', 'datetime', 'timezone', 'Image', 'markdown',
- 'sleep', 'RequestException', 'np', 'platform', 'subprocess', 'tempfile','pd','requests','logger',
- 'pika','traceback','interpolate','PyPDF2','logger','fitz','spacy','nltk'
- ]
|