# -*- coding:utf-8 -*-
import re '''
适应新版本 注意:
1)17A文件改完后缀后,需要转为UTF-8无BOM格式,才能正确处理。
2)fr = open(filename,encoding='utf-8') ''' year='17A'#用户自定义
ss='./data/'#根目录
filename = ss+'UNCL%s.txt'%year#输入文件名 def tncl_note(): p4= r"^(?:\s{5}|X\s{4}|\W\s{4})(\w+)\s+\w.+\n"
p1 = r"^(?:\s{5}|X\s{4}|\W\s{4})(\d\d\d\d)\s\s[A-Z].+\]$"#匹配tncl_id
p2 = r"^(?:\s{5}|X\s{4}|\W\s{4})(\w+)\s+\w.+\n"#匹配tncl_tag
p3 = r"^(?:\s{5}|X\s{4}|\W\s{4})\w+\s+(\w.+)\n"#匹配tncl_name
p4 = r"^\s{14}([^ ].+)\n"#匹配tncl_desc和#Note内容 p5 = r"^\s{11}Note:\s\n"#Note pattern1 = re.compile(p1)
pattern2 = re.compile(p2)
pattern3 = re.compile(p3)
pattern4 = re.compile(p4) pattern5 = re.compile(p5) fr = open(filename,encoding='utf-8')
temp = str();
flag = 0
w2 = open(ss+'tncl_ori%s.txt'%year,'a')#a代表追加 w代表重写
flag1=0
for line in fr.readlines():
matcher1 = re.findall(pattern1,line)
matcher2 = re.findall(pattern2,line)
matcher3 = re.findall(pattern3,line)
matcher4 = re.findall(pattern4,line)
matcher5 = re.findall(pattern5,line) #print matcher if matcher1:
for g in matcher1:
flag = 1
temp = g continue;
if matcher2 and(flag==1 or 4)and(temp!=''): flag = 2
w2.write("\"\n"+temp+",")
for j in matcher2:
for k in j:
w2.write(k) if matcher3 and flag==2:
flag = 3
w2.write(",")
for j in matcher3:
for k in j:
w2.write(k)
w2.write(",\"")
if matcher4 and (flag==3 or flag==4):
flag=4
for j in matcher4:
for k in j:
w2.write(k) if ((matcher5!=[])and(flag == 4)):
# flag = 5
w2.write("\",\"")
# flag1=1 w2.write("\"")
w2.close( )
def join(): f1= open(ss+'tncl_ori%s.txt'%year) list_note=[]
for line1 in f1:
# print(line1) list_note.append(line1) f1.close()
# print(list_note[1].split(','))
# print("%s_%s,%s\n"%(list_note[1].split(',')[0],list_note[1].split(',')[1],list_note[1].strip('\n')))
# list_note[i].strip('\n')
# print(list_note)
f2_w1= open(ss+'tred%s.csv'%year,'a')
f2_w2= open(ss+'b4_%s.csv'%year,'a')
# for i in range(len(list_note)):
# i=0 for i in range(1,len(list_note)): str11="%s_%s,%s\n"%(list_note[i].split(',')[0],list_note[i].split(',')[1],list_note[i].strip('\n')) str12="%s_%s,%s,%s\n"%(list_note[i].split(',')[0],list_note[i].split(',')[1],list_note[i].split(',')[1],year)
f2_w1.write(str11)
f2_w2.write(str12) f2_w1.close()
f2_w2.close()
# f2.close() if __name__ == '__main__': tncl_note()
join()

