Skip to content

Commit

Permalink
Merge pull request HIT-SCIR#33 from niuox/master
Browse files Browse the repository at this point in the history
srl multi-thread for srl_dll and modify the mistaken name.
  • Loading branch information
Oneplus committed Sep 27, 2013
2 parents 365661d + e48ba39 commit bb9ca7c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
40 changes: 21 additions & 19 deletions src/srl/SRL_DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using namespace std;

static DepSRL g_depSRL;
static vector< pair< int, vector< pair<string, pair< int, int > > > > > g_vecSRLResult;

// Load Resources
int SRL_LoadResource(const string &ConfigDir)
Expand All @@ -29,46 +28,49 @@ int DoSRL(
const vector<string> &words,
const vector<string> &POSs,
const vector<string> &NEs,
const vector< pair<int, string> > &parse)
const vector< pair<int, string> > &parse,
vector< pair< int, vector< pair<string, pair< int, int > > > > > &tmp_vecSRLResult)
{
g_vecSRLResult.clear();
if (0 == g_depSRL.GetSRLResult(words, POSs, NEs, parse, g_vecSRLResult)) return -1;;
return g_vecSRLResult.size();
tmp_vecSRLResult.clear();
if (0 == g_depSRL.GetSRLResult(words, POSs, NEs, parse, tmp_vecSRLResult)) return -1;;
return tmp_vecSRLResult.size();
}

int GetSRLResult_size(
vector< pair< int, vector< pair<const char *, pair< int, int > > > > > &vecSRLResult)
vector< pair< int, vector< pair<const char *, pair< int, int > > > > > &vecSRLResult,
vector< pair< int, vector< pair<string, pair< int, int > > > > > &tmp_vecSRLResult)
{
if (vecSRLResult.size() != g_vecSRLResult.size()) {
cerr << "vecSRLResult size != g_vecSRLResult size" << endl;
if (vecSRLResult.size() != tmp_vecSRLResult.size()) {
cerr << "vecSRLResult size != tmp_vecSRLResult size" << endl;
return -1;
}
int i = 0;
for (; i < vecSRLResult.size(); ++i) {
vecSRLResult[i].first = g_vecSRLResult[i].second.size();
vecSRLResult[i].first = tmp_vecSRLResult[i].second.size();
}
return 0;
}

int GetSRLResult(
vector< pair< int, vector< pair<const char *, pair< int, int > > > > > &vecSRLResult)
vector< pair< int, vector< pair<const char *, pair< int, int > > > > > &vecSRLResult,
vector< pair< int, vector< pair<string, pair< int, int > > > > > &tmp_vecSRLResult)
{
if (vecSRLResult.size() != g_vecSRLResult.size()) {
cerr << "vecSRLResult size != g_vecSRLResult size" << endl;
if (vecSRLResult.size() != tmp_vecSRLResult.size()) {
cerr << "vecSRLResult size != tmp_vecSRLResult size" << endl;
return -1;
}
int i = 0;
for (; i < vecSRLResult.size(); ++i) {
if (vecSRLResult[i].second.size() != g_vecSRLResult[i].second.size()) {
cerr << "vecSRLResult[i].second.size() != g_vecSRLResult[i].second.size()" << endl
if (vecSRLResult[i].second.size() != tmp_vecSRLResult[i].second.size()) {
cerr << "vecSRLResult[i].second.size() != tmp_vecSRLResult[i].second.size()" << endl
<< "i = " << i << endl;
}
vecSRLResult[i].first = g_vecSRLResult[i].first;
vecSRLResult[i].first = tmp_vecSRLResult[i].first;
int j = 0;
for (; j < g_vecSRLResult[i].second.size(); ++j) {
vecSRLResult[i].second[j].first = g_vecSRLResult[i].second[j].first.c_str();
vecSRLResult[i].second[j].second.first = g_vecSRLResult[i].second[j].second.first;
vecSRLResult[i].second[j].second.second = g_vecSRLResult[i].second[j].second.second;
for (; j < tmp_vecSRLResult[i].second.size(); ++j) {
vecSRLResult[i].second[j].first = tmp_vecSRLResult[i].second[j].first.c_str();
vecSRLResult[i].second[j].second.first = tmp_vecSRLResult[i].second[j].second.first;
vecSRLResult[i].second[j].second.second = tmp_vecSRLResult[i].second[j].second.second;
}
}
return 0;
Expand Down
9 changes: 6 additions & 3 deletions src/srl/SRL_DLL.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ SRL_DLL_API int DoSRL(
const vector<string> &words,
const vector<string> &POSs,
const vector<string> &NEs,
const vector< pair<int, string> > &parse
const vector< pair<int, string> > &parse,
vector< pair< int, vector< pair<string, pair< int, int > > > > > &tmp_vecSRLResult
);

SRL_DLL_API int GetSRLResult_size(
vector< pair< int, vector< pair<const char *, pair< int, int > > > > > &vecSRLResult);
vector< pair< int, vector< pair<const char *, pair< int, int > > > > > &vecSRLResult,
vector< pair< int, vector< pair<string, pair< int, int > > > > > &tmp_vecSRLResult);


SRL_DLL_API int GetSRLResult(
vector< pair< int, vector< pair<const char *, pair< int, int > > > > > &vecSRLResult);
vector< pair< int, vector< pair<const char *, pair< int, int > > > > > &vecSRLResult,
vector< pair< int, vector< pair<string, pair< int, int > > > > > &tmp_vecSRLResult);

#endif

Expand Down
7 changes: 4 additions & 3 deletions src/srl/SRL_DLL_x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ int SRL(
)
{
vecSRLResult.clear();
int resultNum = DoSRL(words, POSs, NEs, parse);
vector< pair< int, vector< pair<string, pair< int, int > > > > > tmp_vecSRLResult;
int resultNum = DoSRL(words, POSs, NEs, parse,tmp_vecSRLResult);
if (resultNum < 0) return -1;
if (resultNum == 0) return 0;
vecSRLResult.resize(resultNum);
if (0 != GetSRLResult_size(vecSRLResult)) return -1;
if (0 != GetSRLResult_size(vecSRLResult,tmp_vecSRLResult)) return -1;
int i = 0;
for (; i < resultNum; ++i) {
vecSRLResult[i].second.resize( vecSRLResult[i].first );
}
return GetSRLResult(vecSRLResult);
return GetSRLResult(vecSRLResult,tmp_vecSRLResult);
}

0 comments on commit bb9ca7c

Please sign in to comment.