|
| 1 | +package com.fzu; |
| 2 | + |
| 3 | +import com.alibaba.fastjson.JSONArray; |
| 4 | +import com.alibaba.fastjson.JSONObject; |
| 5 | + |
| 6 | +import com.fzu.pojo.Paper; |
| 7 | +import com.fzu.service.PaperService; |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; |
| 9 | +import org.springframework.boot.ApplicationArguments; |
| 10 | +import org.springframework.boot.ApplicationRunner; |
| 11 | +import org.springframework.stereotype.Component; |
| 12 | + |
| 13 | +import java.io.File; |
| 14 | +import java.util.ArrayList; |
| 15 | +import java.util.Collections; |
| 16 | +import java.util.List; |
| 17 | +import java.util.Scanner; |
| 18 | + |
| 19 | +//@Component |
| 20 | +public class ApplicationRunnerImpl implements ApplicationRunner { |
| 21 | +// @Autowired |
| 22 | + PaperService paperService; |
| 23 | + public List<Paper> cvprJsonParse() { |
| 24 | + List<Paper> paperList=new ArrayList<>(); |
| 25 | + String dir=System.getProperty("user.dir"); |
| 26 | + System.out.println(dir); |
| 27 | + File file=new File(dir+"/src/main/resources/论文数据/1"); |
| 28 | + if(file.exists()){ |
| 29 | + File []child=file.listFiles(); |
| 30 | + for(int i=0;i<child.length;i++){ |
| 31 | + Paper paper=new Paper(); |
| 32 | + String json=jsonRead(child[i]); |
| 33 | + json=json.replace(";",""); |
| 34 | + JSONObject jsonObject=JSONObject.parseObject(json); |
| 35 | + String title=jsonObject.getString("title"); |
| 36 | + String abstractContent=jsonObject.getString("abstract"); |
| 37 | + if (abstractContent==null)abstractContent="暂无"; |
| 38 | + if(abstractContent.length()>=150){ |
| 39 | + abstractContent=abstractContent.substring(0,150); |
| 40 | + } |
| 41 | + String link=jsonObject.getString("doiLink"); |
| 42 | + String meet="CVPR"; |
| 43 | + Integer year=Integer.valueOf(jsonObject.getString("publicationYear")); |
| 44 | + List<String> keywordList=new ArrayList<>(); |
| 45 | + JSONArray keywords= jsonObject.getJSONArray("keywords"); |
| 46 | + if(keywords!=null){ |
| 47 | + for(int j=0;j<keywords.size();j++){ |
| 48 | + JSONObject keyword=keywords.getJSONObject(j); |
| 49 | + JSONArray jsonArray=keyword.getJSONArray("kwd"); |
| 50 | + for(int k=0;k<jsonArray.size();k++){ |
| 51 | + keywordList.add(jsonArray.getString(k)); |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + else { |
| 56 | + keywordList.add(" "); |
| 57 | + } |
| 58 | + List<String> authorList=new ArrayList<>(); |
| 59 | + JSONArray authors=jsonObject.getJSONArray("authors"); |
| 60 | + if(authors!=null){ |
| 61 | + for(int j=0;j<authors.size();j++){ |
| 62 | + JSONObject author=authors.getJSONObject(j); |
| 63 | + authorList.add(author.getString("name")); |
| 64 | + } |
| 65 | + } |
| 66 | + else{ |
| 67 | + authorList.add(" "); |
| 68 | + } |
| 69 | + paper.setTitle(title); |
| 70 | + paper.setAbstractContent(abstractContent); |
| 71 | + paper.setAuthor(authorList); |
| 72 | + paper.setKeywords(keywordList); |
| 73 | + paper.setLink(link); |
| 74 | + paper.setMeet(meet); |
| 75 | + paper.setYear(year); |
| 76 | + paperList.add(paper); |
| 77 | + System.out.println(paper.toString()); |
| 78 | + } |
| 79 | + } |
| 80 | + else{ |
| 81 | + System.out.println("文件不存在"); |
| 82 | + } |
| 83 | + return paperList; |
| 84 | + } |
| 85 | + public List<Paper> iccvJsonParse(){ |
| 86 | + List<Paper> paperList=new ArrayList<>(); |
| 87 | + String dir=System.getProperty("user.dir"); |
| 88 | + System.out.println(dir); |
| 89 | + File file=new File(dir+"/src/main/resources/论文数据/3"); |
| 90 | + if(file.exists()){ |
| 91 | + File []child=file.listFiles(); |
| 92 | + for(int i=0;i<child.length;i++){ |
| 93 | + Paper paper=new Paper(); |
| 94 | + String json=jsonRead(child[i]); |
| 95 | + json=json.replace(";",""); |
| 96 | + JSONObject jsonObject=JSONObject.parseObject(json); |
| 97 | + String title=jsonObject.getString("title"); |
| 98 | + String abstractContent=jsonObject.getString("abstract"); |
| 99 | + if (abstractContent==null)abstractContent="暂无"; |
| 100 | + if(abstractContent.length()>=150){ |
| 101 | + abstractContent=abstractContent.substring(0,150); |
| 102 | + } |
| 103 | + String link=jsonObject.getString("doiLink"); |
| 104 | + String meet="ICCV"; |
| 105 | + Integer year=Integer.valueOf(jsonObject.getString("publicationYear")); |
| 106 | + List<String> keywordList=new ArrayList<>(); |
| 107 | + JSONArray keywords= jsonObject.getJSONArray("keywords"); |
| 108 | + if(keywords!=null){ |
| 109 | + for(int j=0;j<keywords.size();j++){ |
| 110 | + JSONObject keyword=keywords.getJSONObject(j); |
| 111 | + JSONArray jsonArray=keyword.getJSONArray("kwd"); |
| 112 | + for(int k=0;k<jsonArray.size();k++){ |
| 113 | + keywordList.add(jsonArray.getString(k)); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + else { |
| 118 | + keywordList.add(" "); |
| 119 | + } |
| 120 | + List<String> authorList=new ArrayList<>(); |
| 121 | + JSONArray authors=jsonObject.getJSONArray("authors"); |
| 122 | + if(authors!=null){ |
| 123 | + for(int j=0;j<authors.size();j++){ |
| 124 | + JSONObject author=authors.getJSONObject(j); |
| 125 | + authorList.add(author.getString("name")); |
| 126 | + } |
| 127 | + } |
| 128 | + else{ |
| 129 | + authorList.add(" "); |
| 130 | + } |
| 131 | + paper.setTitle(title); |
| 132 | + paper.setAbstractContent(abstractContent); |
| 133 | + paper.setAuthor(authorList); |
| 134 | + paper.setKeywords(keywordList); |
| 135 | + paper.setLink(link); |
| 136 | + paper.setMeet(meet); |
| 137 | + paper.setYear(year); |
| 138 | + paperList.add(paper); |
| 139 | + System.out.println(paper.toString()); |
| 140 | + } |
| 141 | + } |
| 142 | + else{ |
| 143 | + System.out.println("文件不存在"); |
| 144 | + } |
| 145 | + return paperList; |
| 146 | + } |
| 147 | + public List<Paper> eccvJsonParse(){ |
| 148 | + List<Paper> paperList=new ArrayList<>(); |
| 149 | + String dir=System.getProperty("user.dir"); |
| 150 | + System.out.println(dir); |
| 151 | + File file=new File(dir+"/src/main/resources/论文数据/2"); |
| 152 | + if(file.exists()){ |
| 153 | + File []child=file.listFiles(); |
| 154 | + for(int i=0;i<child.length;i++){ |
| 155 | + Paper paper=new Paper(); |
| 156 | + String json=jsonRead(child[i]); |
| 157 | + json=json.replace(";",""); |
| 158 | + JSONObject jsonObject=JSONObject.parseObject(json); |
| 159 | + String title=jsonObject.getString("论文名称"); |
| 160 | + String abstractContent=jsonObject.getString("摘要"); |
| 161 | + if (abstractContent==null)abstractContent="暂无"; |
| 162 | + if(abstractContent.length()>=150){ |
| 163 | + abstractContent=abstractContent.substring(0,150); |
| 164 | + } |
| 165 | + String link=jsonObject.getString("原文链接"); |
| 166 | + String author="未知"; |
| 167 | + String meet="ECCV"; |
| 168 | + List<String> keywordList=new ArrayList<>(); |
| 169 | + JSONArray jsonArray=jsonObject.getJSONArray("关键词"); |
| 170 | + if(jsonArray!=null){ |
| 171 | + for(int j=0;j<jsonArray.size();j++){ |
| 172 | + keywordList.add(jsonArray.getString(j)); |
| 173 | + } |
| 174 | + } |
| 175 | + else{ |
| 176 | + keywordList.add(" "); |
| 177 | + } |
| 178 | + List<String> authorList=new ArrayList<>(); |
| 179 | + authorList.add(author); |
| 180 | + String year=jsonObject.getString("发布时间"); |
| 181 | + year=year.substring(year.length()-4,year.length()); |
| 182 | + paper.setTitle(title); |
| 183 | + paper.setMeet(meet); |
| 184 | + paper.setLink(link); |
| 185 | + paper.setYear(Integer.valueOf(year)); |
| 186 | + paper.setAbstractContent(abstractContent); |
| 187 | + paper.setAuthor(authorList); |
| 188 | + paper.setKeywords(keywordList); |
| 189 | + paperList.add(paper); |
| 190 | + System.out.println(paper.toString()); |
| 191 | + } |
| 192 | + } |
| 193 | + return paperList; |
| 194 | + } |
| 195 | + public String jsonRead(File file){ |
| 196 | + Scanner scanner = null; |
| 197 | + StringBuilder buffer = new StringBuilder(); |
| 198 | + try { |
| 199 | + scanner = new Scanner(file, "utf-8"); |
| 200 | + while (scanner.hasNextLine()) { |
| 201 | + buffer.append(scanner.nextLine()); |
| 202 | + } |
| 203 | + } catch (Exception e) { |
| 204 | + |
| 205 | + } finally { |
| 206 | + if (scanner != null) { |
| 207 | + scanner.close(); |
| 208 | + } |
| 209 | + } |
| 210 | + return buffer.toString(); |
| 211 | + } |
| 212 | + @Override |
| 213 | + public void run(ApplicationArguments args) throws Exception { |
| 214 | + |
| 215 | + /* System.out.println("开始上传..."); |
| 216 | + List<Paper> totalList=new ArrayList<>(); |
| 217 | + List<Paper>papers=new ArrayList<>(); |
| 218 | + papers=cvprJsonParse(); |
| 219 | + for (Paper paper : papers) { |
| 220 | + totalList.add(paper); |
| 221 | + } |
| 222 | + System.out.println("CVPR"); |
| 223 | + papers=iccvJsonParse(); |
| 224 | + for (Paper paper : papers) { |
| 225 | + totalList.add(paper); |
| 226 | + } |
| 227 | + System.out.println("ECCV"); |
| 228 | + papers=eccvJsonParse(); |
| 229 | + for (Paper paper : papers) { |
| 230 | + totalList.add(paper); |
| 231 | + } |
| 232 | +
|
| 233 | +
|
| 234 | + for (Paper paper : totalList) { |
| 235 | + paperService.uploadPaper(paper); |
| 236 | + }*/ |
| 237 | + |
| 238 | + |
| 239 | + } |
| 240 | +} |
0 commit comments