Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added workaround for setting JEP value with very special characters #468

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions grobid-core/src/main/java/org/grobid/core/jni/DeLFTModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.grobid.core.GrobidModels;
import org.grobid.core.exceptions.GrobidException;
import org.grobid.core.utilities.GrobidProperties;
import org.grobid.core.utilities.IOUtilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -69,8 +70,29 @@ public LabelTask(String modelName, String data) {
//System.out.println("label thread: " + Thread.currentThread().getId());
this.modelName = modelName;
this.data = data;
}

}

private void setJepStringValueWithFileFallback(
Jep jep, String name, String value
) throws JepException, IOException {
try {
jep.set(name, value);
} catch(JepException e) {
File tempFile = IOUtilities.newTempFile(name, ".data");
LOGGER.debug(
"Falling back to file {} due to exception: {}",
tempFile, e.toString()
);
IOUtilities.writeInFile(tempFile.getAbsolutePath(), value);
jep.eval("from pathlib import Path");
jep.eval(
name + " = Path('" + tempFile.getAbsolutePath() +
"').read_text(encoding='utf-8')"
);
tempFile.delete();
}
}

@Override
public String call() {
Jep jep = JEPThreadPool.getInstance().getJEPInstance();
Expand All @@ -79,7 +101,7 @@ public String call() {
//System.out.println(this.data);

// load and tag
jep.set("input", this.data);
this.setJepStringValueWithFileFallback(jep, "input", this.data);
jep.eval("x_all, f_all = load_data_crf_string(input)");
Object objectResults = jep.getValue(this.modelName+".tag(x_all, None)");

Expand Down