Skip to content

Commit 069108b

Browse files
committed
Add location of wrapper to call of wrapper scripts as first argument.
1 parent a0b6ecd commit 069108b

File tree

3 files changed

+67
-13
lines changed

3 files changed

+67
-13
lines changed

creole.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!-- creole.xml for Learning_Framework -->
22
<CREOLE-DIRECTORY
33
ID="gate.LearningFramework"
4-
VERSION="3.4-beta"
4+
VERSION="3.4-gamma"
55
DESCRIPTION="Learning Framework"
66
HELPURL="https://github.com/GateNLP/gateplugin-LearningFramework/wiki"
77
>

src/gate/plugin/learningframework/engines/EngineSklearnExternal.java

+34-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public class EngineSklearnExternal extends Engine {
4444

4545
ProcessBase process;
4646

47+
// These variables get set from the wrapper-specific config file, java properties or
48+
// environment variables.
49+
private String shellcmd = null;
50+
private String shellparms = null;
51+
private String wrapperhome = null;
52+
4753
/**
4854
* Try to find the script running the sklearn-Wrapper command.
4955
* If apply is true, the executable for application is searched,
@@ -72,17 +78,20 @@ private File findWrapperCommand(File dataDirectory, boolean apply) {
7278
throw new GateRuntimeException("Could not load yaml file "+sklearnInfoFile,ex);
7379
}
7480
tmp = null;
81+
Map map = null;
7582
if(obj instanceof Map) {
76-
Map map = (Map)obj;
83+
map = (Map)obj;
7784
tmp = (String)map.get("sklearnwrapper.home");
7885
} else {
7986
throw new GateRuntimeException("Info file has strange format: "+sklearnInfoFile.getAbsolutePath());
8087
}
81-
if(tmp == null) {
82-
System.err.println("sklearn.yaml file present but does not contain sklearnwrapper.home setting");
83-
} else {
88+
if(tmp != null) {
8489
homeDir = tmp;
8590
}
91+
// Also get any other settings that may be present:
92+
// shell command
93+
shellcmd = (String)map.get("shellcmd");
94+
shellparms = (String)map.get("shellparms");
8695
}
8796
if(homeDir == null) {
8897
throw new GateRuntimeException("SklearnWrapper home not set, please see https://github.com/GateNLP/gateplugin-LearningFramework/wiki/UsingSklearn");
@@ -94,6 +103,7 @@ private File findWrapperCommand(File dataDirectory, boolean apply) {
94103
if(!wrapperHome.isDirectory()) {
95104
throw new GateRuntimeException("SklearnWrapper home is not a directory: "+wrapperHome.getAbsolutePath());
96105
}
106+
wrapperhome = wrapperHome.getAbsolutePath();
97107
// Now, depending on the operating system, and on train/apply,
98108
// find the correct script to execute
99109
File commandFile;
@@ -129,9 +139,18 @@ private File findWrapperCommand(File dataDirectory, boolean apply) {
129139
protected void loadModel(File directory, String parms) {
130140
// Instead of loading a model, this establishes a connection with the
131141
// external sklearn process.
142+
132143
File commandFile = findWrapperCommand(directory, true);
133144
String modelFileName = new File(directory,"sklmodel").getAbsolutePath();
134-
String finalCommand = commandFile.getAbsolutePath()+" "+modelFileName;
145+
String finalCommand = commandFile.getAbsolutePath()+" "+wrapperhome+" "+modelFileName;
146+
// if we have a shell command prepend that, and if we have shell parms too, include them
147+
if(shellcmd != null) {
148+
String tmp = shellcmd;
149+
if(shellparms != null) {
150+
shellcmd += " " + shellparms;
151+
}
152+
finalCommand = shellcmd + " " + finalCommand;
153+
}
135154
System.err.println("Running: "+finalCommand);
136155
// Create a fake Model jsut to make LF_Apply... happy which checks if this is null
137156
model = "ExternalSklearnWrapperModel";
@@ -173,7 +192,15 @@ public void trainModel(File dataDirectory, String instanceType, String parms) {
173192
Exporter.EXPORTER_MATRIXMARKET2_CLASS, dataDirectory, instanceType, parms);
174193
String dataFileName = dataDirectory.getAbsolutePath()+File.separator;
175194
String modelFileName = new File(dataDirectory, "sklmodel").getAbsolutePath();
176-
String finalCommand = commandFile.getAbsolutePath()+" "+dataFileName+" "+modelFileName+" "+sklearnClass+" "+sklearnParms;
195+
String finalCommand = commandFile.getAbsolutePath()+" "+wrapperhome+" "+dataFileName+" "+modelFileName+" "+sklearnClass+" "+sklearnParms;
196+
// if we have a shell command prepend that, and if we have shell parms too, include them
197+
if(shellcmd != null) {
198+
String tmp = shellcmd;
199+
if(shellparms != null) {
200+
shellcmd += " " + shellparms;
201+
}
202+
finalCommand = shellcmd + " " + finalCommand;
203+
}
177204
System.err.println("Running: "+finalCommand);
178205
// Create a fake Model jsut to make LF_Apply... happy which checks if this is null
179206
model = "ExternalSklearnWrapperModel";
@@ -311,4 +338,5 @@ protected void loadMalletCorpusRepresentation(File directory) {
311338
corpusRepresentationMallet = CorpusRepresentationMalletTarget.load(directory);
312339
}
313340

341+
314342
}

src/gate/plugin/learningframework/engines/EngineWekaExternal.java

+32-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public class EngineWekaExternal extends Engine {
4444

4545
ProcessBase process;
4646

47+
// These variables get set from the wrapper-specific config file, java properties or
48+
// environment variables.
49+
private String shellcmd = null;
50+
private String shellparms = null;
51+
private String wrapperhome = null;
52+
4753
/**
4854
* Try to find the script running the Weka-Wrapper command.
4955
* If apply is true, the executable for application is searched,
@@ -72,17 +78,20 @@ private File findWrapperCommand(File dataDirectory, boolean apply) {
7278
throw new GateRuntimeException("Could not load yaml file "+wekaInfoFile,ex);
7379
}
7480
tmp = null;
81+
Map map = null;
7582
if(obj instanceof Map) {
76-
Map map = (Map)obj;
83+
map = (Map)obj;
7784
tmp = (String)map.get("wekawrapper.home");
7885
} else {
7986
throw new GateRuntimeException("Info file has strange format: "+wekaInfoFile.getAbsolutePath());
8087
}
81-
if(tmp == null) {
82-
System.err.println("weka.yaml file present but does not contain wekawrapper.home setting");
83-
} else {
88+
if(tmp != null) {
8489
homeDir = tmp;
8590
}
91+
// Also get any other settings that may be present:
92+
// shell command
93+
shellcmd = (String)map.get("shellcmd");
94+
shellparms = (String)map.get("shellparms");
8695
}
8796
if(homeDir == null) {
8897
throw new GateRuntimeException("WekaWrapper home not set, please see https://github.com/GateNLP/gateplugin-LearningFramework/wiki/UsingWeka");
@@ -94,6 +103,7 @@ private File findWrapperCommand(File dataDirectory, boolean apply) {
94103
if(!wrapperHome.isDirectory()) {
95104
throw new GateRuntimeException("WekaWrapper home is not a directory: "+wrapperHome.getAbsolutePath());
96105
}
106+
wrapperhome = wrapperHome.getAbsolutePath();
97107
// Now, depending on the operating system, and on train/apply,
98108
// find the correct script to execute
99109
File commandFile;
@@ -139,7 +149,15 @@ protected void loadModel(File directory, String parms) {
139149
if(!new File(header).exists()) {
140150
throw new GateRuntimeException("File not found: "+header);
141151
}
142-
String finalCommand = commandFile.getAbsolutePath()+" "+modelFileName+" "+header;
152+
String finalCommand = commandFile.getAbsolutePath()+" "+wrapperhome+" "+modelFileName+" "+header;
153+
// if we have a shell command prepend that, and if we have shell parms too, include them
154+
if(shellcmd != null) {
155+
String tmp = shellcmd;
156+
if(shellparms != null) {
157+
shellcmd += " " + shellparms;
158+
}
159+
finalCommand = shellcmd + " " + finalCommand;
160+
}
143161
System.err.println("Running: "+finalCommand);
144162
// Create a fake Model jsut to make LF_Apply... happy which checks if this is null
145163
model = "ExternalWekaWrapperModel";
@@ -181,7 +199,15 @@ public void trainModel(File dataDirectory, String instanceType, String parms) {
181199
Exporter.EXPORTER_ARFF_CLASS, dataDirectory, instanceType, parms);
182200
String dataFileName = new File(dataDirectory,Globals.dataBasename+".arff").getAbsolutePath();
183201
String modelFileName = new File(dataDirectory, FILENAME_MODEL).getAbsolutePath();
184-
String finalCommand = commandFile.getAbsolutePath()+" "+dataFileName+" "+modelFileName+" "+wekaClass+" "+wekaParms;
202+
String finalCommand = commandFile.getAbsolutePath()+" "+wrapperhome+" "+dataFileName+" "+modelFileName+" "+wekaClass+" "+wekaParms;
203+
// if we have a shell command prepend that, and if we have shell parms too, include them
204+
if(shellcmd != null) {
205+
String tmp = shellcmd;
206+
if(shellparms != null) {
207+
shellcmd += " " + shellparms;
208+
}
209+
finalCommand = shellcmd + " " + finalCommand;
210+
}
185211
System.err.println("Running: "+finalCommand);
186212
// Create a fake Model jsut to make LF_Apply... happy which checks if this is null
187213
model = "ExternalWekaWrapperModel";

0 commit comments

Comments
 (0)