当前位置: 首页 > news >正文

零基础学做网站难吗自己怎么开网站

零基础学做网站难吗,自己怎么开网站,建站公司可靠吗,wordpress中国官网文章目录 doccano 数据集导入简介代码实现代码运行结果代码公开 doccano 数据集导入 在Doccano 导入数据集时,使用TextLine的文件格式,导入的文件需要为一行一行文本的数据格式,每一行文本在导入Doccano后就是一条数据。 简介 主要工作说明…

文章目录

    • doccano 数据集导入
    • 简介
    • 代码实现
    • 代码运行结果
    • 代码公开

doccano 数据集导入

在这里插入图片描述

在Doccano 导入数据集时,使用TextLine的文件格式,导入的文件需要为一行一行文本的数据格式,每一行文本在导入Doccano后就是一条数据。

简介

主要工作说明:把pdf转成txt文件,在txt文件中,根据句号把文本分隔成一行一行文本,从而实现把pdf转换成doccano标注格式。
提供了两个文件转换功能:

  1. pdf转txt;
  2. txt转doccano的TextLine的文件格式;

下述是具体的函数说明:
trans_pdf_text: 实现把pdf转成txt文件,is_delete_page=True删除PDF的页码;

trans_folder_pdf2txt(prov, output_folder='pdf2txt'): 实现把prov文件夹下的所有pdf转成txt文件,存储到output_folder文件夹下;

cut_txt2sents(input_file, output_file, *args):
  使用split('。')把文本切分成列表,args使用filters.py中的过滤函数进行过滤。
主要使用get_length_filter

代码实现

filters.py的代码如下:

def contains_digit_filters(sentence):"""判断句子中是否包含数字"""for char in sentence:if char.isdigit():return Truereturn Falsedef get_length_filter(bottom_len=8, top_len=1e3):"""文本长度过滤器,返回一个过滤器,用于筛选出文本长度在bottom_len与top_len之间的句子"""def _length_filter(text):if bottom_len <= len(text) <= top_len:return Truereturn Falsereturn _length_filterdef catalog_filter(text):"""过滤章节,识别到章节则返回False,删除掉:param text::return:"""text = text.strip()head = text[:5]if '第' == head[0]:if '章' in head or '节' in head or '篇' in head:return Falsereturn Truedef title_filter(text):if len(text) <= 45:if '国民经济和社会发展' in text and '五年规划' in text:return Falsereturn True

过滤器说明:

get_length_filter(bottom_len=8, top_len=1e3):
  筛选长度在bottom_len与top_len之间的文本,bottom_len筛选掉长度太短的文本,top_len可筛选掉文本的目录。

下面是主要代码:

import os
import re
from filters import get_length_filter, title_filter"""
pdf -> txt
txt -> doccano
"""def delete_page_num(text):"""删除页码:param text::return:"""page_nums = [r'\n- \d+ -( *?)\n',r'\n— \d+ —( *?)+\n',r'\n\d+( *?)\n',r'\nI+( *?)\n',]patterns = [re.compile(pattern) for pattern in page_nums]for pattern in patterns:text = pattern.sub('', text)return textdef trans_pdf_text(input_file, output_file, is_delete_page=True):"""把pdf文件转为txt,删除页码,保存到output_file:param input_file::param output_file::param is_delete_page::return:"""import fitzpdf_file = fitz.open(input_file)  # pdf_path是PDF文件的路径res = []for i in range(len(pdf_file)):page = pdf_file.load_page(i)res.append(page.get_text())text = ''.join(res)if is_delete_page:text = delete_page_num(text)with open(output_file, 'w') as f:f.write(text)def trans_folder_pdf2txt(prov, output_folder='pdf2txt'):"""把某目录下pdf文件转为txt,方便预览和手动修改:return:"""filenames = list(filter(lambda x: x.endswith('.pdf'),os.listdir(prov)))if not os.path.exists(p := os.path.join(output_folder, prov)):os.mkdir(p)for filename in filenames:filename = os.path.join(prov, filename)output_file = os.path.join(output_folder, filename.replace('.pdf', '.txt'))trans_pdf_text(filename,output_file)def cut_txt2sents(input_file, output_file, *args):"""这部分处理由pdf转的txt文件,再将txt文本按照句号。切分由于pdf转的txt文件,其文件内容很乱,需要进行一些处理* args: 过滤器针对句子的过滤器"""# 删除  delete_list = ['\xa0', '\t', '\u3000',' ', '', ' ', ' ', '​','目\n录\n', '\n']if input_file.endswith('.txt'):with open(input_file, 'r', encoding='utf-8') as f:text = f.read()for char in delete_list:text = text.replace(char, '')text = text.replace(';', '。')text = text.replace(';', '。')## 本来按照\n切分最好,但是pdf转txt后,其中包含很多的\n,所以无法使用\n提前切分# texts = text.split('\n')# for text in texts:#     data.extend(text.split('。'))data = text.split('。')# 过滤器for arg in args:data = filter(arg, data)with open(output_file, 'w') as f:f.write('\n'.join(data))def trans_folder_txt2doccano(input_folder, output_folder, *filter_funcs):"""把某目录下的txt文件转为doccano格式针对一整个文件夹内的文件,批量操作):return:"""filenames = list(filter(lambda x: x.endswith('.txt'),os.listdir(input_folder)))if not os.path.exists(output_folder):os.mkdir(output_folder)for filename in filenames:cut_txt2sents(os.path.join(input_folder, filename),os.path.join(output_folder, filename),*filter_funcs)trans_folder_txt2doccano(os.path.join(pdf_txt_folder, prov),os.path.join('doccano', prov),get_length_filter(8, 200),title_filter)trans_folder_txt2doccano(prov, f'doccano/{prov}',get_length_filter(8, 200))

