爱看书的阿东

赐他一块白色石头,石头上写着新名

导出数据的踩坑记录

情感分析的导出

  1. 将数据通过excel的形式导入到sqlsever
  2. 查询整个数据表,查找是否已经处理,如果已经处理,跳过,否则,执行情感分析
  3. 使用jsp Update 数据的状态,更新一条将标识位调整
  4. 每隔一定的时间进行处理
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
String sql = "select id,new_name,old_name from m_test where flag = 0";
ObjectManager objectManager = new ObjectManager();
List<IDataSet> dataList = objectManager.list(sql);
if (dataList.isEmpty()) {
out.print("开始执行统计分析程序,没有需要分析的数据!");
return;
}
out.print("开始执行统计分析程序,需要分析:" + dataList.size() + "条");

int i = 0;
for (IDataSet data : dataList) {
String new_name = data.getString("new_name");
String old_name = data.getString("old_name");
SentimentAnalysis new_name_result = null;
SentimentAnalysis old_name_result = null;
try {
new_name_result = NlpApi.sentimentAnalysisByText(new_name);
old_name_result = NlpApi.sentimentAnalysisByText(old_name);
} catch (Exception e) {
System.out.println("调用分析接口出错!" + e.getMessage());
continue;
}

String new_sentimentname = "";
String new_confide = "";
String new_negative = "";
String new_positive = "";
String old_sentimentname = "";
String old_confide = "";
String old_negative = "";
String old_positive = "";

if(null != new_name_result){
new_sentimentname = new_name_result.getSentimentName();
new_confide = String.valueOf(new_name_result.getConfidence());
new_negative = String.valueOf(new_name_result.getNegativeProb());
new_positive = String.valueOf(new_name_result.getPositiveProb());
}

if(null != old_name_result){
old_sentimentname = old_name_result.getSentimentName();
old_confide = String.valueOf(old_name_result.getConfidence());
old_negative = String.valueOf(old_name_result.getNegativeProb());
old_positive = String.valueOf(old_name_result.getPositiveProb());
}

String updateSql = "update m_test set new_confide = ? , new_negative = ? , new_positive = ?, new_anaresult = ?,old_confide = ? , old_negative = ? , old_positive = ?, old_anaresult = ? , flag = 1 where id = ?";

objectManager.update(updateSql, new Object[]{new_sentimentname, new_confide, new_negative, new_positive, old_sentimentname, old_confide, old_negative, old_positive, data.getInt("id")});
i++;
}

out.print("系统执行完毕,执行成功" + i + "条");