Skip to content

Commit

Permalink
revise header include style
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneplus committed Apr 8, 2014
1 parent f5ad9bb commit 3090714
Show file tree
Hide file tree
Showing 80 changed files with 303 additions and 423 deletions.
6 changes: 1 addition & 5 deletions src/ner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
include_directories (
${SOURCE_DIR}/ner
${SOURCE_DIR}/utils
${SOURCE_DIR}/utils/math)
# ${THIRDPARTY_DIR}/boost/include)
include_directories (${SOURCE_DIR}/)

set (ner_VERSION "0.0.1")

Expand Down
130 changes: 65 additions & 65 deletions src/ner/decoder.cpp
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

6 changes: 3 additions & 3 deletions src/ner/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <iostream>
#include <vector>
#include "instance.h"
#include "mat.h"
#include "rulebase.h"
#include "ner/instance.h"
#include "ner/rulebase.h"
#include "utils/math/mat.h"

namespace ltp {
namespace ner {
Expand Down
9 changes: 4 additions & 5 deletions src/ner/extractor.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "extractor.h"
#include "settings.h"

#include "strutils.hpp"
#include "chartypes.hpp"
#include "ner/extractor.h"
#include "ner/settings.h"
#include "utils/strutils.hpp"
#include "utils/chartypes.hpp"

namespace ltp {
namespace ner {
Expand Down
7 changes: 3 additions & 4 deletions src/ner/extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

#include <iostream>
#include <vector>
#include "instance.h"

#include "template.hpp"
#include "strvec.hpp"
#include "ner/instance.h"
#include "utils/template.hpp"
#include "utils/strvec.hpp"

namespace ltp {
namespace ner {
Expand Down
5 changes: 2 additions & 3 deletions src/ner/featurespace.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "featurespace.h"

#include "extractor.h"
#include "ner/featurespace.h"
#include "ner/extractor.h"

namespace ltp {
namespace ner {
Expand Down
2 changes: 1 addition & 1 deletion src/ner/featurespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iostream>
#include <vector>

#include "smartmap.hpp"
#include "utils/smartmap.hpp"

namespace ltp {
namespace ner {
Expand Down
37 changes: 0 additions & 37 deletions src/ner/featurevec.h

This file was deleted.

8 changes: 4 additions & 4 deletions src/ner/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define __LTP_NER_INSTANCE_H__

#include <iostream>
#include "featurevec.h"
#include "mat.h"
#include "sparsevec.h"
#include "utils/math/mat.h"
#include "utils/math/featurevec.h"
#include "utils/math/sparsevec.h"

namespace ltp {
namespace ner {
Expand Down Expand Up @@ -167,7 +167,7 @@ class Instance {
math::SparseVec features; /*< the gold features */
math::SparseVec predicted_features; /*< the predicted features */

math::Mat< FeatureVector *> uni_features;
math::Mat< math::FeatureVector *> uni_features;
math::Mat< double > uni_scores;
math::Mat< double > bi_scores;
};
Expand Down
2 changes: 1 addition & 1 deletion src/ner/model.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "model.h"
#include "ner/model.h"

namespace ltp {
namespace ner {
Expand Down
7 changes: 3 additions & 4 deletions src/ner/model.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#ifndef __LTP_NER_MODEL_H__
#define __LTP_NER_MODEL_H__

#include "featurespace.h"
#include "parameter.h"

#include "smartmap.hpp"
#include "ner/featurespace.h"
#include "ner/parameter.h"
#include "utils/smartmap.hpp"

namespace ltp {
namespace ner {
Expand Down
13 changes: 6 additions & 7 deletions src/ner/ner.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "ner.h"

#include "time.hpp"
#include "logging.hpp"
#include "instance.h"
#include "extractor.h"
#include "options.h"

#include "nerio.h"
#include "utils/time.hpp"
#include "utils/logging.hpp"
#include "ner/instance.h"
#include "ner/extractor.h"
#include "ner/options.h"
#include "ner/nerio.h"

#include <iostream>
#include <sstream>
Expand Down
6 changes: 3 additions & 3 deletions src/ner/ner.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef __LTP_NER_NER_H__
#define __LTP_NER_NER_H__

#include "cfgparser.hpp"
#include "model.h"
#include "decoder.h"
#include "utils/cfgparser.hpp"
#include "ner/model.h"
#include "ner/decoder.h"

namespace ltp {
namespace ner {
Expand Down
13 changes: 5 additions & 8 deletions src/ner/ner_dll.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include "ner_dll.h"

#include "ner.h"
#include "settings.h"
//#include "instance.h"

#include "logging.hpp"
#include "codecs.hpp"
#include "ner/ner_dll.h"
#include "ner/ner.h"
#include "ner/settings.h"
#include "utils/logging.hpp"
#include "utils/codecs.hpp"

#include <iostream>

Expand Down
10 changes: 5 additions & 5 deletions src/ner/nerio.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#define __LTP_NER_IO_H__

#include <iostream>
#include "settings.h"
#include "instance.h"
#include "strutils.hpp"
#include "sbcdbc.hpp"
#include "codecs.hpp"
#include "ner/settings.h"
#include "ner/instance.h"
#include "utils/strutils.hpp"
#include "utils/sbcdbc.hpp"
#include "utils/codecs.hpp"

namespace ltp {
namespace ner {
Expand Down
2 changes: 1 addition & 1 deletion src/ner/options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "options.h"
#include "ner/options.h"

namespace ltp {
namespace ner {
Expand Down
6 changes: 3 additions & 3 deletions src/ner/otner.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <iostream>
#include "cfgparser.hpp"
#include "logging.hpp"
#include "ner.h"
#include "utils/cfgparser.hpp"
#include "utils/logging.hpp"
#include "ner/ner.h"

using namespace ltp::utility;
using namespace ltp::ner;
Expand Down
Loading

0 comments on commit 3090714

Please sign in to comment.