Use python to repair RIS keyword format for vosviewer to do literature analysis

Document Analysis

application background

(60 messages) How to analyze CNKI data with VOSviewer? _nkwshuyi's blog-CSDN blog
(60 messages) How to use VOSviewer to analyze CNKI keyword co-occurrence? _nkwshuyi's Blog - CSDN Blog

Code

import re
import os
input= r'E:\Alark\Desktop'
os.chdir(input)
file='RISsample.txt'
output="RIS参考文献.txt"
if output in set(os.listdir()):
    os.remove(output)
f=open(file, 'r',encoding='utf-8')
#UTF-8-BOM格式要转化为utf8
#with open() as f:
f2=open(output,'w')
flag=0
for line in f:
    #f.readlines()
    print(line)
    if flag==0:
        if re.search('KW  - ', line)!=None:
            flag = 1
            continue
        else:
            f2.write(line)
    if flag==1:
        if re.search('-', line)!=None or line=='\n':
            flag=0
            f2.write(line)
        else:
            line='KW  - '+line
            f2.write(line)
f.close()
f2.close()

Guess you like

Origin blog.csdn.net/qq_37639139/article/details/123686818