allow circle web deps and dedup at runtime
All checks were successful
studiorailgun/trpg/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-30 14:54:15 -05:00
parent f3f9711340
commit 413be570f3
5 changed files with 13 additions and 8 deletions

View File

@ -1,6 +1,7 @@
{
"tag": "linguistics",
"dependencies" : [
"./data/webs/philosophy/philosophy.json",
"./data/webs/linguistics/name.json"
]
}

View File

@ -1,3 +1,2 @@
{
"selfId": 2
}

View File

@ -77,7 +77,8 @@ public class KnowledgeWeb {
public static KnowledgeWeb load(String startPoint){
Map<String,Integer> crossRelationLookupMap = new HashMap<String,Integer>();
List<String> webTagList = new LinkedList<String>();
KnowledgeWeb rVal = KnowledgeWeb.recursivelyLoad(crossRelationLookupMap, webTagList, startPoint);
List<String> parsedFilesList = new LinkedList<String>();
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<String,Integer> crossRelationLookupMap, List<String> foundTags, String startPoint){
private static KnowledgeWeb recursivelyLoad(Map<String,Integer> crossRelationLookupMap, List<String> parsedFilePaths, List<String> 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<Integer,Node> newNodeMap = new HashMap<Integer,Node>();
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);
}
}

View File

@ -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");
});
}

View File

@ -1,6 +1,5 @@
{
"tag" : "top",
"selfId": 2,
"dependencies" : [
"./data/webs/root.json"
]