Commit fc2de381 authored by Duc Cao's avatar Duc Cao
Browse files

Allow Wapiti to take into account both file and folder as input

parent 5d67c91b
...@@ -45,6 +45,19 @@ ...@@ -45,6 +45,19 @@
#include "tools.h" #include "tools.h"
#include "trainers.h" #include "trainers.h"
#include "wapiti.h" #include "wapiti.h"
#include <sys/stat.h>
bool is_file(const char* path) {
struct stat buf;
stat(path, &buf);
return S_ISREG(buf.st_mode);
}
bool is_dir(const char* path) {
struct stat buf;
stat(path, &buf);
return S_ISDIR(buf.st_mode);
}
/******************************************************************************* /*******************************************************************************
* Training * Training
...@@ -198,20 +211,22 @@ static void dolabel(mdl_t *mdl) { ...@@ -198,20 +211,22 @@ static void dolabel(mdl_t *mdl) {
if (file == NULL) if (file == NULL)
pfatal("cannot open input model file"); pfatal("cannot open input model file");
mdl_load(mdl, file); mdl_load(mdl, file);
// Open input and output files if (mdl->opt->inputdir != NULL && is_file(mdl->opt->inputdir)) {
/*FILE *fin = stdin, *fout = stdout;*/ /*Open input and output files*/
/*if (mdl->opt->input != NULL) {*/ FILE *fin = stdin, *fout = stdout;
/*fin = fopen(mdl->opt->input, "r");*/ fin = fopen(mdl->opt->inputdir, "r");
/*if (fin == NULL)*/ if (fin == NULL)
/*pfatal("cannot open input data file");*/ pfatal("cannot open input data file");
/*}*/ fout = fopen(mdl->opt->outputdir, "w");
/*if (mdl->opt->output != NULL) {*/ if (fout == NULL)
/*fout = fopen(mdl->opt->output, "w");*/ pfatal("cannot open output data file");
/*if (fout == NULL)*/ tag_label(mdl, fin, fout);
/*pfatal("cannot open output data file");*/
/*}*/ fclose(fin);
fclose(fout);
}
// Open directory of input files // Open directory of input files
if (mdl->opt->inputdir != NULL && mdl->opt->outputdir != NULL) { else if (mdl->opt->inputdir != NULL && mdl->opt->outputdir != NULL) {
DIR *dp; DIR *dp;
struct dirent *ep; struct dirent *ep;
dp = opendir (mdl->opt->inputdir); dp = opendir (mdl->opt->inputdir);
......
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