__init__.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # 系统模块
  2. import os # 操作系统特定函数,用于文件路径和环境变量操作
  3. import sys # 系统特定参数和函数,用于访问系统变量和函数
  4. import shutil # 高级文件操作,用于文件和目录的复制、移动和删除
  5. import logging # 日志系统,用于记录程序运行中的日志信息
  6. # import threading # 基于线程的并行处理,用于多线程编程
  7. import uuid # 通用唯一标识符,用于生成唯一的标识符
  8. import re # 正则表达式操作,用于字符串的模式匹配和替换
  9. import json # JSON编码器和解码器,用于JSON数据的处理
  10. import time # 时间相关函数,用于时间和日期的处理
  11. import warnings # 警告控制,用于显示或隐藏警告信息
  12. from time import sleep # 时间相关函数中的睡眠函数,用于线程的暂停
  13. import numpy as np # 数值计算库,用于科学计算和数据分析
  14. import platform # 平台信息,用于获取当前运行平台的信息
  15. import subprocess # 子进程管理,用于在Python中执行外部命令
  16. import tempfile # 临时文件管理,用于创建和管理临时文件
  17. import pandas as pd # 数据分析库,用于数据处理和分析
  18. import logger # 自定义日志库,用于记录程序的日志信息
  19. import pika # RabbitMQ客户端库,用于消息队列的处理
  20. import traceback # 异常跟踪库,用于获取异常的跟踪信息
  21. import random
  22. # 第三方模块
  23. import cv2 # 计算机视觉库,用于图像和视频处理
  24. from PIL import Image # Python图像库,用于图像处理和操作
  25. from datetime import timedelta, datetime, timezone # 日期和时间类,用于日期和时间的处理
  26. from io import BytesIO # 二进制流,用于在内存中处理二进制数据
  27. import markdown # Markdown解析,用于将Markdown文本转换为HTML
  28. # from paddleocr import PaddleOCR # Paddle OCR用于文本识别,用于图像中的文本识别
  29. from requests import RequestException # 请求异常处理,用于处理HTTP请求中的异常
  30. import requests # HTTP请求库,用于发送HTTP请求
  31. from scipy import interpolate # 插值库,用于数据的插值和拟合
  32. import PyPDF2 # PDF处理库,用于PDF文件的读取和写入
  33. import fitz
  34. # 增加 了 spacy
  35. """
  36. ps
  37. 1 安装 框架
  38. pip install spacy
  39. 2 下载 语言
  40. python -m spacy download en_core_web_sm
  41. 3 测试代码
  42. import spacy
  43. import re
  44. nlp_zh = spacy.load('zh_core_web_sm')
  45. def process_mixed_text(text):
  46. doc = nlp_zh(re.sub(re.compile("\t|\n"), '', str(text)))
  47. for token in doc.sents:
  48. if len(token) > 10:
  49. print(token.text,'\r\n')
  50. """
  51. import spacy
  52. """
  53. import nltk
  54. # 下载所有 NLTK 资源
  55. # def download_all_resources():
  56. # 使用代理下载 总包 3 G 左右
  57. # nltk.set_proxy('http://127.0.0.1:7890/')
  58. # nltk.download('all')
  59. def tokenize_english(text):
  60. # 句子分割
  61. sentences = nltk.sent_tokenize(text)
  62. # 单词分割
  63. words = [nltk.word_tokenize(sentence) for sentence in sentences]
  64. return sentences, words
  65. sentences, words = tokenize_english(txt)
  66. for x in sentences:
  67. if re.match(r'^[a-zA-Z]', x):
  68. if len(x.split()) > 10:
  69. print("英文句子分割结果:", x, '\r\n')
  70. elif re.match(r'^[\u4e00-\u9fa5]', x):
  71. if len(x) >= 10:
  72. print("中文句子分割结果:", x, '\r\n')
  73. """
  74. import nltk
  75. logger = logging.getLogger(__name__)
  76. formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s')
  77. ch = logging.StreamHandler()
  78. ch.setFormatter(formatter)
  79. logger.addHandler(ch)
  80. # # 创建一个日志记录器
  81. # logger = logging.getLogger(__name__)
  82. # # 设置日志级别
  83. # logger.setLevel(logging.DEBUG)
  84. # # 配置日志文件
  85. # try:
  86. # file_handler = logging.FileHandler('e:/log.txt')
  87. # file_handler.setLevel(logging.DEBUG)
  88. # file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s'))
  89. # logger.addHandler(file_handler)
  90. # except PermissionError:
  91. # print("Permission denied: 'e:\\log.txt'")
  92. # if 'Paddle_OCR' not in locals():
  93. # # Paddle_OCR = PaddleOCR(use_angle_cls=True, lang="ch", use_gpu=False, det_db_thresh=0.3, det_db_box_thresh=0.3)
  94. # Paddle_OCR= []
  95. __all__ = [
  96. 'cv2', 'os', 'sys', 'shutil', 'logging', 'uuid',
  97. 're', 'json', 'time', 'BytesIO', 'warnings',
  98. 'timedelta', 'datetime', 'timezone', 'Image', 'markdown',
  99. 'sleep', 'RequestException', 'np', 'platform', 'subprocess', 'tempfile','pd','requests','logger',
  100. 'pika','traceback','interpolate','PyPDF2','logger','fitz','spacy','nltk'
  101. ]