话题水军识别应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
11 KiB

  1. #coding:utf8
  2. import re
  3. import pymysql
  4. import pandas as pd
  5. import numpy as np
  6. import networkx as nx
  7. import traceback
  8. def mysqlData(inputdata,logging):
  9. result=''
  10. try:
  11. db = pymysql.connect(host=inputdata["host"], user=inputdata["user"], passwd=inputdata["passwd"],
  12. db=inputdata["db"], port=inputdata["port"], charset='utf8',cursorclass=pymysql.cursors.DictCursor, connect_timeout=30)
  13. db.ping(reconnect=True)
  14. cursor = db.cursor()
  15. sql="SELECT ReviewerAccountId, PostAccountId FROM {} WHERE topicId={}".format(inputdata["table"],inputdata["topicId"])
  16. cursor.execute(sql)
  17. result = cursor.fetchall()
  18. db.commit()
  19. cursor.close()
  20. db.close()
  21. except:
  22. logging.info("专题关系数据查询失败!")
  23. logging.info(traceback.format_exc())
  24. return result
  25. def get_replyData(data):
  26. reply=pd.DataFrame(data)
  27. reply = reply.drop_duplicates().reset_index(drop=True) # 去重
  28. reply=reply[['ReviewerAccountId', 'PostAccountId']]
  29. # reply.columns = ['ReviewerAccountId', 'ReviewerAccountName', 'PostAccountId', 'PostAccountName',
  30. # 'ShareCount', 'LikeCount', 'CommentCount', 'CommentTime']
  31. reply = reply[['ReviewerAccountId', 'PostAccountId']]
  32. reply['ReviewerAccountId'] = reply['ReviewerAccountId'].astype(str)
  33. reply['PostAccountId'] = reply['PostAccountId'].astype(str)
  34. reply = reply.groupby(['ReviewerAccountId', 'PostAccountId']).size().reset_index()
  35. # user_net_df = user_net(reply) ##SNA数据清洗
  36. edgeweightset = reply.fillna(0)
  37. edgeweightset.columns = ['source', 'target', 'count']
  38. edgeweightset_l = [[] for _ in range(edgeweightset.shape[0])]
  39. for i in range(len(edgeweightset_l)):
  40. for j in range(edgeweightset.shape[1]):
  41. edgeweightset_l[i].append(edgeweightset.iloc[i, j])
  42. g = nx.DiGraph()
  43. g.add_weighted_edges_from(edgeweightset_l)
  44. degree = [g.degree(),
  45. g.in_degree(),
  46. g.out_degree()]
  47. centrality = [nx.degree_centrality(g), # 计算图 g 中每个节点的度中心性。度中心性是指节点的度(与其他节点相连的边的数量)与图中节点总数的比值。
  48. nx.closeness_centrality(g), # 计算图 g 中每个节点的接近中心性。接近中心性是指节点到其他节点的平均最短路径长度的倒数。
  49. nx.pagerank(g), # 计算图 g 中每个节点的 PageRank 值。PageRank 是一种用于评估网页重要性的算法,也可以应用于其他网络中的节点重要性评估。
  50. nx.clustering(g)] # 计算图 g 中每个节点的聚集系数。聚集系数是指节点的邻居之间存在连接的概率。
  51. #把主贴相关信息拿出来
  52. tmp=edgeweightset["target"].values
  53. node_list = []
  54. nodes = g.nodes() # 提取网络中节点列表
  55. for node in nodes:
  56. if node not in tmp:
  57. continue
  58. node_list.append([node,
  59. degree[0][node],
  60. degree[1][node],
  61. degree[2][node],
  62. centrality[0][node],
  63. centrality[1][node],
  64. centrality[2][node],
  65. centrality[3][node]])
  66. node_list = pd.DataFrame(node_list)
  67. node_list.columns = ['Id', 'degree', 'in_degree', 'out_degree',
  68. 'degree_centrality', 'closeness_centrality', 'pagerank', 'clustering']
  69. node_list['user_flag_infl'] = 0
  70. node_list['user_flag_act'] = 0
  71. node_list.user_flag_infl[node_list['out_degree'] > np.percentile(node_list['out_degree'], 95)] = 1
  72. node_list.user_flag_act[(node_list['in_degree'] > np.percentile(node_list['in_degree'], 90)) &
  73. (node_list['closeness_centrality'] > np.percentile(node_list['closeness_centrality'],
  74. 50))] = 1
  75. node_dic=node_list.set_index('Id')[['degree', 'in_degree','out_degree','degree_centrality','closeness_centrality','pagerank','clustering']].T.to_dict()
  76. return node_dic
  77. def get_content(inputdata,logging):
  78. """
  79. :param inputdata:json数据
  80. :return: prompt及其他参数
  81. """
  82. res={}
  83. admin=inputdata["metadata"]["admin"]
  84. data=inputdata["data"]
  85. prompt=admin["prompt"]
  86. if_user=re.findall("{{(.*)}}",prompt)
  87. if_data=re.findall("@@(.*)@@",prompt)
  88. if if_user != []:
  89. user_data=inputdata["metadata"]["user"]
  90. if if_user[0] in user_data.keys():
  91. tmp=user_data[if_user[0]]
  92. prompt=re.sub("{{(.*)}}",tmp,prompt)
  93. if if_data!=[] and if_data[0] in data.keys():
  94. tmp1=data[if_data[0]]
  95. prompt=re.sub("@@(.*)@@",tmp1,prompt)
  96. res["prompt"]=prompt
  97. res["authorization"]=admin["authorization"]
  98. res["model"]=admin["model"]
  99. res["temperature"]=admin["temperature"]
  100. res["authorization"]=admin["authorization"]
  101. res["top_p"]=admin["top_p"]
  102. res["n"]=admin["n"]
  103. return res
  104. if __name__=="__main__":
  105. inputdata={
  106. "metadata":{
  107. "output":{
  108. "output_type":"table",
  109. "label_col":[
  110. "软件著作抽取结果"
  111. ]
  112. },
  113. "input":{
  114. "input_type":"text",
  115. "label":[
  116. "7_软件著作过滤器"
  117. ]
  118. },
  119. "address":"http://172.18.1.181:9011/chatGpt/",
  120. "admin":{
  121. "authorization":"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",
  122. "top_p":"1",
  123. "user_input":[
  124. {
  125. "keyname":"tag",
  126. "keydesc":""
  127. }
  128. ],
  129. "temperature":"0.2",
  130. "model":"gpt-3.5-turbo-16k",
  131. "prompt":"请在下面这句话中提取出:证书号、软件名称、著作权人,以json格式输出,找不到的字段赋值为空字符串,不要有多余的文字输出,只输出json结构。@@7_软件著作过滤器@@",
  132. "n":"1"
  133. },
  134. "index":1
  135. },
  136. "data":{
  137. "1_项目文件上传":"[{ \"fileUrl\":\"http://172.18.1.130:9985/group33/default/20230816/16/05/1/1-基于时间序列遥感 影像洪涝检测系统.jpg\",\"fileType\":\"jpg\", \"filePath\":\"/软件著作/1-基于时间序列遥感 影像洪涝检测系统.jpg\",\"fileId\":\"cd6592f0389bb1da25afbb44901f9cde\",\"fileName\":\"1-基于时间序列遥感 影像洪涝检测系统.jpg\" },{ \"fileUrl\":\"http://172.18.1.130:9985/group33/default/20230816/16/06/1/2-基于遥感影像的快速变化检测系统.jpg\",\"fileType\":\"jpg\", \"filePath\":\"/软件著作/2-基于遥感影像的快速变化检测系统.jpg\",\"fileId\":\"338847e34904fa96e8834cb220667db8\",\"fileName\":\"2-基于遥感影像的快速变化检测系统.jpg\" },{ \"fileUrl\":\"http://172.18.1.130:9985/group33/default/20230816/16/08/1/3-基于时空模型的遥感时间序列森林火灾检测系统.jpg\",\"fileType\":\"jpg\", \"filePath\":\"/软件著作/1/3-基于时空模型的遥感时间序列森林火灾检测系统.jpg\",\"fileId\":\"944eec1cf98f216ea953459dac4dd505\",\"fileName\":\"3-基于时空模型的遥感时间序列森林火灾检测系统.jpg\" },{ \"fileUrl\":\"http://172.18.1.130:9985/group33/default/20230816/16/09/1/4-基于隐马尔可夫模型的遥感时间序列分类系统.jpg\",\"fileType\":\"jpg\", \"filePath\":\"/软件著作/4-基于隐马尔可夫模型的遥感时间序列分类系统.jpg\",\"fileId\":\"eb378cb9ee914323f601500378dfad76\",\"fileName\":\"4-基于隐马尔可夫模型的遥感时间序列分类系统.jpg\" }]",
  138. "2_文件分类信息":"{\"软件著作\":4}",
  139. "3_OCR识别内容":"{\"content\":\" 22222222222222222222222222222222222222222222222222\\n中华人民共和国国家版权局\\n计算机软件著作权登记证书\\n证书号:软著登字第1623261号\\n软件名称:\\n基于遥感影像的快速变化检测系统\\nV1.0\\n著作权人:中国科学院遥感与数字地球研究所\\n开发完成日期:2016年08月01日\\n首次发表日期:未发表\\n权利取得方式:原始取得\\n权利范围:全部权利\\n登记号:2017SR037977\\n根据《计算机软件保护条例》和《计算机软件著作权登记办法》的\\n规定,经中国版权保护中心审核,对以上事项予以登记\\n计算机软件著作权\\n登记专用章\\n2017年02月10日\\nNo.01433672\",\"fileId\":\"338847e34904fa96e8834cb220667db8\",\"fileName\":\"2-基于遥感影像的快速变化检测系统.jpg\",\"filePath\":\"/软件著作/2-基于遥感影像的快速变化检测系统.jpg\",\"fileType\":\"jpg\",\"fileUrl\":\"http://172.18.1.130:9985/group33/default/20230816/16/06/1/2-基于遥感影像的快速变化检测系统.jpg\",\"pageNum\":1}",
  140. "businessKey":"185aef3b1c810799a6be8314abf6512c",
  141. "7_软件著作过滤器":"{\"content\":\" 22222222222222222222222222222222222222222222222222\\n中华人民共和国国家版权局\\n计算机软件著作权登记证书\\n证书号:软著登字第1623261号\\n软件名称:\\n基于遥感影像的快速变化检测系统\\nV1.0\\n著作权人:中国科学院遥感与数字地球研究所\\n开发完成日期:2016年08月01日\\n首次发表日期:未发表\\n权利取得方式:原始取得\\n权利范围:全部权利\\n登记号:2017SR037977\\n根据《计算机软件保护条例》和《计算机软件著作权登记办法》的\\n规定,经中国版权保护中心审核,对以上事项予以登记\\n计算机软件著作权\\n登记专用章\\n2017年02月10日\\nNo.01433672\",\"fileId\":\"338847e34904fa96e8834cb220667db8\",\"fileName\":\"2-基于遥感影像的快速变化检测系统.jpg\",\"filePath\":\"/软件著作/2-基于遥感影像的快速变化检测系统.jpg\",\"fileType\":\"jpg\",\"fileUrl\":\"http://172.18.1.130:9985/group33/default/20230816/16/06/1/2-基于遥感影像的快速变化检测系统.jpg\",\"pageNum\":1}"
  142. },
  143. "created":1691004265000,
  144. "module":"OCR",
  145. "start_tag":"false",
  146. "last_edit":1692464331000,
  147. "next_app_id":[
  148. {
  149. "start_id":86,
  150. "edge_id":49,
  151. "end_id":90
  152. }
  153. ],
  154. "transfer_id":11,
  155. "blueprint_id":3,
  156. "scenes_id":3,
  157. "scenario":{
  158. "dataloss":1,
  159. "autoCommitTriggerLast":1,
  160. "maxErrors":3,
  161. "autoCommit":1,
  162. "freshVariables":1
  163. },
  164. "wait_condition":[
  165. ],
  166. "scheduling":{
  167. "interval":-1,
  168. "type":"single"
  169. },
  170. "name":"软件著作抽取",
  171. "businessKey":"185aef3b1c810799a6be8314abf6512c",
  172. "id":86,
  173. "describe":"软件著作抽取"
  174. }
  175. a=get_content(inputdata,"")
  176. print(a)