知识点xiugai1

master
you hang 3 months ago committed by youhang20021127
parent 0c6dded6b8
commit 1dcbffefec
  1. 10
      src/main/java/com/teaching/backend/controller/Know/KnowController.java
  2. 3
      src/main/java/com/teaching/backend/service/Know/KnowService.java
  3. 82
      src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java
  4. 151
      src/test/java/com/teaching/TeachingBackendApplicationTests.java

@ -50,6 +50,12 @@ public class KnowController {
BaseResponse<List<KnowPathVO>> knowLearnPath(@RequestParam String corseId){
return knowService.knowLearnPath(corseId);
}
//生成知识点学习路径 默认从第一个知识点到第最后个知识点
@ApiOperation(value = "生成知识点学习路径")
@GetMapping("/knowLearnPathGraph")
BaseResponse<BaseKnowReturn> knowLearnPathGraph(@RequestParam String corseId){
return knowService.knowLearnPathGraph(corseId);
}
//返回depth层知识点
@ApiOperation(value = "返回depth层知识点")
@ -69,8 +75,8 @@ public class KnowController {
//返回课程下指定关系的知识图谱
@ApiOperation(value = "返回课程下指定关系的知识图谱")
@GetMapping("/getRelsNodesByCourseId")
BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(@RequestParam String courseId,@RequestParam List<String>types){
return knowService.getRelsNodesByCourseId(courseId,types);
BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(@RequestParam String courseId,@RequestParam Integer level,@RequestParam List<String>types){
return knowService.getRelsNodesByCourseId(courseId, level,types);
}
//返回知识点的前后知识点

@ -23,6 +23,7 @@ public interface KnowService {
public BaseResponse<BaseKnowReturn> getNodeByDepth(long id,Long depth);
BaseResponse<List<KnowPathVO>> knowLearnPath(String corseId);
BaseResponse<BaseKnowReturn>knowLearnPathGraph(String corseId);
BaseResponse<String> updateLinks(List<LinksVO> linksList);
BaseResponse<String> deleteAllByCourseId(String courseId1);
@ -37,7 +38,7 @@ public interface KnowService {
BaseResponse<BaseKnowReturn> getAllKnowByCourseId(String id);
//返回课程下指定关系的知识图谱
BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(String courseId,List<String>types);
BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(String courseId, Integer level,List<String>types);
//返回课程下指定关系的知识图谱

@ -436,6 +436,75 @@ public class knowServiceImpl implements KnowService {
return ResultUtils.success(knowPathVOList);
}
@Override
public BaseResponse<BaseKnowReturn> knowLearnPathGraph(String corseId) {
//查询第一个知识点-最后一个知识点
List<Long> knowIds = new ArrayList<>();
List<Chapter> chapterList = chapterMapper.selectChapterPIDByCourseId(corseId);
for (int i = 0; i < chapterList.size(); i++) {
List<Chapter> chapterList1 = chapterMapper.selectChapterChildrenOrderByNum(chapterList.get(i).getId());
for (int j = 0; j < chapterList1.size(); j++) {
QueryWrapper queryWrapper = new QueryWrapper<Knowtmp>();
queryWrapper.eq("chapterid", chapterList1.get(j).getId());
List<Knowtmp> knowtmp = knowtmpMapper.selectList(queryWrapper);
for (int k = 0; k < knowtmp.size(); k++) {
Knowtmp knowtmp1 = knowtmp.get(k);
knowIds.add(knowtmp1.getId());
}
}
}
// 生成学习路径
String str = "MATCH p = (:Know{knowId:" + knowIds.get(0) + "})-[*]->(:Know{knowId:" + knowIds.get(knowIds.size() - 1) + "}) WITH p, REDUCE(totalWeight = 0.0, r IN relationships(p) | totalWeight + r.weight) AS pathWeight " +
"RETURN nodes(p) as `p`,relationships(p) as `r`,pathWeight ORDER BY pathWeight desc;" ;
Collection<Map<String, Object>> result = neo4jClient.query(str).fetch().all();
Iterator<Map<String, Object>> iterator = result.iterator();
Set<KnowVO> knowList = new HashSet<>();
Set<Links> linksList = new HashSet<>();
KnowVO knowVO;
List node2 = new ArrayList<>();
Links links;
int p = 0;
while (iterator.hasNext()) {
Map<String, Object> element = iterator.next();
List list1 = (List) element.get("p");
for (int i = 0; i < list1.size(); i++) {
Node node1 = (Node)list1.get(i);
Long id = node1.id();
String name = node1.get("name").asString();
knowVO = new KnowVO();
knowVO.setId(id);
knowVO.setLabel(name);
knowVO.setColor(colorList[0]);
knowList.add(knowVO);
}
List list2 = (List) element.get("r");
if (!list2.isEmpty()) {
for (int i = 0; i < list2.size(); i++) {
InternalRelationship e = (InternalRelationship) list2.get(i);
links = new Links();
links.setId(e.id());
links.setSource(e.startNodeId());
links.setTarget(e.endNodeId());
if ("contain".equals(e.type())) {
links.setLabel("包含");
} else if ("order".equals(e.type())) {
links.setLabel("顺序");
} else if("dependent".equals(e.type())){
links.setLabel("依赖");
}
linksList.add(links);
}
}
Double pathWeight = (Double) element.get("pathWeight");
}
BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList, linksList);
return ResultUtils.success(baseKnowReturn);
}
@Override
public BaseResponse<String> updateLinks(List<LinksVO> linksList) {
for (int i = 0; i < linksList.size(); i++) {
@ -763,7 +832,8 @@ public class knowServiceImpl implements KnowService {
}
@Override
public BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(String courseId, List<String> types) {
public BaseResponse<BaseKnowReturn> getRelsNodesByCourseId(String courseId, Integer level,List<String> types) {
String str = "match(n:Know)-[r:";
for (int i = 0; i < types.size(); i++) {
if (i == types.size() - 1) {
@ -773,7 +843,11 @@ public class knowServiceImpl implements KnowService {
}
}
str = str + "]->(p:Know) where n.courseId = '" + courseId + "' return n as `n`,r as `r`,p as `p`,length(r) as `d`";
if(level == null || level <= 0){
str = str +"]->(p:Know) where n.courseId = '" + courseId + "' return n as `n`,r as `r`,p as `p`,length(r) as `d`";
}else{
str = str +"0.."+level+ "]->(p:Know) where n.courseId = '" + courseId + "' return n as `n`,r as `r`,p as `p`,length(r) as `d`";
}
System.out.println(str);
Collection<Map<String, Object>> all =
neo4jClient.query(str).fetch().all();
@ -812,6 +886,8 @@ public class knowServiceImpl implements KnowService {
links.setLabel("包含");
} else if ("order".equals(e.type())) {
links.setLabel("顺序");
}else if("dependent".equals(e.type())){
links.setLabel("依赖");
}
linksList.add(links);
}
@ -871,6 +947,8 @@ public class knowServiceImpl implements KnowService {
links.setLabel("包含");
} else if ("order".equals(e.type())) {
links.setLabel("顺序");
}else if("dependent".equals(e.type())){
links.setLabel("依赖");
}
linksList.add(links);
}

@ -8,156 +8,7 @@ import java.util.*;
@SpringBootTest
class TeachingBackendApplicationTests {
// Map<String, List<String>> userLearningRecords = new HashMap<>();
public static void main(String[] args) {
public static void main(String[] args) {
// String[] data = {"1", "2", "3", "7", "4", "1-1", "1-5", "1-4", "1-9", "1-2", "3-1", "3-2","1-3","1-6"};
List<String> linkedList = new ArrayList<>();
linkedList.add("1");
linkedList.add("1-1");
linkedList.add("1-2");
linkedList.add("1-3");
linkedList.add("2");
linkedList.add("2-1");
linkedList.add("2-2");
linkedList.add("2-3");
linkedList.add("3");
linkedList.add("3-1");
linkedList.add("3-2");
linkedList.add("3-3");
linkedList.add("4");
linkedList.add("5");
// String x="1";
// String x1="1011-2456";
// String[] split = x1.split("-");
// System.out.println(split[0]);
// System.out.println(split[1]);
// int i = x.indexOf("-");
// System.out.println(i);
// for (String str : data) {
//
// insertInOrder(linkedList, str);
// }
System.out.println("9999");
System.out.println(linkedList);
// String x="2";
String x1="2-1";
int count=0,j=0;
List<String> list = new ArrayList<>();
String[] split1 = x1.split("-");
System.out.println(String.valueOf(Integer.parseInt(split1[0])+1));
for (int i=0;i<linkedList.size();i++){
if (linkedList.get(i).equals(String.valueOf(Integer.parseInt(split1[0])+1))){
j=i;
}
if (linkedList.get(i)==x1){
count=i;
}else{
list.add(linkedList.get(i));
}
}
System.out.println(j);
System.out.println(count);
for (int i=count;i<j-1;i++){
String[] split = list.get(i).split("-");
// System.out.println(split[0]);
// System.out.println(split[1]);
String s = String.valueOf(Integer.parseInt(split[1]) - 1);
list.set(i,split[0]+"-"+s);
}
// for (int i=0;i<linkedList.size();i++){
// if (linkedList.get(i)==x){
//
// j=i;
// }else if (linkedList.get(i).contains(x+"-")){
// count++;
// } else{
// list.add(linkedList.get(i));
// }
// }
// for (int i=j;i<list.size();i++){
// if (list.get(i).indexOf("-")==-1){
// list.set(i,String.valueOf(Integer.parseInt(list.get(i))-1));
// }else{
// String[] split = list.get(i).split("-");
// String s = String.valueOf(Integer.parseInt(split[0]) - 1);
// list.set(i,s+"-"+split[1]);
// }
//
// }
System.out.println(list);
//
// String newData = "1";
// insertInOrder(linkedList, newData);
// printList(linkedList);
//
// deleteEntry(linkedList, newData);
// printList(linkedList);
// deleteEntry(linkedList, "1");
// printList(linkedList);
}
// private static void insertInOrder(LinkedList<String> linkedList, String newData) {
// ListIterator<String> iterator = linkedList.listIterator();
//
// while (iterator.hasNext()) {
// String current = iterator.next();
//
// if (newData.compareTo(current) <= 0) {
// iterator.previous(); // 回到插入位置
// iterator.add(newData);
// return;
// }
// }
//
// linkedList.addLast(newData);
// }
// private static void deleteEntry(LinkedList<String> linkedList, String target) {
// ListIterator<String> iterator = linkedList.listIterator();
//
// while (iterator.hasNext()) {
// String current = iterator.next();
//
// if (current.equals(target)) {
// // 获取target的前缀和序号
// int dashIndex = target.indexOf("-");
// if (dashIndex != -1) {
// String prefix = target.substring(0, dashIndex);
// int number = Integer.parseInt(target.substring(dashIndex + 1));
//
// while (iterator.hasNext()) {
// String next = iterator.next();
// if (next.startsWith(prefix + "-")) {
// // 更新数据序号
// int nextNumber = Integer.parseInt(next.substring(dashIndex + 1));
// String newEntry = prefix + "-" + (nextNumber - 1);
// iterator.remove();
// iterator.add(newEntry);
// } else {
// iterator.previous(); // 回退到上一个位置
// break;
// }
// }
// }
// }
// }
// }
//
// private static void printList(List<String> list) {
// for (String str : list) {
// System.out.print(str + " ");
// }
// System.out.println();
// }
}

Loading…
Cancel
Save