forked from HIT-SCIR/ltp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ltp-unittest' of https://github.com/HIT-SCIR/ltp into p…
…arser
- Loading branch information
Showing
148 changed files
with
32,459 additions
and
1,157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
#include "SRL_DLL.h" | ||
|
||
int main(int argc, char * argv[]) { | ||
if (argc < 2) { | ||
return -1; | ||
} | ||
|
||
SRL_LoadResource(argv[1]); | ||
|
||
std::vector<std::string> words; | ||
std::vector<std::string> postags; | ||
std::vector<std::string> nes; | ||
std::vector<std::pair<int,std::string> > parse; | ||
std::vector< std::pair< int, std::vector< std::pair<std::string, std::pair< int, int > > > > > srl; | ||
words.push_back("一把手"); postags.push_back("n"); nes.push_back("O"); parse.push_back(make_pair(2,"SBV")); | ||
words.push_back("亲自"); postags.push_back("d"); nes.push_back("O"); parse.push_back(make_pair(2,"ADV")); | ||
words.push_back("过问"); postags.push_back("v"); nes.push_back("O"); parse.push_back(make_pair(-1,"HED")); | ||
words.push_back("。"); postags.push_back("wp");nes.push_back("O"); parse.push_back(make_pair(2,"WP")); | ||
|
||
DoSRL(words,postags,nes,parse,srl); | ||
|
||
for(int i = 0;i<srl.size();++i) { | ||
std::cout<<srl[i].first<<":"<<std::endl; | ||
for(int j = 0;j<srl[i].second.size();++j) { | ||
std::cout<<" tpye = "<<srl[i].second[j].first | ||
<<" beg = "<<srl[i].second[j].second.first | ||
<<" end = "<<srl[i].second[j].second.second | ||
<<std::endl; | ||
} | ||
} | ||
|
||
SRL_ReleaseResource(); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1447,4 +1447,3 @@ int XML4NLP::ClearNote(const char *cszNoteName) { | |
note.nodePtr->SetAttribute(cszNoteName, "n"); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,103 @@ | ||
#include "decoder.h" | ||
#include "ner/decoder.h" | ||
|
||
namespace ltp { | ||
namespace ner { | ||
|
||
void Decoder::decode(Instance * inst) { | ||
init_lattice(inst); | ||
viterbi_decode(inst); | ||
get_result(inst); | ||
free_lattice(); | ||
init_lattice(inst); | ||
viterbi_decode(inst); | ||
get_result(inst); | ||
free_lattice(); | ||
} | ||
|
||
void Decoder::init_lattice(const Instance * inst) { | ||
int len = inst->size(); | ||
lattice.resize(len, L); | ||
lattice = NULL; | ||
int len = inst->size(); | ||
lattice.resize(len, L); | ||
lattice = NULL; | ||
} | ||
|
||
void Decoder::viterbi_decode(const Instance * inst) { | ||
int len = inst->size(); | ||
for (int i = 0; i < len; ++ i) { | ||
for (int l = 0; l < L; ++ l) { | ||
if (i == 0) { | ||
LatticeItem * item = new LatticeItem(i, l, inst->uni_scores[i][l], NULL); | ||
lattice_insert(lattice[i][l], item); | ||
} else { | ||
for (int pl = 0; pl < L; ++ pl) { | ||
if (false == base.legal_trans(pl, l)) { | ||
continue; | ||
} | ||
|
||
double score = 0.; | ||
const LatticeItem * prev = lattice[i-1][pl]; | ||
|
||
if (!prev) { | ||
continue; | ||
} | ||
|
||
// std::cout << i << " " << pl << " " << l << std::endl; | ||
score = inst->uni_scores[i][l] + inst->bi_scores[pl][l] + prev->score; | ||
const LatticeItem * item = new LatticeItem(i, l, score, prev); | ||
lattice_insert(lattice[i][l], item); | ||
} | ||
} // end for if i == 0 | ||
int len = inst->size(); | ||
for (int i = 0; i < len; ++ i) { | ||
for (int l = 0; l < L; ++ l) { | ||
if (i == 0) { | ||
LatticeItem * item = new LatticeItem(i, l, inst->uni_scores[i][l], NULL); | ||
lattice_insert(lattice[i][l], item); | ||
} else { | ||
for (int pl = 0; pl < L; ++ pl) { | ||
if (false == base.legal_trans(pl, l)) { | ||
continue; | ||
} | ||
|
||
double score = 0.; | ||
const LatticeItem * prev = lattice[i-1][pl]; | ||
|
||
if (!prev) { | ||
continue; | ||
} | ||
|
||
// std::cout << i << " " << pl << " " << l << std::endl; | ||
score = inst->uni_scores[i][l] + inst->bi_scores[pl][l] + prev->score; | ||
const LatticeItem * item = new LatticeItem(i, l, score, prev); | ||
lattice_insert(lattice[i][l], item); | ||
} | ||
} // end for if i == 0 | ||
} | ||
} | ||
} | ||
|
||
void Decoder::get_result(Instance * inst) { | ||
int len = inst->size(); | ||
const LatticeItem * best_item = NULL; | ||
for (int l = 0; l < L; ++ l) { | ||
if (!lattice[len-1][l]) { | ||
continue; | ||
} | ||
if (best_item == NULL || (lattice[len-1][l]->score > best_item->score)) { | ||
best_item = lattice[len - 1][l]; | ||
} | ||
int len = inst->size(); | ||
const LatticeItem * best_item = NULL; | ||
for (int l = 0; l < L; ++ l) { | ||
if (!lattice[len-1][l]) { | ||
continue; | ||
} | ||
if (best_item == NULL || (lattice[len-1][l]->score > best_item->score)) { | ||
best_item = lattice[len - 1][l]; | ||
} | ||
} | ||
|
||
const LatticeItem * item = best_item; | ||
inst->predicted_tagsidx.resize(len); | ||
const LatticeItem * item = best_item; | ||
inst->predicted_tagsidx.resize(len); | ||
|
||
while (item) { | ||
inst->predicted_tagsidx[item->i] = item->l; | ||
// std::cout << item->i << " " << item->l << std::endl; | ||
item = item->prev; | ||
} | ||
while (item) { | ||
inst->predicted_tagsidx[item->i] = item->l; | ||
// std::cout << item->i << " " << item->l << std::endl; | ||
item = item->prev; | ||
} | ||
} | ||
|
||
void Decoder::free_lattice() { | ||
for (int i = 0; i < lattice.nrows(); ++ i) { | ||
for (int j = 0; j < lattice.ncols(); ++ j) { | ||
if (lattice[i][j]) delete lattice[i][j]; | ||
} | ||
for (int i = 0; i < lattice.nrows(); ++ i) { | ||
for (int j = 0; j < lattice.ncols(); ++ j) { | ||
if (lattice[i][j]) delete lattice[i][j]; | ||
} | ||
} | ||
} | ||
|
||
/*void KBestDecoder::decode(Instance * inst, KBestDecodeResult & result) { | ||
init_lattice(inst); | ||
kbest_viterbi_decode(inst); | ||
get_result(result); | ||
free_lattice(); | ||
init_lattice(inst); | ||
kbest_viterbi_decode(inst); | ||
get_result(result); | ||
free_lattice(); | ||
} | ||
void KBestDecoder::init_lattice(const Instance * inst) { | ||
int len = inst->len(); | ||
lattice.resize(len, L); | ||
int len = inst->len(); | ||
lattice.resize(len, L); | ||
for (int i = 0; i < len; ++ i) { | ||
for (int l = 0; l < L; ++ l) { | ||
lattice[i][l] = new KHeap<LatticeItem>(k); | ||
} | ||
for (int i = 0; i < len; ++ i) { | ||
for (int l = 0; l < L; ++ l) { | ||
lattice[i][l] = new KHeap<LatticeItem>(k); | ||
} | ||
} | ||
} | ||
void KBestDecoder::kbest_viterbi_decode(const Instance * inst) { | ||
}*/ | ||
|
||
|
||
} // end for namespace ner | ||
} // end for namespace ltp | ||
} // end for namespace ner | ||
} // end for namespace ltp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.