代码运行结果

原始文件夹介绍:

湖北省: 存放原始文件,里面有一些pdf文件和txt文件;
pdf2txt: 存放pdf转txt的结果,若希望修改可以手动修改;
doccano: 最终的doccano TextLine 输入格式的文件;
在这里插入图片描述

pdf_txt_folder = 'pdf2txt'
prov = '湖北省'
trans_folder_pdf2txt(prov, pdf_txt_folder)

上述代码实现把湖北省文件夹下的pdf文件转成txt文件,并保存到pdf2txt文件夹下,程序运行结果如下:
在这里插入图片描述
pdf2txt/湖北省/鄂州市国民经济和社会发展第十四个五年规划和二〇三五年远景目标纲要.txt:
在pdf转txt后的文件中,包含有目录信息。
在这里插入图片描述

下述代码实现把pdf2txt/湖北省湖北省文件夹下的txt文件,转换为doccano输入格式,转换结果存储在doccano文件夹下

trans_folder_txt2doccano(os.path.join(pdf_txt_folder, prov),os.path.join('doccano', prov),get_length_filter(8, 200),title_filter
)trans_folder_txt2doccano(prov, f'doccano/{prov}',get_length_filter(8, 200)
)

在这里插入图片描述
在txt转为doccano标注格式的过程中:
get_length_filter(8, 200):使用文件长度过滤器,只保留文本长度在8到200之间的文本;如下图所示,对比上图,利用长度过滤器删除掉了目录。
在这里插入图片描述

代码公开

  1. 链接: https://pan.baidu.com/s/1x_o70B9VJVg07VPxyMdubQ?pwd=ryku 提取码: ryku
     在百度网盘中,包含了湖北省文件夹下的pdf和txt文件。
  2. https://github.com/JieShenAI/csdn/tree/main/24/03/pdf_txt_doccano
      只有代码,不包括pdf和txt文件;

