Commit 1e9d0be3 authored by Duc Cao's avatar Duc Cao

Use modified version of wapiti library in order to execute wapiti task faster

parent 959daaa0
......@@ -84,7 +84,10 @@ public class ExtractSource extends TrainingUnLabel {
WapitiLabeling wapitiPrim = WapitiLabeling.getWapitiInstance(modelPrim);
// wapiti label -m modelPrim input=tests_files_one_by_one
// output=DIR_BIO_FILES_FOR_CONVERSION_WAPITI_UNLABELED_PRIM -p
wapitiPrim.wapitiTest(this.paths.DIR_TEST_FILES_UNLABELED_PRIM, this.paths.DIR_BIO_FILES_FOR_CONVERSION_WAPITI_UNLABELED_PRIM, jubNumber);
wapitiPrim.wapitiTest(this.paths.DIR_TEST_FILES_UNLABELED_PRIM,
this.paths.DIR_BIO_FILES_FOR_CONVERSION_WAPITI_UNLABELED_PRIM, jubNumber,
modelPrim.getAbsolutePath(),
extractorConfig.getDirLib().getAbsolutePath());
if (searchSecondary) {
System.err.println();
......@@ -95,7 +98,10 @@ public class ExtractSource extends TrainingUnLabel {
// wapiti label -m modelSec input=tests_files_one_by_one
// output=DIR_BIO_FILES_FOR_CONVERSION_WAPITI_UNLABELED_Sec
// -p
wapitiSec.wapitiTest(this.paths.DIR_TEST_FILES_UNLABELED_SEC, this.paths.DIR_BIO_FILES_FOR_CONVERSION_WAPITI_UNLABELED_SEC, jubNumber);
wapitiSec.wapitiTest(this.paths.DIR_TEST_FILES_UNLABELED_SEC,
this.paths.DIR_BIO_FILES_FOR_CONVERSION_WAPITI_UNLABELED_SEC, jubNumber,
modelSec.getAbsolutePath(),
extractorConfig.getDirLib().getAbsolutePath());
}
System.err.println();
......
package fr.limsi.sourceExtractor.wapiti;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ForkJoinPool;
......@@ -9,22 +12,59 @@ import java.util.concurrent.ForkJoinPool;
import org.apache.commons.lang3.SystemUtils;
import fr.limsi.sourceExtractor.ProcessingThreadFactory;
import fr.limsi.wapiti.Wapiti;
public abstract class WapitiLabeling {
public abstract void label(File input, File outputDir, String filename)
public abstract void label(File input, File outputDir, String filename)
throws UnsupportedEncodingException, FileNotFoundException;
/**
* Méthode permettant d'utiliser wapiti sur les fichiers de tests
* @param input Fichier ou dossier à tester
* @param modelsFile Le modèle wapiti
* @param outputDir Le dossier de sortie des fichiers
* @throws FileNotFoundException
* @throws UnsupportedEncodingException
* @throws InterruptedException
*
* @param input Fichier ou dossier à tester
* @param modelsFile Le modèle wapiti
* @param outputDir Le dossier de sortie des fichiers
* @throws FileNotFoundException
* @throws UnsupportedEncodingException
* @throws InterruptedException
*/
public void wapitiTest(File input, File outputDir, int jobNumber) throws UnsupportedEncodingException, FileNotFoundException, InterruptedException {
public void wapitiTest(File inputDir, File outputDir, int jobNumber,
String modelFile, String dirLib)
throws UnsupportedEncodingException, FileNotFoundException, InterruptedException {
if (!outputDir.exists()) {
outputDir.mkdirs();
}
try {
String command = String.format("%s/wapiti"
+ " label -m "
+ "%s "
+ "-i %s/ "
+ "-o %s/ -p", dirLib, modelFile, inputDir.getAbsolutePath(), outputDir.getAbsolutePath());
System.err.println(command);
String line;
Process p = Runtime.getRuntime().exec(command);
BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = bri.readLine()) != null) {
System.out.println(line);
}
bri.close();
while ((line = bre.readLine()) != null) {
System.out.println(line);
}
bre.close();
p.waitFor();
} catch (IOException e) {
e.printStackTrace();
}
}
public void wapitiTest(File input, File outputDir, int jobNumber)
throws UnsupportedEncodingException, FileNotFoundException, InterruptedException {
if (!outputDir.exists()) {
outputDir.mkdirs();
}
......@@ -51,39 +91,36 @@ public abstract class WapitiLabeling {
throw new RuntimeException();
}
}
public void wapitiLabeled(File input, String fileId, String extension, File outputDir){
public void wapitiLabeled(File input, String fileId, String extension, File outputDir) {
if (!outputDir.exists()) {
outputDir.mkdirs();
}
File inFile = new File(input, fileId+"."+extension);
File inFile = new File(input, fileId + "." + extension);
WapitiTask task = new WapitiTask(inFile, outputDir, this);
task.compute();
}
//Doublon par rapport a WapitiTask
/*private static void wapitiLabelFile(File input, File outputDir, WapitiLabeling wapitiLabeler)
throws UnsupportedEncodingException, FileNotFoundException {
String filename = input.getName();
int pos = filename.lastIndexOf(".");
if (pos > 0) {
filename = filename.substring(0, pos);
}
wapitiLabeler.label(input, outputDir, filename);
}*/
// Doublon par rapport a WapitiTask
/*
* private static void wapitiLabelFile(File input, File outputDir,
* WapitiLabeling wapitiLabeler) throws UnsupportedEncodingException,
* FileNotFoundException { String filename = input.getName();
*
* int pos = filename.lastIndexOf(".");
*
* if (pos > 0) { filename = filename.substring(0, pos); }
*
* wapitiLabeler.label(input, outputDir, filename); }
*/
public static WapitiLabeling getWapitiInstance(File modelFile) throws UnsupportedEncodingException, FileNotFoundException {
public static WapitiLabeling getWapitiInstance(File modelFile)
throws UnsupportedEncodingException, FileNotFoundException {
if (org.apache.commons.lang3.SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC) {
return new WapitiLabelingLinux(modelFile);
}
else if (SystemUtils.IS_OS_WINDOWS) {
} else if (SystemUtils.IS_OS_WINDOWS) {
return new WapitiLabelingWindows(modelFile);
}
else {
} else {
throw new RuntimeException("Unknown OS");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment