From 5aec036d5d95b9039ca84616a789e012e3f45523 Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Thu, 25 May 2023 14:21:22 +0200 Subject: [PATCH 01/18] Start refactor using Lombok lib --- pom.xml | 7 +++++++ src/main/java/nl/uu/cs/ape/APE.java | 7 +++---- .../cs/ape/core/solutionStructure/DefaultCWLCreator.java | 2 +- src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index c81c297..dde09bb 100644 --- a/pom.xml +++ b/pom.xml @@ -155,6 +155,13 @@ okhttp 5.0.0-alpha.11 + + + org.projectlombok + lombok + 1.18.26 + provided + diff --git a/src/main/java/nl/uu/cs/ape/APE.java b/src/main/java/nl/uu/cs/ape/APE.java index 76708d1..80bb6eb 100644 --- a/src/main/java/nl/uu/cs/ape/APE.java +++ b/src/main/java/nl/uu/cs/ape/APE.java @@ -10,7 +10,6 @@ import nl.uu.cs.ape.constraints.ConstraintTemplate; import nl.uu.cs.ape.core.SynthesisEngine; import nl.uu.cs.ape.core.implSAT.SATSynthesisEngine; -import nl.uu.cs.ape.core.solutionStructure.AbstractCWLCreator; import nl.uu.cs.ape.core.solutionStructure.DefaultCWLCreator; import nl.uu.cs.ape.core.solutionStructure.ExecutableCWLCreator; import nl.uu.cs.ape.core.solutionStructure.SolutionWorkflow; @@ -524,8 +523,7 @@ public static boolean writeControlFlowGraphs(SolutionsList allSolutions) { * @param orientation Orientation in which the graph will be presented. * @return true if the generating was successfully performed, false otherwise. */ - public static boolean writeControlFlowGraphs(SolutionsList allSolutions, RankDir orientation) - { + public static boolean writeControlFlowGraphs(SolutionsList allSolutions, RankDir orientation) { Path graphsFolder = allSolutions.getRunConfiguration().getSolutionDirPath2Figures(); Integer noGraphs = allSolutions.getRunConfiguration().getNoGraphs(); if (graphsFolder == null || noGraphs == null || noGraphs == 0 || allSolutions.isEmpty()) { @@ -616,7 +614,8 @@ public static boolean writeCWLWorkflows(SolutionsList allSolutions) { * @param filePrefix The prefix of the files to delete. */ private static void deleteExistingFiles(File dirName, String filePrefix) { - File[] oldFiles = dirName.listFiles((dir, fileName) -> fileName.toLowerCase().startsWith(filePrefix.toLowerCase())); + File[] oldFiles = dirName + .listFiles((dir, fileName) -> fileName.toLowerCase().startsWith(filePrefix.toLowerCase())); if (oldFiles != null) { Arrays.stream(oldFiles).forEach(f -> { try { diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java index 9eaf25f..7e53272 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java @@ -198,7 +198,7 @@ private void generateDefaultStepRun(ModuleNode moduleNode) { // Class .append(ind(baseInd + 1)) .append("class: Operation") - .append("\n"); */ + .append("\n"); // Inputs cwlRepresentation .append(ind(baseInd + 1)) diff --git a/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java b/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java index 964a8d9..2ec303b 100644 --- a/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java +++ b/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java @@ -207,7 +207,7 @@ public ConstraintTemplate getConstraintTemplate(String constraintID) { } /** - * Method read the constraints from a JSON object and updates the + * Method reads the constraints from a JSON object and updates the * {@link APEDomainSetup} object accordingly. * * @param constraintsJSON JSON object containing the constraints From aaa9b9a4c8323cc6064654dab6c12bc23cd88c9e Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Thu, 25 May 2023 17:20:37 +0200 Subject: [PATCH 02/18] Fix CWL file execution path --- .../solutionStructure/DefaultCWLCreator.java | 326 +++++++++--------- 1 file changed, 172 insertions(+), 154 deletions(-) diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java index 7e53272..fcb51f1 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java @@ -11,12 +11,14 @@ public class DefaultCWLCreator extends CWLCreatorBase { /** * Maintain a list of the CWL parameter names which represent {@link TypeNode}s. - * I.e. this hashmap has TypeNode IDs as keys and their names in the CWL file as values. + * I.e. this hashmap has TypeNode IDs as keys and their names in the CWL file as + * values. */ private final HashMap workflowParameters = new HashMap<>(); /** * Instantiates a new CWL creator. + * * @param solution The solution to represent in CWL. */ public DefaultCWLCreator(SolutionWorkflow solution) { @@ -49,19 +51,19 @@ private void generateWorkflowInputs() { String inputName = String.format("input%o", workflowParameters.size() + 1); addParameter(typeNode, inputName); cwlRepresentation - // Name - .append(ind(1)) - .append(inputName) - .append(":\n") - // Data type - .append(ind(2)) - .append("type: File") - .append("\n") - // Format - .append(ind(2)) - .append("format: ") - .append(typeNode.getFormat()) - .append("\n"); + // Name + .append(ind(1)) + .append(inputName) + .append(":\n") + // Data type + .append(ind(2)) + .append("type: File") + .append("\n") + // Format + .append(ind(2)) + .append("format: ") + .append(typeNode.getFormat()) + .append("\n"); } } @@ -74,29 +76,31 @@ private void generateWorkflowOutputs() { int i = 1; for (TypeNode typeNode : solution.getWorkflowOutputTypeStates()) { cwlRepresentation - // Name - .append(ind(1)) - .append(String.format("output%o", i)) - .append(":\n") - // Data type - .append(ind(2)) - .append("type: File") - .append("\n") - // Format - .append(ind(2)) - .append("format: ") - .append(typeNode.getFormat()) - .append("\n") - // outputSource - .append(ind(2)) - .append("outputSource: ") - .append(stepName(typeNode.getCreatedByModule())) - .append("/"); - // Get the id of the step run's output bound to this workflow output (step_name/output_name_ID) - int outId = typeNode.getCreatedByModule().getOutputTypes().get(i - 1).getAutomatonState().getLocalStateNumber(); + // Name + .append(ind(1)) + .append(String.format("output%o", i)) + .append(":\n") + // Data type + .append(ind(2)) + .append("type: File") + .append("\n") + // Format + .append(ind(2)) + .append("format: ") + .append(typeNode.getFormat()) + .append("\n") + // outputSource + .append(ind(2)) + .append("outputSource: ") + .append(stepName(typeNode.getCreatedByModule())) + .append("/"); + // Get the id of the step run's output bound to this workflow output + // (step_name/output_name_ID) + int outId = typeNode.getCreatedByModule().getOutputTypes().get(i - 1).getAutomatonState() + .getLocalStateNumber(); cwlRepresentation - .append(inOutName(typeNode.getCreatedByModule(), "out", outId + 1)) - .append("\n"); + .append(inOutName(typeNode.getCreatedByModule(), "out", outId + 1)) + .append("\n"); i++; } } @@ -113,15 +117,16 @@ private void generateWorkflowSteps() { /** * Generate one workflow step. + * * @param moduleNode The {@link ModuleNode} related to the step. */ private void generateStep(ModuleNode moduleNode) { final int baseInd = 1; // Name cwlRepresentation - .append(ind(baseInd)) - .append(stepName(moduleNode)) - .append(":\n"); + .append(ind(baseInd)) + .append(stepName(moduleNode)) + .append(":\n"); generateDefaultStepRun(moduleNode); generateStepIn(moduleNode); generateStepOut(moduleNode); @@ -129,6 +134,7 @@ private void generateStep(ModuleNode moduleNode) { /** * Generate the "in" section of a workflow step. + * * @param moduleNode The {@link ModuleNode} that is the step. */ private void generateStepIn(ModuleNode moduleNode) { @@ -140,162 +146,167 @@ private void generateStepIn(ModuleNode moduleNode) { // Remove the last newline so the array is on the same line as "in:" deleteLastCharacters(1); cwlRepresentation - .append(" ") - .append("[]") - .append("\n"); + .append(" ") + .append("[]") + .append("\n"); return; } int i = 0; for (TypeNode typeNode : moduleNode.getInputTypes()) { cwlRepresentation - .append(ind(baseInd + 1)) - .append(inOutName(moduleNode, "in", i + 1)) - .append(": ") - .append(workflowParameters.get(typeNode.getNodeID())) - .append("\n"); + .append(ind(baseInd + 1)) + .append(inOutName(moduleNode, "in", i + 1)) + .append(": ") + .append(workflowParameters.get(typeNode.getNodeID())) + .append("\n"); i++; } } /** * Generate the "out" section of a workflow step. + * * @param moduleNode The {@link ModuleNode} that is the step. */ private void generateStepOut(ModuleNode moduleNode) { final int baseInd = 2; cwlRepresentation - // "out" key - .append(ind(baseInd)) - .append("out: ") - // The outputs array - .append("["); + // "out" key + .append(ind(baseInd)) + .append("out: ") + // The outputs array + .append("["); int i = 1; for (TypeNode typeNode : moduleNode.getOutputTypes()) { String name = inOutName(moduleNode, "out", i); addParameter(typeNode, String.format("%s/%s", stepName(moduleNode), name)); cwlRepresentation - .append(name) - .append(", "); + .append(name) + .append(", "); i++; } deleteLastCharacters(2); cwlRepresentation.append("]").append("\n"); } - /** + /** * Generate the run field of a workflow step. + * * @param moduleNode The {@link ModuleNode} related to the step. */ private void generateDefaultStepRun(ModuleNode moduleNode) { final int baseInd = 2; + String moduleName = moduleNode.getUsedModule().getPredicateLabel(); cwlRepresentation - // Main key - .append(ind(baseInd)) - .append("run: " + moduleNode.getUsedModule().getPredicateLabel() + ".cwl") - .append("\n"); - /* - // Class - .append(ind(baseInd + 1)) - .append("class: Operation") - .append("\n"); - // Inputs - cwlRepresentation - .append(ind(baseInd + 1)) - .append("inputs:") - .append("\n"); - generateTypeNodes(moduleNode, moduleNode.getInputTypes(), true, baseInd + 2); - // Outputs - cwlRepresentation - .append(ind(baseInd + 1)) - .append("outputs:") - .append("\n"); - generateTypeNodes(moduleNode, moduleNode.getOutputTypes(), false, baseInd + 2); + // Main key + .append(ind(baseInd)) + .append("run: /cwl/tools/" + moduleName + "/" + moduleName + ".cwl") + .append("\n"); /* - // Hints and intent - generateStepHints(moduleNode, baseInd + 1); - generateStepIntent(moduleNode, baseInd + 1); - */ + * // Class + * .append(ind(baseInd + 1)) + * .append("class: Operation") + * .append("\n"); + * // Inputs + * cwlRepresentation + * .append(ind(baseInd + 1)) + * .append("inputs:") + * .append("\n"); + * generateTypeNodes(moduleNode, moduleNode.getInputTypes(), true, baseInd + 2); + * // Outputs + * cwlRepresentation + * .append(ind(baseInd + 1)) + * .append("outputs:") + * .append("\n"); + * generateTypeNodes(moduleNode, moduleNode.getOutputTypes(), false, baseInd + + * 2); + * /* + * // Hints and intent + * generateStepHints(moduleNode, baseInd + 1); + * generateStepIntent(moduleNode, baseInd + 1); + */ } /** * Generate the run field of a workflow step. + * * @param moduleNode The {@link ModuleNode} related to the step. */ private void generateStepRun(ModuleNode moduleNode) { final int baseInd = 2; cwlRepresentation - // Main key - .append(ind(baseInd)) - .append("run:") - .append("\n") - // Class - .append(ind(baseInd + 1)) - .append("class: Operation") - .append("\n"); + // Main key + .append(ind(baseInd)) + .append("run:") + .append("\n") + // Class + .append(ind(baseInd + 1)) + .append("class: Operation") + .append("\n"); // Inputs cwlRepresentation - .append(ind(baseInd + 1)) - .append("inputs:") - .append("\n"); + .append(ind(baseInd + 1)) + .append("inputs:") + .append("\n"); generateTypeNodes(moduleNode, moduleNode.getInputTypes(), true, baseInd + 2); // Outputs cwlRepresentation - .append(ind(baseInd + 1)) - .append("outputs:") - .append("\n"); + .append(ind(baseInd + 1)) + .append("outputs:") + .append("\n"); generateTypeNodes(moduleNode, moduleNode.getOutputTypes(), false, baseInd + 2); // Hints and intent - generateStepHints(moduleNode, baseInd + 1); - generateStepIntent(moduleNode, baseInd + 1); + generateStepHints(moduleNode, baseInd + 1); + generateStepIntent(moduleNode, baseInd + 1); } /** * Generate the hints related to this step's run. + * * @param moduleNode The {@link ModuleNode} that is the step. - * @param baseInd The indentation at which the hints should start. + * @param baseInd The indentation at which the hints should start. */ private void generateStepHints(ModuleNode moduleNode, int baseInd) { cwlRepresentation - // "hints" key - .append(ind(baseInd)) - .append("hints:") - .append("\n") - // "SoftwareRequirement" key - .append(ind(baseInd + 1)) - .append("SoftWareRequirement:") - .append("\n") - // "packages" key - .append(ind(baseInd + 2)) - .append("packages:") - .append("\n") - // The required package - .append(ind(baseInd + 3)) - .append( - String.format("%s: [\"%s\"]", - moduleNode.getNodeLabel(), - moduleNode.getUsedModule().getPredicateID() - ) - ) - .append("\n"); + // "hints" key + .append(ind(baseInd)) + .append("hints:") + .append("\n") + // "SoftwareRequirement" key + .append(ind(baseInd + 1)) + .append("SoftWareRequirement:") + .append("\n") + // "packages" key + .append(ind(baseInd + 2)) + .append("packages:") + .append("\n") + // The required package + .append(ind(baseInd + 3)) + .append( + String.format("%s: [\"%s\"]", + moduleNode.getNodeLabel(), + moduleNode.getUsedModule().getPredicateID())) + .append("\n"); } /** * Generate the intent for a workflow step's run. + * * @param moduleNode The {@link ModuleNode} that is the workflow step. - * @param baseInd The indentation level at which the intent should start. + * @param baseInd The indentation level at which the intent should start. */ private void generateStepIntent(ModuleNode moduleNode, int baseInd) { cwlRepresentation - .append(ind(baseInd)) - .append("intent: ") - .append("["); + .append(ind(baseInd)) + .append("intent: ") + .append("["); for (TaxonomyPredicate predicate : moduleNode.getUsedModule().getSuperPredicates()) { cwlRepresentation - .append("\"") - .append(predicate.getPredicateID()) - .append("\"") - .append(", "); + .append("\"") + .append(predicate.getPredicateID()) + .append("\"") + .append(", "); } deleteLastCharacters(2); cwlRepresentation.append("]").append("\n"); @@ -303,20 +314,25 @@ private void generateStepIntent(ModuleNode moduleNode, int baseInd) { /** * Generate the inputs or outputs of a step's run. - * @param moduleNode The {@link ModuleNode} that is the workflow step. - * @param typeNodeList The {@link TypeNode}s that are either the input or output nodes. - * @param input Whether the type nodes are inputs. If false, they are consider outputs. - * @param baseInd The indentation level of the "inputs:" or "outputs:" line preceding this function. + * + * @param moduleNode The {@link ModuleNode} that is the workflow step. + * @param typeNodeList The {@link TypeNode}s that are either the input or output + * nodes. + * @param input Whether the type nodes are inputs. If false, they are + * consider outputs. + * @param baseInd The indentation level of the "inputs:" or "outputs:" line + * preceding this function. */ private void generateTypeNodes(ModuleNode moduleNode, List typeNodeList, boolean input, int baseInd) { - // If the input or output nodes are empty, give an empty array as input or output + // If the input or output nodes are empty, give an empty array as input or + // output if (typeNodeList.isEmpty()) { // Remove the last newline so the array is on the same line as "inputs:" deleteLastCharacters(1); cwlRepresentation - .append(" ") - .append("[]") - .append("\n"); + .append(" ") + .append("[]") + .append("\n"); return; } @@ -329,43 +345,44 @@ private void generateTypeNodes(ModuleNode moduleNode, List typeNodeLis i++; cwlRepresentation - // Name - .append(ind(baseInd)) - .append(inOutName(moduleNode, input ? "in" : "out", i)) - .append(":\n") - // Data type - .append(ind(baseInd + 1)) - .append("type: File") - .append("\n") - // Format - .append(ind(baseInd + 1)) - .append("format: ") - .append(typeNode.getFormat()) - .append("\n"); + // Name + .append(ind(baseInd)) + .append(inOutName(moduleNode, input ? "in" : "out", i)) + .append(":\n") + // Data type + .append(ind(baseInd + 1)) + .append("type: File") + .append("\n") + // Format + .append(ind(baseInd + 1)) + .append("format: ") + .append(typeNode.getFormat()) + .append("\n"); } } /** * Generate the name of the input or output of a step's run input or output. * I.e. "moduleName_indicator_n". + * * @param moduleNode The {@link ModuleNode} that is the workflow step. - * @param indicator Indicator whether it is an input or an output. - * @param n The n-th input or output this is. + * @param indicator Indicator whether it is an input or an output. + * @param n The n-th input or output this is. * @return The name of the input or output. */ private String inOutName(ModuleNode moduleNode, String indicator, int n) { return String.format("%s_%s_%o", - moduleNode.getNodeLabel(), - indicator, - n - ); + moduleNode.getNodeLabel(), + indicator, + n); } /** * Add a parameter to the parameter hashmap. * Will log an error to the error output if {@link TypeNode} is already known. + * * @param typeNode The {@link TypeNode} that is the input parameter. - * @param name The name of the parameter. + * @param name The name of the parameter. */ private void addParameter(TypeNode typeNode, String name) { if (workflowParameters.putIfAbsent(typeNode.getNodeID(), name) != null) { @@ -375,6 +392,7 @@ private void addParameter(TypeNode typeNode, String name) { /** * Generate the name for a step in the workflow. + * * @param moduleNode The {@link ModuleNode} that is the workflow step. * @return The name of the workflow step. */ From 4fb5a383ac3f487702096665332f7518c356e52e Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Fri, 26 May 2023 13:45:35 +0200 Subject: [PATCH 03/18] Update the version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dde09bb..db08ff2 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.sanctuuary APE - 2.1.1 + 2.1.2 jar io.github.sanctuuary:APE APE is a command line tool and an API for the automated exploration of possible computational pipelines (workflows) from large collections of computational tools. From 2ba0ff14ee5f9e6321028a5205256fe60100d71e Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Sat, 27 May 2023 03:15:18 +0200 Subject: [PATCH 04/18] Update solution file naming --- src/main/java/nl/uu/cs/ape/APE.java | 23 ++++++------- .../solutionStructure/SolutionWorkflow.java | 32 +++++++++++-------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/main/java/nl/uu/cs/ape/APE.java b/src/main/java/nl/uu/cs/ape/APE.java index 80bb6eb..d560a79 100644 --- a/src/main/java/nl/uu/cs/ape/APE.java +++ b/src/main/java/nl/uu/cs/ape/APE.java @@ -419,7 +419,7 @@ public static boolean writeExecutableWorkflows(SolutionsList allSolutions) { final File executeDir = executionsFolder.toFile(); if (executeDir.isDirectory()) { // If the directory already exists, empty it first - deleteExistingFiles(executeDir, "workflowSolution_"); + deleteExistingFiles(executeDir, SolutionWorkflow.getFileNamePrefix()); } else { executeDir.mkdir(); } @@ -428,8 +428,7 @@ public static boolean writeExecutableWorkflows(SolutionsList allSolutions) { /* Creating the requested scripts in parallel. */ allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noExecutions).forEach(solution -> { try { - String title = "workflowSolution_" + solution.getIndex() + ".sh"; - File script = executionsFolder.resolve(title).toFile(); + File script = executionsFolder.resolve(solution.getFileName() + ".sh").toFile(); APEFiles.write2file(solution.getScriptExecution(), script, false); System.out.print("."); } catch (IOException e) { @@ -477,7 +476,7 @@ public static boolean writeDataFlowGraphs(SolutionsList allSolutions, RankDir or File graphDir = graphsFolder.toFile(); if (graphDir.isDirectory()) { // If the directory already exists, empty it first - deleteExistingFiles(graphDir, "SolutionNo"); + deleteExistingFiles(graphDir, SolutionWorkflow.getFileNamePrefix()); } else { graphDir.mkdir(); } @@ -485,7 +484,7 @@ public static boolean writeDataFlowGraphs(SolutionsList allSolutions, RankDir or /* Creating the requested graphs in parallel. */ allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noGraphs).forEach(solution -> { try { - String title = "SolutionNo_" + solution.getIndex() + "_length_" + solution.getSolutionLength(); + String title = solution.getFileName(); Path path = graphsFolder.resolve(title); solution.getDataflowGraph(title, orientation).write2File(path.toFile(), allSolutions.getRunConfiguration().getDebugMode()); @@ -536,7 +535,7 @@ public static boolean writeControlFlowGraphs(SolutionsList allSolutions, RankDir File graphDir = graphsFolder.toFile(); if (graphDir.isDirectory()) { // If the directory already exists, empty it first - deleteExistingFiles(graphDir, "SolutionNo"); + deleteExistingFiles(graphDir, SolutionWorkflow.getFileNamePrefix()); } else { graphDir.mkdir(); } @@ -544,7 +543,7 @@ public static boolean writeControlFlowGraphs(SolutionsList allSolutions, RankDir /* Creating the requested graphs in parallel. */ allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noGraphs).forEach(solution -> { try { - String title = "SolutionNo_" + solution.getIndex() + "_length_" + solution.getSolutionLength(); + String title = solution.getFileName(); Path path = graphsFolder.resolve(title); solution.getControlflowGraph(title, orientation).write2File(path.toFile(), allSolutions.getRunConfiguration().getDebugMode()); @@ -578,11 +577,10 @@ public static boolean writeCWLWorkflows(SolutionsList allSolutions) { APEUtils.printHeader(null, String.format("Writing the first %o solution(s) to CWL files", noCWLFiles)); APEUtils.timerStart(timerID, true); - final String filePrefix = "workflowSolution_"; final File cwlDir = cwlFolder.toFile(); if (cwlDir.isDirectory()) { // If the directory already exists, empty it first - deleteExistingFiles(cwlDir, filePrefix); + deleteExistingFiles(cwlDir, SolutionWorkflow.getFileNamePrefix()); } else { // Create the CWL directory if it does not already exist cwlDir.mkdir(); @@ -592,7 +590,7 @@ public static boolean writeCWLWorkflows(SolutionsList allSolutions) { // Write the CWL files allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noCWLFiles).forEach(solution -> { try { - String title = String.format("%s%o.cwl", filePrefix, solution.getIndex()); + String title = solution.getFileName() + ".cwl"; File script = cwlFolder.resolve(title).toFile(); DefaultCWLCreator cwlCreator = new DefaultCWLCreator(solution); APEFiles.write2file(cwlCreator.generate(), script, false); @@ -653,11 +651,10 @@ public static boolean writeExecutableCWLWorkflows(SolutionsList allSolutions, AP APEUtils.printHeader(null, String.format("Writing the first %o solution(s) to executable CWL files", noFiles)); APEUtils.timerStart(timerID, true); - final String filePrefix = "workflowSolution_"; final File cwlDir = executableCWLFolder.toFile(); if (cwlDir.isDirectory()) { // If the directory already exists, empty it first - deleteExistingFiles(cwlDir, filePrefix); + deleteExistingFiles(cwlDir, SolutionWorkflow.getFileNamePrefix()); } else { // Create the CWL directory if it does not already exist cwlDir.mkdir(); @@ -667,7 +664,7 @@ public static boolean writeExecutableCWLWorkflows(SolutionsList allSolutions, AP // Write the CWL files allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noFiles).forEach(solution -> { try { - String title = String.format("%s%o.cwl", filePrefix, solution.getIndex()); + String title = solution.getFileName() + ".cwl"; File script = executableCWLFolder.resolve(title).toFile(); ExecutableCWLCreator cwlCreator = new ExecutableCWLCreator(solution); APEFiles.write2file(cwlCreator.generate(), script, false); diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java index 0d7c25c..11c9f7f 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java @@ -41,6 +41,8 @@ */ public class SolutionWorkflow { + private static final String fileNamePrefix = "workflowSolution_"; + /** * List of module nodes ordered according to their position in the workflow. */ @@ -352,6 +354,23 @@ public SolutionGraph getControlflowGraph(String title, RankDir orientation) { } } + /** + * Get the prefix of the file name that is used to store the solution. + * + * @return the field {@link #fileNamePrefix}. + */ + public static String getFileNamePrefix() { + return fileNamePrefix; + } + + /** + * Get file name of the solution file (without the extension). + * @return The file name of the solution file (without the file extension). + */ + public String getFileName() { + return String.format("%s%o", this.fileNamePrefix, getIndex()); + } + /** * Get the graphical representation of the control-flow diagram with the * required title and in the defined orientation. @@ -368,19 +387,6 @@ public BufferedImage getControlflowGraphPNG(RankDir orientation) { } } - /** - * Returns the negated solution in mapped format. Negating the original solution - * created by the SAT solver. Usually used to add to the solver to find new - * solutions. - * - * @param toolSeqRepeat variable defining if the provided solutions should be - * distinguished based on the tool sequences alone - * @return int[] representing the negated solution - */ - // public int[] getNegatedMappedSolutionArray(boolean toolSeqRepeat) { - // return this.nativeSolution.getNegatedMappedSolutionArray(toolSeqRepeat); - // } - /** * Get a readable version of the workflow solution. * From a98a82778963cc7a20725a8c20c8051817dfb57f Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Sat, 27 May 2023 06:33:53 +0200 Subject: [PATCH 05/18] Version update --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index db08ff2..2730561 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.sanctuuary APE - 2.1.2 + 2.1.4 jar io.github.sanctuuary:APE APE is a command line tool and an API for the automated exploration of possible computational pipelines (workflows) from large collections of computational tools. From 58ccd844bb28c5aff1cd88bbc8c2caa590d1d201 Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Tue, 4 Jul 2023 14:45:52 +0200 Subject: [PATCH 06/18] Setup loggin using Slf4j --- pom.xml | 5 + src/main/java/nl/uu/cs/ape/APE.java | 65 ++++---- src/main/java/nl/uu/cs/ape/Main.java | 5 +- .../uu/cs/ape/automaton/ModuleAutomaton.java | 15 -- .../nl/uu/cs/ape/automaton/TypeAutomaton.java | 25 --- .../implSAT/EnforceModuleRelatedRules.java | 12 +- .../ape/core/implSAT/SATSynthesisEngine.java | 27 +-- .../solutionStructure/SolutionWorkflow.java | 5 +- .../core/solutionStructure/SolutionsList.java | 155 ++++++++++-------- src/main/java/nl/uu/cs/ape/io/APEFiles.java | 4 +- .../logic/constructs/TaxonomyPredicate.java | 4 +- .../nl/uu/cs/ape/utils/APEDomainSetup.java | 7 +- .../java/nl/uu/cs/ape/utils/APEUtils.java | 116 ++++++------- .../java/nl/uu/cs/ape/utils/BioToolsAPI.java | 65 ++++---- src/main/resources/simplelogger.properties | 34 ++++ .../test/configuration/APEConfigTagTest.java | 30 ++-- .../sat/test/configuration/APEConfigTest.java | 83 ++++++---- .../uu/cs/ape/sat/test/utils/Evaluation.java | 5 +- .../uu/cs/ape/sat/test/utils/GitHubRepo.java | 25 ++- .../uu/cs/ape/test/sat/ape/UseCaseTest.java | 27 ++- 20 files changed, 400 insertions(+), 314 deletions(-) create mode 100644 src/main/resources/simplelogger.properties diff --git a/pom.xml b/pom.xml index 2730561..2207616 100644 --- a/pom.xml +++ b/pom.xml @@ -128,6 +128,11 @@ 5.8.2 test + + org.slf4j + slf4j-api + 2.0.7 + org.slf4j slf4j-simple diff --git a/src/main/java/nl/uu/cs/ape/APE.java b/src/main/java/nl/uu/cs/ape/APE.java index d560a79..8d0bf25 100644 --- a/src/main/java/nl/uu/cs/ape/APE.java +++ b/src/main/java/nl/uu/cs/ape/APE.java @@ -1,6 +1,3 @@ -/** - * - */ package nl.uu.cs.ape; import guru.nidi.graphviz.attribute.Rank.RankDir; @@ -15,6 +12,7 @@ import nl.uu.cs.ape.core.solutionStructure.SolutionWorkflow; import nl.uu.cs.ape.core.solutionStructure.SolutionsList; import nl.uu.cs.ape.io.APEFiles; +import nl.uu.cs.ape.models.MappingsException; import nl.uu.cs.ape.models.enums.SynthesisFlag; import nl.uu.cs.ape.models.logic.constructs.TaxonomyPredicate; import nl.uu.cs.ape.configuration.APECoreConfig; @@ -37,12 +35,15 @@ import java.nio.file.Path; import java.util.*; +import lombok.extern.slf4j.Slf4j; + /** * The {@code APE} class is the main class of the library and is supposed to be * the main interface for working with the library. * * @author Vedran Kasalica */ +@Slf4j public class APE implements APEInterface { /** Core configuration object defined from the configuration file. */ @@ -128,7 +129,7 @@ private boolean setupDomain() throws APEDimensionsException, IOException, OWLOnt boolean ontologyRead = owlReader.readOntology(); if (!ontologyRead) { - System.out.println("Error occurred while reading the provided ontology."); + log.warn("Error occurred while reading the provided ontology."); return false; } @@ -145,7 +146,7 @@ private boolean setupDomain() throws APEDimensionsException, IOException, OWLOnt succRun &= apeDomainSetup .updateCWLAnnotationsFromYaml(cwlAnnotations); } catch (FileNotFoundException e) { - System.err.println("Could not find CWL yaml configuration file!"); + log.error("Could not find CWL yaml configuration file!"); e.printStackTrace(); } } @@ -325,7 +326,7 @@ private SolutionsList executeSynthesis(APERunConfig runConfig) throws IOExceptio /* Encoding of the synthesis problem */ if (!implSynthesis.synthesisEncoding()) { - System.err.println("Internal error in problem encoding."); + log.error("Internal error in problem encoding."); return null; } /* Execution of the synthesis - updates the object allSolutions */ @@ -349,7 +350,7 @@ private SolutionsList executeSynthesis(APERunConfig runConfig) throws IOExceptio allSolutions.setFlag(SynthesisFlag.UNKNOWN); } - System.out.println(allSolutions.getFlag().getMessage()); + log.info(allSolutions.getFlag().getMessage()); long runTimeMS = APEUtils.timerPrintSolutions(globalTimerID, allSolutions.getNumberOfSolutions()); allSolutions.setSolvingTime(runTimeMS); @@ -423,21 +424,21 @@ public static boolean writeExecutableWorkflows(SolutionsList allSolutions) { } else { executeDir.mkdir(); } - System.out.print("Loading"); + log.trace("Loading"); /* Creating the requested scripts in parallel. */ allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noExecutions).forEach(solution -> { try { File script = executionsFolder.resolve(solution.getFileName() + ".sh").toFile(); APEFiles.write2file(solution.getScriptExecution(), script, false); - System.out.print("."); + log.trace("."); } catch (IOException e) { - System.err.println("Error occurred while writing a graph to the file system."); + log.error("Error occurred while writing a graph to the file system."); e.printStackTrace(); } }); - APEUtils.timerPrintText("executingWorkflows", "\nWorkflows have been executed."); + APEUtils.timerPrintText("executingWorkflows", "Workflows have been executed."); return true; } @@ -471,7 +472,7 @@ public static boolean writeDataFlowGraphs(SolutionsList allSolutions, RankDir or } APEUtils.printHeader(null, "Generating graphical representation", "of the first " + noGraphs + " workflows"); APEUtils.timerStart("drawingGraphs", true); - System.out.println(); + /* Removing the existing files from the file system. */ File graphDir = graphsFolder.toFile(); if (graphDir.isDirectory()) { @@ -480,7 +481,7 @@ public static boolean writeDataFlowGraphs(SolutionsList allSolutions, RankDir or } else { graphDir.mkdir(); } - System.out.print("Loading"); + log.trace("Loading"); /* Creating the requested graphs in parallel. */ allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noGraphs).forEach(solution -> { try { @@ -488,14 +489,14 @@ public static boolean writeDataFlowGraphs(SolutionsList allSolutions, RankDir or Path path = graphsFolder.resolve(title); solution.getDataflowGraph(title, orientation).write2File(path.toFile(), allSolutions.getRunConfiguration().getDebugMode()); - System.out.print("."); + log.trace("."); } catch (IOException e) { - System.err.println("Error occurred while writing a graph to the file system."); + log.error("Error occurred while writing a graph to the file system."); e.printStackTrace(); } }); - APEUtils.timerPrintText("drawingGraphs", "\nGraphical files have been generated."); + APEUtils.timerPrintText("drawingGraphs", "Graphical files have been generated."); return true; } @@ -530,7 +531,7 @@ public static boolean writeControlFlowGraphs(SolutionsList allSolutions, RankDir } APEUtils.printHeader(null, "Generating graphical representation", "of the first " + noGraphs + " workflows"); APEUtils.timerStart("drawingGraphs", true); - System.out.println(); + /* Removing the existing files from the file system. */ File graphDir = graphsFolder.toFile(); if (graphDir.isDirectory()) { @@ -539,7 +540,7 @@ public static boolean writeControlFlowGraphs(SolutionsList allSolutions, RankDir } else { graphDir.mkdir(); } - System.out.print("Loading"); + log.trace("Loading"); /* Creating the requested graphs in parallel. */ allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noGraphs).forEach(solution -> { try { @@ -547,13 +548,13 @@ public static boolean writeControlFlowGraphs(SolutionsList allSolutions, RankDir Path path = graphsFolder.resolve(title); solution.getControlflowGraph(title, orientation).write2File(path.toFile(), allSolutions.getRunConfiguration().getDebugMode()); - System.out.print("."); + log.trace("."); } catch (IOException e) { - System.err.println("Error occurred while writing a graph to the file system."); + log.error("Error occurred while writing a graph to the file system."); e.printStackTrace(); } }); - APEUtils.timerPrintText("drawingGraphs", "\nGraphical files have been generated."); + APEUtils.timerPrintText("drawingGraphs", "Graphical files have been generated."); return true; } @@ -585,23 +586,23 @@ public static boolean writeCWLWorkflows(SolutionsList allSolutions) { // Create the CWL directory if it does not already exist cwlDir.mkdir(); } - System.out.print("Loading"); + log.trace("Loading"); // Write the CWL files allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noCWLFiles).forEach(solution -> { try { - String title = solution.getFileName() + ".cwl"; + String title = solution.getFileName() + ".cwl"; File script = cwlFolder.resolve(title).toFile(); DefaultCWLCreator cwlCreator = new DefaultCWLCreator(solution); APEFiles.write2file(cwlCreator.generate(), script, false); - System.out.print("."); + log.trace("."); } catch (IOException e) { - System.err.println("Error occurred while writing a CWL file to the file system."); + log.error("Error occurred while writing a CWL file to the file system."); e.printStackTrace(); } }); - APEUtils.timerPrintText(timerID, "\nCWL files have been generated."); + APEUtils.timerPrintText(timerID, "CWL files have been generated."); return true; } @@ -637,7 +638,7 @@ private static void deleteExistingFiles(File dirName, String filePrefix) { public static boolean writeExecutableCWLWorkflows(SolutionsList allSolutions, APECoreConfig coreConfig) { // Check if the CWL annotations file is configured. if (!coreConfig.getCwlAnnotationsFile().isPresent()) { - System.out.println("CWL annotations file not configured. No executable CWL files are generated."); + log.warn("CWL annotations file not configured. No executable CWL files are generated."); return false; } @@ -659,23 +660,23 @@ public static boolean writeExecutableCWLWorkflows(SolutionsList allSolutions, AP // Create the CWL directory if it does not already exist cwlDir.mkdir(); } - System.out.print("Loading"); + log.trace("Loading"); // Write the CWL files allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noFiles).forEach(solution -> { try { - String title = solution.getFileName() + ".cwl"; + String title = solution.getFileName() + ".cwl"; File script = executableCWLFolder.resolve(title).toFile(); ExecutableCWLCreator cwlCreator = new ExecutableCWLCreator(solution); APEFiles.write2file(cwlCreator.generate(), script, false); - System.out.print("."); + log.trace("."); } catch (IOException e) { - System.err.println("Error occurred while writing an executable CWL file to the file system."); + log.error("Error occurred while writing an executable CWL file to the file system."); e.printStackTrace(); } }); - APEUtils.timerPrintText(timerID, "\nExecutable CWL files have been generated."); + APEUtils.timerPrintText(timerID, "Executable CWL files have been generated."); return true; } } diff --git a/src/main/java/nl/uu/cs/ape/Main.java b/src/main/java/nl/uu/cs/ape/Main.java index a4275f6..ad65539 100644 --- a/src/main/java/nl/uu/cs/ape/Main.java +++ b/src/main/java/nl/uu/cs/ape/Main.java @@ -1,11 +1,11 @@ package nl.uu.cs.ape; import guru.nidi.graphviz.attribute.Rank.RankDir; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.configuration.APEConfigException; import nl.uu.cs.ape.configuration.APERunConfig; import nl.uu.cs.ape.core.solutionStructure.SolutionsList; import nl.uu.cs.ape.io.APEFiles; -import nl.uu.cs.ape.utils.APEUtils; import org.json.JSONException; import org.json.JSONObject; @@ -20,6 +20,7 @@ * * @author Vedran Kasalica */ +@Slf4j public class Main { /** @@ -92,7 +93,7 @@ public static void main(String[] args) { * Writing solutions to the specified file in human readable format */ if (solutions.isEmpty()) { - System.out.println("UNSAT"); + log.info("The problem is UNSAT."); } else { try { APE.writeSolutionToFile(solutions); diff --git a/src/main/java/nl/uu/cs/ape/automaton/ModuleAutomaton.java b/src/main/java/nl/uu/cs/ape/automaton/ModuleAutomaton.java index 76e4e3e..e5ab3b4 100644 --- a/src/main/java/nl/uu/cs/ape/automaton/ModuleAutomaton.java +++ b/src/main/java/nl/uu/cs/ape/automaton/ModuleAutomaton.java @@ -91,21 +91,6 @@ public List getAllStates() { return moduleStates; } - /** - * Print. - */ - public void print() { - System.out.println("-------------------------------------------------------------"); - System.out.println("\tModule automaton:"); - System.out.println("-------------------------------------------------------------"); - for (State state : moduleStates) { - System.out.println( - "\tModule state: " + state.getPredicateID() + ", order number: " + state.getAbsoluteStateNumber()); - } - System.out.println("-------------------------------------------------------------"); - - } - /** * Gets state object which corresponds to the type and order number (w.r.t. the * type) of the state. diff --git a/src/main/java/nl/uu/cs/ape/automaton/TypeAutomaton.java b/src/main/java/nl/uu/cs/ape/automaton/TypeAutomaton.java index c91e5c5..68fe080 100644 --- a/src/main/java/nl/uu/cs/ape/automaton/TypeAutomaton.java +++ b/src/main/java/nl/uu/cs/ape/automaton/TypeAutomaton.java @@ -317,31 +317,6 @@ public List getUsedStatesAfterBlockNo(int minBlockNo) { return afterStates; } - /** - * Prints the used types and memory types to the console. - */ - public void print() { - System.out.println("-------------------------------------------------------------"); - System.out.println("\tType automaton:"); - System.out.println("-------------------------------------------------------------"); - for (Block memBlock : memoryTypesAutomaton) { - for (State memState : memBlock.getStates()) { - System.out.println("\tType state: " + memState.getPredicateID() + ", order number: " - + memState.getAbsoluteStateNumber()); - } - } - System.out.println("-------------------------------------------------------------"); - for (Block usedBlock : usedTypesAutomaton) { - for (State usedState : usedBlock.getStates()) { - System.out.println("\tType state: " + usedState.getPredicateID() + ", order number: " - + usedState.getAbsoluteStateNumber()); - } - } - - System.out.println("-------------------------------------------------------------"); - - } - /* * (non-Javadoc) * diff --git a/src/main/java/nl/uu/cs/ape/core/implSAT/EnforceModuleRelatedRules.java b/src/main/java/nl/uu/cs/ape/core/implSAT/EnforceModuleRelatedRules.java index ddc2915..b4f6a18 100644 --- a/src/main/java/nl/uu/cs/ape/core/implSAT/EnforceModuleRelatedRules.java +++ b/src/main/java/nl/uu/cs/ape/core/implSAT/EnforceModuleRelatedRules.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Set; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.automaton.Block; import nl.uu.cs.ape.automaton.ModuleAutomaton; import nl.uu.cs.ape.automaton.State; @@ -31,11 +32,11 @@ /** * The {@code ModuleUtils} class is used to encode SLTLx constraints based on - * the - * module annotations that would encode the workflow structure. + * the module annotations that would encode the workflow structure. * * @author Vedran Kasalica */ +@Slf4j public final class EnforceModuleRelatedRules { /** @@ -985,8 +986,9 @@ public static Set moduleTaxonomyStructure(AllModules allModules, T } /** - * Providing the recursive method used in - * {@link #moduleEnforceTaxonomyStructure}. + * The recursive method used in + * {@link #moduleEnforceTaxonomyStructure}, to enforce the taxonomy structure in + * the solution. * * @param allModules All the modules. * @param currModule Module that should be used. @@ -1005,7 +1007,7 @@ private static Set moduleTaxonomyStructureForState(AllModules allM */ for (TaxonomyPredicate subModule : APEUtils.safe(currModule.getSubPredicates())) { if (subModule == null) { - System.out.println("Null error: " + currModule.getPredicateID() + " ->" + log.error("Submodule is 'null': " + currModule.getPredicateID() + " ->" + currModule.getSubPredicates().toString()); } SLTLxAtom subModuleState = new SLTLxAtom(AtomType.MODULE, subModule, moduleState); diff --git a/src/main/java/nl/uu/cs/ape/core/implSAT/SATSynthesisEngine.java b/src/main/java/nl/uu/cs/ape/core/implSAT/SATSynthesisEngine.java index 3a95bc9..7526e74 100644 --- a/src/main/java/nl/uu/cs/ape/core/implSAT/SATSynthesisEngine.java +++ b/src/main/java/nl/uu/cs/ape/core/implSAT/SATSynthesisEngine.java @@ -7,6 +7,7 @@ import org.sat4j.reader.Reader; import org.sat4j.specs.*; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.automaton.ModuleAutomaton; import nl.uu.cs.ape.automaton.TypeAutomaton; import nl.uu.cs.ape.configuration.APERunConfig; @@ -43,6 +44,7 @@ * * @author Vedran Kasalica */ +@Slf4j public class SATSynthesisEngine implements SynthesisEngine { /** * Object that contains all the domain information. @@ -144,7 +146,7 @@ public boolean synthesisEncoding() throws IOException { TaxonomyPredicate rootModule = domainSetup.getAllModules().getRootModule(); if (rootModule == null) { - System.err.println("Taxonomies have not been setup properly."); + log.error("Taxonomies have not been setup properly."); return false; } /* Generate the automaton */ @@ -276,14 +278,17 @@ public boolean synthesisEncoding() throws IOException { /* add the cnf encoding file to Desktop */ // Files.copy(satInputFile, new File("~/Desktop/tmp"+ problemSetupStartTime)); - /* add human readable version of the cnf encoding file to Desktop. Used when needed. */ + /* + * add human readable version of the cnf encoding file to Desktop. Used when + * needed. + */ // FileInputStream cnfStream = new FileInputStream(satInputFile); // String encoding = APEUtils.convertCNF2humanReadable(cnfStream, mappings); // cnfStream.close(); // APEFiles.write2file(encoding, new File("~/Desktop/tmp.txt"), false); long problemSetupTimeElapsedMillis = System.currentTimeMillis() - problemSetupStartTime; - System.out.println("Total problem setup time: " + (problemSetupTimeElapsedMillis / 1000F) + " sec (" + clauses + log.info("Total problem setup time: " + (problemSetupTimeElapsedMillis / 1000F) + " sec (" + clauses + " clauses)."); encodingTime += problemSetupTimeElapsedMillis; return true; @@ -328,7 +333,7 @@ private List runMiniSAT(InputStream satInput, int solutionsFou long globalTimeoutMs = runConfig.getTimeoutMs(); long currTimeout = APEUtils.timerTimeLeft("globalTimer", globalTimeoutMs); if (currTimeout <= 0) { - System.err.println("Timeout. Total solving took longer than the timeout: " + globalTimeoutMs + " ms."); + log.warn("Timeout. Total solving took longer than the timeout: " + globalTimeoutMs + " ms."); return solutions; } // set timeout (in ms) @@ -346,7 +351,7 @@ private List runMiniSAT(InputStream satInput, int solutionsFou solutionsFound++; if (solutionsFound % 500 == 0) { realTimeElapsedMillis = System.currentTimeMillis() - realStartTime; - System.out.println("Found in total " + solutionsFound + " solutions. Solving time: " + log.info("Found in total " + solutionsFound + " solutions. Solving time: " + (realTimeElapsedMillis / 1000F) + " sec."); } /* @@ -359,24 +364,24 @@ private List runMiniSAT(InputStream satInput, int solutionsFou } satInput.close(); } catch (ParseFormatException e) { - System.out.println("Error while parsing the cnf encoding of the problem by the MiniSAT solver."); - System.err.println(e.getMessage()); + log.error("Error while parsing the cnf encoding of the problem by the MiniSAT solver."); + log.error(e.getMessage()); return solutions; } catch (ContradictionException e) { if (solutionsFound == 0) { - System.err.println("Unsatisfiable"); + log.warn("Unsatisfiable"); return solutions; } } catch (TimeoutException e) { - System.err.println("Timeout. Total solving took longer than the timeout: " + globalTimeoutMs + " ms."); + log.warn("Timeout. Total solving took longer than the timeout: " + globalTimeoutMs + " ms."); } catch (IOException e) { - System.err.println("Internal error while parsing the encoding."); + log.warn("Internal error while parsing the encoding."); return solutions; } if (solutionsFound == 0 || solutionsFound % 500 != 0) { realTimeElapsedMillis = System.currentTimeMillis() - realStartTime; - System.out.println("Found " + solutionsFound + " solutions. Solving time: " + log.info("Found " + solutionsFound + " solutions. Solving time: " + (realTimeElapsedMillis / 1000F) + " sec."); satSolvingTime += realTimeElapsedMillis; } diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java index 11c9f7f..4a2b5dc 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java @@ -354,7 +354,7 @@ public SolutionGraph getControlflowGraph(String title, RankDir orientation) { } } - /** + /** * Get the prefix of the file name that is used to store the solution. * * @return the field {@link #fileNamePrefix}. @@ -365,6 +365,7 @@ public static String getFileNamePrefix() { /** * Get file name of the solution file (without the extension). + * * @return The file name of the solution file (without the file extension). */ public String getFileName() { @@ -458,7 +459,7 @@ public String getSolutionDotFormat() { for (TypeNode workflowInput : this.workflowInputTypeStates) { if (!inputDefined) { - System.out.println(input + " [shape=box, color = red];\n"); + // System.out.println(input + " [shape=box, color = red];\n"); inputDefined = true; } solution.append(input + "->" + workflowInput.getNodeID() + ";\n"); diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionsList.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionsList.java index 4c81a47..3d3a906 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionsList.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionsList.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.stream.Stream; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.configuration.APEConfigException; import nl.uu.cs.ape.configuration.APERunConfig; import nl.uu.cs.ape.models.Pair; @@ -17,6 +18,7 @@ * * @author Vedran Kasalica */ +@Slf4j public class SolutionsList { private List solutions; @@ -39,23 +41,23 @@ public class SolutionsList { * APE run configuration. */ private final APERunConfig runConfig; - + /** - * Synthesis result flag, i.e., the reason why the synthesis execution was interrupted. + * Synthesis result flag, i.e., the reason why the synthesis execution was + * interrupted. */ private SynthesisFlag runFlag; - + /** * Total synthesis solving time in MS. */ private long synthesisTimeMS; - + /** * Pars of the numbeR of solutions found at each workflow length. */ - private List> solutionsPerLength; - - + private List> solutionsPerLength; + /** * Create an object that will contain all the solutions of the synthesis. * @@ -64,16 +66,18 @@ public class SolutionsList { public SolutionsList(APERunConfig runConfig) { this.solutions = new ArrayList(); this.runConfig = runConfig; - /* Provides mapping from each atom/predicate to a number/string, and vice versa */ - if(runConfig.getSolverType() == SolverType.SAT) { - this. mappings = new SATAtomMappings(); + /* + * Provides mapping from each atom/predicate to a number/string, and vice versa + */ + if (runConfig.getSolverType() == SolverType.SAT) { + this.mappings = new SATAtomMappings(); } else { - throw new APEConfigException("Solver type has to be SAT."); + throw new APEConfigException("Solver type has to be SAT."); } - /* Variables defining the current and maximum lengths and solutions count.*/ + /* Variables defining the current and maximum lengths and solutions count. */ this.maxSolutions = runConfig.getMaxNoSolutions(); - if (this.maxSolutions > 1000) { - System.out.println("Looking for " + maxSolutions + " solutions might take some time."); + if (this.maxSolutions > 100) { + log.info("Looking for " + maxSolutions + " solutions might take some time."); } } @@ -87,7 +91,8 @@ public int getNumberOfSolutions() { } /** - * Get max number of solutions that should be found. This number is defined in the config.json file. + * Get max number of solutions that should be found. This number is defined in + * the config.json file. * * @return Max number of solutions that should be found. */ @@ -112,23 +117,29 @@ public SATAtomMappings getMappings() { public boolean isEmpty() { return this.solutions.isEmpty(); } - + /** * Get the ape run configuration available at the start. + * * @return the object that contains the run configuration information. */ public APERunConfig getRunConfiguration() { - return runConfig; + return runConfig; } /** - * Appends all of the elements in the specified collection to the end of this list, in the order - * that they are returned by the specified collection's iterator (optional operation). The behavior - * of this operation is undefined if the specified collection is modified while the operation - * is in progress. (Note that this will occur if the specified collection is this list, + * Appends all of the elements in the specified collection to the end of this + * list, in the order + * that they are returned by the specified collection's iterator (optional + * operation). The behavior + * of this operation is undefined if the specified collection is modified while + * the operation + * is in progress. (Note that this will occur if the specified collection is + * this list, * and it's nonempty.) * - * @param currSolutions Solutions that should be added to the list of all solutions. + * @param currSolutions Solutions that should be added to the list of all + * solutions. * @return true if this list changed as a result of the call. */ public boolean addSolutions(List currSolutions) { @@ -159,29 +170,34 @@ public SolutionWorkflow get(int index) { public int size() { return this.solutions.size(); } - + /** - * Set a specific number to be the number of solutions that are found up to the specified length. - * @param length - the length up until which the solutions are evaluated - * @param noSolutions - number of solutions that can be found up until the given length + * Set a specific number to be the number of solutions that are found up to the + * specified length. + * + * @param length - the length up until which the solutions are evaluated + * @param noSolutions - number of solutions that can be found up until the given + * length */ public void addNoSolutionsForLength(Integer length, Integer noSolutions) { - if(noSolutions == 0) - return; - if(solutionsPerLength == null) { - solutionsPerLength = new ArrayList<>(); - } - solutionsPerLength.add(new Pair(length, noSolutions)); + if (noSolutions == 0) + return; + if (solutionsPerLength == null) { + solutionsPerLength = new ArrayList<>(); + } + solutionsPerLength.add(new Pair(length, noSolutions)); } - + /** - * Returns list of pairs (X, Y), where Y describes the number of solutions up until length X. + * Returns list of pairs (X, Y), where Y describes the number of solutions up + * until length X. + * * @return */ public List> getSolutionsPerLength() { - return solutionsPerLength; + return solutionsPerLength; } - + /** * Return the stream that represent the solutions. * @@ -201,36 +217,43 @@ public Stream getParallelStream() { } /** - * Set the synthesis result flag, i.e., set the reason why the synthesis execution was interrupted. + * Set the synthesis result flag, i.e., set the reason why the synthesis + * execution was interrupted. + * * @param flag - the {@link SynthesisFlag} that should be set */ - public void setFlag(SynthesisFlag flag) { - this.runFlag = flag; - - } - - /** - * Get the synthesis result flag, i.e., the reason why the synthesis execution was interrupted. - * @return Returns the {@link SynthesisFlag} representing the reason synthesis execution was interrupted. - */ - public SynthesisFlag getFlag() { - return runFlag; - } - - /** - * Get total synthesis time (in MS). - * @return the total synthesis time in MS. - */ - public long getSolvingTime() { - return this.synthesisTimeMS; - } - - /** - * Set total synthesis time (in MS). - * @param synthesisTimeMS the synthesis time in MS - */ - public void setSolvingTime(long synthesisTimeMS) { - this.synthesisTimeMS = synthesisTimeMS; - } - + public void setFlag(SynthesisFlag flag) { + this.runFlag = flag; + + } + + /** + * Get the synthesis result flag, i.e., the reason why the synthesis execution + * was interrupted. + * + * @return Returns the {@link SynthesisFlag} representing the reason synthesis + * execution was interrupted. + */ + public SynthesisFlag getFlag() { + return runFlag; + } + + /** + * Get total synthesis time (in MS). + * + * @return the total synthesis time in MS. + */ + public long getSolvingTime() { + return this.synthesisTimeMS; + } + + /** + * Set total synthesis time (in MS). + * + * @param synthesisTimeMS the synthesis time in MS + */ + public void setSolvingTime(long synthesisTimeMS) { + this.synthesisTimeMS = synthesisTimeMS; + } + } diff --git a/src/main/java/nl/uu/cs/ape/io/APEFiles.java b/src/main/java/nl/uu/cs/ape/io/APEFiles.java index 22f3d6f..201c11b 100644 --- a/src/main/java/nl/uu/cs/ape/io/APEFiles.java +++ b/src/main/java/nl/uu/cs/ape/io/APEFiles.java @@ -6,6 +6,7 @@ import org.json.JSONException; import org.json.JSONObject; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.configuration.APEConfigException; import nl.uu.cs.ape.models.sltlxStruc.CNFClause; import nl.uu.cs.ape.utils.APEUtils; @@ -35,6 +36,7 @@ /** * The type Ape files. */ +@Slf4j public class APEFiles { /** @@ -205,7 +207,7 @@ private static void createDirectory(String tag, Path path) throws APEConfigExcep APEUtils.printWarning(absolutePath + "' does not exist. Directory will be created."); if (new File(absolutePath).mkdirs()) { - System.out.println("Successfully created directory '" + absolutePath + "'"); + log.debug("Successfully created directory '" + absolutePath + "'"); } else { throw new APEConfigException("Could not create directory '" + absolutePath + "' for tag '" + tag + "'"); } diff --git a/src/main/java/nl/uu/cs/ape/models/logic/constructs/TaxonomyPredicate.java b/src/main/java/nl/uu/cs/ape/models/logic/constructs/TaxonomyPredicate.java index c89f0af..0282202 100644 --- a/src/main/java/nl/uu/cs/ape/models/logic/constructs/TaxonomyPredicate.java +++ b/src/main/java/nl/uu/cs/ape/models/logic/constructs/TaxonomyPredicate.java @@ -2,6 +2,7 @@ import java.util.*; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.automaton.State; import nl.uu.cs.ape.models.AllPredicates; import nl.uu.cs.ape.models.enums.NodeType; @@ -17,6 +18,7 @@ * * @author Vedran Kasalica */ +@Slf4j public abstract class TaxonomyPredicate implements PredicateLabel { /** @@ -306,7 +308,7 @@ public String toShortString() { * @param allPredicates Set of all the predicates. */ public void printTree(String str, AllPredicates allPredicates) { - System.out.println(str + toShortString() + "[" + getNodeType() + "]"); + log.debug(str + toShortString() + "[" + getNodeType() + "]"); for (TaxonomyPredicate predicate : APEUtils.safe(this.subPredicates)) { predicate.printTree(str + ". ", allPredicates); } diff --git a/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java b/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java index 2ec303b..e2f2be0 100644 --- a/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java +++ b/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java @@ -6,6 +6,7 @@ import org.json.JSONException; import org.json.JSONObject; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.configuration.APECoreConfig; import nl.uu.cs.ape.constraints.ConstraintFactory; import nl.uu.cs.ape.constraints.ConstraintFormatException; @@ -26,6 +27,7 @@ * * @author Vedran Kasalica */ +@Slf4j public class APEDomainSetup { /* Helper objects used to keep track of the domain quality. */ @@ -387,8 +389,7 @@ private boolean updateModuleFromJson(JSONObject jsonModule) } } catch (APEDimensionsException badDimension) { wrongToolIO.add(moduleLabel); - System.err.println("Operation '" + "' was not included." + badDimension.getMessage()); - // System.out.println("Skipped " + (counterErrors ++) + " tool annotations."); + log.warn("Operation '" + "' was not included." + badDimension.getMessage()); return false; } @@ -398,7 +399,7 @@ private boolean updateModuleFromJson(JSONObject jsonModule) } if (inputs.isEmpty() && outputs.isEmpty()) { emptyTools.add(moduleLabel); - System.out.println("Operation '" + "' was not included as it has no (valid) inputs and outputs specified."); + log.debug("Operation '" + "' was not included as it has no (valid) inputs and outputs specified."); return false; } /* diff --git a/src/main/java/nl/uu/cs/ape/utils/APEUtils.java b/src/main/java/nl/uu/cs/ape/utils/APEUtils.java index 31fd7f9..4927032 100644 --- a/src/main/java/nl/uu/cs/ape/utils/APEUtils.java +++ b/src/main/java/nl/uu/cs/ape/utils/APEUtils.java @@ -2,8 +2,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.apache.commons.io.LineIterator; -import org.apache.commons.io.output.FileWriterWithEncoding; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -20,28 +18,24 @@ import nl.uu.cs.ape.models.enums.LogicOperation; import nl.uu.cs.ape.models.logic.constructs.PredicateLabel; import nl.uu.cs.ape.models.logic.constructs.TaxonomyPredicate; -import nl.uu.cs.ape.models.sltlxStruc.CNFClause; import nl.uu.cs.ape.models.sltlxStruc.SLTLxAtom; import nl.uu.cs.ape.models.sltlxStruc.SLTLxAtomVar; import nl.uu.cs.ape.models.sltlxStruc.SLTLxFormula; import nl.uu.cs.ape.parser.SLTLxSATVisitor; import java.io.*; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.*; import java.util.stream.IntStream; +import lombok.extern.slf4j.Slf4j; + /** * The {@link APEUtils} class is used for storing {@code Static} methods. * * @author Vedran Kasalica */ +@Slf4j public final class APEUtils { private static final Map timers = new HashMap<>(); @@ -82,7 +76,7 @@ public static String encodeAPEConstraints(SATSynthesisEngine synthesisEngine, AP currConst++; /* ENCODE THE CONSTRAINT */ if (domainSetup.getConstraintTemplate(constraint.getConstraintID()) == null) { - System.err.println("Constraint ID provided: '" + constraint.getConstraintID() + log.warn("Constraint ID provided: '" + constraint.getConstraintID() + "' is not valid. Constraint skipped."); } else { String currConstrEncoding = constraintSATEncoding(constraint.getConstraintID(), @@ -251,7 +245,7 @@ public static List getListFromJson(JSONObject jsonObject, String key, Cla jsonList.add(element); } } catch (JSONException e) { - System.err.println("Json parsing error. Expected object '" + clazz.getSimpleName() + "' under the tag '" + log.warn("Json parsing error. Expected object '" + clazz.getSimpleName() + "' under the tag '" + key + "'. The following object does not match the provided format:\n" + jsonObject.toString()); return jsonList; @@ -297,72 +291,72 @@ public static void debugPrintout(APERunConfig runConfig, APEDomainSetup domainSe /* * Printing the constraint templates */ - System.out.println(line); - System.out.println("\tConstraint templates:"); - System.out.println(line); - System.out.println(domainSetup.getConstraintFactory().printConstraintsCodes() + "\n"); + log.debug(line); + log.debug("\tConstraint templates:"); + log.debug(line); + log.debug(domainSetup.getConstraintFactory().printConstraintsCodes() + "\n"); /* * Printing the Module and Taxonomy Tree */ - System.out.println(line); - System.out.println("\tTool Taxonomy:"); - System.out.println(line); + log.debug(line); + log.debug("\tTool Taxonomy:"); + log.debug(line); domainSetup.getAllModules().getRootModule().printTree(" ", domainSetup.getAllModules()); - System.out.println("\n" + line); - System.out.println("\tData Taxonomy dimensions:"); + log.debug("\n" + line); + log.debug("\tData Taxonomy dimensions:"); for (TaxonomyPredicate dimension : domainSetup.getAllTypes().getRootPredicates()) { - System.out.println("\n" + line); - System.out.println("\t" + dimension.getPredicateLabel() + "Taxonomy:"); - System.out.println(line); + log.debug("\n" + line); + log.debug("\t" + dimension.getPredicateLabel() + "Taxonomy:"); + log.debug(line); dimension.printTree(" ", domainSetup.getAllTypes()); } - System.out.println(line); - System.out.println("\tLabels Taxonomy:"); - System.out.println(line); + log.debug(line); + log.debug("\tLabels Taxonomy:"); + log.debug(line); domainSetup.getAllTypes().getLabelRoot().printTree(" ", domainSetup.getAllTypes()); /* * Printing the tool annotations */ boolean noTools = true; - System.out.println(line); - System.out.println("\tAnnotated tools:"); - System.out.println(line); + log.debug(line); + log.debug("\tAnnotated tools:"); + log.debug(line); for (TaxonomyPredicate module : domainSetup.getAllModules().getModules()) { if (module instanceof Module) { - System.out.println(module.toString()); + log.debug(module.toString()); noTools = false; } } if (noTools) { - System.out.println("\tNo annotated tools."); + log.debug("\tNo annotated tools."); } /* * Print out the constraints */ - System.out.println(line); - System.out.println("\tConstraints:"); - System.out.println(line); + log.debug(line); + log.debug("\tConstraints:"); + log.debug(line); for (ConstraintTemplateData constr : domainSetup.getUnformattedConstr()) { - System.out.println(domainSetup.getConstraintFactory().getDescription(constr)); + log.debug(domainSetup.getConstraintFactory().getDescription(constr)); } if (domainSetup.getUnformattedConstr().isEmpty()) { - System.out.println("\tNo constraints."); + log.debug("\tNo constraints."); } - System.out.println(line); + log.debug(line); int i = 1; for (Type input : runConfig.getProgramInputs()) { - System.out.println((i++) + ". program input is " + input.toShortString()); + log.debug((i++) + ". program input is " + input.toShortString()); } - System.out.println(line); + log.debug(line); i = 1; for (Type output : runConfig.getProgramOutputs()) { - System.out.println((i++) + ". program output is " + output.toShortString()); + log.debug((i++) + ". program output is " + output.toShortString()); } - System.out.println(line); + log.debug(line); } } @@ -377,12 +371,12 @@ public static void printHeader(Integer argument, String... title) { String arg = (argument == null) ? "" : (" " + argument); - System.out.println("\n" + line); - System.out.println("\t" + title[0] + arg); + log.info(line); + log.info("\t" + title[0] + arg); if (title.length > 1) { - System.out.println("\t" + title[1] + arg); + log.info("\t" + title[1] + arg); } - System.out.println(line); + log.info(line); } /** @@ -520,7 +514,7 @@ public static void timerRestartAndPrint(String timerID, String printString) { return; } long printTime = System.currentTimeMillis() - timers.get(timerID); - System.out.println(printString + " setup time: " + (printTime / 1000F) + " sec."); + log.info(printString + " setup time: " + (printTime / 1000F) + " sec."); timers.put(timerID, System.currentTimeMillis()); // APEUtils.printMemoryStatus(true); @@ -538,12 +532,10 @@ public static long timerPrintSolutions(String timerID, int solutionsFound) { return -1; } long printTime = System.currentTimeMillis() - timers.get(timerID); - System.out.println("\n" - + "APE found " + solutionsFound + " solutions.\n" - + "Total APE runtime: \t\t" + (printTime / 1000F) + " sec.\n" - + "Total encoding time: \t\t" + (SATSynthesisEngine.encodingTime / 1000F) + " sec.\n" - + "Total SAT solving time: \t" + (SATSynthesisEngine.satSolvingTime / 1000F) + " sec."); - System.out.println(); + log.info("APE found " + solutionsFound + " solutions."); + log.info("Total APE runtime: \t\t" + (printTime / 1000F) + " sec."); + log.info("Total encoding time: \t\t" + (SATSynthesisEngine.encodingTime / 1000F) + " sec."); + log.info("Total SAT solving time: \t" + (SATSynthesisEngine.satSolvingTime / 1000F) + " sec."); return printTime; } @@ -558,7 +550,7 @@ public static void timerPrintText(String timerID, String text) { return; } long printTime = System.currentTimeMillis() - timers.get(timerID); - System.out.println("\n" + text + " Running time: " + (printTime / 1000F) + " sec."); + log.info(text + " Running time: " + (printTime / 1000F) + " sec."); } /** @@ -596,9 +588,11 @@ public static String convertCNF2humanReadable(InputStream temp_sat_input, SATAto SLTLxAtom atom = mappings.findOriginal(-intAtom); if (atom == null) { SLTLxAtomVar varAtom = mappings.findOriginalVar(-intAtom); - if (varAtom == null) - System.out.println(intAtom); - humanReadable.append("-").append(varAtom.toString()).append(" "); + if (varAtom == null) { + log.error("Error: Could not find atom for " + intAtom); + } else { + humanReadable.append("-").append(varAtom.toString()).append(" "); + } } else { humanReadable.append("-").append(atom.toString()).append(" "); } @@ -663,7 +657,7 @@ public static String getLabelFromList(SortedSet relatedPredic * @param params additional parameters (uses String.format) */ public static void printWarning(String message, Object... params) { - System.out.println("\u001B[35mWARNING: " + String.format(message, params) + "\u001B[0m"); + log.warn("\u001B[35mWARNING: " + String.format(message, params) + "\u001B[0m"); } /** @@ -692,6 +686,12 @@ public static JSONObject clone(JSONObject original) { return new JSONObject(original, JSONObject.getNames(original)); } + /** + * Count the number of lines in a file. + * + * @param cnfEncoding - file to count lines + * @return number of lines + */ public static int countLines(File cnfEncoding) { int lines = 0; try (BufferedReader b = new BufferedReader(new FileReader(cnfEncoding))) { @@ -724,7 +724,7 @@ public static void printMemoryStatus(boolean debugMode) { StringBuilder memoryStatus = new StringBuilder(); IntStream.range(0, currMemChars).forEach(step -> memoryStatus.append("#")); IntStream.range(currMemChars, totalMemChars).forEach(step -> memoryStatus.append(" ")); - System.out.print("\n[" + memoryStatus.toString() + "]\t" + totalMemMB + "\tMB \r"); + log.info("\n[" + memoryStatus.toString() + "]\t" + totalMemMB + "\tMB \r"); } diff --git a/src/main/java/nl/uu/cs/ape/utils/BioToolsAPI.java b/src/main/java/nl/uu/cs/ape/utils/BioToolsAPI.java index d1e8b62..59ab190 100644 --- a/src/main/java/nl/uu/cs/ape/utils/BioToolsAPI.java +++ b/src/main/java/nl/uu/cs/ape/utils/BioToolsAPI.java @@ -1,51 +1,55 @@ package nl.uu.cs.ape.utils; - import java.io.File; import java.io.IOException; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.apache.commons.io.FileUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.io.APEFiles; -import nl.uu.cs.ape.utils.APEUtils; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; +/** + * The {@code BioToolsAPI} class provides methods for fetching tool annotations + * from bio.tools API. + */ +@Slf4j public class BioToolsAPI { /** Http-Client */ public final static OkHttpClient client = new OkHttpClient(); - - /** - * Send Get request to get tool annotations for each elements in JSONArray from bio.tools API. It writes the result to a file. - * - * @param listFilePath Path to the file with the list of tools. - * @param destinationFilePath Path to the file where the result will be written. - * @throws IOException - If the file cannot be read or written. - */ + /** + * Send Get request to get tool annotations for each elements in JSONArray from + * bio.tools API. It writes the result to a file. + * + * @param listFilePath Path to the file with the list of tools. + * @param destinationFilePath Path to the file where the result will be written. + * @throws IOException - If the file cannot be read or written. + */ public static void fetchToolSet(String listFilePath, String destinationFilePath) throws IOException { - + // Fetch the Limited (predefined) set of tool JSONArray bioToolsRAW = readListOfTools(listFilePath); - + JSONObject apeToolAnnotation = convertBioTools2Ape(bioToolsRAW); APEFiles.write2file(apeToolAnnotation.toString(4), new File(destinationFilePath), false); } - /** - * Send Get request to get tool annotations for each elements in JSONArray from bio.tools API. It writes the result to a JSONArray. - * @param filePath Path to the file with the list of tools. - * @return JSONArray with the tool annotations. - * @throws IOException - If the file cannot be read or written. - */ + /** + * Send Get request to get tool annotations for each elements in JSONArray from + * bio.tools API. It writes the result to a JSONArray. + * + * @param filePath Path to the file with the list of tools. + * @return JSONArray with the tool annotations. + * @throws IOException - If the file cannot be read or written. + */ public static JSONArray readListOfTools(String filePath) throws IOException { File toolList = new File(filePath); @@ -55,11 +59,13 @@ public static JSONArray readListOfTools(String filePath) throws IOException { } /** - * Send Get request to get tool annotations for each elements in JSONArray from bio.tools API. It writes the result to a JSONArray. - * @param domainName Path to the file with the list of tools. - * @return JSONArray with the tool annotations. - * @throws IOException - If the file cannot be read or written. - */ + * Send Get request to get tool annotations for each elements in JSONArray from + * bio.tools API. It writes the result to a JSONArray. + * + * @param domainName Path to the file with the list of tools. + * @return JSONArray with the tool annotations. + * @throws IOException - If the file cannot be read or written. + */ public static JSONArray getToolsFromDomain(String domainName) throws IOException { JSONArray toolAnnotations = null; if (!domainName.equals("")) { @@ -69,10 +75,11 @@ public static JSONArray getToolsFromDomain(String domainName) throws IOException } return toolAnnotations; } - + /** - * Send Get request to get tool annotations Saves JSONArray with all + * Send Get request to get tool annotations Saves JSONArray with all * bio.tools that belong to a certain EDAM topic. + * * @throws IOException */ public static JSONArray getToolsFromEDAMTopic(String topicName) throws IOException { @@ -106,7 +113,7 @@ private static JSONArray fetchToolListFromBioTools(JSONArray toolListJson) throw bioToolAnnotations.put(i, responseJson); } } - System.out.println("Tools fetched."); + log.debug("The list of tools successfully fetched from bio.tools."); return bioToolAnnotations; } @@ -144,7 +151,7 @@ private static JSONArray fetchToolsFromURI(String url) throws JSONException, IOE } } - System.out.println("Tools fetched."); + log.debug("Tools fetched from a given URL."); return bioToolAnnotations; } diff --git a/src/main/resources/simplelogger.properties b/src/main/resources/simplelogger.properties new file mode 100644 index 0000000..38a76ee --- /dev/null +++ b/src/main/resources/simplelogger.properties @@ -0,0 +1,34 @@ +# SLF4J's SimpleLogger configuration file +# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. + +# Default logging detail level for all instances of SimpleLogger. +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, defaults to "info". +#org.slf4j.simpleLogger.defaultLogLevel=info + +# Logging detail level for a SimpleLogger instance named "xxxxx". +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, the default logging detail level is used. +#org.slf4j.simpleLogger.log.xxxxx= + +# Set to true if you want the current date and time to be included in output messages. +# Default is false, and will output the number of milliseconds elapsed since startup. +#org.slf4j.simpleLogger.showDateTime=false + +# The date and time format to be used in the output messages. +# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. +# If the format is not specified or is invalid, the default format is used. +# The default format is yyyy-MM-dd HH:mm:ss:SSS Z. +#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z + +# Set to true if you want to output the current thread name. +# Defaults to true. +org.slf4j.simpleLogger.showThreadName=true + +# Set to true if you want the Logger instance name to be included in output messages. +# Defaults to true. +org.slf4j.simpleLogger.showLogName=true + +# Set to true if you want the last component of the name to be included in output messages. +# Defaults to false. +org.slf4j.simpleLogger.showShortLogName=false \ No newline at end of file diff --git a/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTagTest.java b/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTagTest.java index a796e77..c107174 100644 --- a/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTagTest.java +++ b/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTagTest.java @@ -13,6 +13,8 @@ import org.junit.jupiter.api.Test; import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import lombok.extern.slf4j.Slf4j; + import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -21,17 +23,23 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * The {@code APEConfigTagTest} class is used to test the functionality of the + * {@link APEConfigTag} class. + */ +@Slf4j public class APEConfigTagTest { @Test public void infoOutputTest() { - System.out.println("Test type tags.."); + log.debug("Test type tags.."); for (APEConfigTag.Info tag : APERunConfig.TAGS.getAll()) { if (tag.type == APEConfigTag.TagType.INTEGER) { - System.out.printf("Web API shows `%s` box for tag `%s`, with min:`%s` and max:`%s`\n", tag.type, tag.label, tag.constraints.getInt("min"), tag.constraints.getInt("max")); + System.out.printf("Web API shows `%s` box for tag `%s`, with min:`%s` and max:`%s`\n", tag.type, + tag.label, tag.constraints.getInt("min"), tag.constraints.getInt("max")); } } @@ -53,8 +61,9 @@ public void coreValidationTest() { assertFalse(results.hasFails()); - /* Test missing obligatory tag */ - List tags = APECoreConfig.TAGS.getObligatory().stream().map(info -> info.tag_name).collect(Collectors.toList()); + /* Test missing obligatory tag */ + List tags = APECoreConfig.TAGS.getObligatory().stream().map(info -> info.tag_name) + .collect(Collectors.toList()); for (String tag : tags) { JSONObject altered_config = APEUtils.clone(correct_config); @@ -68,7 +77,7 @@ public void coreValidationTest() { success("CoreConfig is missing an obligatory tag -> %s", results.getFails().get(0).toJSON().toString()); } - /* Test missing optional tag */ + /* Test missing optional tag */ tags = APECoreConfig.TAGS.getOptional().stream().map(info -> info.tag_name).collect(Collectors.toList()); for (String tag : tags) { @@ -80,7 +89,7 @@ public void coreValidationTest() { assertFalse(results.hasFails()); } - /* Test incorrect tag */ + /* Test incorrect tag */ tags = APECoreConfig.TAGS.getAll().stream().map(info -> info.tag_name).collect(Collectors.toList()); for (String tag : tags) { @@ -111,8 +120,9 @@ public void runValidationTest() throws IOException, OWLOntologyCreationException assertFalse(results.hasFails()); - /* Test missing obligatory tag */ - List tags = APERunConfig.TAGS.getObligatory().stream().map(info -> info.tag_name).collect(Collectors.toList()); + /* Test missing obligatory tag */ + List tags = APERunConfig.TAGS.getObligatory().stream().map(info -> info.tag_name) + .collect(Collectors.toList()); for (String tag : tags) { JSONObject altered_config = APEUtils.clone(correct_config); @@ -126,7 +136,7 @@ public void runValidationTest() throws IOException, OWLOntologyCreationException success("RunConfig is missing an obligatory tag -> %s", results.getFails().get(0).toJSON().toString()); } - /* Test missing optional tag */ + /* Test missing optional tag */ tags = APERunConfig.TAGS.getOptional().stream().map(info -> info.tag_name).collect(Collectors.toList()); for (String tag : tags) { @@ -138,7 +148,7 @@ public void runValidationTest() throws IOException, OWLOntologyCreationException assertFalse(results.hasFails()); } - /* Test incorrect tag */ + /* Test incorrect tag */ tags = APERunConfig.TAGS.getAll().stream().map(info -> info.tag_name).collect(Collectors.toList()); for (String tag : tags) { diff --git a/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTest.java b/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTest.java index e4f7e1a..8f053b1 100644 --- a/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTest.java +++ b/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTest.java @@ -36,7 +36,7 @@ class APEConfigTest { .put("ontology_path", TestResources.getAbsoluteResourcePath("template/ontology.owl")) .put("ontologyPrefixIRI", "http://www.co-ode.org/ontologies/ont.owl#") .put("toolsTaxonomyRoot", "ToolsTaxonomy") - .put("dataDimensionsTaxonomyRoots", new String[]{"TypesTaxonomy"}) + .put("dataDimensionsTaxonomyRoots", new String[] { "TypesTaxonomy" }) .put("tool_annotations_path", TestResources.getAbsoluteResourcePath("template/tool_annotations.json")) .put("constraints_path", TestResources.getAbsoluteResourcePath("template/constraints.json")) .put("solutions_dir_path", TestResources.getAbsoluteResourcePath("template")) @@ -45,8 +45,9 @@ class APEConfigTest { .put("solutions", 5) .put("number_of_execution_scripts", 1) .put("number_of_generated_graphs", 1) - .put("inputs", new JSONObject[]{new JSONObject().put("TypesTaxonomy", new String[]{"XYZ_table_file"})}) - .put("outputs", new JSONObject[]{new JSONObject().put("TypesTaxonomy", new String[]{"PostScript"})}) + .put("inputs", + new JSONObject[] { new JSONObject().put("TypesTaxonomy", new String[] { "XYZ_table_file" }) }) + .put("outputs", new JSONObject[] { new JSONObject().put("TypesTaxonomy", new String[] { "PostScript" }) }) .put("use_workflow_input", ConfigEnum.ALL.toString()) .put("debug_mode", false) .put("use_all_generated_data", ConfigEnum.ONE.toString()) @@ -60,37 +61,37 @@ class APEConfigTest { * - Incorrect value examples * - Tag names of this type. */ - private static final TagInfo[] tagTypes = new TagInfo[]{ + private static final TagInfo[] tagTypes = new TagInfo[] { new TagInfo( "Boolean", true, - new Object[]{"wrong", 1}, - new String[]{"debug_mode", "tool_seq_repeat"}), + new Object[] { "wrong", 1 }, + new String[] { "debug_mode", "tool_seq_repeat" }), new TagInfo( "Enum", ConfigEnum.ONE.toString(), - new Object[]{false, "wrong", 1}, - new String[]{"use_workflow_input", "use_all_generated_data"}), + new Object[] { false, "wrong", 1 }, + new String[] { "use_workflow_input", "use_all_generated_data" }), new TagInfo( "Integer", 1, - new Object[]{false, "wrong"}, - new String[]{"solutions", "number_of_execution_scripts", "number_of_generated_graphs"}), + new Object[] { false, "wrong" }, + new String[] { "solutions", "number_of_execution_scripts", "number_of_generated_graphs" }), new TagInfo( "Range", new JSONObject().put(Range.MIN_TAG, 2).put(Range.MAX_TAG, 5), - new Object[]{false, "wrong", 2}, - new String[]{"solution_length"}), + new Object[] { false, "wrong", 2 }, + new String[] { "solution_length" }), new TagInfo( "TaxonomyEntity", "ToolsTaxonomy", - new Object[]{false, "wrong"}, - new String[]{"toolsTaxonomyRoot"}), + new Object[] { false, "wrong" }, + new String[] { "toolsTaxonomyRoot" }), new TagInfo( "TaxonomyEntity", "TypesTaxonomy", - new Object[]{false, "wrong"}, - new String[]{"dataDimensionsTaxonomyRoots"}), + new Object[] { false, "wrong" }, + new String[] { "dataDimensionsTaxonomyRoots" }), }; /** @@ -123,14 +124,20 @@ public void verifyCorrectTemplate() { @Test public void testMissingTags() { - /* Missing one of the obligatory core tags should result in an exception while creating the framework. */ + /* + * Missing one of the obligatory core tags should result in an exception while + * creating the framework. + */ for (APEConfigTag.Info info : APECoreConfig.TAGS.getObligatory()) { JSONObject obj = getCorrectTemplate(); obj.remove(info.tag_name); assertThrows(APEConfigException.class, () -> new APECoreConfig(obj)); } - /* Missing one of the obligatory run tags should result in an exception while executing the run phase. */ + /* + * Missing one of the obligatory run tags should result in an exception while + * executing the run phase. + */ for (APEConfigTag.Info tag : APERunConfig.TAGS.getObligatory()) { JSONObject obj = getCorrectTemplate(); obj.remove(tag.tag_name); @@ -138,7 +145,10 @@ public void testMissingTags() { assertThrows(APEConfigException.class, () -> setupRun(obj)); } - /* Missing one of the optional tags should not throw an exception, but should display a warning. */ + /* + * Missing one of the optional tags should not throw an exception, but should + * display a warning. + */ for (APEConfigTag.Info tag_info : APECoreConfig.TAGS.getOptional()) { JSONObject obj = getCorrectTemplate(); obj.remove(tag_info.tag_name); @@ -156,17 +166,21 @@ public void testMissingTags() { @Test public void testIncorrectFilePaths() { - final String[] pathTags = new String[]{"ontology_path", "tool_annotations_path"}; - final String[] wrongPaths = new String[]{null, "", "./does/not/exist.json", "does/not/exist.json", "./does/not/exist/", "does/not/exist/", TestResources.getAbsoluteResourcePath("") + "\\doesnotexist.json"}; + final String[] pathTags = new String[] { "ontology_path", "tool_annotations_path" }; + final String[] wrongPaths = new String[] { null, "", "./does/not/exist.json", "does/not/exist.json", + "./does/not/exist/", "does/not/exist/", + TestResources.getAbsoluteResourcePath("") + "\\doesnotexist.json" }; for (String tag : pathTags) { for (String path : wrongPaths) { try { setupRun(getCorrectTemplate().put(tag, path)); - fail("Expected exception for APECoreConfig with a wrong path '%s' for tag '%s' was not thrown.", path, tag); + fail("Expected exception for APECoreConfig with a wrong path '%s' for tag '%s' was not thrown.", + path, tag); } catch (APEConfigException | JSONException | IOException | OWLOntologyCreationException e) { assertTrue(e.getMessage().contains(tag)); - success("Expected exception was thrown for APECoreConfig with a wrong path for tag '%s'\nAPE message was: %s", tag, e.getMessage()); + success("Expected exception was thrown for APECoreConfig with a wrong path for tag '%s'\nAPE message was: %s", + tag, e.getMessage()); } } } @@ -181,17 +195,20 @@ public void testIncorrectFilePaths() { @Test public void testIncorrectDirectoryPaths() { - final String[] pathTags = new String[]{"solutions_dir_path"}; - final String[] wrongPaths = new String[]{"file.json", TestResources.getAbsoluteResourcePath("") + "\\file.json"}; + final String[] pathTags = new String[] { "solutions_dir_path" }; + final String[] wrongPaths = new String[] { "file.json", + TestResources.getAbsoluteResourcePath("") + "\\file.json" }; for (String tag : pathTags) { for (String path : wrongPaths) { try { setupRun(getCorrectTemplate().put(tag, path)); - fail("Expected exception for APEConfig with a wrong path '%s' for tag '%s' was not thrown.", path, tag); + fail("Expected exception for APEConfig with a wrong path '%s' for tag '%s' was not thrown.", path, + tag); } catch (APEConfigException | JSONException | IOException | OWLOntologyCreationException e) { assertTrue(e.getMessage().contains(tag)); - success("Expected exception was thrown for APEConfig with a wrong path for tag '%s'\nAPE message was: %s", tag, e.getMessage()); + success("Expected exception was thrown for APEConfig with a wrong path for tag '%s'\nAPE message was: %s", + tag, e.getMessage()); } } } @@ -208,7 +225,9 @@ public void tagTypeTest() { evaluation = new Evaluation.TagTypeEvaluation(tagInfo.tagType, false); for (String tag : tagInfo.tags) { try { - setupRun(getCorrectTemplate().put(tag, tagInfo.correctExample)); // set invalid value for non-boolean tag and run the configuration + setupRun(getCorrectTemplate().put(tag, tagInfo.correctExample)); // set invalid value for + // non-boolean tag and run the + // configuration evaluation.forTag(tag).result(true); } catch (Exception e) { evaluation.forTag(tag).result(false, e); @@ -218,9 +237,8 @@ public void tagTypeTest() { for (String tag : tagInfo.tags) { for (Object wrongExample : tagInfo.wrongExamples) { try { - //System.out.println("tag " + tag); - //System.out.println("value " + wrongExample); - setupRun(getCorrectTemplate().put(tag, wrongExample)); // set invalid value for boolean tag and run the configuration + setupRun(getCorrectTemplate().put(tag, wrongExample)); // set invalid value for boolean tag and + // run the configuration evaluation.forTag(tag).result(false); } catch (Exception e) { evaluation.forTag(tag).result(true, e); @@ -234,7 +252,8 @@ public void tagTypeTest() { * Creates a configuration from JSON and executes {@link APECoreConfig} * * @param obj The configuration to set up. - * @throws IOException Error if a path provided in the configuration file is incorrect. + * @throws IOException Error if a path provided in the + * configuration file is incorrect. * @throws OWLOntologyCreationException Error reading the OWL (ontology) file. */ private void setupRun(JSONObject obj) throws IOException, OWLOntologyCreationException { diff --git a/src/test/java/nl/uu/cs/ape/sat/test/utils/Evaluation.java b/src/test/java/nl/uu/cs/ape/sat/test/utils/Evaluation.java index 310ac46..289ea36 100644 --- a/src/test/java/nl/uu/cs/ape/sat/test/utils/Evaluation.java +++ b/src/test/java/nl/uu/cs/ape/sat/test/utils/Evaluation.java @@ -2,13 +2,16 @@ import org.junit.jupiter.api.Assertions; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public abstract class Evaluation { private static boolean debugMode = true; public static void success(String message, Object... params) { if (debugMode) { - System.out.println("\u001B[32mSUCCESS: " + String.format(message, params) + "\u001B[0m"); + log.info("\u001B[32mSUCCESS: " + String.format(message, params) + "\u001B[0m"); } } diff --git a/src/test/java/nl/uu/cs/ape/sat/test/utils/GitHubRepo.java b/src/test/java/nl/uu/cs/ape/sat/test/utils/GitHubRepo.java index 7dee596..3bd5e8b 100644 --- a/src/test/java/nl/uu/cs/ape/sat/test/utils/GitHubRepo.java +++ b/src/test/java/nl/uu/cs/ape/sat/test/utils/GitHubRepo.java @@ -3,6 +3,8 @@ import org.apache.commons.io.FileUtils; import org.json.JSONObject; +import lombok.extern.slf4j.Slf4j; + import java.io.*; import java.net.URL; import java.net.URLConnection; @@ -18,6 +20,11 @@ import static nl.uu.cs.ape.sat.test.utils.Evaluation.success; import static org.junit.jupiter.api.Assertions.assertFalse; +/** + * The {@code GitHubRepo} class is used to download test use cases from a GitHub + * repository. + */ +@Slf4j public class GitHubRepo { private String absoluteLocalRoot; @@ -43,7 +50,7 @@ public void cleanUp() { FileUtils.deleteDirectory(directory); assertFalse(directory.exists()); } catch (IOException e) { - System.out.println(String.format("Could not delete folder '%s':\n%s", this.absoluteLocalRoot, e.getMessage())); + log.info(String.format("Could not delete folder '%s':\n%s", this.absoluteLocalRoot, e.getMessage())); } } @@ -88,7 +95,8 @@ public JSONObject getJSONObject(String filePath) { private static int file_count = 0; public String createJSONFile(JSONObject put, String name) { - TempFile temp = new TempFile(absoluteLocalRoot, new SimpleDateFormat("yyyyMMdd_HHmmss_").format(new Date()) + name + "_" + (file_count++) + ".json"); + TempFile temp = new TempFile(absoluteLocalRoot, + new SimpleDateFormat("yyyyMMdd_HHmmss_").format(new Date()) + name + "_" + (file_count++) + ".json"); temp.write(put.toString(3)); int key = temp.hash(); if (!files.containsKey(key)) { @@ -102,14 +110,15 @@ private static class TempFile { private String folder = ""; private String file = ""; - public TempFile(String folder, String file){ + public TempFile(String folder, String file) { this.folder = folder; this.file = file; } - public TempFile(){ } + public TempFile() { + } - public String getFilePath(){ + public String getFilePath() { return Paths.get(folder, file).toString(); } @@ -194,7 +203,8 @@ private void fetchFile() { File targetFile; byte[] fileData; try { - url = new URL(String.format("https://raw.githubusercontent.com/%s/%s/%s", this.repository, this.commit, this.relative_file_path).replace("\\", "/")); + url = new URL(String.format("https://raw.githubusercontent.com/%s/%s/%s", this.repository, this.commit, + this.relative_file_path).replace("\\", "/")); con = url.openConnection(); // open the url connection. dis = new DataInputStream(con.getInputStream()); fileData = new byte[con.getContentLength()]; @@ -214,7 +224,8 @@ private void fetchFile() { @Override public String toString() { - return String.format("https://github.com/%s/blob/%s/%s", this.repository, this.commit, this.relative_file_path); + return String.format("https://github.com/%s/blob/%s/%s", this.repository, this.commit, + this.relative_file_path); } } } diff --git a/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java b/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java index f79b4ae..62f236c 100644 --- a/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java +++ b/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java @@ -15,6 +15,8 @@ import org.junit.jupiter.api.Test; import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import lombok.extern.slf4j.Slf4j; + import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -31,6 +33,7 @@ * * @author Maurin Voshol */ +@Slf4j class UseCaseTest { private static GitHubRepo repo; @@ -74,9 +77,7 @@ void MassSpectometry() throws APEConfigException, OWLOntologyCreationException, void testUseCase(String name, String evaluationPath) throws APEConfigException, OWLOntologyCreationException, IOException { - System.out.println("-------------------------------------------------------------"); - System.out.println(" TEST " + name); - System.out.println("-------------------------------------------------------------"); + log.debug("PERFORM TEST: " + name); UseCase useCase = new UseCase(evaluationPath, repo); @@ -267,34 +268,32 @@ public JSONObject execute(JSONObject base_configuration) { } public void print(String name) { - System.out.println("-------------------------------------------------------------"); - System.out.println(" MUTATION FOR: " + name); + log.debug("\tMUTATION FOR: " + name); if (description != null) { - System.out.println(" DESCRIPTION: " + description); + log.debug("\tDESCRIPTION: " + description); } if (config_mutations != null) { - System.out.println(" CONFIG MUTATION: " + config_mutations.toString()); + log.debug("\tCONFIG MUTATION: " + config_mutations.toString()); } if (add_constraints != null) { - System.out.println(" ADD CONSTRAINTS: " + add_constraints.toString()); + log.debug("\tADD CONSTRAINTS: " + add_constraints.toString()); } if (replace_constraints != null) { - System.out.println( - " REPLACE CONSTRAINTS: " + replace_constraints.getJSONArray(CONSTRAINTS).toString()); + log.debug( + "\tREPLACE CONSTRAINTS: " + replace_constraints.getJSONArray(CONSTRAINTS).toString()); } if (number_of_cwl_files != 0) { - System.out.println(" NUMBER OF CWL FILES: " + number_of_cwl_files); + log.debug("\tNUMBER OF CWL FILES: " + number_of_cwl_files); } - System.out.println(" MINIMAL SOLUTION LENGTH: " + solution_length_start); - System.out.println(" EXPECTED AMOUNT OF SOLUTIONS STARTING AT MINIMAL SOLUTIONS: " + log.debug("\tMINIMAL SOLUTION LENGTH: " + solution_length_start); + log.debug("\tEXPECTED AMOUNT OF SOLUTIONS STARTING AT MINIMAL SOLUTIONS: " + Arrays.toString(expected_no_solutions)); - System.out.println("-------------------------------------------------------------\n"); } } } From c44d3f1c224846192de84c1c139ec7c91a0b5d43 Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Tue, 4 Jul 2023 17:43:30 +0200 Subject: [PATCH 07/18] Refactor & generate CWL input (YML) file --- src/main/java/nl/uu/cs/ape/APE.java | 38 ++- src/main/java/nl/uu/cs/ape/Main.java | 22 +- .../cs/ape/constraints/ConstraintFactory.java | 168 +++++------ .../ape/constraints/ConstraintTemplate.java | 4 +- .../ConstraintTemplateParameter.java | 4 +- .../implSAT/EnforceModuleRelatedRules.java | 2 +- .../solutionStructure/AbstractCWLCreator.java | 279 ++++++++++-------- .../solutionStructure/CWLCreatorBase.java | 22 +- .../solutionStructure/DefaultCWLCreator.java | 43 ++- .../ExecutableCWLCreator.java | 99 +++++-- .../core/solutionStructure/ModuleNode.java | 40 ++- .../solutionStructure/SolutionWorkflow.java | 2 +- .../ape/core/solutionStructure/TypeNode.java | 71 +++-- src/main/java/nl/uu/cs/ape/io/APEFiles.java | 6 +- .../java/nl/uu/cs/ape/models/AllTypes.java | 24 +- src/main/java/nl/uu/cs/ape/models/Type.java | 3 +- .../logic/constructs/TaxonomyPredicate.java | 6 +- .../ape/models/sltlxStruc/SLTLxFormula.java | 1 - .../cs/ape/models/sltlxStruc/SLTLxUntil.java | 1 + .../SLTLxVariableSubstitutionCollection.java | 2 +- .../SLTLxTemplateFormula.java | 234 +++++++-------- .../nl/uu/cs/ape/parser/SLTLxSATVisitor.java | 6 +- .../nl/uu/cs/ape/utils/APEDomainSetup.java | 6 +- .../java/nl/uu/cs/ape/utils/APEUtils.java | 3 +- .../java/nl/uu/cs/ape/utils/BioToolsAPI.java | 5 +- .../java/nl/uu/cs/ape/utils/OWLReader.java | 17 +- .../test/configuration/APEConfigTagTest.java | 4 +- .../uu/cs/ape/sat/test/utils/GitHubRepo.java | 4 +- .../cs/ape/sat/test/utils/TestResources.java | 26 +- 29 files changed, 628 insertions(+), 514 deletions(-) diff --git a/src/main/java/nl/uu/cs/ape/APE.java b/src/main/java/nl/uu/cs/ape/APE.java index 8d0bf25..7e51da9 100644 --- a/src/main/java/nl/uu/cs/ape/APE.java +++ b/src/main/java/nl/uu/cs/ape/APE.java @@ -424,21 +424,21 @@ public static boolean writeExecutableWorkflows(SolutionsList allSolutions) { } else { executeDir.mkdir(); } - log.trace("Loading"); + log.debug("Generating executable scripts."); /* Creating the requested scripts in parallel. */ allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noExecutions).forEach(solution -> { try { File script = executionsFolder.resolve(solution.getFileName() + ".sh").toFile(); APEFiles.write2file(solution.getScriptExecution(), script, false); - log.trace("."); + } catch (IOException e) { - log.error("Error occurred while writing a graph to the file system."); + log.error("Error occurred while writing an executable (workflow) script to the file system."); e.printStackTrace(); } }); - APEUtils.timerPrintText("executingWorkflows", "Workflows have been executed."); + APEUtils.timerPrintText("executingWorkflows", "Workflow executables have been generated."); return true; } @@ -481,7 +481,7 @@ public static boolean writeDataFlowGraphs(SolutionsList allSolutions, RankDir or } else { graphDir.mkdir(); } - log.trace("Loading"); + log.debug("Generating data flow graphs (png)."); /* Creating the requested graphs in parallel. */ allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noGraphs).forEach(solution -> { try { @@ -489,9 +489,9 @@ public static boolean writeDataFlowGraphs(SolutionsList allSolutions, RankDir or Path path = graphsFolder.resolve(title); solution.getDataflowGraph(title, orientation).write2File(path.toFile(), allSolutions.getRunConfiguration().getDebugMode()); - log.trace("."); + } catch (IOException e) { - log.error("Error occurred while writing a graph to the file system."); + log.error("Error occurred while data flow graphs (png) to the file system."); e.printStackTrace(); } }); @@ -540,7 +540,7 @@ public static boolean writeControlFlowGraphs(SolutionsList allSolutions, RankDir } else { graphDir.mkdir(); } - log.trace("Loading"); + log.debug("Generating control flow graphs (png)."); /* Creating the requested graphs in parallel. */ allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noGraphs).forEach(solution -> { try { @@ -548,9 +548,9 @@ public static boolean writeControlFlowGraphs(SolutionsList allSolutions, RankDir Path path = graphsFolder.resolve(title); solution.getControlflowGraph(title, orientation).write2File(path.toFile(), allSolutions.getRunConfiguration().getDebugMode()); - log.trace("."); + } catch (IOException e) { - log.error("Error occurred while writing a graph to the file system."); + log.error("Error occurred while writing control flow graphs (png) to the file system."); e.printStackTrace(); } }); @@ -586,16 +586,22 @@ public static boolean writeCWLWorkflows(SolutionsList allSolutions) { // Create the CWL directory if it does not already exist cwlDir.mkdir(); } - log.trace("Loading"); + log.debug("Generating CWL files."); // Write the CWL files allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noCWLFiles).forEach(solution -> { try { - String title = solution.getFileName() + ".cwl"; - File script = cwlFolder.resolve(title).toFile(); + // Write the cwl file to the file system + String titleCWL = solution.getFileName() + ".cwl"; + File script = cwlFolder.resolve(titleCWL).toFile(); DefaultCWLCreator cwlCreator = new DefaultCWLCreator(solution); APEFiles.write2file(cwlCreator.generate(), script, false); - log.trace("."); + + // Write the cwl input file (in YML) to the file system + String titleInputs = solution.getFileName() + "_inp.yml"; + File inputScipt = cwlFolder.resolve(titleInputs).toFile(); + APEFiles.write2file(cwlCreator.generateCWLWorkflowInputs(), inputScipt, false); + } catch (IOException e) { log.error("Error occurred while writing a CWL file to the file system."); e.printStackTrace(); @@ -620,7 +626,7 @@ private static void deleteExistingFiles(File dirName, String filePrefix) { try { Files.delete(f.toPath()); } catch (IOException e) { - System.err.printf("Failed to delete file %s%n", f.getName()); + log.warn("Failed to delete file {}.", f.getName()); } }); } @@ -669,7 +675,7 @@ public static boolean writeExecutableCWLWorkflows(SolutionsList allSolutions, AP File script = executableCWLFolder.resolve(title).toFile(); ExecutableCWLCreator cwlCreator = new ExecutableCWLCreator(solution); APEFiles.write2file(cwlCreator.generate(), script, false); - log.trace("."); + } catch (IOException e) { log.error("Error occurred while writing an executable CWL file to the file system."); e.printStackTrace(); diff --git a/src/main/java/nl/uu/cs/ape/Main.java b/src/main/java/nl/uu/cs/ape/Main.java index ad65539..44b5312 100644 --- a/src/main/java/nl/uu/cs/ape/Main.java +++ b/src/main/java/nl/uu/cs/ape/Main.java @@ -40,13 +40,13 @@ public static void main(String[] args) { try { solutionsNo = Integer.parseInt(args[1]); } catch (NumberFormatException e) { - System.err.println("Second parameter is not an integer."); + log.error("Second parameter is not an integer."); } } else { path = "./config.json"; } if (!APEFiles.isValidReadFile(path)) { - System.err.println("Bad path."); + log.error("Bad path."); return; } @@ -57,8 +57,8 @@ public static void main(String[] args) { apeFramework = new APE(path); } catch (APEConfigException | JSONException | IOException | OWLOntologyCreationException e) { - System.err.println("Error in setting up the APE framework:"); - System.err.println(e.getMessage()); + log.error("Error in setting up the APE framework:"); + log.error(e.getMessage()); return; } @@ -75,17 +75,17 @@ public static void main(String[] args) { solutions = apeFramework.runSynthesis(runConfig); } catch (APEConfigException e) { - System.err.println("Error in synthesis execution. APE configuration error:"); - System.err.println(e.getMessage()); + log.error("Error in synthesis execution. APE configuration error:"); + log.error(e.getMessage()); return; } catch (JSONException e) { - System.err.println( + log.error( "Error in synthesis execution. Bad JSON formatting (APE configuration or constriants JSON). "); - System.err.println(e.getMessage()); + log.error(e.getMessage()); return; } catch (IOException e) { - System.err.println("Error in synthesis execution."); - System.err.println(e.getMessage()); + log.error("Error in synthesis execution."); + log.error(e.getMessage()); return; } @@ -103,7 +103,7 @@ public static void main(String[] args) { APE.writeCWLWorkflows(solutions); APE.writeExecutableCWLWorkflows(solutions, apeFramework.getConfig()); } catch (IOException e) { - System.err.println("Error in writing the solutions. to the file system."); + log.error("Error in writing the solutions. to the file system."); e.printStackTrace(); } } diff --git a/src/main/java/nl/uu/cs/ape/constraints/ConstraintFactory.java b/src/main/java/nl/uu/cs/ape/constraints/ConstraintFactory.java index de1321a..f0cb773 100644 --- a/src/main/java/nl/uu/cs/ape/constraints/ConstraintFactory.java +++ b/src/main/java/nl/uu/cs/ape/constraints/ConstraintFactory.java @@ -2,6 +2,7 @@ import java.util.*; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.automaton.ModuleAutomaton; import nl.uu.cs.ape.automaton.TypeAutomaton; import nl.uu.cs.ape.models.AllModules; @@ -22,6 +23,7 @@ * * @author Vedran Kasalica */ +@Slf4j public class ConstraintFactory { private Map constraintTemplates; @@ -63,7 +65,7 @@ public ConstraintTemplate getConstraintTemplate(String constraintID) { */ public boolean addConstraintTemplate(ConstraintTemplate constraintTemplate) { if (constraintTemplates.put(constraintTemplate.getConstraintID(), constraintTemplate) != null) { - System.err.println("Duplicate constraint ID: " + constraintTemplate.getConstraintID() + log.warn("Duplicate constraint ID: " + constraintTemplate.getConstraintID() + ". Please change the ID in order to be able to use the constraint template."); return false; } @@ -111,124 +113,124 @@ public boolean initializeConstraints(AllModules allModules, AllTypes allTypes) { /* * ID: ite_m */ - ConstraintTemplate currTemplate = new Constraint_if_then_module("ite_m", moduleParam2, + ConstraintTemplate currTemplate = new ConstraintIfThenModule("ite_m", moduleParam2, "If 1st operation is used, then 2nd operation must be used subsequently."); addConstraintTemplate(currTemplate); /* * ID: itn_m */ - currTemplate = new Constraint_if_then_not_module("itn_m", moduleParam2, + currTemplate = new ConstraintIfThenNotModule("itn_m", moduleParam2, "If 1st operation is used, then 2nd operation cannot be used subsequently."); addConstraintTemplate(currTemplate); /* * ID: depend_m */ - currTemplate = new Constraint_depend_module("depend_m", moduleParam2, + currTemplate = new ConstraintDependModule("depend_m", moduleParam2, "If 1st operation is used, then we must have used 2nd operation prior to it."); addConstraintTemplate(currTemplate); /* * ID: next_m */ - currTemplate = new Constraint_next_module("next_m", moduleParam2, + currTemplate = new Constraint_nextModule("next_m", moduleParam2, "If 1st operation is used, then 2nd operation must be used as the next operation in the sequence."); addConstraintTemplate(currTemplate); /* * ID: prev_m */ - currTemplate = new Constraint_prev_module("prev_m", moduleParam2, + currTemplate = new Constraint_prevModule("prev_m", moduleParam2, "If 1st operation is used, then we must have used 2nd operation as a previous operation in the sequence."); addConstraintTemplate(currTemplate); /* * ID: use_m */ - currTemplate = new Constraint_use_module("use_m", moduleParam1, "Use operation in the solution."); + currTemplate = new ConstraintUseModule("use_m", moduleParam1, "Use operation in the solution."); addConstraintTemplate(currTemplate); /* * ID: nuse_m */ - currTemplate = new Constraint_not_use_module("nuse_m", moduleParam1, + currTemplate = new ConstraintNotUseModule("nuse_m", moduleParam1, "Do not use operation in the solution."); addConstraintTemplate(currTemplate); /* * ID: last_m */ - currTemplate = new Constraint_last_module("last_m", moduleParam1, + currTemplate = new Constraint_lastModule("last_m", moduleParam1, "Use operation as the last operation in the solution."); addConstraintTemplate(currTemplate); /* * ID: use_t */ - currTemplate = new Constraint_use_type("use_t", typeParam1, "Use type in the solution."); + currTemplate = new ConstraintUseType("use_t", typeParam1, "Use type in the solution."); addConstraintTemplate(currTemplate); /* * ID: nuse_t */ - currTemplate = new Constraint_not_use_type("nuse_t", typeParam1, + currTemplate = new ConstraintNotUseType("nuse_t", typeParam1, "Do not use type in the solution."); addConstraintTemplate(currTemplate); /* * ID: use_ite_t */ - currTemplate = new Constraint_if_use_then_type("use_ite_t", typeParam2, + currTemplate = new ConstraintIfUseThenType("use_ite_t", typeParam2, "If 1st data is used, then 2nd data must be used subsequently."); addConstraintTemplate(currTemplate); /* * ID: use_itn_t */ - currTemplate = new Constraint_if_use_then_not_type("use_itn_t", typeParam2, + currTemplate = new ConstraintIfUseThenNotType("use_itn_t", typeParam2, "If 1st data is used, then 2nd data cannot be used subsequently."); addConstraintTemplate(currTemplate); /* - * ID: operation_input + * ID: operationInput */ - currTemplate = new Constraint_use_module_with_input("operation_input", moduleNlabel, + currTemplate = new ConstraintUseModuleWithInput("operationInput", moduleNlabel, "Use the operation with an input of the given type."); addConstraintTemplate(currTemplate); /* - * ID: operation_output + * ID: operationOutput */ - currTemplate = new Constraint_use_module_with_output("operation_output", moduleNlabel, + currTemplate = new ConstraintUseModuleWithOutput("operationOutput", moduleNlabel, "Use the operation to generate an output of the given type."); addConstraintTemplate(currTemplate); /* * ID: connected_op */ - currTemplate = new Constraint_connected_modules("connected_op", moduleParam2, + currTemplate = new Constraint_connectedModules("connected_op", moduleParam2, "1st operation should generate an output used by the 2nd operation."); addConstraintTemplate(currTemplate); /* * ID: not_connected_op */ - currTemplate = new Constraint_not_connected_modules("not_connected_op", moduleParam2, + currTemplate = new ConstraintNot_connectedModules("not_connected_op", moduleParam2, "1st operation should never generate an output used by the 2nd operation."); addConstraintTemplate(currTemplate); /* * ID: not_repeat_op */ - currTemplate = new Constraint_not_repeat_modules("not_repeat_op", moduleParam1, + currTemplate = new ConstraintNot_repeatModules("not_repeat_op", moduleParam1, "No operation that belongs to the subtree should be repeated over."); addConstraintTemplate(currTemplate); /* * ID: gen_t * - * currTemplate = new Constraint_gen_type("gen_t", typeParam1, + * currTemplate = new ConstraintGenType("gen_t", typeParam1, * "Generate type ${parameter_1} in the solution."); * addConstraintTemplate(currTemplate); */ @@ -236,7 +238,7 @@ public boolean initializeConstraints(AllModules allModules, AllTypes allTypes) { /* * ID: ngen_t Do not generate type ${parameter_1} in the solution. * - * currTemplate = new Constraint_not_gen_type("ngen_t", typeParam1, + * currTemplate = new ConstraintNotGenType("ngen_t", typeParam1, * "Do not generate type ${parameter_1} in the solution."); * addConstraintTemplate(currTemplate); */ @@ -245,7 +247,7 @@ public boolean initializeConstraints(AllModules allModules, AllTypes allTypes) { * ID: gen_ite_t If we have data type ${parameter_1}, then generate type * ${parameter_2} subsequently. * - * currTemplate = new Constraint_if_gen_then_type("gen_ite_t", typeParam2, + * currTemplate = new ConstraintIf_genThenType("gen_ite_t", typeParam2, * "If we have generated data type ${parameter_1}, then generate type ${parameter_2} subsequently." * ); * addConstraintTemplate(currTemplate); @@ -254,7 +256,7 @@ public boolean initializeConstraints(AllModules allModules, AllTypes allTypes) { /* * ID: gen_itn_t If we have generated data type ${parameter_1}, then do not * generate type ${parameter_2} subsequently. - * currTemplate = new Constraint_if_gen_then_not_type("gen_itn_t", typeParam2, + * currTemplate = new ConstraintIf_genThenNotType("gen_itn_t", typeParam2, * "If we have generated data type ${parameter_1}, then do not generate type ${parameter_2} subsequently." * ); * addConstraintTemplate(currTemplate); @@ -315,7 +317,7 @@ public boolean isGoodConstraintFormat(String constraintID, Listparameters[0], then we must have used * parameters[1] prior to it using the function {@link #getConstraint}. */ - public class Constraint_depend_module extends ConstraintTemplate { + public class ConstraintDependModule extends ConstraintTemplate { /** * Instantiates a new Constraint depend module. * @@ -323,7 +325,7 @@ public class Constraint_depend_module extends ConstraintTemplate { * @param parameterTypes the parameter types * @param description the description */ - protected Constraint_depend_module(String id, List parameterTypes, + protected ConstraintDependModule(String id, List parameterTypes, String description) { super(id, parameterTypes, description); } @@ -335,7 +337,7 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.depend_module(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); + return SLTLxTemplateFormula.dependModule(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); } } @@ -344,7 +346,7 @@ public String getConstraint(List parameters, APEDomainSetup d * Generate type parameters[0] in the solution using the function * {@link #getConstraint}. */ - public class Constraint_gen_type extends ConstraintTemplate { + public class ConstraintGenType extends ConstraintTemplate { /** * Instantiates a new Constraint gen type. * @@ -352,7 +354,7 @@ public class Constraint_gen_type extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_gen_type(String id, List parametersNo, String description) { + protected ConstraintGenType(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -376,7 +378,7 @@ public String getConstraint(List parameters, APEDomainSetup d * type parameters[1] subsequently using the function * {@link #getConstraint}. */ - public class Constraint_if_gen_then_not_type extends ConstraintTemplate { + public class ConstraintIf_genThenNotType extends ConstraintTemplate { /** * Instantiates a new Constraint if gen then not type. * @@ -384,7 +386,7 @@ public class Constraint_if_gen_then_not_type extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_if_gen_then_not_type(String id, List parametersNo, + protected ConstraintIf_genThenNotType(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -396,8 +398,8 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.itn_type(parameters.get(0), parameters.get(1), AtomType.MEMORY_TYPE, - moduleAutomaton, typeAutomaton.getMemoryTypesBlocks(), mappings); + return SLTLxTemplateFormula.itnType(parameters.get(0), parameters.get(1), AtomType.MEMORY_TYPE, + typeAutomaton.getMemoryTypesBlocks(), mappings); } } @@ -406,7 +408,7 @@ public String getConstraint(List parameters, APEDomainSetup d * If we have generated data module parameters[0], then generate * parameters[1] subsequently using the function {@link #getConstraint}. */ - public class Constraint_if_gen_then_type extends ConstraintTemplate { + public class ConstraintIf_genThenType extends ConstraintTemplate { /** * Instantiates a new Constraint if gen then type. * @@ -414,7 +416,7 @@ public class Constraint_if_gen_then_type extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_if_gen_then_type(String id, List parametersNo, + protected ConstraintIf_genThenType(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -426,8 +428,8 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.ite_type(parameters.get(0), parameters.get(1), AtomType.MEMORY_TYPE, - moduleAutomaton, typeAutomaton.getMemoryTypesBlocks(), mappings); + return SLTLxTemplateFormula.iteType(parameters.get(0), parameters.get(1), AtomType.MEMORY_TYPE, + typeAutomaton.getMemoryTypesBlocks(), mappings); } } @@ -436,7 +438,7 @@ public String getConstraint(List parameters, APEDomainSetup d * If we use module parameters[0], then use parameters[1] * subsequently using the function {@link #getConstraint}. */ - public class Constraint_if_then_module extends ConstraintTemplate { + public class ConstraintIfThenModule extends ConstraintTemplate { /** * Instantiates a new Constraint if then module. * @@ -444,7 +446,7 @@ public class Constraint_if_then_module extends ConstraintTemplate { * @param parameterTypes the parameter types * @param description the description */ - protected Constraint_if_then_module(String id, List parameterTypes, + protected ConstraintIfThenModule(String id, List parameterTypes, String description) { super(id, parameterTypes, description); } @@ -456,7 +458,7 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.ite_module(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); + return SLTLxTemplateFormula.iteModule(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); } } @@ -465,7 +467,7 @@ public String getConstraint(List parameters, APEDomainSetup d * If we use module parameters[0], then do not use parameters[1] * subsequently using the function {@link #getConstraint}. */ - public class Constraint_if_then_not_module extends ConstraintTemplate { + public class ConstraintIfThenNotModule extends ConstraintTemplate { /** * Instantiates a new Constraint if then not module. * @@ -473,7 +475,7 @@ public class Constraint_if_then_not_module extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_if_then_not_module(String id, List parametersNo, + protected ConstraintIfThenNotModule(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -485,7 +487,7 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.itn_module(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); + return SLTLxTemplateFormula.itnModule(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); } } @@ -494,7 +496,7 @@ public String getConstraint(List parameters, APEDomainSetup d * If we have used data module parameters[0], then do not use type * parameters[1] subsequently using the function {@link #getConstraint}. */ - public class Constraint_if_use_then_not_type extends ConstraintTemplate { + public class ConstraintIfUseThenNotType extends ConstraintTemplate { /** * Instantiates a new Constraint if use then not type. * @@ -502,7 +504,7 @@ public class Constraint_if_use_then_not_type extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_if_use_then_not_type(String id, List parametersNo, + protected ConstraintIfUseThenNotType(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -514,8 +516,8 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.itn_type(parameters.get(0), parameters.get(1), AtomType.USED_TYPE, - moduleAutomaton, typeAutomaton.getUsedTypesBlocks(), mappings); + return SLTLxTemplateFormula.itnType(parameters.get(0), parameters.get(1), AtomType.USED_TYPE, + typeAutomaton.getUsedTypesBlocks(), mappings); } } @@ -524,7 +526,7 @@ public String getConstraint(List parameters, APEDomainSetup d * If we have used data module parameters[0], then use * parameters[1] subsequently using the function {@link #getConstraint}. */ - public class Constraint_if_use_then_type extends ConstraintTemplate { + public class ConstraintIfUseThenType extends ConstraintTemplate { /** * Instantiates a new Constraint if use then type. * @@ -532,7 +534,7 @@ public class Constraint_if_use_then_type extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_if_use_then_type(String id, List parametersNo, + protected ConstraintIfUseThenType(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -544,8 +546,8 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.ite_type(parameters.get(0), parameters.get(1), AtomType.USED_TYPE, - moduleAutomaton, typeAutomaton.getUsedTypesBlocks(), mappings); + return SLTLxTemplateFormula.iteType(parameters.get(0), parameters.get(1), AtomType.USED_TYPE, + typeAutomaton.getUsedTypesBlocks(), mappings); } } @@ -554,7 +556,7 @@ public String getConstraint(List parameters, APEDomainSetup d * Use parameters[0] as last module in the solution. using the function * {@link #getConstraint}. */ - public class Constraint_last_module extends ConstraintTemplate { + public class Constraint_lastModule extends ConstraintTemplate { /** * Instantiates a new Constraint last module. * @@ -562,7 +564,7 @@ public class Constraint_last_module extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_last_module(String id, List parametersNo, + protected Constraint_lastModule(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -583,7 +585,7 @@ public String getConstraint(List parameters, APEDomainSetup d * If we use module parameters[0], then use parameters[1] as a * next module in the sequence using the function {@link #getConstraint}. */ - public class Constraint_next_module extends ConstraintTemplate { + public class Constraint_nextModule extends ConstraintTemplate { /** * Instantiates a new Constraint next module. * @@ -591,7 +593,7 @@ public class Constraint_next_module extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_next_module(String id, List parametersNo, + protected Constraint_nextModule(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -603,7 +605,7 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.next_module(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); + return SLTLxTemplateFormula.nextModule(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); } } @@ -612,7 +614,7 @@ public String getConstraint(List parameters, APEDomainSetup d * Do not generate type parameters[0] in the solution using the function * {@link #getConstraint}. */ - public class Constraint_not_gen_type extends ConstraintTemplate { + public class ConstraintNotGenType extends ConstraintTemplate { /** * Instantiates a new Constraint not gen type. * @@ -620,7 +622,7 @@ public class Constraint_not_gen_type extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_not_gen_type(String id, List parametersNo, + protected ConstraintNotGenType(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -644,7 +646,7 @@ public String getConstraint(List parameters, APEDomainSetup d * Do not use module parameters[0] in the solution using the function * {@link #getConstraint}. */ - public class Constraint_not_use_module extends ConstraintTemplate { + public class ConstraintNotUseModule extends ConstraintTemplate { /** * Instantiates a new Constraint not use module. * @@ -652,7 +654,7 @@ public class Constraint_not_use_module extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_not_use_module(String id, List parametersNo, + protected ConstraintNotUseModule(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -675,7 +677,7 @@ public String getConstraint(List parameters, APEDomainSetup d * Do not use type parameters[0] in the solution using the function * {@link #getConstraint}. */ - public class Constraint_not_use_type extends ConstraintTemplate { + public class ConstraintNotUseType extends ConstraintTemplate { /** * Instantiates a new Constraint not use type. * @@ -683,7 +685,7 @@ public class Constraint_not_use_type extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_not_use_type(String id, List parametersNo, + protected ConstraintNotUseType(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -707,7 +709,7 @@ public String getConstraint(List parameters, APEDomainSetup d * parameters[1] as a previous module in the sequence. using the function * {@link #getConstraint}. */ - public class Constraint_prev_module extends ConstraintTemplate { + public class Constraint_prevModule extends ConstraintTemplate { /** * Instantiates a new Constraint prev module. * @@ -715,7 +717,7 @@ public class Constraint_prev_module extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_prev_module(String id, List parametersNo, + protected Constraint_prevModule(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -727,7 +729,7 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.prev_module(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); + return SLTLxTemplateFormula.prevModule(parameters.get(0), parameters.get(1), moduleAutomaton, mappings); } } @@ -736,7 +738,7 @@ public String getConstraint(List parameters, APEDomainSetup d * Use module parameters[0] in the solution using the function * {@link #getConstraint}. */ - public class Constraint_use_module extends ConstraintTemplate { + public class ConstraintUseModule extends ConstraintTemplate { /** * Instantiates a new Constraint use module. * @@ -744,7 +746,7 @@ public class Constraint_use_module extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_use_module(String id, List parametersNo, String description) { + protected ConstraintUseModule(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -766,7 +768,7 @@ public String getConstraint(List parameters, APEDomainSetup d * Use type parameters[0] in the solution using the function * {@link #getConstraint}. */ - public class Constraint_use_type extends ConstraintTemplate { + public class ConstraintUseType extends ConstraintTemplate { /** * Instantiates a new Constraint use type. * @@ -774,7 +776,7 @@ public class Constraint_use_type extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_use_type(String id, List parametersNo, String description) { + protected ConstraintUseType(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -796,7 +798,7 @@ public String getConstraint(List parameters, APEDomainSetup d * Use operation ${parameter_1} with input labeled ${parameter_2}. * {@link #getConstraint}. */ - public class Constraint_use_module_with_input extends ConstraintTemplate { + public class ConstraintUseModuleWithInput extends ConstraintTemplate { /** * Instantiates a new Constraint use type. * @@ -804,7 +806,7 @@ public class Constraint_use_module_with_input extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_use_module_with_input(String id, List parametersNo, + protected ConstraintUseModuleWithInput(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -817,7 +819,7 @@ public String getConstraint(List parameters, APEDomainSetup d return null; } - return SLTLxTemplateFormula.use_module_input(parameters.get(0), parameters.get(1), moduleAutomaton, + return SLTLxTemplateFormula.useModuleInput(parameters.get(0), parameters.get(1), moduleAutomaton, typeAutomaton, mappings); } } @@ -827,7 +829,7 @@ public String getConstraint(List parameters, APEDomainSetup d * Use operation ${parameter_1} to generate output labeled ${parameter_2} * {@link #getConstraint}. */ - public class Constraint_use_module_with_output extends ConstraintTemplate { + public class ConstraintUseModuleWithOutput extends ConstraintTemplate { /** * Instantiates a new Constraint use type. * @@ -835,7 +837,7 @@ public class Constraint_use_module_with_output extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_use_module_with_output(String id, List parametersNo, + protected ConstraintUseModuleWithOutput(String id, List parametersNo, String description) { super(id, parametersNo, description); } @@ -848,7 +850,7 @@ public String getConstraint(List parameters, APEDomainSetup d return null; } - return SLTLxTemplateFormula.use_module_output(parameters.get(0), parameters.get(1), moduleAutomaton, + return SLTLxTemplateFormula.useModuleOutput(parameters.get(0), parameters.get(1), moduleAutomaton, typeAutomaton, mappings); } } @@ -858,7 +860,7 @@ public String getConstraint(List parameters, APEDomainSetup d * 1st operation should generate an output used by the 2nd operation * subsequently using the function {@link #getConstraint}. */ - public class Constraint_connected_modules extends ConstraintTemplate { + public class Constraint_connectedModules extends ConstraintTemplate { /** * Instantiates a new Constraint if then module. * @@ -866,7 +868,7 @@ public class Constraint_connected_modules extends ConstraintTemplate { * @param parameterTypes the parameter types * @param description the description */ - protected Constraint_connected_modules(String id, List parameterTypes, + protected Constraint_connectedModules(String id, List parameterTypes, String description) { super(id, parameterTypes, description); } @@ -878,7 +880,7 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.connected_modules(parameters.get(0), parameters.get(1), domainSetup, + return SLTLxTemplateFormula.connectedModules(parameters.get(0), parameters.get(1), moduleAutomaton, typeAutomaton, mappings); } } @@ -888,7 +890,7 @@ public String getConstraint(List parameters, APEDomainSetup d * 1st operation should not generate an output used by the 2nd operation * subsequently using the function {@link #getConstraint}. */ - public class Constraint_not_connected_modules extends ConstraintTemplate { + public class ConstraintNot_connectedModules extends ConstraintTemplate { /** * Instantiates a new Constraint if then module. * @@ -896,7 +898,7 @@ public class Constraint_not_connected_modules extends ConstraintTemplate { * @param parameterTypes the parameter types * @param description the description */ - protected Constraint_not_connected_modules(String id, List parameterTypes, + protected ConstraintNot_connectedModules(String id, List parameterTypes, String description) { super(id, parameterTypes, description); } @@ -908,7 +910,7 @@ public String getConstraint(List parameters, APEDomainSetup d super.throwParametersError(parameters.size()); return null; } - return SLTLxTemplateFormula.not_connected_modules(parameters.get(0), parameters.get(1), domainSetup, + return SLTLxTemplateFormula.notConnectedModules(parameters.get(0), parameters.get(1), moduleAutomaton, typeAutomaton, mappings); } } @@ -918,7 +920,7 @@ public String getConstraint(List parameters, APEDomainSetup d * No operation that belongs to the subtree should be repeated over. * {@link #getConstraint}. */ - public class Constraint_not_repeat_modules extends ConstraintTemplate { + public class ConstraintNot_repeatModules extends ConstraintTemplate { /** * Instantiates a new Constraint last module. * @@ -926,7 +928,7 @@ public class Constraint_not_repeat_modules extends ConstraintTemplate { * @param parametersNo the parameters no * @param description the description */ - protected Constraint_not_repeat_modules(String id, List parametersNo, + protected ConstraintNot_repeatModules(String id, List parametersNo, String description) { super(id, parametersNo, description); } diff --git a/src/main/java/nl/uu/cs/ape/constraints/ConstraintTemplate.java b/src/main/java/nl/uu/cs/ape/constraints/ConstraintTemplate.java index 74d3d01..e3342c1 100644 --- a/src/main/java/nl/uu/cs/ape/constraints/ConstraintTemplate.java +++ b/src/main/java/nl/uu/cs/ape/constraints/ConstraintTemplate.java @@ -3,6 +3,7 @@ import org.json.JSONArray; import org.json.JSONObject; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.automaton.ModuleAutomaton; import nl.uu.cs.ape.automaton.TypeAutomaton; import nl.uu.cs.ape.models.SATAtomMappings; @@ -17,6 +18,7 @@ * * @author Vedran Kasalica */ +@Slf4j public abstract class ConstraintTemplate { /** @@ -155,7 +157,7 @@ public JSONObject toJSON() { * @param givenParameters Provided number of parameters. */ public void throwParametersError(int givenParameters) { - System.err.println( + log.error( "Error in the constraints file.\nConstraint: " + this.description + "\nExpected number of parameters: " + parameters.size() + ".\nProvided number of parameters: " + givenParameters); diff --git a/src/main/java/nl/uu/cs/ape/constraints/ConstraintTemplateParameter.java b/src/main/java/nl/uu/cs/ape/constraints/ConstraintTemplateParameter.java index f50cf3b..eb82b44 100644 --- a/src/main/java/nl/uu/cs/ape/constraints/ConstraintTemplateParameter.java +++ b/src/main/java/nl/uu/cs/ape/constraints/ConstraintTemplateParameter.java @@ -6,6 +6,7 @@ import org.json.JSONException; import org.json.JSONObject; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.models.AbstractModule; import nl.uu.cs.ape.models.Module; import nl.uu.cs.ape.models.Type; @@ -21,6 +22,7 @@ * * @author Vedran Kasalica */ +@Slf4j public class ConstraintTemplateParameter { /** @@ -57,7 +59,7 @@ public ConstraintTemplateParameter() { */ public void addParameter(TaxonomyPredicate newParam) { if (newParam == null) { - System.err.println("Cannot add null as a dimension that characterises a Taxonomy Instance."); + log.warn("Cannot add null as a dimension that characterises a Taxonomy Instance."); } else { this.parameterTypes.add(newParam); } diff --git a/src/main/java/nl/uu/cs/ape/core/implSAT/EnforceModuleRelatedRules.java b/src/main/java/nl/uu/cs/ape/core/implSAT/EnforceModuleRelatedRules.java index b4f6a18..16d8f3b 100644 --- a/src/main/java/nl/uu/cs/ape/core/implSAT/EnforceModuleRelatedRules.java +++ b/src/main/java/nl/uu/cs/ape/core/implSAT/EnforceModuleRelatedRules.java @@ -941,7 +941,7 @@ public static Set moduleMandatoryUsage(AllModules allModules, Modu Set fullEncoding = new HashSet<>(); if (allModules.getModules().isEmpty()) { - System.err.println("No tools were I/O annotated."); + log.warn("No tools were I/O annotated."); return fullEncoding; } diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/AbstractCWLCreator.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/AbstractCWLCreator.java index baa13af..b1fed2f 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/AbstractCWLCreator.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/AbstractCWLCreator.java @@ -5,18 +5,23 @@ import java.util.HashMap; import java.util.List; +import lombok.extern.slf4j.Slf4j; + /** * Class to generate a CWL workflow structure from a given workflow solution. */ +@Slf4j public class AbstractCWLCreator extends CWLCreatorBase { /** * Maintain a list of the CWL parameter names which represent {@link TypeNode}s. - * I.e. this hashmap has TypeNode IDs as keys and their names in the CWL file as values. + * I.e. this hashmap has TypeNode IDs as keys and their names in the CWL file as + * values. */ private final HashMap workflowParameters = new HashMap<>(); /** * Instantiates a new CWL creator. + * * @param solution The solution to represent in CWL. */ public AbstractCWLCreator(SolutionWorkflow solution) { @@ -25,7 +30,8 @@ public AbstractCWLCreator(SolutionWorkflow solution) { @Override public String getCWLVersion() { - // CWL version 1.2.0-dev2 is the minimum version required for the features we use here. + // CWL version 1.2.0-dev2 is the minimum version required for the features we + // use here. return "v1.2.0-dev2"; } @@ -50,19 +56,19 @@ private void generateWorkflowInputs() { String inputName = String.format("input%o", workflowParameters.size() + 1); addParameter(typeNode, inputName); cwlRepresentation - // Name - .append(ind(1)) - .append(inputName) - .append(":\n") - // Data type - .append(ind(2)) - .append("type: File") - .append("\n") - // Format - .append(ind(2)) - .append("format: ") - .append(typeNode.getNodeID()) - .append("\n"); + // Name + .append(ind(1)) + .append(inputName) + .append(":\n") + // Data type + .append(ind(2)) + .append("type: File") + .append("\n") + // Format + .append(ind(2)) + .append("format: ") + .append(typeNode.getNodeID()) + .append("\n"); } } @@ -75,29 +81,31 @@ private void generateWorkflowOutputs() { int i = 1; for (TypeNode typeNode : solution.getWorkflowOutputTypeStates()) { cwlRepresentation - // Name - .append(ind(1)) - .append(String.format("output%o", i)) - .append(":\n") - // Data type - .append(ind(2)) - .append("type: File") - .append("\n") - // Format - .append(ind(2)) - .append("format: ") - .append(typeNode.getNodeID()) - .append("\n") - // outputSource - .append(ind(2)) - .append("outputSource: ") - .append(stepName(typeNode.getCreatedByModule())) - .append("/"); - // Get the id of the step run's output bound to this workflow output (step_name/output_name_ID) - int outId = typeNode.getCreatedByModule().getOutputTypes().get(i - 1).getAutomatonState().getLocalStateNumber(); + // Name + .append(ind(1)) + .append(String.format("output%o", i)) + .append(":\n") + // Data type + .append(ind(2)) + .append("type: File") + .append("\n") + // Format + .append(ind(2)) + .append("format: ") + .append(typeNode.getNodeID()) + .append("\n") + // outputSource + .append(ind(2)) + .append("outputSource: ") + .append(stepName(typeNode.getCreatedByModule())) + .append("/"); + // Get the id of the step run's output bound to this workflow output + // (step_name/output_name_ID) + int outId = typeNode.getCreatedByModule().getOutputTypes().get(i - 1).getAutomatonState() + .getLocalStateNumber(); cwlRepresentation - .append(inOutName(typeNode.getCreatedByModule(), "out", outId + 1)) - .append("\n"); + .append(inOutName(typeNode.getCreatedByModule(), "out", outId + 1)) + .append("\n"); i++; } } @@ -114,15 +122,16 @@ private void generateWorkflowSteps() { /** * Generate one workflow step. + * * @param moduleNode The {@link ModuleNode} related to the step. */ private void generateStep(ModuleNode moduleNode) { final int baseInd = 1; // Name cwlRepresentation - .append(ind(baseInd)) - .append(stepName(moduleNode)) - .append(":\n"); + .append(ind(baseInd)) + .append(stepName(moduleNode)) + .append(":\n"); generateStepIn(moduleNode); generateStepOut(moduleNode); generateStepRun(moduleNode); @@ -130,6 +139,7 @@ private void generateStep(ModuleNode moduleNode) { /** * Generate the "in" section of a workflow step. + * * @param moduleNode The {@link ModuleNode} that is the step. */ private void generateStepIn(ModuleNode moduleNode) { @@ -141,43 +151,44 @@ private void generateStepIn(ModuleNode moduleNode) { // Remove the last newline so the array is on the same line as "in:" deleteLastCharacters(1); cwlRepresentation - .append(" ") - .append("[]") - .append("\n"); + .append(" ") + .append("[]") + .append("\n"); return; } int i = 0; for (TypeNode typeNode : moduleNode.getInputTypes()) { cwlRepresentation - .append(ind(baseInd + 1)) - .append(inOutName(moduleNode, "in", i + 1)) - .append(": ") - .append(workflowParameters.get(typeNode.getNodeID())) - .append("\n"); + .append(ind(baseInd + 1)) + .append(inOutName(moduleNode, "in", i + 1)) + .append(": ") + .append(workflowParameters.get(typeNode.getNodeID())) + .append("\n"); i++; } } /** * Generate the "out" section of a workflow step. + * * @param moduleNode The {@link ModuleNode} that is the step. */ private void generateStepOut(ModuleNode moduleNode) { final int baseInd = 2; cwlRepresentation - // "out" key - .append(ind(baseInd)) - .append("out: ") - // The outputs array - .append("["); + // "out" key + .append(ind(baseInd)) + .append("out: ") + // The outputs array + .append("["); int i = 1; for (TypeNode typeNode : moduleNode.getOutputTypes()) { String name = inOutName(moduleNode, "out", i); addParameter(typeNode, String.format("%s/%s", stepName(moduleNode), name)); cwlRepresentation - .append(name) - .append(", "); + .append(name) + .append(", "); i++; } deleteLastCharacters(2); @@ -186,82 +197,83 @@ private void generateStepOut(ModuleNode moduleNode) { /** * Generate the run field of a workflow step. + * * @param moduleNode The {@link ModuleNode} related to the step. */ private void generateStepRun(ModuleNode moduleNode) { final int baseInd = 2; cwlRepresentation - // Main key - .append(ind(baseInd)) - .append("run:") - .append("\n") - // Class - .append(ind(baseInd + 1)) - .append("class: Operation") - .append("\n"); + // Main key + .append(ind(baseInd)) + .append("run:") + .append("\n") + // Class + .append(ind(baseInd + 1)) + .append("class: Operation") + .append("\n"); // Inputs cwlRepresentation - .append(ind(baseInd + 1)) - .append("inputs:") - .append("\n"); + .append(ind(baseInd + 1)) + .append("inputs:") + .append("\n"); generateTypeNodes(moduleNode, moduleNode.getInputTypes(), true, baseInd + 2); // Outputs cwlRepresentation - .append(ind(baseInd + 1)) - .append("outputs:") - .append("\n"); + .append(ind(baseInd + 1)) + .append("outputs:") + .append("\n"); generateTypeNodes(moduleNode, moduleNode.getOutputTypes(), false, baseInd + 2); // Hints and intent - generateStepHints(moduleNode, baseInd + 1); - generateStepIntent(moduleNode, baseInd + 1); + generateStepHints(moduleNode, baseInd + 1); + generateStepIntent(moduleNode, baseInd + 1); } /** * Generate the hints related to this step's run. + * * @param moduleNode The {@link ModuleNode} that is the step. - * @param baseInd The indentation at which the hints should start. + * @param baseInd The indentation at which the hints should start. */ private void generateStepHints(ModuleNode moduleNode, int baseInd) { cwlRepresentation - // "hints" key - .append(ind(baseInd)) - .append("hints:") - .append("\n") - // "SoftwareRequirement" key - .append(ind(baseInd + 1)) - .append("SoftWareRequirement:") - .append("\n") - // "packages" key - .append(ind(baseInd + 2)) - .append("packages:") - .append("\n") - // The required package - .append(ind(baseInd + 3)) - .append( - String.format("%s: [\"%s\"]", - moduleNode.getNodeLabel(), - moduleNode.getUsedModule().getPredicateID() - ) - ) - .append("\n"); + // "hints" key + .append(ind(baseInd)) + .append("hints:") + .append("\n") + // "SoftwareRequirement" key + .append(ind(baseInd + 1)) + .append("SoftWareRequirement:") + .append("\n") + // "packages" key + .append(ind(baseInd + 2)) + .append("packages:") + .append("\n") + // The required package + .append(ind(baseInd + 3)) + .append( + String.format("%s: [\"%s\"]", + moduleNode.getNodeLabel(), + moduleNode.getUsedModule().getPredicateID())) + .append("\n"); } /** * Generate the intent for a workflow step's run. + * * @param moduleNode The {@link ModuleNode} that is the workflow step. - * @param baseInd The indentation level at which the intent should start. + * @param baseInd The indentation level at which the intent should start. */ private void generateStepIntent(ModuleNode moduleNode, int baseInd) { cwlRepresentation - .append(ind(baseInd)) - .append("intent: ") - .append("["); + .append(ind(baseInd)) + .append("intent: ") + .append("["); for (TaxonomyPredicate predicate : moduleNode.getUsedModule().getSuperPredicates()) { cwlRepresentation - .append("\"") - .append(predicate.getPredicateID()) - .append("\"") - .append(", "); + .append("\"") + .append(predicate.getPredicateID()) + .append("\"") + .append(", "); } deleteLastCharacters(2); cwlRepresentation.append("]").append("\n"); @@ -269,20 +281,25 @@ private void generateStepIntent(ModuleNode moduleNode, int baseInd) { /** * Generate the inputs or outputs of a step's run. - * @param moduleNode The {@link ModuleNode} that is the workflow step. - * @param typeNodeList The {@link TypeNode}s that are either the input or output nodes. - * @param input Whether the type nodes are inputs. If false, they are consider outputs. - * @param baseInd The indentation level of the "inputs:" or "outputs:" line preceding this function. + * + * @param moduleNode The {@link ModuleNode} that is the workflow step. + * @param typeNodeList The {@link TypeNode}s that are either the input or output + * nodes. + * @param input Whether the type nodes are inputs. If false, they are + * consider outputs. + * @param baseInd The indentation level of the "inputs:" or "outputs:" line + * preceding this function. */ private void generateTypeNodes(ModuleNode moduleNode, List typeNodeList, boolean input, int baseInd) { - // If the input or output nodes are empty, give an empty array as input or output + // If the input or output nodes are empty, give an empty array as input or + // output if (typeNodeList.isEmpty()) { // Remove the last newline so the array is on the same line as "inputs:" deleteLastCharacters(1); cwlRepresentation - .append(" ") - .append("[]") - .append("\n"); + .append(" ") + .append("[]") + .append("\n"); return; } @@ -295,52 +312,54 @@ private void generateTypeNodes(ModuleNode moduleNode, List typeNodeLis i++; cwlRepresentation - // Name - .append(ind(baseInd)) - .append(inOutName(moduleNode, input ? "in" : "out", i)) - .append(":\n") - // Data type - .append(ind(baseInd + 1)) - .append("type: File") - .append("\n") - // Format - .append(ind(baseInd + 1)) - .append("format: ") - .append(typeNode.getNodeID()) - .append("\n"); + // Name + .append(ind(baseInd)) + .append(inOutName(moduleNode, input ? "in" : "out", i)) + .append(":\n") + // Data type + .append(ind(baseInd + 1)) + .append("type: File") + .append("\n") + // Format + .append(ind(baseInd + 1)) + .append("format: ") + .append(typeNode.getNodeID()) + .append("\n"); } } /** * Generate the name of the input or output of a step's run input or output. * I.e. "moduleName_indicator_n". + * * @param moduleNode The {@link ModuleNode} that is the workflow step. - * @param indicator Indicator whether it is an input or an output. - * @param n The n-th input or output this is. + * @param indicator Indicator whether it is an input or an output. + * @param n The n-th input or output this is. * @return The name of the input or output. */ private String inOutName(ModuleNode moduleNode, String indicator, int n) { return String.format("%s_%s_%o", - moduleNode.getNodeLabel(), - indicator, - n - ); + moduleNode.getNodeLabel(), + indicator, + n); } /** * Add a parameter to the parameter hashmap. * Will log an error to the error output if {@link TypeNode} is already known. + * * @param typeNode The {@link TypeNode} that is the input parameter. - * @param name The name of the parameter. + * @param name The name of the parameter. */ private void addParameter(TypeNode typeNode, String name) { if (workflowParameters.putIfAbsent(typeNode.getNodeID(), name) != null) { - System.err.printf("Duplicate key \"%s\" in workflow inputs!%n", typeNode.getNodeID()); + log.warn("Duplicate key \"{}\" in workflow inputs!\n", typeNode.getNodeID()); } } /** * Generate the name for a step in the workflow. + * * @param moduleNode The {@link ModuleNode} that is the workflow step. * @return The name of the workflow step. */ diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/CWLCreatorBase.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/CWLCreatorBase.java index 1c9d885..02b6398 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/CWLCreatorBase.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/CWLCreatorBase.java @@ -4,9 +4,9 @@ * Base class with shared behaviour for CWL export classes. */ public abstract class CWLCreatorBase { - /** - * Cwl representation. - */ + /** + * Cwl representation. + */ protected final StringBuilder cwlRepresentation; /** * Solution. @@ -19,6 +19,7 @@ public abstract class CWLCreatorBase { /** * Generate the creator base from the workflow solution. + * * @param solution - APE workflow solution */ protected CWLCreatorBase(SolutionWorkflow solution) { @@ -29,6 +30,7 @@ protected CWLCreatorBase(SolutionWorkflow solution) { /** * Override the default indentation style. + * * @param indentStyle The indentation style to use. * @return A reference to this CWLCreator. */ @@ -39,19 +41,21 @@ public CWLCreatorBase setIndentStyle(IndentStyle indentStyle) { /** * Get the CWL version required for the CWL file. + * * @return The required CWL version. */ public abstract String getCWLVersion(); /** * Generates the CWL representation. + * * @return The CWL representation. */ public String generate() { // Top of file comment generateTopComment(); - cwlRepresentation.append(String.format("cwlVersion: %s\n", getCWLVersion())); + cwlRepresentation.append(String.format("cwlVersion: %s%n", getCWLVersion())); cwlRepresentation.append("class: Workflow").append("\n"); // Label and doc @@ -67,12 +71,13 @@ public String generate() { * Adds the comment at the top of the file. */ protected void generateTopComment() { - cwlRepresentation.append(String.format("# %s\n", getWorkflowName())); + cwlRepresentation.append(String.format("# %s%n", getWorkflowName())); cwlRepresentation.append("# This workflow is generated by APE (https://github.com/sanctuuary/APE).\n"); } /** * Get the name of the workflow. + * * @return The name of the workflow. */ private String getWorkflowName() { @@ -88,8 +93,8 @@ private void generateDoc() { // List all used tools for (ModuleNode moduleNode : solution.getModuleNodes()) { cwlRepresentation - .append(moduleNode.getNodeLabel()) - .append(", "); + .append(moduleNode.getNodeLabel()) + .append(", "); } deleteLastCharacters(2); cwlRepresentation.append(".").append("\n").append("\n"); @@ -102,6 +107,7 @@ private void generateDoc() { /** * Gets the CWL representation. + * * @return The CWL representation. */ public String getCWL() { @@ -110,6 +116,7 @@ public String getCWL() { /** * Delete a number of characters at the end of the CWL file. + * * @param number The number of characters to remove. */ protected void deleteLastCharacters(int number) { @@ -118,6 +125,7 @@ protected void deleteLastCharacters(int number) { /** * Generate the indentation at the start of a line. + * * @param level The level of indentation. * @return The indentation of the given level. */ diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java index fcb51f1..b8f4851 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java @@ -5,9 +5,12 @@ import java.util.HashMap; import java.util.List; +import lombok.extern.slf4j.Slf4j; + /** * Class to generate a CWL workflow structure from a given workflow solution. */ +@Slf4j public class DefaultCWLCreator extends CWLCreatorBase { /** * Maintain a list of the CWL parameter names which represent {@link TypeNode}s. @@ -36,21 +39,34 @@ public String getCWLVersion() { @Override protected void generateCWLRepresentation() { // Workflow - generateWorkflowInputs(); + generateWorkflowInputs(false); generateWorkflowSteps(); generateWorkflowOutputs(); } /** * Generate the top-level inputs definition of the workflow. + * + * @param includePath Whether to include the file path in the definition. */ - private void generateWorkflowInputs() { + private void generateWorkflowInputs(boolean includePath) { cwlRepresentation.append("inputs:").append("\n"); - // Inputs + cwlRepresentation.append(getInputsInCWL(includePath)); + } + + /** + * Generate the top-level outputs definition of the workflow. + * + * @param includePath Whether to include the file path in the definition. + * + * @return The CWL representation of the workflow outputs. + */ + private String getInputsInCWL(boolean includePath) { + StringBuilder inputsInCWL = new StringBuilder(); for (TypeNode typeNode : solution.getWorkflowInputTypeStates()) { String inputName = String.format("input%o", workflowParameters.size() + 1); addParameter(typeNode, inputName); - cwlRepresentation + inputsInCWL // Name .append(ind(1)) .append(inputName) @@ -64,7 +80,15 @@ private void generateWorkflowInputs() { .append("format: ") .append(typeNode.getFormat()) .append("\n"); + if (includePath) { + inputsInCWL + .append(ind(2)) + .append("path: ") + .append("set_path_to_the_file_here") + .append("\n"); + } } + return inputsInCWL.toString(); } /** @@ -386,7 +410,7 @@ private String inOutName(ModuleNode moduleNode, String indicator, int n) { */ private void addParameter(TypeNode typeNode, String name) { if (workflowParameters.putIfAbsent(typeNode.getNodeID(), name) != null) { - System.err.printf("Duplicate key \"%s\" in workflow inputs!%n", typeNode.getNodeID()); + log.warn("Duplicate key \"{}\" in workflow inputs!", typeNode.getNodeID()); } } @@ -400,4 +424,13 @@ private String stepName(ModuleNode moduleNode) { return moduleNode.getUsedModule().getPredicateLabel() + moduleNode.getAutomatonState().getLocalStateNumber(); } + + /** + * Generates the CWL inputs as a YML file content. + * + * @return Content of a YML file that describes the CWL workflow inputs. + */ + public String generateCWLWorkflowInputs() { + return getInputsInCWL(true); + } } diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/ExecutableCWLCreator.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/ExecutableCWLCreator.java index 9581155..2eae8c4 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/ExecutableCWLCreator.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/ExecutableCWLCreator.java @@ -2,6 +2,8 @@ import org.yaml.snakeyaml.Yaml; +import lombok.extern.slf4j.Slf4j; + import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -9,18 +11,29 @@ /** * Class to generate executable CWL workflows from a given workflow solution. */ +@Slf4j public class ExecutableCWLCreator extends CWLCreatorBase { - /** Keep track of the inputs that are available in the workflow (key: TypeNode NodeID, value: input name). */ + /** + * Keep track of the inputs that are available in the workflow (key: TypeNode + * NodeID, value: input name). + */ private final HashMap inputMap = new HashMap<>(); - /** Keep track of the step names related to the ModuleNode NodeIDs (key: NodeID, value: step name). */ + /** + * Keep track of the step names related to the ModuleNode NodeIDs (key: NodeID, + * value: step name). + */ private final HashMap stepNames = new HashMap<>(); /** Keep track the current step number being added to the result. */ private int stepIndex = 1; - /** A list of error messages generated by any missing CWL annotations related to generating the CWL file. */ + /** + * A list of error messages generated by any missing CWL annotations related to + * generating the CWL file. + */ private final ArrayList missingAnnotationMessages; /** - * Create executable cwl creator from an APE solution + * Create executable cwl creator from an APE solution + * * @param solution - APE workflow solution */ public ExecutableCWLCreator(SolutionWorkflow solution) { @@ -43,14 +56,15 @@ protected void generateCWLRepresentation() { generateSteps(); generateOutputs(offset); - // When some CWL annotations could not be found, list all missing annotations in the output file - if (missingAnnotationMessages.size() > 0) { + // When some CWL annotations could not be found, list all missing annotations in + // the output file + if (!missingAnnotationMessages.isEmpty()) { this.cwlRepresentation.delete(0, cwlRepresentation.length()); generateTopComment(); this.cwlRepresentation.append("\n"); for (String message : this.missingAnnotationMessages) { this.cwlRepresentation.append("# ").append(message).append("\n"); - System.err.printf("Workflow %s: %s%n", solution.getIndex(), message); + log.warn("Workflow {}: {}", solution.getIndex(), message); } } } @@ -60,9 +74,9 @@ protected void generateCWLRepresentation() { */ private void generateRequirements() { cwlRepresentation - .append("requirements:").append("\n") - .append(ind(1)).append("ShellCommandRequirement: {}").append("\n") - .append(ind(1)).append("InlineJavascriptRequirement: {}").append("\n"); + .append("requirements:").append("\n") + .append(ind(1)).append("ShellCommandRequirement: {}").append("\n") + .append(ind(1)).append("InlineJavascriptRequirement: {}").append("\n"); } /** @@ -99,7 +113,8 @@ private void generateInputs() { addMissingInput(module); } - // If a module does not have any input types, it is assumed it is a workflow input + // If a module does not have any input types, it is assumed it is a workflow + // input if (module.getInputTypes().isEmpty()) { for (int i = 0; i < module.getOutputTypes().size(); i++) { TypeNode node = module.getOutputTypes().get(i); @@ -112,7 +127,8 @@ private void generateInputs() { // Keep track of the name replacements that need to be done. ArrayList toReplace = new ArrayList<>(); - // Keep track of how many times a certain input name appears. Used to prevent duplicate names. + // Keep track of how many times a certain input name appears. Used to prevent + // duplicate names. HashMap nameCounter = new HashMap<>(); Yaml yaml = new Yaml(); // Give each input a unique name @@ -155,10 +171,10 @@ private void generateOutputs(int offset) { continue; } toInsert - .append("outputs:").append("\n") - .append(ind(1)).append("out:").append("\n") - .append(ind(2)).append("type: File").append("\n") - .append(ind(2)).append("outputSource: ").append(name).append("\n"); + .append("outputs:").append("\n") + .append(ind(1)).append("out:").append("\n") + .append(ind(2)).append("type: File").append("\n") + .append(ind(2)).append("outputSource: ").append(name).append("\n"); } cwlRepresentation.insert(offset, toInsert); } @@ -188,6 +204,7 @@ private void generateSteps() { /** * Get the input name from the CWL code defined in the CWL annotations. + * * @param cwl The CWL code. * @return The name of the input in the CWL code. */ @@ -200,10 +217,12 @@ private String getInputName(String cwl) { /** * Replace the CWL annotations name of an input in the CWL code. - * @param cwl The CWL code wherein the name should be replaced. - * @param old The old name of the input in the CWL code. + * + * @param cwl The CWL code wherein the name should be replaced. + * @param old The old name of the input in the CWL code. * @param newName The new name for the input. - * @return The CWL code with CWL annotations name for the input replaced by the new name. + * @return The CWL code with CWL annotations name for the input replaced by the + * new name. */ private String replaceInputName(String cwl, String old, String newName) { return cwl.replaceFirst(String.format("\\\\@%s\\\\@", old), newName); @@ -212,9 +231,12 @@ private String replaceInputName(String cwl, String old, String newName) { /** * Give a step its name in the generated CWL file. * This guarantees each workflow step has a unique name. - * @param moduleNode The {@link ModuleNode} that is represented in this step. + * + * @param moduleNode The {@link ModuleNode} that is represented in this + * step. * @param implementation The CWL implementation of this step. - * @return The CWL implementation as a string after giving all steps their definitive name. + * @return The CWL implementation as a string after giving all steps their + * definitive name. */ private String setStepName(ModuleNode moduleNode, Map implementation) { String cwl = new Yaml().dump(implementation); @@ -233,9 +255,11 @@ private String setStepName(ModuleNode moduleNode, Map implementa /** * Replace all placeholder input names from the annotations with * the definitive input names that are used in the generated CWL file. + * * @param moduleNode The {@link ModuleNode} that is represented in this step. - * @param cwl The CWL implementation of this step. - * @return The CWL implementation as a string, where all inputs have the correct names. + * @param cwl The CWL implementation of this step. + * @return The CWL implementation as a string, where all inputs have the correct + * names. */ private String connectStepInputs(ModuleNode moduleNode, String cwl) { Pattern pattern = Pattern.compile("\\'\\\\\\@input\\[(\\d+)\\]\\'"); @@ -248,8 +272,10 @@ private String connectStepInputs(ModuleNode moduleNode, String cwl) { int index = Integer.parseInt(number); String newName = inputMap.get(inputs.get(index).getNodeID()); /* - * When a module did not have CWL inputs when it generated the inputs, it has not been added to the input map. - * The CWL file will already output all missing annotations, no need to show any errors here. + * When a module did not have CWL inputs when it generated the inputs, it has + * not been added to the input map. + * The CWL file will already output all missing annotations, no need to show any + * errors here. * Just continue so the output file can be completed. */ if (newName == null) { @@ -261,9 +287,11 @@ private String connectStepInputs(ModuleNode moduleNode, String cwl) { } /** - * Detect the output(s) of a workflow step and store them in the input map, so they can be used as input in other steps. + * Detect the output(s) of a workflow step and store them in the input map, so + * they can be used as input in other steps. + * * @param moduleNode The {@link ModuleNode} that is represented by this step. - * @param cwl The CWL implementation of this step. + * @param cwl The CWL implementation of this step. */ private void findOutputs(ModuleNode moduleNode, String cwl) { Yaml yaml = new Yaml(); @@ -285,7 +313,8 @@ private void findOutputs(ModuleNode moduleNode, String cwl) { /** * Append YAML data line-by-line to get the desired indentation level. - * @param data The data to be appended. + * + * @param data The data to be appended. * @param indentLevel The desired indentation level. */ private void appendYamlData(String data, int indentLevel) { @@ -295,18 +324,24 @@ private void appendYamlData(String data, int indentLevel) { } /** - * Append the information that a module node is missing its CWL inputs annotation. + * Append the information that a module node is missing its CWL inputs + * annotation. + * * @param moduleNode The ModuleNode that is missing its CWL inputs. */ private void addMissingInput(ModuleNode moduleNode) { - this.missingAnnotationMessages.add(String.format("Tool \"%s\" is missing its CWL inputs.", moduleNode.getNodeLabel())); + this.missingAnnotationMessages + .add(String.format("Tool \"%s\" is missing its CWL inputs.", moduleNode.getNodeLabel())); } /** - * Append the information that a module node is missing its CWL implementation annotation. + * Append the information that a module node is missing its CWL implementation + * annotation. + * * @param moduleNode The ModuleNode that is missing its CWL implementation. */ private void addMissingImplementation(ModuleNode moduleNode) { - this.missingAnnotationMessages.add(String.format("Tool \"%s\" is missing its CWL implementation.", moduleNode.getNodeLabel())); + this.missingAnnotationMessages + .add(String.format("Tool \"%s\" is missing its CWL implementation.", moduleNode.getNodeLabel())); } } diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/ModuleNode.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/ModuleNode.java index b5b3871..e70fed4 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/ModuleNode.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/ModuleNode.java @@ -5,6 +5,7 @@ import guru.nidi.graphviz.attribute.Shape; import guru.nidi.graphviz.attribute.Style; import guru.nidi.graphviz.model.Graph; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.automaton.ModuleAutomaton; import nl.uu.cs.ape.automaton.State; import nl.uu.cs.ape.models.AbstractModule; @@ -20,14 +21,17 @@ import static guru.nidi.graphviz.model.Factory.node; /** - * The {@code ModuleNode} class is used to represent module step in the actual solution workflow. + * The {@code ModuleNode} class is used to represent module step in the actual + * solution workflow. * Each {@code ModuleNode} represents an action/tool in the solution workflow. *

- * When compared to the {@link ModuleAutomaton} representation of the problem, a Workflow {@code TypeNode} + * When compared to the {@link ModuleAutomaton} representation of the problem, a + * Workflow {@code TypeNode} * correspond to a {@link State} of a {@link AtomType#MODULE} element. * * @author Vedran Kasalica */ +@Slf4j public class ModuleNode extends SolutionWorkflowNode { /** @@ -63,9 +67,12 @@ public class ModuleNode extends SolutionWorkflowNode { /** * Creating Workflow Node that corresponds to a tool usage. * - * @param automatonState state in the {@link ModuleAutomaton} that corresponds to the workflow node. - * @throws ExceptionInInitializerError Exception when the Tool Workflow Node is instantiated using - * a State in ModuleAutomaton that does not correspond to a {@code AtomType#MODULE}.. + * @param automatonState state in the {@link ModuleAutomaton} that corresponds + * to the workflow node. + * @throws ExceptionInInitializerError Exception when the Tool Workflow Node is + * instantiated using + * a State in ModuleAutomaton that does not + * correspond to a {@code AtomType#MODULE}.. */ public ModuleNode(State automatonState) throws ExceptionInInitializerError { super(automatonState); @@ -91,7 +98,8 @@ public void setUsedModule(Module module) { } /** - * Add the abstract module to the list of modules that describes the tool instance. + * Add the abstract module to the list of modules that describes the tool + * instance. * * @param abstractModule - abstract type that describes the instance. */ @@ -99,7 +107,7 @@ public void addAbstractDescriptionOfUsedType(AbstractModule abstractModule) { if (!abstractModule.isSimplePredicate()) { this.abstractModules.add(abstractModule); } else { - System.err.println("Actual tool cannot be uset to describe a module in an abstract way."); + log.warn("A concrete tool cannot be used to describe an abstract module."); } } @@ -179,7 +187,8 @@ public ModuleNode getNextModuleNode() { /** * Has next module boolean. * - * @return True if the current operation is not the last one in the workflow, false otherwise. + * @return True if the current operation is not the last one in the workflow, + * false otherwise. */ public boolean hasNextModule() { return nextModuleNode != null; @@ -188,7 +197,8 @@ public boolean hasNextModule() { /** * Has prev module boolean. * - * @return True if the current operation is not the first one in the workflow, false otherwise. + * @return True if the current operation is not the first one in the workflow, + * false otherwise. */ public boolean hasPrevModule() { return prevModuleNode != null; @@ -233,7 +243,8 @@ public boolean isEmpty() { /** * Get string representation of the ModuleNode. * - * @return Printable string that can be used for the presentation of this workflow node. + * @return Printable string that can be used for the presentation of this + * workflow node. */ public String toString() { if (usedModule == null) { @@ -262,7 +273,8 @@ public String getDotDefinition() { */ public Graph addModuleToGraph(Graph workflowGraph) { return workflowGraph = workflowGraph - .with(node(getNodeID()).with(Label.of(getNodeLabel() + " "), Shape.RECTANGLE, Color.BLUE, Style.BOLD)); + .with(node(getNodeID()).with(Label.of(getNodeLabel() + " "), Shape.RECTANGLE, Color.BLUE, + Style.BOLD)); } /** @@ -282,11 +294,11 @@ public String getNodeID() { public String getNodeLabel() { return this.usedModule.getPredicateLabel(); } - + /** - * Gets node descriptive label, containing module IDs. + * Gets node descriptive label, containing module IDs. */ public String getNodeLongLabel() { - return this.usedModule.getPredicateLongLabel(); + return this.usedModule.getPredicateLongLabel(); } } diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java index 4a2b5dc..9cb2daa 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/SolutionWorkflow.java @@ -459,7 +459,7 @@ public String getSolutionDotFormat() { for (TypeNode workflowInput : this.workflowInputTypeStates) { if (!inputDefined) { - // System.out.println(input + " [shape=box, color = red];\n"); + solution.append(input + " [shape=box, color = red];\n"); inputDefined = true; } solution.append(input + "->" + workflowInput.getNodeID() + ";\n"); diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java index 01d5d57..9be2dbf 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java @@ -2,6 +2,7 @@ import guru.nidi.graphviz.attribute.Label; import guru.nidi.graphviz.model.Graph; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.automaton.State; import nl.uu.cs.ape.automaton.TypeAutomaton; import nl.uu.cs.ape.models.Type; @@ -25,10 +26,12 @@ * * @author Vedran Kasalica */ +@Slf4j public class TypeNode extends SolutionWorkflowNode { /** - * Types that define the data instance. The set cannot contain {@code EmptyType}. + * Types that define the data instance. The set cannot contain + * {@code EmptyType}. */ private SortedSet usedTypes; @@ -52,9 +55,12 @@ public class TypeNode extends SolutionWorkflowNode { /** * Creating Workflow Node that corresponds to a type instance in memory. * - * @param automatonState State in the {@link TypeAutomaton} that corresponds to the workflow node. - * @throws ExceptionInInitializerError Exception when the Type Workflow Node is instantiated using a State in - * TypeAutomaton that does not correspond to a {@code AtomType#MEMORY_TYPE}. + * @param automatonState State in the {@link TypeAutomaton} that corresponds to + * the workflow node. + * @throws ExceptionInInitializerError Exception when the Type Workflow Node is + * instantiated using a State in + * TypeAutomaton that does not correspond to + * a {@code AtomType#MEMORY_TYPE}. */ public TypeNode(State automatonState) throws ExceptionInInitializerError { super(automatonState); @@ -78,7 +84,7 @@ public void addUsedType(Type simpleType) { if (simpleType.isSimplePredicate()) { this.usedTypes.add(simpleType); } else { - System.err.println("Abstract and Empty Type cannot be used to define an instance."); + log.warn("Abstract and Empty Type cannot be used to define an instance."); } } @@ -91,7 +97,7 @@ public void addAbstractDescriptionOfUsedType(Type abstractType) { if (!abstractType.isSimplePredicate()) { this.abstractTypes.add(abstractType); } else { - System.err.println("Simple Type cannot be used to describe an instance."); + log.warn("Simple Type cannot be used to describe an instance."); } } @@ -99,7 +105,8 @@ public void addAbstractDescriptionOfUsedType(Type abstractType) { * Add a tool, that uses this data instance as input, to the List * {@link TypeNode#usedByModules}. * - * @param usedByTool Tool/module node in the workflow, that uses this data instance as input. + * @param usedByTool Tool/module node in the workflow, that uses this data + * instance as input. */ public void addUsedByTool(ModuleNode usedByTool) { usedByModules.add(usedByTool); @@ -108,7 +115,8 @@ public void addUsedByTool(ModuleNode usedByTool) { /** * Sets created by module. * - * @param createdByModule Set the tool/workflow step that creates this data instance. + * @param createdByModule Set the tool/workflow step that creates this data + * instance. */ public void setCreatedByModule(ModuleNode createdByModule) { this.createdByModule = createdByModule; @@ -136,7 +144,8 @@ public SortedSet getAbstractTypes() { /** * Get tool step in the workflow that creates this data instance as output. * - * @return The {@link ModuleNode} that uses this data type. If null data instance corresponds to the initial workflow input. + * @return The {@link ModuleNode} that uses this data type. If null data + * instance corresponds to the initial workflow input. */ public ModuleNode getCreatedByModule() { return createdByModule; @@ -146,7 +155,8 @@ public ModuleNode getCreatedByModule() { * Get all module nodes that use the data instance in input. If null is * in the list, the type is used as workflow output. * - * @return List of modules that used the type instance (a null value represent the workflow output). + * @return List of modules that used the type instance (a null value represent + * the workflow output). */ public List getUsedByModules() { return usedByModules; @@ -165,7 +175,7 @@ public boolean isEmpty() { * Get string representation of the TypeNode. * * @return Printable string that can be used for the presentation of this - * workflow node. + * workflow node. */ public String toString() { StringBuilder printString = new StringBuilder(); @@ -199,7 +209,7 @@ public String getDotDefinition() { * @return The {@link Graph} extended with the current {@link TypeNode}. */ public Graph addTypeToGraph(Graph workflowGraph) { - return workflowGraph = workflowGraph.with(node(getNodeID()).with(Label.of(getNodeLabel() + " "))); + return workflowGraph.with(node(getNodeID()).with(Label.of(getNodeLabel() + " "))); } /** @@ -209,11 +219,11 @@ public String getNodeLabel() { StringBuilder printString = new StringBuilder(); int i = 0; for (Type type : this.usedTypes) { - String typeLabel = type.getPredicateLabel(); - if(typeLabel.endsWith("_p")) { - // remove "_plain" suffix - typeLabel = APEUtils.removeNLastChar(typeLabel, 2); - } + String typeLabel = type.getPredicateLabel(); + if (typeLabel.endsWith("_p")) { + // remove "_plain" suffix + typeLabel = APEUtils.removeNLastChar(typeLabel, 2); + } printString.append(typeLabel); if (++i < this.usedTypes.size()) { printString.append(", "); @@ -246,31 +256,30 @@ public String getNodeID() { public String getFormat() { StringBuilder printString = new StringBuilder("\""); - int i = 0; for (Type type : this.usedTypes) { - if(type.getRootNodeID().equals("http://edamontology.org/format_1915")){ + if (type.getRootNodeID().equals("http://edamontology.org/format_1915")) { printString.append(type.getPredicateID()).append("\" # ").append(type.getPredicateLabel()); } - + } return printString.toString(); } - + /** * Gets node descriptive label, containing type IDs. */ public String getNodeLongLabel() { - StringBuilder printString = new StringBuilder(); - int i = 0; - for (Type type : this.usedTypes) { - String typeLabel = type.getPredicateLongLabel(); - printString.append(typeLabel); - if (++i < this.usedTypes.size()) { - printString.append(", "); - } - } - return printString.toString(); + StringBuilder printString = new StringBuilder(); + int i = 0; + for (Type type : this.usedTypes) { + String typeLabel = type.getPredicateLongLabel(); + printString.append(typeLabel); + if (++i < this.usedTypes.size()) { + printString.append(", "); + } + } + return printString.toString(); } /** diff --git a/src/main/java/nl/uu/cs/ape/io/APEFiles.java b/src/main/java/nl/uu/cs/ape/io/APEFiles.java index 201c11b..fac6ed2 100644 --- a/src/main/java/nl/uu/cs/ape/io/APEFiles.java +++ b/src/main/java/nl/uu/cs/ape/io/APEFiles.java @@ -409,16 +409,16 @@ public static File prependToFile(String prefix, File file) throws IOException { */ public static boolean isValidReadFile(String path) { if (path == null || path.equals("")) { - System.err.println("Path is not provided correctly."); + log.error("Path is not provided correctly."); return false; } File f = new File(path); if (!f.isFile()) { - System.err.println("Provided path: \"" + path + "\" is not a file."); + log.error("Provided path: \"" + path + "\" is not a file."); return false; } else { if (!f.canRead()) { - System.err.println("Provided file: \"" + path + "\" is missing the reading permission."); + log.error("Provided file: \"" + path + "\" is missing the reading permission."); return false; } } diff --git a/src/main/java/nl/uu/cs/ape/models/AllTypes.java b/src/main/java/nl/uu/cs/ape/models/AllTypes.java index fca657c..50392b5 100644 --- a/src/main/java/nl/uu/cs/ape/models/AllTypes.java +++ b/src/main/java/nl/uu/cs/ape/models/AllTypes.java @@ -4,6 +4,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.configuration.APECoreConfig; import nl.uu.cs.ape.models.enums.NodeType; import nl.uu.cs.ape.models.logic.constructs.PredicateLabel; @@ -19,6 +20,7 @@ * * @author Vedran Kasalica */ +@Slf4j public class AllTypes extends AllPredicates { private static String empty = "empty"; @@ -67,7 +69,7 @@ public AllTypes(List typeTaxonomyRoots) { super(Stream.concat(typeTaxonomyRoots.stream(), Stream.of(apeLabel)) .collect(Collectors.toList())); emptyType = new Type(empty, empty, empty, NodeType.EMPTY); - Type apeLabelRoot = new Type(apeLabel, apeLabel, apeLabel, NodeType.ROOT); + apeLabelRoot = new Type(apeLabel, apeLabel, apeLabel, NodeType.ROOT); emptyLabelType = new Type(emptyLabel, emptyLabel, apeLabel, NodeType.EMPTY_LABEL); setRelevant(emptyType); setRelevant(apeLabelRoot); @@ -93,8 +95,7 @@ private void setRelevant(Type type) { * @return The {@link Collection} of {@link Type}s. */ public Collection getTypes() { - Collection types = getMappedPredicates().values(); - return types; + return getMappedPredicates().values(); } /** @@ -149,20 +150,6 @@ public Type addPredicate(TaxonomyPredicate newType) throws ExceptionInInitialize } - /* - * Returns the type to which the specified key is mapped to, or null if - * the typeID has no mappings. - * - * @param typeID - the key whose associated value is to be returned - * - * @return The {@link Type} to which the specified key is mapped to, or null - * if the typeID has no mappings - * - * public Type get(String typeID) { - * return (Type) getPredicates().get(typeID); - * } - */ - /** * Returns the type to which the specified key is mapped to under the given * dimension, or null if @@ -219,6 +206,7 @@ public boolean existsType(String typeID) { * @param dimensionID ID of the data dimension that is searched for. * @return true if the dimensionID exists in the domain. */ + @Override public boolean existsRoot(String dimensionID) { return getAllRootIDs().contains(dimensionID); } @@ -269,7 +257,7 @@ public List> getTypePairsForEachSubTaxonomy() { if (subTreesMap.get(type.getRootNodeID()) != null) { subTreesMap.get(type.getRootNodeID()).add(type); } else { - System.err.println("ERROR!!"); + log.error("Type " + type.getPredicateID() + " has no root node"); } } else if (type.isEmptyPredicate()) { diff --git a/src/main/java/nl/uu/cs/ape/models/Type.java b/src/main/java/nl/uu/cs/ape/models/Type.java index c28bb3b..0f50284 100644 --- a/src/main/java/nl/uu/cs/ape/models/Type.java +++ b/src/main/java/nl/uu/cs/ape/models/Type.java @@ -179,10 +179,9 @@ public static Type taxonomyInstanceFromJson(JSONObject jsonParam, APEDomainSetup parameterDimensions.add(allTypes.getLabelRoot()); } } - Type taxonomyInstance = AuxTypePredicate.generateAuxiliaryPredicate(parameterDimensions, LogicOperation.AND, + return AuxTypePredicate.generateAuxiliaryPredicate(parameterDimensions, LogicOperation.AND, domainSetup); - return taxonomyInstance; } } diff --git a/src/main/java/nl/uu/cs/ape/models/logic/constructs/TaxonomyPredicate.java b/src/main/java/nl/uu/cs/ape/models/logic/constructs/TaxonomyPredicate.java index 0282202..5d667b8 100644 --- a/src/main/java/nl/uu/cs/ape/models/logic/constructs/TaxonomyPredicate.java +++ b/src/main/java/nl/uu/cs/ape/models/logic/constructs/TaxonomyPredicate.java @@ -325,7 +325,7 @@ public boolean addSubPredicate(TaxonomyPredicate predicate) { subPredicates.add(predicate); return true; } else { - System.err.println("Cannot add sub-predicate to a leaf or empty taxonomy term: " + getPredicateID() + "."); + log.warn("Cannot add sub-predicate to a leaf or empty taxonomy term: " + getPredicateID() + "."); return false; } } @@ -359,7 +359,7 @@ public boolean removeSubPredicate(TaxonomyPredicate subPredicateToRemove) { public boolean removeAllSubPredicates(Collection subPredicatesToRemove) { boolean done = false; if (subPredicatesToRemove != null && !subPredicatesToRemove.isEmpty()) { - done = done || this.subPredicates.removeAll(subPredicatesToRemove); + done = this.subPredicates.removeAll(subPredicatesToRemove); } return done; } @@ -379,7 +379,7 @@ public boolean addSuperPredicate(TaxonomyPredicate predicate) { superPredicates.add(predicate); return true; } else { - System.err.println("Cannot add super-predicate to a root taxonomy term!"); + log.warn("Cannot add super-predicate to a root taxonomy term!"); return false; } } diff --git a/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxFormula.java b/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxFormula.java index a93a59e..0371fe1 100644 --- a/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxFormula.java +++ b/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxFormula.java @@ -8,7 +8,6 @@ import nl.uu.cs.ape.core.implSAT.SATSynthesisEngine; import nl.uu.cs.ape.io.APEFiles; -import nl.uu.cs.ape.utils.APEUtils; /** * Abstract class that represents any SLTLx formula. diff --git a/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxUntil.java b/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxUntil.java index 932697d..89c7013 100644 --- a/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxUntil.java +++ b/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxUntil.java @@ -21,6 +21,7 @@ public SLTLxUntil(SLTLxFormula formulaFrom, SLTLxFormula formulaUntil) { super(); this.formulaFrom = formulaFrom; this.formulaUntil = formulaUntil; + throw new UnsupportedOperationException("Not implemented yet."); } @Override diff --git a/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxVariableSubstitutionCollection.java b/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxVariableSubstitutionCollection.java index 01c4955..581e09f 100644 --- a/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxVariableSubstitutionCollection.java +++ b/src/main/java/nl/uu/cs/ape/models/sltlxStruc/SLTLxVariableSubstitutionCollection.java @@ -59,7 +59,7 @@ public SLTLxVariableSubstitutionCollection(SLTLxVariableSubstitutionCollection e * @return Unique variable that corresponds to the current variable binding. */ public SLTLxVariable addNewVariable(SLTLxVariable existingVar, Set varDomain) { - SLTLxVariable newVar = new SLTLxVariable("uniqVar_" + this.variableNo++); + SLTLxVariable newVar = new SLTLxVariable("uniqVar_" + (this.variableNo++)); this.mappedVariables.put(existingVar, newVar); this.mappedVariables.put(newVar, newVar); this.variableDomain.put(newVar, varDomain); diff --git a/src/main/java/nl/uu/cs/ape/models/templateFormulas/SLTLxTemplateFormula.java b/src/main/java/nl/uu/cs/ape/models/templateFormulas/SLTLxTemplateFormula.java index 819c5d2..08e09a6 100644 --- a/src/main/java/nl/uu/cs/ape/models/templateFormulas/SLTLxTemplateFormula.java +++ b/src/main/java/nl/uu/cs/ape/models/templateFormulas/SLTLxTemplateFormula.java @@ -117,27 +117,27 @@ public abstract String getCNF(ModuleAutomaton moduleAutomaton, List typeS /** * Creates a CNF representation of the Constraint:
- * If if_predicate is used, tool then_predicate has to be used + * If ifPredicate is used, tool thenPredicate has to be used * subsequently. * - * @param if_predicate Predicate that enforce the usage of - * then_predicate. - * @param then_predicate Predicate that is enforced by if_predicate. + * @param ifPredicate Predicate that enforce the usage of + * thenPredicate. + * @param thenPredicate Predicate that is enforced by ifPredicate. * @param moduleAutomaton Module automaton. * @param mappings Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. */ - public static String ite_module(TaxonomyPredicate if_predicate, TaxonomyPredicate then_predicate, + public static String iteModule(TaxonomyPredicate ifPredicate, TaxonomyPredicate thenPredicate, ModuleAutomaton moduleAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); int automatonSize = moduleAutomaton.getAllStates().size(); for (int i = 0; i < automatonSize; i++) { constraints.append("-" - + mappings.add(if_predicate, moduleAutomaton.getAllStates().get(i), AtomType.MODULE) + + mappings.add(ifPredicate, moduleAutomaton.getAllStates().get(i), AtomType.MODULE) + " "); for (int j = i + 1; j < automatonSize; j++) { - constraints.append(mappings.add(then_predicate, moduleAutomaton.get(j), AtomType.MODULE)).append(" "); + constraints.append(mappings.add(thenPredicate, moduleAutomaton.get(j), AtomType.MODULE)).append(" "); } constraints.append("0\n"); } @@ -146,12 +146,12 @@ public static String ite_module(TaxonomyPredicate if_predicate, TaxonomyPredicat /** * Creates a CNF representation of the Constraint:
- * If type if_predicate is used/generated (depending on the @typeBlocks), - * then type then_predicate has to be used/generated subsequently. + * If type ifPredicate is used/generated (depending on the @typeBlocks), + * then type thenPredicate has to be used/generated subsequently. * - * @param if_predicate Predicate that enforce the usage of - * then_predicate. - * @param then_predicate Predicate that is enforced by if_predicate. + * @param ifPredicate Predicate that enforce the usage of + * thenPredicate. + * @param thenPredicate Predicate that is enforced by ifPredicate. * @param typeElement Workflow element type. * @param moduleAutomaton Module automaton. * @param typeBlocks Type blocks (corresponding to the memory or used type @@ -159,8 +159,8 @@ public static String ite_module(TaxonomyPredicate if_predicate, TaxonomyPredicat * @param mappings Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. */ - public static String ite_type(TaxonomyPredicate if_predicate, TaxonomyPredicate then_predicate, - AtomType typeElement, ModuleAutomaton moduleAutomaton, + public static String iteType(TaxonomyPredicate ifPredicate, TaxonomyPredicate thenPredicate, + AtomType typeElement, List typeBlocks, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); int numberOfBlocks = typeBlocks.size(); @@ -168,14 +168,14 @@ public static String ite_type(TaxonomyPredicate if_predicate, TaxonomyPredicate for (int i_block = 0; i_block < numberOfBlocks; i_block++) { for (int i_state = 0; i_state < numberOfStates; i_state++) { - /* If if_predicate is used in any state of a certain block */ - constraints.append("-").append(mappings.add(if_predicate, + /* If ifPredicate is used in any state of a certain block */ + constraints.append("-").append(mappings.add(ifPredicate, typeBlocks.get(i_block).getState(i_state), typeElement)).append(" "); - /* then then_predicate must be used in a state of the subsequent blocks. */ + /* then thenPredicate must be used in a state of the subsequent blocks. */ for (int j_block = i_block + 1; j_block < numberOfBlocks; j_block++) { for (int j_state = i_state + 1; j_state < numberOfBlocks; j_state++) { - constraints.append(mappings.add(then_predicate, + constraints.append(mappings.add(thenPredicate, typeBlocks.get(j_block).getState(j_state), typeElement)).append(" "); } @@ -188,27 +188,27 @@ public static String ite_type(TaxonomyPredicate if_predicate, TaxonomyPredicate /** * Creates a CNF representation of the Constraint:
- * If if_predicate is used, tool then_predicate cannot be used + * If ifPredicate is used, tool thenPredicate cannot be used * subsequently. * - * @param if_predicate Predicate that forbids the usage of - * then_not_predicate. - * @param then_not_predicate Module that is forbidden by if_predicate. - * @param moduleAutomaton Module automaton. - * @param mappings Set of the mappings for the literals. + * @param ifPredicate Predicate that forbids the usage of + * thenNotPredicate. + * @param thenNotPredicate Module that is forbidden by ifPredicate. + * @param moduleAutomaton Module automaton. + * @param mappings Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. */ - public static String itn_module(TaxonomyPredicate if_predicate, TaxonomyPredicate then_not_predicate, + public static String itnModule(TaxonomyPredicate ifPredicate, TaxonomyPredicate thenNotPredicate, ModuleAutomaton moduleAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); int automatonSize = moduleAutomaton.getAllStates().size(); for (int i = 0; i < automatonSize - 1; i++) { State currModuleState = moduleAutomaton.getAllStates().get(i); for (int j = i + 1; j < automatonSize; j++) { - constraints.append("-").append(mappings.add(if_predicate, currModuleState, AtomType.MODULE)) + constraints.append("-").append(mappings.add(ifPredicate, currModuleState, AtomType.MODULE)) .append(" "); constraints.append("-" - + mappings.add(then_not_predicate, moduleAutomaton.get(j), AtomType.MODULE) + + mappings.add(thenNotPredicate, moduleAutomaton.get(j), AtomType.MODULE) + " 0\n"); } } @@ -218,21 +218,21 @@ public static String itn_module(TaxonomyPredicate if_predicate, TaxonomyPredicat /** * Creates a CNF representation of the Constraint:
- * If type if_predicate is used/generated (depending on the @typeBlocks), - * then do not use/generate type then_not_predicate subsequently. + * If type ifPredicate is used/generated (depending on the @typeBlocks), + * then do not use/generate type thenNotPredicate subsequently. * - * @param if_predicate Predicate that forbids the usage of - * then_not_predicate. - * @param then_not_predicate Predicate that is forbidden by if_predicate. - * @param typeElement Workflow element type. - * @param moduleAutomaton Module automaton. - * @param typeBlocks Type blocks (corresponding to the memory or used - * type states). - * @param mappings Set of the mappings for the literals. + * @param ifPredicate Predicate that forbids the usage of + * thenNotPredicate. + * @param thenNotPredicate Predicate that is forbidden by ifPredicate. + * @param typeElement Workflow element type. + * @param moduleAutomaton Module automaton. + * @param typeBlocks Type blocks (corresponding to the memory or used + * type states). + * @param mappings Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. */ - public static String itn_type(TaxonomyPredicate if_predicate, TaxonomyPredicate then_not_predicate, - AtomType typeElement, ModuleAutomaton moduleAutomaton, + public static String itnType(TaxonomyPredicate ifPredicate, TaxonomyPredicate thenNotPredicate, + AtomType typeElement, List typeBlocks, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); int numberOfBlocks = typeBlocks.size(); @@ -242,14 +242,14 @@ public static String itn_type(TaxonomyPredicate if_predicate, TaxonomyPredicate for (int j_block = i_block + 1; j_block < numberOfBlocks; j_block++) { for (int j_state = 0; j_state < numberOfStates; j_state++) { /* - * If if_predicate is used in any state of a certain block + * If ifPredicate is used in any state of a certain block */ - constraints.append("-").append(mappings.add(if_predicate, + constraints.append("-").append(mappings.add(ifPredicate, typeBlocks.get(i_block).getState(i_state), typeElement)).append(" "); /* - * then then_predicate cannot be used in a state of the subsequent blocks. + * then thenPredicate cannot be used in a state of the subsequent blocks. */ - constraints.append("-").append(mappings.add(then_not_predicate, + constraints.append("-").append(mappings.add(thenNotPredicate, typeBlocks.get(j_block).getState(j_state), typeElement)).append(" 0\n"); } @@ -261,27 +261,27 @@ public static String itn_type(TaxonomyPredicate if_predicate, TaxonomyPredicate /** * Creates a CNF representation of the Constraint:
- * If we use module second_module_in_sequence, - * then we must have used first_module_in_sequence prior to it. + * If we use module secondModuleInSequence, + * then we must have used firstModuleInSequence prior to it. * - * @param second_module_in_sequence Predicate that enforces the usage of - * first_predicate. - * @param first_module_in_sequence Predicate that is enforced by - * second_predicate. - * @param moduleAutomaton Module automaton. - * @param mappings Set of the mappings for the literals. + * @param secondModuleInSequence Predicate that enforces the usage of + * firstPredicate. + * @param firstModuleInSequence Predicate that is enforced by + * secondPredicate. + * @param moduleAutomaton Module automaton. + * @param mappings Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. */ - public static String depend_module(TaxonomyPredicate second_module_in_sequence, - TaxonomyPredicate first_module_in_sequence, + public static String dependModule(TaxonomyPredicate secondModuleInSequence, + TaxonomyPredicate firstModuleInSequence, ModuleAutomaton moduleAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); int automatonSize = moduleAutomaton.getAllStates().size(); for (int i = 0; i < automatonSize; i++) { - constraints.append("-").append(mappings.add(second_module_in_sequence, + constraints.append("-").append(mappings.add(secondModuleInSequence, moduleAutomaton.getAllStates().get(i), AtomType.MODULE)).append(" "); for (int j = 0; j < i; j++) { - constraints.append(mappings.add(first_module_in_sequence, + constraints.append(mappings.add(firstModuleInSequence, moduleAutomaton.get(j), AtomType.MODULE)).append(" "); } constraints.append("0\n"); @@ -291,29 +291,29 @@ public static String depend_module(TaxonomyPredicate second_module_in_sequence, /** * Creates a CNF representation of the Constraint:
- * If we use predicate first_module_in_sequence, then use - * second_module_in_sequence as a next predicate in the sequence. + * If we use predicate firstModuleInSequence, then use + * secondModuleInSequence as a next predicate in the sequence. * - * @param first_module_in_sequence Predicate that enforce the usage of - * second_predicate. - * @param second_module_in_sequence Predicate that is enforced by - * first_predicate. - * @param moduleAutomaton Module automaton. - * @param mappings Set of the mappings for the literals. + * @param firstModuleInSequence Predicate that enforce the usage of + * secondPredicate. + * @param secondModuleInSequence Predicate that is enforced by + * firstPredicate. + * @param moduleAutomaton Module automaton. + * @param mappings Set of the mappings for the literals. * @return The String CNF representation of the constraint. */ - public static String next_module(TaxonomyPredicate first_module_in_sequence, - TaxonomyPredicate second_module_in_sequence, + public static String nextModule(TaxonomyPredicate firstModuleInSequence, + TaxonomyPredicate secondModuleInSequence, ModuleAutomaton moduleAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); int automatonSize = moduleAutomaton.getAllStates().size(); for (int i = 0; i < automatonSize; i++) { - constraints.append("-").append(mappings.add(first_module_in_sequence, + constraints.append("-").append(mappings.add(firstModuleInSequence, moduleAutomaton.getAllStates().get(i), AtomType.MODULE)).append(" "); - /* Clause that forbids using first_predicate as the last in the sequence */ + /* Clause that forbids using firstPredicate as the last in the sequence */ if (i < automatonSize - 1) { - constraints.append(mappings.add(second_module_in_sequence, + constraints.append(mappings.add(secondModuleInSequence, moduleAutomaton.get(i + 1), AtomType.MODULE)).append(" "); } constraints.append("0\n"); @@ -323,32 +323,32 @@ public static String next_module(TaxonomyPredicate first_module_in_sequence, /** * Creates a CNF representation of the Constraint:
- * If we use predicate first_predicate, then use - * second_predicate as a next predicate in the sequence. + * If we use predicate firstPredicate, then use + * secondPredicate as a next predicate in the sequence. * - * @param second_module_in_sequence Predicate that is enforced by - * first_predicate. - * @param first_module_in_sequence Predicate that enforce the usage of - * second_predicate. - * @param moduleAutomaton Module automaton. - * @param mappings Set of the mappings for the literals. + * @param secondModuleInSequence Predicate that is enforced by + * firstPredicate. + * @param firstModuleInSequence Predicate that enforce the usage of + * secondPredicate. + * @param moduleAutomaton Module automaton. + * @param mappings Set of the mappings for the literals. * @return The String CNF representation of the constraint. */ - public static String prev_module(TaxonomyPredicate second_module_in_sequence, - TaxonomyPredicate first_module_in_sequence, + public static String prevModule(TaxonomyPredicate secondModuleInSequence, + TaxonomyPredicate firstModuleInSequence, ModuleAutomaton moduleAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); int automatonSize = moduleAutomaton.getAllStates().size(); for (int i = 0; i < automatonSize; i++) { - constraints.append("-").append(mappings.add(second_module_in_sequence, + constraints.append("-").append(mappings.add(secondModuleInSequence, moduleAutomaton.getAllStates().get(i), AtomType.MODULE)).append(" "); /* - * Clause that forbids using second_module_in_sequence as the first tool in the + * Clause that forbids using secondModuleInSequence as the first tool in the * sequence */ if (i > 0) { - constraints.append(mappings.add(first_module_in_sequence, + constraints.append(mappings.add(firstModuleInSequence, moduleAutomaton.get(i - 1), AtomType.MODULE)).append(" "); } constraints.append("0\n"); @@ -358,20 +358,20 @@ public static String prev_module(TaxonomyPredicate second_module_in_sequence, /** * Creates a CNF representation of the Constraint:
- * Use last_module as last module in the solution. + * Use lastModule as last module in the solution. * - * @param last_module The module. + * @param lastModule The module. * @param moduleAutomaton Automaton of all the module states. * @param mappings Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. */ - public static String useAsLastModule(TaxonomyPredicate last_module, ModuleAutomaton moduleAutomaton, + public static String useAsLastModule(TaxonomyPredicate lastModule, ModuleAutomaton moduleAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); List moduleAutomatonStates = moduleAutomaton.getAllStates(); State lastModuleState = moduleAutomatonStates.get(moduleAutomatonStates.size() - 1); - constraints.append(mappings.add(last_module, lastModuleState, AtomType.MODULE)).append(" 0\n"); + constraints.append(mappings.add(lastModule, lastModuleState, AtomType.MODULE)).append(" 0\n"); return constraints.toString(); } @@ -397,27 +397,6 @@ public static String useAsNthModule(TaxonomyPredicate module, int n, ModuleAutom return constraints.toString(); } - /** - * TODO: Creates a CNF representation of the Constraint:
- * Use module in the solution exactly n times. - * - * @param module Module to be used. - * @param n Number of repetitions. - * @param moduleAutomaton Automaton of all the module states. - * @param mappings Set of the mappings for the literals. - * @return The String CNF representation of the SLTLx formula. - */ - public static String useModuleNtimes(TaxonomyPredicate module, int n, ModuleAutomaton moduleAutomaton, - SATAtomMappings mappings) { - // StringBuilder constraints = new StringBuilder(); - // - // List moduleAutomatonStates = moduleAutomaton.getModuleStates(); - // ModuleState nthModuleState = moduleAutomatonStates.get(index - 1); - // constraints.append(mappings.add(module, nthModuleState)).append(" 0\n"; - - return null; - } - /** * Creates a CNF representation of the Constraint:
* Use module with data inputType as one of the inputs. @@ -429,7 +408,7 @@ public static String useModuleNtimes(TaxonomyPredicate module, int n, ModuleAuto * @param mappings Set of the mappings for the literals. * @return */ - public static String use_module_input(TaxonomyPredicate module, TaxonomyPredicate inputType, + public static String useModuleInput(TaxonomyPredicate module, TaxonomyPredicate inputType, ModuleAutomaton moduleAutomaton, TypeAutomaton typeAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); @@ -484,7 +463,7 @@ public static String use_module_input(TaxonomyPredicate module, TaxonomyPredicat * @param mappings Set of the mappings for the literals. * @return */ - public static String use_module_output(TaxonomyPredicate module, TaxonomyPredicate outputType, + public static String useModuleOutput(TaxonomyPredicate module, TaxonomyPredicate outputType, ModuleAutomaton moduleAutomaton, TypeAutomaton typeAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); @@ -532,16 +511,15 @@ public static String use_module_output(TaxonomyPredicate module, TaxonomyPredica * Creates a CNF representation of the Constraint:
* 1st operation should generate an output used by the 2nd operation. * - * @param first_predicate - Module type that generates the data as output - * @param second_predicate - Module type that uses the generated data as input - * @param domainSetup - setup of the domain - * @param moduleAutomaton - module automaton. - * @param typeAutomaton - type automaton - * @param mappings - Set of the mappings for the literals. + * @param firstPredicate - Module type that generates the data as output + * @param secondPredicate - Module type that uses the generated data as input + * @param moduleAutomaton - module automaton. + * @param typeAutomaton - type automaton + * @param mappings - Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. */ - public static String connected_modules(TaxonomyPredicate first_predicate, TaxonomyPredicate second_predicate, - APEDomainSetup domainSetup, ModuleAutomaton moduleAutomaton, + public static String connectedModules(TaxonomyPredicate firstPredicate, TaxonomyPredicate secondPredicate, + ModuleAutomaton moduleAutomaton, TypeAutomaton typeAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); Set allCombinations = new HashSet<>(); @@ -576,10 +554,10 @@ public static String connected_modules(TaxonomyPredicate first_predicate, Taxono for (Integer currComb : allCombinations) { // enforce tools constraints.append("-" + currComb + " ") - .append(mappings.add(first_predicate, opOrderStates.get(currComb).getFirst(), AtomType.MODULE)) + .append(mappings.add(firstPredicate, opOrderStates.get(currComb).getFirst(), AtomType.MODULE)) .append(" 0\n"); constraints.append("-" + currComb + " ") - .append(mappings.add(second_predicate, opOrderStates.get(currComb).getSecond(), AtomType.MODULE)) + .append(mappings.add(secondPredicate, opOrderStates.get(currComb).getSecond(), AtomType.MODULE)) .append(" 0\n"); // enforce output/input dependencies constraints.append("-" + currComb + " "); @@ -598,16 +576,16 @@ public static String connected_modules(TaxonomyPredicate first_predicate, Taxono * Creates a CNF representation of the Constraint:
* 1st operation should not generate an output used by the 2nd operation. * - * @param first_predicate - Module type that generates the data as output - * @param second_predicate - Module type that uses the generated data as input - * @param domainSetup - setup of the domain - * @param moduleAutomaton - module automaton. - * @param typeAutomaton - type automaton - * @param mappings - Set of the mappings for the literals. + * @param firstPredicate - Module type that generates the data as output + * @param secondPredicate - Module type that uses the generated data as input + * @param domainSetup - setup of the domain + * @param moduleAutomaton - module automaton. + * @param typeAutomaton - type automaton + * @param mappings - Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. */ - public static String not_connected_modules(TaxonomyPredicate first_predicate, TaxonomyPredicate second_predicate, - APEDomainSetup domainSetup, ModuleAutomaton moduleAutomaton, + public static String notConnectedModules(TaxonomyPredicate firstPredicate, TaxonomyPredicate secondPredicate, + ModuleAutomaton moduleAutomaton, TypeAutomaton typeAutomaton, SATAtomMappings mappings) { StringBuilder constraints = new StringBuilder(); @@ -625,13 +603,13 @@ public static String not_connected_modules(TaxonomyPredicate first_predicate, Ta // are not connected Set> statePairs = APEUtils.getUniquePairs(op1outputs, op2inputs); for (Pair currIOpair : statePairs) { - constraints.append("-").append(mappings.add(first_predicate, firstModuleState, AtomType.MODULE)) + constraints.append("-").append(mappings.add(firstPredicate, firstModuleState, AtomType.MODULE)) .append(" "); constraints.append("-" + mappings.add(currIOpair.getFirst(), currIOpair.getSecond(), AtomType.MEM_TYPE_REFERENCE) + " "); constraints.append("-" - + mappings.add(second_predicate, secondModuleState, AtomType.MODULE) + + mappings.add(secondPredicate, secondModuleState, AtomType.MODULE) + " 0\n"); } diff --git a/src/main/java/nl/uu/cs/ape/parser/SLTLxSATVisitor.java b/src/main/java/nl/uu/cs/ape/parser/SLTLxSATVisitor.java index 9787674..ef57e97 100644 --- a/src/main/java/nl/uu/cs/ape/parser/SLTLxSATVisitor.java +++ b/src/main/java/nl/uu/cs/ape/parser/SLTLxSATVisitor.java @@ -9,6 +9,7 @@ import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.tree.ParseTree; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.core.implSAT.SATSynthesisEngine; import nl.uu.cs.ape.models.AbstractModule; import nl.uu.cs.ape.models.AllModules; @@ -61,6 +62,7 @@ * @author Vedran Kasalica * */ +@Slf4j public class SLTLxSATVisitor extends SLTLxBaseVisitor { static int usedState = 0; @@ -145,7 +147,7 @@ public SLTLxFormula visitUnaryModal(UnaryModalContext ctx) { } else if (ctx.getChild(0).getText().equals("X")) { return new SLTLxNext(subFormula); } else { - System.err.println("Modal operation '" + ctx.getChild(1).getText() + "' id not recognised."); + log.warn("Modal operation '" + ctx.getChild(1).getText() + "' is not recognised."); /* In case modal operator is not recognized return null. */ return null; } @@ -179,7 +181,7 @@ public SLTLxFormula visitBinaryBool(BinaryBoolContext ctx) { } else if (ctx.getChild(1).getText().equals("<->")) { return new SLTLxEquivalence(subFormula1, subFormula2); } else { - System.err.println("Binary operation '" + ctx.getChild(1).getText() + "' is not recognised."); + log.warn("Binary operation '" + ctx.getChild(1).getText() + "' is not recognised."); /* In case binary operator is not recognised return null. */ return null; } diff --git a/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java b/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java index e2f2be0..6f02e5b 100644 --- a/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java +++ b/src/main/java/nl/uu/cs/ape/utils/APEDomainSetup.java @@ -307,7 +307,7 @@ public boolean updateToolAnnotationsFromJson(JSONObject toolAnnotationsFile) thr updateModuleFromJson(jsonModule); } if (currModule == 0) { - System.err.println("No tools were annotated."); + log.warn("No tools were annotated in the current domain."); return false; } return true; @@ -337,7 +337,7 @@ private boolean updateModuleFromJson(JSONObject jsonModule) for (String taxonomyModule : taxonomyModules) { String taxonomyModuleIRI = APEUtils.createClassIRI(taxonomyModule, ontologyPrefixIRI); if (allModules.get(taxonomyModuleIRI) == null) { - System.err.println("Tool '" + moduleIRI + "' annotation issue. " + log.warn("Tool '" + moduleIRI + "' annotation issue. " + "Referenced '" + APECoreConfig.getJsonTags("taxonomyOperations") + "': '" + taxonomyModuleIRI + "' cannot be found in the Tool Taxonomy."); wrongToolTax.add(moduleLabel); @@ -351,7 +351,7 @@ private boolean updateModuleFromJson(JSONObject jsonModule) * used as superclass of the tool. */ if (taxonomyModules.isEmpty()) { - System.err.println("Tool '" + moduleIRI + "' annotation issue. " + log.warn("Tool '" + moduleIRI + "' annotation issue. " + "None of the referenced '" + APECoreConfig.getJsonTags("taxonomyOperations") + "' can be found in the Tool Taxonomy."); taxonomyModules.add(allModules.getRootModuleID()); diff --git a/src/main/java/nl/uu/cs/ape/utils/APEUtils.java b/src/main/java/nl/uu/cs/ape/utils/APEUtils.java index 4927032..473087f 100644 --- a/src/main/java/nl/uu/cs/ape/utils/APEUtils.java +++ b/src/main/java/nl/uu/cs/ape/utils/APEUtils.java @@ -82,8 +82,7 @@ public static String encodeAPEConstraints(SATSynthesisEngine synthesisEngine, AP String currConstrEncoding = constraintSATEncoding(constraint.getConstraintID(), constraint.getParameters(), domainSetup, moduleAutomaton, typeAutomaton, mappings); if (currConstrEncoding == null) { - System.err - .println("Error in constraint file. Constraint no: " + currConst + ". Constraint skipped."); + log.warn("Error in constraint file. Constraint no: " + currConst + ". Constraint skipped."); } else { cnf_SLTL.append(currConstrEncoding); } diff --git a/src/main/java/nl/uu/cs/ape/utils/BioToolsAPI.java b/src/main/java/nl/uu/cs/ape/utils/BioToolsAPI.java index 59ab190..a2991ea 100644 --- a/src/main/java/nl/uu/cs/ape/utils/BioToolsAPI.java +++ b/src/main/java/nl/uu/cs/ape/utils/BioToolsAPI.java @@ -130,7 +130,6 @@ private static JSONArray fetchToolsFromURI(String url) throws JSONException, IOE String next = ""; int i = 1; while (next != null) { - System.out.print("\n" + (i++) + ") "); Request request = new Request.Builder().url(url + "&format=json" + next.replace('?', '&')).build(); try (Response response = client.newCall(request).execute()) { if (!response.isSuccessful()) @@ -141,7 +140,6 @@ private static JSONArray fetchToolsFromURI(String url) throws JSONException, IOE for (int j = 0; j < toolListJson.length(); j++) { JSONObject tool = toolListJson.getJSONObject(j); bioToolAnnotations.put(tool); - System.out.print("."); } try { next = responseJson.getString("next"); @@ -149,9 +147,10 @@ private static JSONArray fetchToolsFromURI(String url) throws JSONException, IOE next = null; } } + log.trace("bio.tools: page " + i + " fetched."); } - log.debug("Tools fetched from a given URL."); + log.debug("All tools fetched from a given URL."); return bioToolAnnotations; } diff --git a/src/main/java/nl/uu/cs/ape/utils/OWLReader.java b/src/main/java/nl/uu/cs/ape/utils/OWLReader.java index 343fe3d..5ac175c 100644 --- a/src/main/java/nl/uu/cs/ape/utils/OWLReader.java +++ b/src/main/java/nl/uu/cs/ape/utils/OWLReader.java @@ -8,6 +8,7 @@ import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory; import org.semanticweb.owlapi.search.EntitySearcher; +import lombok.extern.slf4j.Slf4j; import nl.uu.cs.ape.models.AbstractModule; import nl.uu.cs.ape.models.AllModules; import nl.uu.cs.ape.models.AllTypes; @@ -25,6 +26,7 @@ * * @author Vedran Kasalica */ +@Slf4j public class OWLReader { /** File containing the ontology */ @@ -263,7 +265,7 @@ private void exploreTypeOntologyRec(OWLReasoner reasoner, OWLClass currClass, OW } List subClasses = reasoner.getSubClasses(currClass, true).entities() - .filter(child -> reasoner.isSatisfiable(child)).collect(Collectors.toList()); + .filter(reasoner::isSatisfiable).collect(Collectors.toList()); subClasses.forEach(child -> exploreTypeOntologyRec(reasoner, child, currClass, currRoot)); @@ -279,11 +281,20 @@ private void exploreTypeOntologyRec(OWLReasoner reasoner, OWLClass currClass, OW artificialSubType.addSuperPredicate(currType); artificialSubType.setNodePredicate(NodeType.LEAF); } else { - System.err.println("Artificial predicate '" + getLabel(currClass) + "' was not created correctly."); + log.warn("Artificial predicate '" + getLabel(currClass) + "' was not created correctly."); } } } + /** + * Adding a new type to the {@link #allTypes} object. + * + * @param classLabel The label of the class. + * @param classID The ID of the class. + * @param rootID The ID of the root class. + * @param currNodeType The node type of the class. + * @return The newly created type. + */ private Type addNewTypeToAllTypes(String classLabel, String classID, String rootID, NodeType currNodeType) { Type currType = null; /* Generate the Type that corresponds to the taxonomy class. */ @@ -332,7 +343,7 @@ private String getLabel(OWLClass currClass) { */ private String getIRI(OWLClass currClass) { if (currClass == null) { - return null; + return "N/A"; } return currClass.toStringID(); } diff --git a/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTagTest.java b/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTagTest.java index c107174..74a8d05 100644 --- a/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTagTest.java +++ b/src/test/java/nl/uu/cs/ape/sat/test/configuration/APEConfigTagTest.java @@ -38,12 +38,12 @@ public void infoOutputTest() { for (APEConfigTag.Info tag : APERunConfig.TAGS.getAll()) { if (tag.type == APEConfigTag.TagType.INTEGER) { - System.out.printf("Web API shows `%s` box for tag `%s`, with min:`%s` and max:`%s`\n", tag.type, + log.debug("Web API shows `{}` box for tag `{}`, with min:`{}` and max:`{}`\n", tag.type, tag.label, tag.constraints.getInt("min"), tag.constraints.getInt("max")); } } - System.out.printf("\n### Display all tag info ####\nCORE:\n%s\n\nRUN:\n%s\n", + log.debug("\n### Display all tag info ####\nCORE:\n{}\n\nRUN:\n{}\n", APECoreConfig.TAGS.toJSON().toString(3), APERunConfig.TAGS.toJSON().toString(3)); } diff --git a/src/test/java/nl/uu/cs/ape/sat/test/utils/GitHubRepo.java b/src/test/java/nl/uu/cs/ape/sat/test/utils/GitHubRepo.java index 3bd5e8b..88b03ae 100644 --- a/src/test/java/nl/uu/cs/ape/sat/test/utils/GitHubRepo.java +++ b/src/test/java/nl/uu/cs/ape/sat/test/utils/GitHubRepo.java @@ -50,7 +50,7 @@ public void cleanUp() { FileUtils.deleteDirectory(directory); assertFalse(directory.exists()); } catch (IOException e) { - log.info(String.format("Could not delete folder '%s':\n%s", this.absoluteLocalRoot, e.getMessage())); + log.info("Could not delete folder '{}':\n{}", this.absoluteLocalRoot, e.getMessage()); } } @@ -156,7 +156,7 @@ public void write(String content) { fw.write(content); fw.flush(); } catch (IOException e) { - e.printStackTrace(); + log.error(e.getMessage()); fail("Cannot write to file '%s'", getFilePath()); } } diff --git a/src/test/java/nl/uu/cs/ape/sat/test/utils/TestResources.java b/src/test/java/nl/uu/cs/ape/sat/test/utils/TestResources.java index edda423..71082f9 100644 --- a/src/test/java/nl/uu/cs/ape/sat/test/utils/TestResources.java +++ b/src/test/java/nl/uu/cs/ape/sat/test/utils/TestResources.java @@ -3,6 +3,8 @@ import org.apache.commons.io.IOUtils; import org.json.JSONObject; +import lombok.extern.slf4j.Slf4j; + import static nl.uu.cs.ape.sat.test.utils.Evaluation.fail; import java.io.File; @@ -16,10 +18,13 @@ import java.util.Objects; /** - * The {@code TestUtil} class is used to read contents of resource files more easily, as functional tests will make use of json files in the test resource folders. + * The {@code TestUtil} class is used to read contents of resource files more + * easily, as functional tests will make use of json files in the test resource + * folders. * * @author Maurin Voshol */ +@Slf4j public class TestResources { /** @@ -28,7 +33,8 @@ public class TestResources { */ public static String getAbsoluteResourcePath(String resource) { try { - return Paths.get(Objects.requireNonNull(TestResources.class.getClassLoader().getResource(resource)).toURI()).toAbsolutePath().toString(); + return Paths.get(Objects.requireNonNull(TestResources.class.getClassLoader().getResource(resource)).toURI()) + .toAbsolutePath().toString(); } catch (URISyntaxException | NullPointerException e) { e.printStackTrace(); fail("Could not retrieve resource '%s'", resource); @@ -37,7 +43,8 @@ public static String getAbsoluteResourcePath(String resource) { } /** - * @return the absolute path of a the resource root that can be used by the library. + * @return the absolute path of a the resource root that can be used by the + * library. */ public static String getAbsoluteRoot() { return getAbsoluteResourcePath(""); @@ -50,7 +57,9 @@ public static String getAbsoluteRoot() { */ public static String getTextResource(String resource, Charset charset) { try { - return IOUtils.toString(Objects.requireNonNull(TestResources.class.getClassLoader().getResourceAsStream(resource)), charset); + return IOUtils.toString( + Objects.requireNonNull(TestResources.class.getClassLoader().getResourceAsStream(resource)), + charset); } catch (IOException e) { e.printStackTrace(); fail("Could not retrieve %s resource '%s' ", charset, resource); @@ -80,15 +89,15 @@ public static String writeFile(String relativePath, String content) { try { File folder = absoluteParentPath.toFile(); if (!folder.exists() && folder.mkdirs()) { - System.out.printf("Directories created for file '%s'\n", relativePath); + log.debug("Directories created for file '{}'\n", relativePath); } File file = absolutePath.toFile(); if (!file.exists() && file.createNewFile()) { - System.out.printf("File '%s' was created\n", relativePath); + log.debug("File '{}' was created\n", relativePath); } Files.write(absolutePath, content.getBytes()); - System.out.printf("Wrote content to '%s'\n", absolutePath); + log.debug("Wrote content to '{}'\n", absolutePath); } catch (IOException e) { e.printStackTrace(); @@ -96,7 +105,8 @@ public static String writeFile(String relativePath, String content) { return absolutePath.toString(); } - public static JSONObject getConfigResource(String base_config_path, String ontology_path, String tools_path, String constraints_path, String solution_dir_path){ + public static JSONObject getConfigResource(String base_config_path, String ontology_path, String tools_path, + String constraints_path, String solution_dir_path) { return getJSONResource(base_config_path) // add paths to the other files to the configuration .put("ontology_path", getAbsoluteResourcePath(ontology_path)) From 4d999962f9f3c35381838667bcd5eb4c7d797b1c Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Thu, 6 Jul 2023 00:38:17 +0200 Subject: [PATCH 08/18] Fix CWL input YML file format --- .../solutionStructure/AbstractCWLCreator.java | 8 +- .../solutionStructure/CWLCreatorBase.java | 10 +- .../solutionStructure/DefaultCWLCreator.java | 113 ++++++++---------- .../core/solutionStructure/ModuleNode.java | 19 +++ 4 files changed, 81 insertions(+), 69 deletions(-) diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/AbstractCWLCreator.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/AbstractCWLCreator.java index b1fed2f..ba7c054 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/AbstractCWLCreator.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/AbstractCWLCreator.java @@ -149,7 +149,7 @@ private void generateStepIn(ModuleNode moduleNode) { // If there are no inputs, give an empty array as input if (moduleNode.getInputTypes().isEmpty()) { // Remove the last newline so the array is on the same line as "in:" - deleteLastCharacters(1); + deleteLastNCharactersFromCWL(1); cwlRepresentation .append(" ") .append("[]") @@ -191,7 +191,7 @@ private void generateStepOut(ModuleNode moduleNode) { .append(", "); i++; } - deleteLastCharacters(2); + deleteLastNCharactersFromCWL(2); cwlRepresentation.append("]").append("\n"); } @@ -275,7 +275,7 @@ private void generateStepIntent(ModuleNode moduleNode, int baseInd) { .append("\"") .append(", "); } - deleteLastCharacters(2); + deleteLastNCharactersFromCWL(2); cwlRepresentation.append("]").append("\n"); } @@ -295,7 +295,7 @@ private void generateTypeNodes(ModuleNode moduleNode, List typeNodeLis // output if (typeNodeList.isEmpty()) { // Remove the last newline so the array is on the same line as "inputs:" - deleteLastCharacters(1); + deleteLastNCharactersFromCWL(1); cwlRepresentation .append(" ") .append("[]") diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/CWLCreatorBase.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/CWLCreatorBase.java index 02b6398..0d049a9 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/CWLCreatorBase.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/CWLCreatorBase.java @@ -1,7 +1,7 @@ package nl.uu.cs.ape.core.solutionStructure; /** - * Base class with shared behaviour for CWL export classes. + * Base class with shared behavior for CWL export classes. */ public abstract class CWLCreatorBase { /** @@ -96,7 +96,7 @@ private void generateDoc() { .append(moduleNode.getNodeLabel()) .append(", "); } - deleteLastCharacters(2); + deleteLastNCharactersFromCWL(2); cwlRepresentation.append(".").append("\n").append("\n"); } @@ -117,10 +117,10 @@ public String getCWL() { /** * Delete a number of characters at the end of the CWL file. * - * @param number The number of characters to remove. + * @param numberOfCharToDel The number of characters to remove. */ - protected void deleteLastCharacters(int number) { - cwlRepresentation.delete(cwlRepresentation.length() - number, cwlRepresentation.length()); + protected void deleteLastNCharactersFromCWL(int numberOfCharToDel) { + cwlRepresentation.delete(cwlRepresentation.length() - numberOfCharToDel, cwlRepresentation.length()); } /** diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java index b8f4851..b849d31 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.List; +import java.util.stream.IntStream; import lombok.extern.slf4j.Slf4j; @@ -39,52 +40,59 @@ public String getCWLVersion() { @Override protected void generateCWLRepresentation() { // Workflow - generateWorkflowInputs(false); + generateWorkflowInputs(); generateWorkflowSteps(); generateWorkflowOutputs(); } /** * Generate the top-level inputs definition of the workflow. - * - * @param includePath Whether to include the file path in the definition. */ - private void generateWorkflowInputs(boolean includePath) { + private void generateWorkflowInputs() { cwlRepresentation.append("inputs:").append("\n"); - cwlRepresentation.append(getInputsInCWL(includePath)); + cwlRepresentation.append(getInputsInCWL(false)); } /** * Generate the top-level outputs definition of the workflow. * - * @param includePath Whether to include the file path in the definition. + * @param formatForCwlInputsYmlFile Whether the inputs are used to generate the + * CWL inputs.yml file. * * @return The CWL representation of the workflow outputs. */ - private String getInputsInCWL(boolean includePath) { + private String getInputsInCWL(boolean formatForCwlInputsYmlFile) { StringBuilder inputsInCWL = new StringBuilder(); + + int indentLevel = 1; + String typeLabel = "type"; + if (formatForCwlInputsYmlFile) { + indentLevel = 0; + typeLabel = "class"; + } + int i = 1; for (TypeNode typeNode : solution.getWorkflowInputTypeStates()) { - String inputName = String.format("input%o", workflowParameters.size() + 1); - addParameter(typeNode, inputName); + String inputName = String.format("input%o", i++); + addNewParameterToMap(typeNode, inputName); inputsInCWL // Name - .append(ind(1)) + .append(ind(indentLevel)) .append(inputName) .append(":\n") // Data type - .append(ind(2)) - .append("type: File") + .append(ind(indentLevel + 1)) + .append(typeLabel + ": File") .append("\n") // Format - .append(ind(2)) + .append(ind(indentLevel + 1)) .append("format: ") .append(typeNode.getFormat()) .append("\n"); - if (includePath) { + if (formatForCwlInputsYmlFile) { inputsInCWL - .append(ind(2)) + .append(ind(indentLevel + 1)) .append("path: ") - .append("set_path_to_the_file_here") + .append("set_full_path_to_the_file_with_extension_here") .append("\n"); } } @@ -166,25 +174,22 @@ private void generateStepIn(ModuleNode moduleNode) { // "in" key cwlRepresentation.append(ind(baseInd)).append("in").append(":\n"); // If there are no inputs, give an empty array as input - if (moduleNode.getInputTypes().isEmpty()) { + if (!moduleNode.hasInputTypes()) { // Remove the last newline so the array is on the same line as "in:" - deleteLastCharacters(1); + deleteLastNCharactersFromCWL(1); cwlRepresentation .append(" ") .append("[]") .append("\n"); - return; - } - - int i = 0; - for (TypeNode typeNode : moduleNode.getInputTypes()) { - cwlRepresentation - .append(ind(baseInd + 1)) - .append(inOutName(moduleNode, "in", i + 1)) - .append(": ") - .append(workflowParameters.get(typeNode.getNodeID())) - .append("\n"); - i++; + } else { + List inputs = moduleNode.getInputTypes(); + IntStream.range(0, inputs.size()).filter(i -> !inputs.get(i).isEmpty()) + .forEach(i -> cwlRepresentation + .append(ind(baseInd + 1)) + .append(inOutName(moduleNode, "in", i + 1)) + .append(": ") + .append(workflowParameters.get(inputs.get(i).getNodeID())) + .append("\n")); } } @@ -201,16 +206,20 @@ private void generateStepOut(ModuleNode moduleNode) { .append("out: ") // The outputs array .append("["); - int i = 1; - for (TypeNode typeNode : moduleNode.getOutputTypes()) { - String name = inOutName(moduleNode, "out", i); - addParameter(typeNode, String.format("%s/%s", stepName(moduleNode), name)); - cwlRepresentation - .append(name) - .append(", "); - i++; + + List outputs = moduleNode.getOutputTypes(); + IntStream.range(0, outputs.size()).filter(i -> !outputs.get(i).isEmpty()) + .forEach(i -> { + String name = inOutName(moduleNode, "out", i + 1); + addNewParameterToMap(outputs.get(i), String.format("%s/%s", stepName(moduleNode), name)); + cwlRepresentation + .append(name) + .append(", "); + }); + if (moduleNode.hasOutputTypes()) { + // Remove the last comma + deleteLastNCharactersFromCWL(2); } - deleteLastCharacters(2); cwlRepresentation.append("]").append("\n"); } @@ -228,24 +237,6 @@ private void generateDefaultStepRun(ModuleNode moduleNode) { .append("run: /cwl/tools/" + moduleName + "/" + moduleName + ".cwl") .append("\n"); /* - * // Class - * .append(ind(baseInd + 1)) - * .append("class: Operation") - * .append("\n"); - * // Inputs - * cwlRepresentation - * .append(ind(baseInd + 1)) - * .append("inputs:") - * .append("\n"); - * generateTypeNodes(moduleNode, moduleNode.getInputTypes(), true, baseInd + 2); - * // Outputs - * cwlRepresentation - * .append(ind(baseInd + 1)) - * .append("outputs:") - * .append("\n"); - * generateTypeNodes(moduleNode, moduleNode.getOutputTypes(), false, baseInd + - * 2); - * /* * // Hints and intent * generateStepHints(moduleNode, baseInd + 1); * generateStepIntent(moduleNode, baseInd + 1); @@ -332,7 +323,7 @@ private void generateStepIntent(ModuleNode moduleNode, int baseInd) { .append("\"") .append(", "); } - deleteLastCharacters(2); + deleteLastNCharactersFromCWL(2); cwlRepresentation.append("]").append("\n"); } @@ -352,7 +343,7 @@ private void generateTypeNodes(ModuleNode moduleNode, List typeNodeLis // output if (typeNodeList.isEmpty()) { // Remove the last newline so the array is on the same line as "inputs:" - deleteLastCharacters(1); + deleteLastNCharactersFromCWL(1); cwlRepresentation .append(" ") .append("[]") @@ -407,11 +398,13 @@ private String inOutName(ModuleNode moduleNode, String indicator, int n) { * * @param typeNode The {@link TypeNode} that is the input parameter. * @param name The name of the parameter. + * @return The ID of the parameter. */ - private void addParameter(TypeNode typeNode, String name) { + private String addNewParameterToMap(TypeNode typeNode, String name) { if (workflowParameters.putIfAbsent(typeNode.getNodeID(), name) != null) { log.warn("Duplicate key \"{}\" in workflow inputs!", typeNode.getNodeID()); } + return typeNode.getNodeID(); } /** diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/ModuleNode.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/ModuleNode.java index e70fed4..1a8e657 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/ModuleNode.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/ModuleNode.java @@ -17,6 +17,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static guru.nidi.graphviz.model.Factory.node; @@ -222,6 +223,15 @@ public List getInputTypes() { return inputTypes; } + /** + * Check if the module has any non empty input types. + * + * @return {@code true} is the module has input types, {@code false} otherwise. + */ + public boolean hasInputTypes() { + return !inputTypes.stream().filter(typeNode -> !typeNode.isEmpty()).collect(Collectors.toList()).isEmpty(); + } + /** * Gets output types. * @@ -231,6 +241,15 @@ public List getOutputTypes() { return outputTypes; } + /** + * Check if the module has any non empty output types. + * + * @return {@code true} is the module has output types, {@code false} otherwise. + */ + public boolean hasOutputTypes() { + return !outputTypes.stream().filter(typeNode -> !typeNode.isEmpty()).collect(Collectors.toList()).isEmpty(); + } + /** * Is empty boolean. * From 73dbbab6d2c0cff1c7a458bb9aec87d8a31aa745 Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Thu, 6 Jul 2023 15:34:57 +0200 Subject: [PATCH 09/18] Fix tests --- src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java b/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java index 62f236c..2655fa9 100644 --- a/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java +++ b/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java @@ -22,6 +22,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; +import java.util.stream.Stream; import static nl.uu.cs.ape.sat.test.utils.Evaluation.fail; import static nl.uu.cs.ape.sat.test.utils.Evaluation.success; @@ -149,7 +150,8 @@ void testUseCase(String name, String evaluationPath) File[] files = cwlFolder.toFile().listFiles(); assertNotNull(files); - assertEquals(mutation.number_of_cwl_files, files.length); + assertEquals(mutation.number_of_cwl_files, + Stream.of(files).filter(file -> file.getName().endsWith(".cwl")).count()); for (File f : files) { assertTrue(f.getName().startsWith("workflowSolution_")); } From 26c36ad188090e794c3fe33cb86c6113696575fe Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Thu, 6 Jul 2023 15:41:23 +0200 Subject: [PATCH 10/18] Added tests for CWL input (YML) files --- src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java b/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java index 2655fa9..f2febc5 100644 --- a/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java +++ b/src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java @@ -152,6 +152,8 @@ void testUseCase(String name, String evaluationPath) assertNotNull(files); assertEquals(mutation.number_of_cwl_files, Stream.of(files).filter(file -> file.getName().endsWith(".cwl")).count()); + assertEquals(mutation.number_of_cwl_files, + Stream.of(files).filter(file -> file.getName().endsWith("inp.yml")).count()); for (File f : files) { assertTrue(f.getName().startsWith("workflowSolution_")); } From fa8302f98b33db038b2305e42004cd3fa346218e Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Thu, 6 Jul 2023 16:06:43 +0200 Subject: [PATCH 11/18] Fix javadoc --- .../templateFormulas/SLTLxTemplateFormula.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/nl/uu/cs/ape/models/templateFormulas/SLTLxTemplateFormula.java b/src/main/java/nl/uu/cs/ape/models/templateFormulas/SLTLxTemplateFormula.java index 08e09a6..a386234 100644 --- a/src/main/java/nl/uu/cs/ape/models/templateFormulas/SLTLxTemplateFormula.java +++ b/src/main/java/nl/uu/cs/ape/models/templateFormulas/SLTLxTemplateFormula.java @@ -149,14 +149,13 @@ public static String iteModule(TaxonomyPredicate ifPredicate, TaxonomyPredicate * If type ifPredicate is used/generated (depending on the @typeBlocks), * then type thenPredicate has to be used/generated subsequently. * - * @param ifPredicate Predicate that enforce the usage of - * thenPredicate. - * @param thenPredicate Predicate that is enforced by ifPredicate. - * @param typeElement Workflow element type. - * @param moduleAutomaton Module automaton. - * @param typeBlocks Type blocks (corresponding to the memory or used type - * states). - * @param mappings Set of the mappings for the literals. + * @param ifPredicate Predicate that enforce the usage of + * thenPredicate. + * @param thenPredicate Predicate that is enforced by ifPredicate. + * @param typeElement Workflow element type. + * @param typeBlocks Type blocks (corresponding to the memory or used type + * states). + * @param mappings Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. */ public static String iteType(TaxonomyPredicate ifPredicate, TaxonomyPredicate thenPredicate, @@ -225,7 +224,6 @@ public static String itnModule(TaxonomyPredicate ifPredicate, TaxonomyPredicate * thenNotPredicate. * @param thenNotPredicate Predicate that is forbidden by ifPredicate. * @param typeElement Workflow element type. - * @param moduleAutomaton Module automaton. * @param typeBlocks Type blocks (corresponding to the memory or used * type states). * @param mappings Set of the mappings for the literals. @@ -578,8 +576,6 @@ public static String connectedModules(TaxonomyPredicate firstPredicate, Taxonomy * * @param firstPredicate - Module type that generates the data as output * @param secondPredicate - Module type that uses the generated data as input - * @param domainSetup - setup of the domain - * @param moduleAutomaton - module automaton. * @param typeAutomaton - type automaton * @param mappings - Set of the mappings for the literals. * @return The String CNF representation of the SLTLx formula. From d2bc5b373995f79233b3515d316bb381bd4d9f6f Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Thu, 6 Jul 2023 16:21:55 +0200 Subject: [PATCH 12/18] Fix 'format' field in CWL(for not EDAM ontology) --- .../nl/uu/cs/ape/core/solutionStructure/TypeNode.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java index 9be2dbf..9ade8da 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java @@ -254,13 +254,15 @@ public String getNodeID() { * Get the unique ID of the current workflow node in .dot representation. */ public String getFormat() { - StringBuilder printString = new StringBuilder("\""); + StringBuilder printString = new StringBuilder(); for (Type type : this.usedTypes) { if (type.getRootNodeID().equals("http://edamontology.org/format_1915")) { - printString.append(type.getPredicateID()).append("\" # ").append(type.getPredicateLabel()); + printString.append("\"").append(type.getPredicateID()).append("\" # ").append(type.getPredicateLabel()); } - + } + if (printString.isEmpty()) { + printString.append("\"unknown\""); } return printString.toString(); From 4793ac1ce3f54ecdd3b8b999c36232252c1b47f5 Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Thu, 6 Jul 2023 16:39:57 +0200 Subject: [PATCH 13/18] Fix error in using StringBuilder --- src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java index 9ade8da..83f4a1f 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/TypeNode.java @@ -261,7 +261,7 @@ public String getFormat() { printString.append("\"").append(type.getPredicateID()).append("\" # ").append(type.getPredicateLabel()); } } - if (printString.isEmpty()) { + if (printString.length() == 0) { printString.append("\"unknown\""); } From 4e3aeca9c4c49ed5d1de58b329ec1429b83effce Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Mon, 31 Jul 2023 20:35:30 +0200 Subject: [PATCH 14/18] Update CWL verification --- .travis.yml | 8 ++++---- .../cs/ape/core/solutionStructure/DefaultCWLCreator.java | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 32fa41d..5bf1be6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,9 +22,9 @@ jobs: # Build JAR - mvn package -DskipTests=true # Run use case - - git clone https://github.com/sanctuuary/APE_UseCases - - cd APE_UseCases - - java -jar ../target/APE-*-executable.jar ./GeoGMT/E0/config.json + - git clone https://github.com/Workflomics/domain-annotations + - cd domain-annotations + - java -jar ../target/APE-*-executable.jar config_local.json # Validate with CWL runner - - cd ./GeoGMT/E0/CWL + - cd ./WombatP_tools/CWL - cwltool --enable-dev --validate workflowSolution_0.cwl diff --git a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java index b849d31..6f0d34c 100644 --- a/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java +++ b/src/main/java/nl/uu/cs/ape/core/solutionStructure/DefaultCWLCreator.java @@ -234,7 +234,8 @@ private void generateDefaultStepRun(ModuleNode moduleNode) { cwlRepresentation // Main key .append(ind(baseInd)) - .append("run: /cwl/tools/" + moduleName + "/" + moduleName + ".cwl") + .append("run: https://raw.githubusercontent.com/Workflomics/containers/main/cwl/tools/" + moduleName + + "/" + moduleName + ".cwl") .append("\n"); /* * // Hints and intent From 152024dfb013ab20ad46e33ad731faad1c210a3e Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Mon, 31 Jul 2023 20:45:18 +0200 Subject: [PATCH 15/18] Update developer info --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2207616..f92a762 100644 --- a/pom.xml +++ b/pom.xml @@ -19,9 +19,9 @@ Vedran Kasalica - v.kasalica@uu.nl - Utrecht University - https://www.uu.nl/ + v.kasalica@esciencecenter.nl + Netherlands eScience Center + https://www.esciencecenter.nl/ From e74c40eb2c70301735d9a85fc6baedd5e3adeeeb Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Mon, 31 Jul 2023 20:59:03 +0200 Subject: [PATCH 16/18] Update CLI execution --- .travis.yml | 2 +- src/main/java/nl/uu/cs/ape/Main.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5bf1be6..81e86ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ jobs: # Run use case - git clone https://github.com/Workflomics/domain-annotations - cd domain-annotations - - java -jar ../target/APE-*-executable.jar config_local.json + - java -jar ../target/APE-*-executable.jar WombatP_tools/config_local.json # Validate with CWL runner - cd ./WombatP_tools/CWL - cwltool --enable-dev --validate workflowSolution_0.cwl diff --git a/src/main/java/nl/uu/cs/ape/Main.java b/src/main/java/nl/uu/cs/ape/Main.java index 44b5312..8561a24 100644 --- a/src/main/java/nl/uu/cs/ape/Main.java +++ b/src/main/java/nl/uu/cs/ape/Main.java @@ -99,9 +99,9 @@ public static void main(String[] args) { APE.writeSolutionToFile(solutions); APE.writeDataFlowGraphs(solutions, RankDir.TOP_TO_BOTTOM); // APE.writeControlFlowGraphs(solutions, RankDir.LEFT_TO_RIGHT); - APE.writeExecutableWorkflows(solutions); + // APE.writeExecutableWorkflows(solutions); APE.writeCWLWorkflows(solutions); - APE.writeExecutableCWLWorkflows(solutions, apeFramework.getConfig()); + // APE.writeExecutableCWLWorkflows(solutions, apeFramework.getConfig()); } catch (IOException e) { log.error("Error in writing the solutions. to the file system."); e.printStackTrace(); From 02c948518c0cc0a54c438a1d48ae7c6cdf4f6c65 Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Mon, 31 Jul 2023 21:05:11 +0200 Subject: [PATCH 17/18] Fix the CLI command --- src/main/java/nl/uu/cs/ape/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/uu/cs/ape/Main.java b/src/main/java/nl/uu/cs/ape/Main.java index 8561a24..ce8f290 100644 --- a/src/main/java/nl/uu/cs/ape/Main.java +++ b/src/main/java/nl/uu/cs/ape/Main.java @@ -99,7 +99,7 @@ public static void main(String[] args) { APE.writeSolutionToFile(solutions); APE.writeDataFlowGraphs(solutions, RankDir.TOP_TO_BOTTOM); // APE.writeControlFlowGraphs(solutions, RankDir.LEFT_TO_RIGHT); - // APE.writeExecutableWorkflows(solutions); + APE.writeExecutableWorkflows(solutions); APE.writeCWLWorkflows(solutions); // APE.writeExecutableCWLWorkflows(solutions, apeFramework.getConfig()); } catch (IOException e) { From 4673f5ef5dee22d1c50b175ab6bcaa635cc1bc4e Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Mon, 31 Jul 2023 21:22:25 +0200 Subject: [PATCH 18/18] Update github actions --- .github/workflows/maven.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9aeabd0..990641b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,10 +35,10 @@ jobs: pip3 install cwlref-runner - name: Test CWL generation run: | - git clone https://github.com/sanctuuary/APE_UseCases - cd APE_UseCases - java -jar ../target/APE-*-executable.jar ./GeoGMT/E0/config.json - cd ./GeoGMT/E0/CWL + git clone https://github.com/Workflomics/domain-annotations + cd domain-annotations + java -jar ../target/APE-*-executable.jar ./WombatP_tools/config_local.json + cd ./WombatP_tools/CWL cwltool --enable-dev --validate workflowSolution_0.cwl # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive