diff --git a/data/webs/linguistics/linguistics.json b/data/webs/linguistics/linguistics.json index 4ab145e..db191da 100644 --- a/data/webs/linguistics/linguistics.json +++ b/data/webs/linguistics/linguistics.json @@ -1,6 +1,7 @@ { "tag": "linguistics", "dependencies" : [ + "./data/webs/philosophy/philosophy.json", "./data/webs/linguistics/name.json" ] } \ No newline at end of file diff --git a/data/webs/test/web_no_tag.json b/data/webs/test/web_no_tag.json index 17e7123..7a73a41 100644 --- a/data/webs/test/web_no_tag.json +++ b/data/webs/test/web_no_tag.json @@ -1,3 +1,2 @@ { - "selfId": 2 } \ No newline at end of file diff --git a/src/main/java/org/studiorailgun/knowledge/KnowledgeWeb.java b/src/main/java/org/studiorailgun/knowledge/KnowledgeWeb.java index 8621bfb..98a0344 100644 --- a/src/main/java/org/studiorailgun/knowledge/KnowledgeWeb.java +++ b/src/main/java/org/studiorailgun/knowledge/KnowledgeWeb.java @@ -77,7 +77,8 @@ public class KnowledgeWeb { public static KnowledgeWeb load(String startPoint){ Map crossRelationLookupMap = new HashMap(); List webTagList = new LinkedList(); - KnowledgeWeb rVal = KnowledgeWeb.recursivelyLoad(crossRelationLookupMap, webTagList, startPoint); + List parsedFilesList = new LinkedList(); + KnowledgeWeb rVal = KnowledgeWeb.recursivelyLoad(crossRelationLookupMap, parsedFilesList, webTagList, startPoint); if(rVal.getTag() == null){ throw new UnsupportedOperationException("Web without tag defined! " + startPoint); } @@ -143,7 +144,7 @@ public class KnowledgeWeb { * @param root The path to the current root knowledge web * @return Merged knowledge web */ - private static KnowledgeWeb recursivelyLoad(Map crossRelationLookupMap, List foundTags, String startPoint){ + private static KnowledgeWeb recursivelyLoad(Map crossRelationLookupMap, List parsedFilePaths, List foundTags, String startPoint){ KnowledgeWeb rVal = FileUtils.loadObjectFromFile(new File(startPoint), KnowledgeWeb.class); if(rVal == null){ throw new Error("Failed to load file! " + startPoint); @@ -151,6 +152,7 @@ public class KnowledgeWeb { if(foundTags.contains(rVal.getTag())){ throw new UnsupportedOperationException("Trying to load two webs with the same tag! " + rVal.getTag()); } + parsedFilePaths.add(startPoint); //add nodes to crossrelational lookup map HashMap newNodeMap = new HashMap(); for(Node node : rVal.nodes.values()){ @@ -179,7 +181,10 @@ public class KnowledgeWeb { //parse children if(rVal.getDependencies() != null && rVal.getDependencies().size() > 0){ for(String child : rVal.getDependencies()){ - KnowledgeWeb childWeb = KnowledgeWeb.recursivelyLoad(crossRelationLookupMap, foundTags, child); + if(parsedFilePaths.contains(child)){ + continue; + } + KnowledgeWeb childWeb = KnowledgeWeb.recursivelyLoad(crossRelationLookupMap, parsedFilePaths, foundTags, child); KnowledgeWeb.registerChildItems(crossRelationLookupMap, rVal, childWeb); } } diff --git a/src/test/java/org/studiorailgun/LoadingTests.java b/src/test/java/org/studiorailgun/LoadingTests.java index 7c07fef..4982a60 100644 --- a/src/test/java/org/studiorailgun/LoadingTests.java +++ b/src/test/java/org/studiorailgun/LoadingTests.java @@ -26,9 +26,10 @@ public class LoadingTests { @Test public void testExportCSV(){ assertDoesNotThrow(() -> { - KnowledgeWeb web = FileUtils.loadObjectFromFile(new File("./data/webs/test/web.json"), KnowledgeWeb.class); - web.initLinks(); - Globals.web = web; + Globals.init("./data/webs/test/web.json"); + if(Globals.web.getNodes().size() == 0){ + throw new Error("No nodes defined in main test web!"); + } CSVExport.export("test"); }); } diff --git a/web.json b/web.json index 7f55206..f569141 100644 --- a/web.json +++ b/web.json @@ -1,6 +1,5 @@ { "tag" : "top", - "selfId": 2, "dependencies" : [ "./data/webs/root.json" ]