diff --git a/creole.xml b/creole.xml index 058bca2..993b996 100644 --- a/creole.xml +++ b/creole.xml @@ -1,7 +1,7 @@ diff --git a/lib-static/interaction-1.0-SNAPSHOT.jar b/lib-static/interaction-1.0-SNAPSHOT.jar index 6c0a2b1..8088b13 100644 Binary files a/lib-static/interaction-1.0-SNAPSHOT.jar and b/lib-static/interaction-1.0-SNAPSHOT.jar differ diff --git a/src/gate/plugin/learningframework/engines/EngineSklearnExternal.java b/src/gate/plugin/learningframework/engines/EngineSklearnExternal.java index d3d16b1..4f39f00 100644 --- a/src/gate/plugin/learningframework/engines/EngineSklearnExternal.java +++ b/src/gate/plugin/learningframework/engines/EngineSklearnExternal.java @@ -20,6 +20,7 @@ import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -137,19 +138,22 @@ private File findWrapperCommand(File dataDirectory, boolean apply) { @Override protected void loadModel(File directory, String parms) { + ArrayList finalCommand = new ArrayList(); // Instead of loading a model, this establishes a connection with the // external sklearn process. File commandFile = findWrapperCommand(directory, true); String modelFileName = new File(directory,"sklmodel").getAbsolutePath(); - String finalCommand = commandFile.getAbsolutePath()+" "+wrapperhome+" "+modelFileName; + finalCommand.add(commandFile.getAbsolutePath()); + finalCommand.add(wrapperhome); + finalCommand.add(modelFileName); // if we have a shell command prepend that, and if we have shell parms too, include them if(shellcmd != null) { String tmp = shellcmd; if(shellparms != null) { shellcmd += " " + shellparms; } - finalCommand = shellcmd + " " + finalCommand; + finalCommand.add(0,shellcmd); } System.err.println("Running: "+finalCommand); // Create a fake Model jsut to make LF_Apply... happy which checks if this is null @@ -168,13 +172,15 @@ protected void saveModel(File directory) { @Override public void trainModel(File dataDirectory, String instanceType, String parms) { + ArrayList finalCommand = new ArrayList(); // invoke the sklearn wrapper for training // NOTE: for this the first word in parms must be the full sklearn class name, the rest are parms - if(parms == null || parms.isEmpty()) { + if(parms == null || parms.trim().isEmpty()) { throw new GateRuntimeException("Cannot train using SklearnWrapper, algorithmParameter must contain fulle SciKit Learn algorithm class name as first word"); } String sklearnClass = null; String sklearnParms = ""; + parms = parms.trim(); int spaceIdx = parms.indexOf(" "); if(spaceIdx<0) { sklearnClass = parms; @@ -192,16 +198,27 @@ public void trainModel(File dataDirectory, String instanceType, String parms) { Exporter.EXPORTER_MATRIXMARKET2_CLASS, dataDirectory, instanceType, parms); String dataFileName = dataDirectory.getAbsolutePath()+File.separator; String modelFileName = new File(dataDirectory, "sklmodel").getAbsolutePath(); - String finalCommand = commandFile.getAbsolutePath()+" "+wrapperhome+" "+dataFileName+" "+modelFileName+" "+sklearnClass+" "+sklearnParms; + finalCommand.add(commandFile.getAbsolutePath()); + finalCommand.add(wrapperhome); + finalCommand.add(dataFileName); + finalCommand.add(modelFileName); + finalCommand.add(sklearnClass); + if(!sklearnParms.isEmpty()) { + String[] tmp = sklearnParms.split("\\s+",-1); + finalCommand.addAll(Arrays.asList(tmp)); + } // if we have a shell command prepend that, and if we have shell parms too, include them if(shellcmd != null) { String tmp = shellcmd; if(shellparms != null) { shellcmd += " " + shellparms; } - finalCommand = shellcmd + " " + finalCommand; + finalCommand.add(0,shellcmd); + } + System.err.println("Running: "); + for(int i=0; i"+finalCommand.get(i)+"<"); } - System.err.println("Running: "+finalCommand); // Create a fake Model jsut to make LF_Apply... happy which checks if this is null model = "ExternalSklearnWrapperModel"; diff --git a/src/gate/plugin/learningframework/engines/EngineWekaExternal.java b/src/gate/plugin/learningframework/engines/EngineWekaExternal.java index fa0f015..0a2fd99 100644 --- a/src/gate/plugin/learningframework/engines/EngineWekaExternal.java +++ b/src/gate/plugin/learningframework/engines/EngineWekaExternal.java @@ -19,6 +19,7 @@ import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import org.yaml.snakeyaml.Yaml; @@ -49,6 +50,8 @@ public class EngineWekaExternal extends Engine { private String shellcmd = null; private String shellparms = null; private String wrapperhome = null; + private boolean linuxLike = true; + private boolean windowsLike = false; /** * Try to find the script running the Weka-Wrapper command. @@ -110,8 +113,8 @@ private File findWrapperCommand(File dataDirectory, boolean apply) { // we use the simple heuristic that if the file separator is "/" // we assume we can use the bash script, if it is "\" we use the windows // script and otherwise we give up - boolean linuxLike = System.getProperty("file.separator").equals("/"); - boolean windowsLike = System.getProperty("file.separator").equals("\\"); + linuxLike = System.getProperty("file.separator").equals("/"); + windowsLike = System.getProperty("file.separator").equals("\\"); if(linuxLike) { if(apply) commandFile = new File(new File(wrapperHome,"bin"),"wekaWrapperApply.sh"); @@ -137,6 +140,7 @@ private File findWrapperCommand(File dataDirectory, boolean apply) { @Override protected void loadModel(File directory, String parms) { + ArrayList finalCommand = new ArrayList(); // Instead of loading a model, this establishes a connection with the // external weka process. For this, we expect an additional file in the // directory, weka.yaml, which describes how to run the weka wrapper @@ -149,14 +153,18 @@ protected void loadModel(File directory, String parms) { if(!new File(header).exists()) { throw new GateRuntimeException("File not found: "+header); } - String finalCommand = commandFile.getAbsolutePath()+" "+wrapperhome+" "+modelFileName+" "+header; + finalCommand.add(commandFile.getAbsolutePath()); + finalCommand.add(wrapperhome); + finalCommand.add(modelFileName); + finalCommand.add(header); + // if we have a shell command prepend that, and if we have shell parms too, include them if(shellcmd != null) { String tmp = shellcmd; if(shellparms != null) { shellcmd += " " + shellparms; } - finalCommand = shellcmd + " " + finalCommand; + finalCommand.add(0,shellcmd); } System.err.println("Running: "+finalCommand); // Create a fake Model jsut to make LF_Apply... happy which checks if this is null @@ -175,13 +183,15 @@ protected void saveModel(File directory) { @Override public void trainModel(File dataDirectory, String instanceType, String parms) { + ArrayList finalCommand = new ArrayList(); // TODO: invoke the weka wrapper // NOTE: for this the first word in parms must be the full weka class name, the rest are parms - if(parms == null || parms.isEmpty()) { + if(parms == null || parms.trim().isEmpty()) { throw new GateRuntimeException("Cannot train using WekaWrapper, algorithmParameter must contain Weka algorithm class as first word"); } String wekaClass = null; String wekaParms = ""; + parms = parms.trim(); int spaceIdx = parms.indexOf(" "); if(spaceIdx<0) { wekaClass = parms; @@ -199,16 +209,28 @@ public void trainModel(File dataDirectory, String instanceType, String parms) { Exporter.EXPORTER_ARFF_CLASS, dataDirectory, instanceType, parms); String dataFileName = new File(dataDirectory,Globals.dataBasename+".arff").getAbsolutePath(); String modelFileName = new File(dataDirectory, FILENAME_MODEL).getAbsolutePath(); - String finalCommand = commandFile.getAbsolutePath()+" "+wrapperhome+" "+dataFileName+" "+modelFileName+" "+wekaClass+" "+wekaParms; + + finalCommand.add(commandFile.getAbsolutePath()); + finalCommand.add(wrapperhome); + finalCommand.add(dataFileName); + finalCommand.add(modelFileName); + finalCommand.add(wekaClass); + if(!wekaParms.isEmpty()) { + String[] tmp = wekaParms.split("\\s+",-1); + finalCommand.addAll(Arrays.asList(tmp)); + } // if we have a shell command prepend that, and if we have shell parms too, include them if(shellcmd != null) { String tmp = shellcmd; if(shellparms != null) { shellcmd += " " + shellparms; } - finalCommand = shellcmd + " " + finalCommand; + finalCommand.add(0,shellcmd); + } + System.err.println("Running: "); + for(int i=0; i"+finalCommand.get(i)+"<"); } - System.err.println("Running: "+finalCommand); // Create a fake Model jsut to make LF_Apply... happy which checks if this is null model = "ExternalWekaWrapperModel";