b4和tncl_extract_UNCL_new的更多相关文章

  1. Google数据中心B4网络具体实现

    ① 背景介绍 Google的网络有两种,一种是数据中心内部网络,另外一种是WAN网,其中WAN网又分为两种:一是数据中心之间的互联网络,属于内部网络(G-Scale Network),另外一种是面向I ...

  2. B4 and After: Managing Hierarchy, Partitioning, and Asymmetry for Availability and Scale in Google’s Sofware-Defined WAN

    B4及之后:为谷歌软件定义WAN的可用性和扩展管理层次化.划分和不对称 本文为SIGCOMM 2018会议论文,由谷歌提供. 笔者翻译了该论文.由于时间仓促,且笔者英文能力有限,错误之处在所难免:欢迎 ...

  3. Google B4网络阅读记录(翻译)

    3.设计 这一章我们描述软件定义广域网架构的细节. 3.1.概述 我们的软件定义网络从逻辑上可以看做三层,如图所示, B4服务于多个广域网节点,每个节点都有很多服务器集群.在每个B4节点内,交换机硬件 ...

  4. [转帖]B4. Concurrent JVM 锁机制(synchronized)

    B4. Concurrent JVM 锁机制(synchronized) https://www.cnblogs.com/zlxyt/p/11050346.html 挺好的 感觉这个文章写的 不过想要 ...

  5. Python小白的数学建模课-B4. 新冠疫情 SIR模型

    Python小白的数学建模课-B4. 新冠疫情 SIR模型 传染病的数学模型是数学建模中的典型问题,常见的传染病模型有 SI.SIR.SIRS.SEIR 模型. SIR 模型将人群分为易感者(S类). ...

  6. 【MYSQL】MYSQL报错解决方法: Warning: (3719, "'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8M B4 in a future release."

    用python3.6.5创建mysql库时出现如下报错,虽然报错,但是数据库可以插入成功. D:\python3\lib\site-packages\pymysql\cursors.py:170: W ...

  7. 第十章 优先级队列 (b4)完全二叉堆:批量建堆

  8. 第八章 高级搜索树 (b4)B-树: 插入

  9. b4

    吴晓晖(组长) 过去两天完成了哪些任务 昨天FloatingActionButton和权限获取调整 今天复习,没写东西,晚点有空了写 展示GitHub当日代码/文档签入记录 接下来的计划 推荐算法 还 ...

随机推荐

  1. LESS CSS 实例

    值得参考的 10 个 LESS CSS 实例   2 收藏(185) LESS, Sass 和其他 CSS 预处理器是一种超棒的方法用来扩展 CSS 功能,使之更适合程序员.你可以使用变量.函数.混合 ...

  2. Unified shader model

    https://en.wikipedia.org/wiki/Unified_shader_model In the field of 3D computer graphics, the Unified ...

  3. spring中作用域的问题

    在一般情况下:我们登录系统时,第一次登录当用户名或密码输入错误,在登录页面给出错误原因,当我们再刷新登录页面,应该是首次登录系统的页面(这时就不应该再给出出错提示),这时我们就应该想到错误提示信息到底 ...

  4. node集成mysql——pool连接池

    安装 mysql npm install mysql or cnpm install mysql 创建db.js,实现mysql操作模块 var mysql = require('mysql'); v ...

  5. 域名相关:DNS A记录 NS记录 MX记录 CNAME记录

    1. DNSDNS:Domain Name System 域名管理系统 域名是由圆点分开一串单词或缩写组成的,每一个域名都对应一个惟一的IP地址,这一命名的方法或这样管理域名的系统叫做域名管理系统.D ...

  6. oracle以逗号分隔查询结果列表

    select wmsys.wm_concat(id) from table_name where id >= 5000 and id < 6000

  7. Spring简单获得实体类的实例, 使用ApplicationContext()方法的几点注意事项

    今天接触了Spring的初步用法, 感觉跟实例化实体类没啥区别, 像这种简单的代码还不如直接实例化来的方便, 这样使用Spring的话总共需要三个文件 第一个当然是一个实体类了, 定义好属性, get ...

  8. 第六章 图(b1)邻接矩阵

  9. Spring声明式事务管理(基于注解方式实现)

    ----------------------siwuxie095                                 Spring 声明式事务管理(基于注解方式实现)         以转 ...

  10. Ubuntu-18.04Python2与Python3自由切换

    一.配置ssh链接 安装openssh-server devops@devops-virtual-machine:~$ sudo apt-get install openssh-server 二.安装 ...