Browse Source

yangshi

small-tupu
菅振宇 6 months ago
parent
commit
02f52d6999
  1. 8
      gyxtp/src/view/docInfo.vue
  2. 6
      gyxtp/src/view/graphPageNB927.vue
  3. 179
      ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java
  4. 162
      ruoyi-api/src/main/java/com/ruoyi/api/service/impl/PointService.java
  5. 13
      坦克.txt

8
gyxtp/src/view/docInfo.vue

@ -1015,8 +1015,8 @@ export default {
label: 5,
},
docId: nodeList[a].docId,
width: 140,
height: 140,
width: 180,
height: 180,
color: 'rgb(65,154,255)'
})
}
@ -1030,8 +1030,8 @@ export default {
label: 6,
},
docId: nodeList[a].docId,
width: 110,
height: 110,
width: 180,
height: 180,
color: 'rgb(0,228,255)'
})
}

6
gyxtp/src/view/graphPageNB927.vue

@ -744,7 +744,7 @@ export default {
}
//
const baseRadius = 1200; //
const baseRadius = 1500; //
const centerX = 0, centerY = 0;
//
@ -882,10 +882,10 @@ export default {
color = 'rgb(248,143,248)';
break;
case "5":
color = 'rgb(65,154,255)';
color = 'rgb(0,228,255)';
break;
case "6":
color = 'rgb(0,228,255)';
color = 'rgba(255, 255, 255, 0.6)';
break;
default:
color = 'rgba(255, 255, 255, 0.6)';

179
ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java

@ -7,12 +7,17 @@ import com.ruoyi.api.mapper.ZhyPointMapper;
import com.ruoyi.api.service.impl.PointService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.Neo4jUtil;
import com.ruoyi.system.domain.ZhyArticle;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -37,10 +42,182 @@ public class TestXiaoTuPuController extends BaseController {
private static final Type LIST_MAP_TYPE = new TypeToken<List<Map<String, Object>>>(){}.getType();
@GetMapping("test10")
public void test10(){
public void test10() throws IOException {
System.out.println(10);
List<ZhyArticle> articles = new ArrayList<>();
System.out.println("有");
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(new FileInputStream("坦克.txt"), StandardCharsets.UTF_8))) {
String line;
ZhyArticle zhyArticle = null;
String currentField = null; // 当前字段:"authors", "agencies", "summary"
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) continue;
// ✅ 步骤1:检查前8个字符内是否有冒号(: 或 :)
int sepIndex = -1;
char separator = '\0';
String prefix = line.substring(0, Math.min(8, line.length())); // 前最多8个字符
if (prefix.contains(":")) {
sepIndex = prefix.indexOf(":");
separator = ':';
} else if (prefix.contains(":")) {
sepIndex = prefix.indexOf(":");
separator = ':';
}
// 判断是否是“字段行”(前8字符内有冒号)
if (sepIndex != -1) {
String fieldKey = line.substring(0, sepIndex).trim();
String value = line.substring(sepIndex + (separator == ':' ? 1 : 1)).trim();
System.out.println(fieldKey);
System.out.println(value);
// ✅ 只处理你关心的四个字段
if ("题名".equals(fieldKey)) {
if (zhyArticle != null) {
articles.add(zhyArticle);
}
zhyArticle = new ZhyArticle();
zhyArticle.setName(value);
currentField = null;
} else if ("作者".equals(fieldKey)) {
if (zhyArticle != null) {
zhyArticle.setAuthors(value);
currentField = "authors";
}
} else if ("单位".equals(fieldKey)) {
if (zhyArticle != null) {
zhyArticle.setAgencies(value);
currentField = "agencies";
}
}else if ("学位授予单位".equals(fieldKey)) {
if (zhyArticle != null) {
zhyArticle.setAgencies(value);
currentField = "agencies";
}
} else if ("摘要".equals(fieldKey)) {
if (zhyArticle != null) {
zhyArticle.setSummary(value);
currentField = "summary";
}
} else if ("关键词".equals(fieldKey)) {
if (zhyArticle != null) {
zhyArticle.setKeywords(value);
currentField = "keywords";
}
}
// ✅ 如果字段不在白名单内(如“中文刊名”),则:
// - 不处理
// - 不追加
// - 重置 currentField(防止后续行追加到错误字段)
else {
currentField = null; // 关键:断开与之前字段的联系
}
}
// ✅ 普通行:不是字段行,追加到 currentField
else {
if (zhyArticle != null && currentField != null) {
if ("authors".equals(currentField)) {
String existing = zhyArticle.getAuthors();
zhyArticle.setAuthors((existing != null ? existing : "") + "\n" + line);
} else if ("agencies".equals(currentField)) {
String existing = zhyArticle.getAgencies();
zhyArticle.setAgencies((existing != null ? existing : "") + "\n" + line);
} else if ("summary".equals(currentField)) {
String existing = zhyArticle.getSummary();
zhyArticle.setSummary((existing != null ? existing : "") + "\n" + line);
}
}
// 如果 currentField == null,说明前面是未知字段,跳过
}
}
// 添加最后一条记录
if (zhyArticle != null) {
articles.add(zhyArticle);
}
} catch (IOException e) {
System.err.println("读取文件时发生错误:" + e.getMessage());
e.printStackTrace();
}
System.out.println(articles);
pointService.buildPoint(articles,"坦克","维普");
//
//
// List<Map<String, String>> dataList = new ArrayList<>();
// for (int i = 0; i < articles.size(); i++) {
//
// String authorsstr = articles.get(i).getAuthors();
//
// if (authorsstr != null && !authorsstr.isEmpty()) {
// // 判断字符串长度大于0,且最后一个字符是 '等'
// if (authorsstr.charAt(authorsstr.length() - 1) == '等') {
// authorsstr = authorsstr.substring(0, authorsstr.length() - 1); // 去掉最后一个字符
// }
// }
//
// // 按中文分号或英文逗号分割作者
// String[] authors = authorsstr.split("[;,;,]");
// String[] agencies = articles.get(i).getAgencies().split(",");
// if (agencies.length>1){
// for (int j = 0; j < authors.length; j++) {
// authors[j] = authors[j]+generateSequence(agencies.length);
// }
// }
// Map<String, String> map = new HashMap<>();
// map.put("main_keyword","坦克");
// map.put("title",articles.get(i).getName());
// map.put("authors",formatAuthorsWithAgencies(authors,agencies));
// map.put("urls","");
// if (articles.get(i).getKeywords()==null){
// map.put("keywords","");
// }else{
// map.put("keywords",articles.get(i).getKeywords().replace(",", ";"));
// }
// dataList.add(map);
// }
// System.out.println(dataList);
}
public static String generateSequence(int n) {
if (n <= 0) return "";
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= n; i++) {
sb.append(i);
if (i < n) {
sb.append(",");
}
}
return sb.toString();
}
public static String formatAuthorsWithAgencies(String[] authors, String[] agencies) {
// 处理作者:去除空值或空字符串,并用中文逗号连接
String authorPart = Arrays.stream(authors)
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.joining(","));
// 处理机构:去除空值或空字符串,并用中文分号连接
String agencyPart = Arrays.stream(agencies)
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.joining(";"));
// 拼接最终结果
if (!agencyPart.isEmpty()) {
return authorPart + "(" + agencyPart + ")";
} else {
return authorPart;
}
}
@GetMapping("test1")
public void test1(){

162
ruoyi-api/src/main/java/com/ruoyi/api/service/impl/PointService.java

@ -2,6 +2,7 @@ package com.ruoyi.api.service.impl;
import com.ruoyi.api.mapper.ZhyPointMapper;
import com.ruoyi.common.utils.Neo4jUtil;
import com.ruoyi.system.domain.ZhyArticle;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
@ -39,6 +40,167 @@ public class PointService {
build_DO(dataList);
}
public void buildPoint(List<ZhyArticle> articles,String keyword,String type) throws IOException {
if (type.equals("CNKI")){
List<Map<String, String>> dataList = new ArrayList<>();
for (int i = 0; i < articles.size(); i++) {
if (articles.get(i).getAuthors()==null || articles.get(i).getAgencies()==null){
continue;
}
// 按中文分号或英文逗号分割作者
String[] authors = articles.get(i).getAuthors().split("[;,;,]");
String[] agencies = articles.get(i).getAgencies().split(",");
if (agencies.length>1){
for (int j = 0; j < authors.length; j++) {
authors[j] = authors[j]+generateSequence(agencies.length);
}
}
Map<String, String> map = new HashMap<>();
map.put("main_keyword",keyword);
map.put("title",articles.get(i).getName());
map.put("authors",formatAuthorsWithAgencies(authors,agencies));
map.put("urls","");
if (articles.get(i).getKeywords()==null){
map.put("keywords","");
}else{
map.put("keywords",articles.get(i).getKeywords().replace(";;", ";"));
}
dataList.add(map);
}
build_DO(dataList);
}
if (type.equals("万方")){
List<Map<String, String>> dataList = new ArrayList<>();
for (int i = 0; i < articles.size(); i++) {
if (articles.get(i).getAuthors()==null || articles.get(i).getAgencies()==null){
continue;
}
String authorsstr = articles.get(i).getAuthors();
if (authorsstr != null && !authorsstr.isEmpty()) {
// 判断字符串长度大于0,且最后一个字符是 '等'
if (authorsstr.charAt(authorsstr.length() - 1) == '等') {
authorsstr = authorsstr.substring(0, authorsstr.length() - 1); // 去掉最后一个字符
}
}
// 按中文分号或英文逗号分割作者
String[] authors = authorsstr.split("[;,;,]");
String[] agencies = articles.get(i).getAgencies().split(",");
if (agencies.length>1){
for (int j = 0; j < authors.length; j++) {
authors[j] = authors[j]+generateSequence(agencies.length);
}
}
Map<String, String> map = new HashMap<>();
map.put("main_keyword","坦克");
map.put("title",articles.get(i).getName());
map.put("authors",formatAuthorsWithAgencies(authors,agencies));
map.put("urls","");
if (articles.get(i).getKeywords()==null){
map.put("keywords","");
}else{
map.put("keywords",articles.get(i).getKeywords().replace(",", ";"));
}
dataList.add(map);
}
build_DO(dataList);
}
if (type.equals("维普")){
List<Map<String, String>> dataList = new ArrayList<>();
for (int i = 0; i < articles.size(); i++) {
if (articles.get(i).getAuthors()==null || articles.get(i).getAgencies()==null){
continue;
}
String agenciesstr = articles.get(i).getAgencies();
agenciesstr = agenciesstr.replaceAll("\\[.*?\\]", "");
// 按中文分号或英文逗号分割作者
String[] authors = articles.get(i).getAuthors().split(";");
String[] agencies = agenciesstr.split(";");
if (agencies.length>1){
for (int j = 0; j < authors.length; j++) {
authors[j] = authors[j]+generateSequence(agencies.length);
}
}
Map<String, String> map = new HashMap<>();
map.put("main_keyword","坦克");
map.put("title",articles.get(i).getName());
map.put("authors",formatAuthorsWithAgencies(authors,agencies));
map.put("urls","");
if (articles.get(i).getKeywords()==null){
map.put("keywords","");
}else{
String keywrods = articles.get(i).getKeywords();
keywrods = keywrods.replaceAll("\\[.*?\\]", "");
map.put("keywords",keywrods.replace(";", ";"));
}
dataList.add(map);
}
build_DO(dataList);
}
if (type.equals("军事")){
List<Map<String, String>> dataList = new ArrayList<>();
for (int i = 0; i < articles.size(); i++) {
if (articles.get(i).getAuthors()==null || articles.get(i).getAgencies()==null){
continue;
}
String authorsstr = articles.get(i).getAuthors();
// 按中文分号或英文逗号分割作者
String[] authors = authorsstr.split(";");
String[] agencies = articles.get(i).getAgencies().split(";");
if (agencies.length>1){
for (int j = 0; j < authors.length; j++) {
authors[j] = authors[j]+generateSequence(agencies.length);
}
}
Map<String, String> map = new HashMap<>();
map.put("main_keyword","坦克");
map.put("title",articles.get(i).getName());
map.put("authors",formatAuthorsWithAgencies(authors,agencies));
map.put("urls","");
if (articles.get(i).getKeywords()==null){
map.put("keywords","");
}else{
map.put("keywords",articles.get(i).getKeywords().replace(";", ";"));
}
dataList.add(map);
}
build_DO(dataList);
}
}
public static String generateSequence(int n) {
if (n <= 0) return "";
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= n; i++) {
sb.append(i);
if (i < n) {
sb.append(",");
}
}
return sb.toString();
}
public static String formatAuthorsWithAgencies(String[] authors, String[] agencies) {
// 处理作者:去除空值或空字符串,并用中文逗号连接
String authorPart = Arrays.stream(authors)
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.joining(","));
// 处理机构:去除空值或空字符串,并用中文分号连接
String agencyPart = Arrays.stream(agencies)
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.joining(";"));
// 拼接最终结果
if (!agencyPart.isEmpty()) {
return authorPart + "(" + agencyPart + ")";
} else {
return authorPart;
}
}
public void build_DO(List<Map<String, String>> dataList) {
Map<String, Integer> nameToId = new HashMap<>();

13
坦克.txt

@ -0,0 +1,13 @@
题名: 文献名字1
作者: 王刚;陈慧敏;娃哈哈
中文刊名: 我不需要
单位: [1]实验室1;[2]单位22
摘要: 摘要我不需要
题名: 文献名字2
作者: 李强;康师傅
中文刊名: 我不需要22
学位授予单位: [1]实验室2,
摘要: 摘要我不需要2
关键词: [ss]关键词55;[dddd]关键词3
Loading…
Cancel
Save