基于规则嵌入的论文比对系统——创新实训记录9

6-23 词云可视化
对不同年份、不同会议的论文关键词进行词云可视化。

创新实训记录9

  • 数据预处理
  • 可视化

数据预处理

首先根据数据集生成所需要的年份列表、会议列表、关键词列表。

# 年份列表
file_years = 'D:/大学资料/大三下/项目实训/code+data/ACM数据集/years.txt'
fyears = open(file_years,'r')
years = []
for line in fyears:
    year = line.strip()
    years.append(year)
print(len(years))

# 会议列表
file_venues = 'D:/大学资料/大三下/项目实训/code+data/ACM数据集/venues.txt'
fvenues = open(file_venues,'r')
venues = []
for line in fvenues:
    venue = line.strip()
    venues.append(venue)
print(len(venues))


# 关键词列表
key_path = 'D:/大学资料/大三下/项目实训/code+data/ACM数据集/keywords.txt'
key_file = open(key_path,'r')
word_list =[]
for line in key_file:
    word = line.strip().split()
    word_list.append(word)
print(len(word_list))   

然后根据年份会议找到对应的论文的关键词,并对其进行统计。可视化的数据是一个list,其中每一个元素是一个元组(‘keyword’,185)的形式。

 # 定义根据年份会议获取数据的函数   
def getData(year,venue):
    word_dict = {} #某年某个关键词出现的次数统计
    use_data = [] #可视化时传入的data
    yea = str(year) #将输入的年份转为str
    venu = str(venue)
    for i in range(len(years)):
        if yea == years[i].strip() and venu == venues[i].strip():
            sword = word_list[i]
            for word in sword:
                if word in word_dict.keys() and word is not '':
                    word_dict[word]+=1
                elif word is not '':
                    temp = { }
                    temp[word]=1
                    word_dict.update(temp)
                else:
                    continue
    # 对word_dict进行处理,筛选词语
    length = len(word_dict)
    if length>60:
        for k,v in word_dict.items():
            if v>1:
                tup = (k,v)
                use_data.append(tup)
    else:
        for k,v in word_dict.items():
            tup = (k,v)
            use_data.append(tup)
    return use_data

可视化

定义可视化函数,参数为年份和会议,返回一个pyecharts对象。

from pyecharts import options as opts
from pyecharts.charts import WordCloud
 
def getWordClo(year,venue):
    wtitle  = str(year)+' '+venue+':关键词词云展示'
    data = getData(year,venue)
    print(len(data))
    mywordcloud = WordCloud()
    mywordcloud.add('',data,shape='triangle')\
               .set_global_opts(title_opts=opts.TitleOpts(
                               title=wtitle))
    return mywordcloud

我们调用函数看一下效果。
基于规则嵌入的论文比对系统——创新实训记录9_第1张图片
基于规则嵌入的论文比对系统——创新实训记录9_第2张图片

你可能感兴趣的:(基于规则嵌入的论文比对系统——创新实训记录9)