Skip to content
Snippets Groups Projects
Commit 7bd49271 authored by 家乐 袁's avatar 家乐 袁
Browse files

Merge branch '201250076' into 'master'

更新了后端

See merge request 0010-qingyun/backend!51
parents 04ee19af 78275e07
No related branches found
No related tags found
No related merge requests found
Pipeline #69921 passed
......@@ -22,10 +22,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
public class SURMinerServiceImpl implements SURMinerService {
......@@ -56,10 +53,11 @@ public class SURMinerServiceImpl implements SURMinerService {
* @param userVO 用户信息VO
* @param platform 爬取的平台名称(华为,苹果)
* @param appName 需要爬取的应用名称
* @param count 用户期望的评论条数
* @return List<RawComment> 爬取下来的用户评论列表
*/
@Override
public List<RawComment> crawlComments(UserVO userVO, String platform, String appName) {
public List<RawComment> crawlComments(UserVO userVO, String platform, String appName,int count) {
List<RawComment> ans = new ArrayList<>();
try {
// 创建RestTemplate对象
......@@ -79,11 +77,17 @@ public class SURMinerServiceImpl implements SURMinerService {
JSONArray sentences = jsonObject.getJSONArray("sentence");
JSONArray stars = jsonObject.getJSONArray("star");
JSONArray timeStamps = jsonObject.getJSONArray("timestamp");
for (int i = 0; i < sentences.size(); i++) {
int len=Math.min(sentences.size(),count);
ArrayList<Integer> indexList=new ArrayList<>();
for(int i=0;i<len;i++){
indexList.add(i);
}
Collections.shuffle(indexList);
for (int index : indexList) {
RawComment rawComment = RawComment.builder()
.comment(sentences.get(i).toString())
.star(Integer.parseInt(stars.get(i).toString()))
.timeStamp(timeStamps.get(i).toString()).build();
.comment(sentences.get(index).toString())
.star(Integer.parseInt(stars.get(index).toString()))
.timeStamp(timeStamps.get(index).toString()).build();
ans.add(rawComment);
}
} catch (Exception e) {
......
......@@ -25,9 +25,10 @@ public interface SURMinerService {
* @param userVO 用户信息VO
* @param platform 爬取的平台名称(华为,苹果)
* @param appName 需要爬取的应用名称
* @param count 用户期望的评论条数
* @return List<RawComment> 爬取下来的用户评论列表
*/
List<RawComment> crawlComments(UserVO userVO, String platform, String appName);
List<RawComment> crawlComments(UserVO userVO, String platform, String appName,int count);
/**
* SUR-Miner步骤一:文本预处理
......
......@@ -26,13 +26,15 @@ public class SURMinerController {
* @param userVO 用户信息VO
* @param platform 爬取的平台名称(华为,苹果)
* @param appName 需要爬取的应用名称
* @param count 用户期望的评论条数
* @return Response 返回前端的信息
*/
@GetMapping("/crawlComments")
@Authorized
public Response crawlComments(UserVO userVO, @RequestParam(value = "platform") String platform,
@RequestParam(value = "appName") String appName) {
return Response.buildSuccess(surMinerService.crawlComments(userVO, platform, appName));
@RequestParam(value = "appName") String appName,
@RequestParam(value = "count") int count) {
return Response.buildSuccess(surMinerService.crawlComments(userVO, platform, appName,count));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment