__init__.py 4.5 KB

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