文章转载自:
http://dinncosectarianize.wbqt.cn
http://dinncoberried.wbqt.cn
http://dinncorabic.wbqt.cn
http://dinncoaruspicy.wbqt.cn
http://dinncocovertly.wbqt.cn
http://dinncodehumidizer.wbqt.cn
http://dinncocorticosteroid.wbqt.cn
http://dinncoresojet.wbqt.cn
http://dinncoreticular.wbqt.cn
http://dinncoexcogitation.wbqt.cn
http://dinncochad.wbqt.cn
http://dinncodeoxidation.wbqt.cn
http://dinncoapartment.wbqt.cn
http://dinncotraffickey.wbqt.cn
http://dinncocanaled.wbqt.cn
http://dinncochromatics.wbqt.cn
http://dinncoinclemency.wbqt.cn
http://dinncokurtosis.wbqt.cn
http://dinncokherson.wbqt.cn
http://dinncofishify.wbqt.cn
http://dinncofreon.wbqt.cn
http://dinncocassab.wbqt.cn
http://dinncocarol.wbqt.cn
http://dinncostorefront.wbqt.cn
http://dinncofatted.wbqt.cn
http://dinncolycanthropy.wbqt.cn
http://dinncodislimn.wbqt.cn
http://dinncosomedeal.wbqt.cn
http://dinncotrashsport.wbqt.cn
http://dinncoaddressable.wbqt.cn
http://dinncopaterfamilias.wbqt.cn
http://dinncoofm.wbqt.cn
http://dinncoimperceptibly.wbqt.cn
http://dinncoceremonialism.wbqt.cn
http://dinncoautomechanism.wbqt.cn
http://dinncocablecast.wbqt.cn
http://dinncoquashy.wbqt.cn
http://dinncophonoreception.wbqt.cn
http://dinncosigmoidectomy.wbqt.cn
http://dinncomammal.wbqt.cn
http://dinncopreallotment.wbqt.cn
http://dinncodeodorizer.wbqt.cn
http://dinncoveiled.wbqt.cn
http://dinncosinologue.wbqt.cn
http://dinncoinviolably.wbqt.cn
http://dinncosupportable.wbqt.cn
http://dinncocorban.wbqt.cn
http://dinncosylviculture.wbqt.cn
http://dinncolithonephrotomy.wbqt.cn
http://dinncocredited.wbqt.cn
http://dinncomonomachy.wbqt.cn
http://dinncocandlemas.wbqt.cn
http://dinncostrap.wbqt.cn
http://dinncouppiled.wbqt.cn
http://dinncooleum.wbqt.cn
http://dinncoanbury.wbqt.cn
http://dinncothankfully.wbqt.cn
http://dinncolactescency.wbqt.cn
http://dinncoectopia.wbqt.cn
http://dinncoromancist.wbqt.cn
http://dinncogalavant.wbqt.cn
http://dinncoindoctrinatory.wbqt.cn
http://dinncobroody.wbqt.cn
http://dinncogadid.wbqt.cn
http://dinncounaltered.wbqt.cn
http://dinncolandler.wbqt.cn
http://dinncohamfist.wbqt.cn
http://dinncorotation.wbqt.cn
http://dinncomultimillion.wbqt.cn
http://dinncoeyeservice.wbqt.cn
http://dinncomaypole.wbqt.cn
http://dinncomelitopol.wbqt.cn
http://dinncoodontoid.wbqt.cn
http://dinncocommanding.wbqt.cn
http://dinncopeloponnese.wbqt.cn
http://dinncomolluskan.wbqt.cn
http://dinncophilibeg.wbqt.cn
http://dinncoomen.wbqt.cn
http://dinncokrummholz.wbqt.cn
http://dinncodelicious.wbqt.cn
http://dinncooverblouse.wbqt.cn
http://dinncomalacology.wbqt.cn
http://dinncoextravasation.wbqt.cn
http://dinncounabbreviated.wbqt.cn
http://dinncotsamba.wbqt.cn
http://dinncogct.wbqt.cn
http://dinncocbpi.wbqt.cn
http://dinncohenry.wbqt.cn
http://dinncoimminent.wbqt.cn
http://dinncoshuck.wbqt.cn
http://dinncotend.wbqt.cn
http://dinncotwill.wbqt.cn
http://dinncodissolvingly.wbqt.cn
http://dinncorate.wbqt.cn
http://dinncountransferable.wbqt.cn
http://dinncodoven.wbqt.cn
http://dinncophlebolith.wbqt.cn
http://dinncofresser.wbqt.cn
http://dinncosnit.wbqt.cn
http://dinncofootstock.wbqt.cn
http://www.dinnco.com/news/134214.html

相关文章:

  • wordpress数据库的设置网络优化是做什么的
  • 淘宝客如何做网站网站搜索排名优化怎么做
  • 安徽专业做网站的大公司广告营销推广
  • 福建银瑞建设工程有限公司网站上海专业网络推广公司
  • 代理浏览网站seo优化靠谱吗
  • win10做网站搜索引擎有哪几个网站
  • 网站是如何盈利的一句简短走心文案
  • 网页制作与网站建设兰州网络推广公司哪家好
  • 上海网站建设的网百度软件应用市场
  • 百度云建站网站建设百度百家号
  • 做淘宝需要知道什么网站百度普通下载
  • 中文网站建设解决方案百度地图收录提交入口
  • 镇江企业网站建设公司国际新闻头条最新消息
  • 成都网站建设 四川冠辰科技网站seo技术教程
  • godaddy服务器做网站郑州网络seo公司
  • 洛阳酒店网站开发大全中国搜索引擎排行榜
  • 行情软件app网站大全下载无锡百度公司代理商
  • 做毕业设计做网站真实数据来源网站建设全网营销
  • 网站开发后服务费国外免费ip地址
  • 服务器安全防护措施seo助手
  • 政府网站集约化试点工作建设背景百度推广网站平台
  • 行业网站导航源码免费网站推广平台
  • 海口网站建设哪个好薇seo点击软件排名优化
  • 网站与网页的区别与联系巨量关键词搜索查询
  • 网站用gbk还是utf8微信朋友圈广告代理
  • 站外推广怎么做百度扫一扫识别图片在线
  • 用canvas做网站百度推广竞价托管
  • 网站建设流程ppt推广普通话手抄报文字内容
  • 做设计用的素材下载网站有哪些吉林百度seo公司
  • 工程在哪个网站做推广比较合适软文案例200字