本文整理汇总了C++中Sentence::from_corpus_block方法的典型用法代码示例。如果您正苦于以下问题:C++ Sentence::from_corpus_block方法的具体用法?C++ Sentence::from_corpus_block怎么用?C++ Sentence::from_corpus_block使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sentence
的用法示例。
在下文中一共展示了Sentence::from_corpus_block方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExtractPrgFeatures
void SRLBaselineExt::ExtractPrgFeatures(vector< vector<string> >& vecPrgFeatures) const
{
vecPrgFeatures.clear();
Sentence sentence;
vector<string> vecRows;
convert2ConllFormat(vecRows);
sentence.from_corpus_block(vecRows);
const size_t row_count = sentence.get_row_count();
m_featureExtractor->set_target_sentence(sentence);
m_featureExtractor->calc_node_features();
vector< vector<string> > vec_feature_values;
for (size_t i = 0; i < m_prgFeatureNumbers.size(); ++i)
{
vector<string> feature_values;
const int feature_number = m_prgFeatureNumbers[i];
const string& feature_prefix = m_prgFeaturePrefixes[i];
bool feature_empty_flag = false;
try {
m_featureExtractor->get_feature_for_rows(feature_number, feature_values);
} catch (...) {
feature_empty_flag = true;
}
if (feature_empty_flag)
{
feature_values.clear();
for (size_t row = 0; row <= row_count; ++row)
{
feature_values.push_back("");
}
}
vec_feature_values.push_back(feature_values);
}
for (size_t row = 1; row <= row_count; ++row)
{
vector<string> instance;
for (size_t i = 0; i < m_prgFeatureNumbers.size(); ++i)
{
string feature = m_prgFeaturePrefixes[i] + "@"
+ vec_feature_values[i][row];
instance.push_back(feature);
}
vecPrgFeatures.push_back(instance);
}
}
示例2: ExtractSrlFeatures
void SRLBaselineExt::ExtractSrlFeatures(
VecFeatForSent& vecAllFeatures,
VecPosForSent& vecAllPos) const
{
vecAllFeatures.clear();
vecAllPos.clear();
Sentence sentence;
map<int, int> feat_number_index;
feat_number_index.clear();
for (size_t k = 0; k < m_srlFeatureNumbers.size(); ++k)
{
feat_number_index[m_srlFeatureNumbers[k]] = k;
}
vector<string> vecRows;
convert2ConllFormat(vecRows);
sentence.from_corpus_block(vecRows);
const size_t predicate_count = sentence.get_predicates().size();
const size_t row_count = sentence.get_row_count();
//feature_extractor.set_target_sentence(sentence);
m_featureExtractor->set_target_sentence(sentence);
vector<string> feature_values;
vector< vector<string> > all_feature_values;
// loop for each predicate
for (size_t predicate_index = 0; predicate_index < predicate_count; ++predicate_index)
{
VecFeatForVerb vecFeatAllCons;
VecFeatForCons vecForCons;
VecPosForVerb vecPosVerb;
int predID = m_vecPredicate[predicate_index];
all_feature_values.clear();
// calculate features
//feature_extractor.calc_features(predicate_index);
m_featureExtractor->calc_features(predicate_index);
// loop for each feature
for (size_t i = 0; i < m_srlFeatureNumbers.size(); ++i)
{
const int feature_number = m_srlFeatureNumbers[i];
const string& feature_prefix = m_srlFeaturePrefixes[i];
bool feature_empty_flag = false;
try
{
m_featureExtractor->get_feature_for_rows(feature_number, feature_values);
}
catch (...)
{
feature_empty_flag = true;
}
if (feature_empty_flag)
{
feature_values.clear();
// loop for each row
for (size_t row = 1; row <= row_count; ++row)
{
feature_values.push_back("");
}
}
all_feature_values.push_back(feature_values);
}
for (size_t row = 1; row <= row_count; ++row)
{
vecForCons.clear();
if (IsFilter(row-1, predID))
continue;
for (size_t i = 0; i < m_srlSelectFeatures.size(); ++i)
{
string select_feature;
select_feature.clear();
for (size_t j = 0; j < m_srlSelectFeatures[i].size(); ++j)
{
string feat_name = m_srlSelectFeatures[i][j];
int feat_number = m_featureCollection->get_feature_number(feat_name);
int value_index = feat_number_index[feat_number];
if (j == m_srlSelectFeatures[i].size()-1)
select_feature += m_srlFeaturePrefixes[value_index] + "@" + all_feature_values[value_index][row];
else
select_feature += m_srlFeaturePrefixes[value_index] + "@" + all_feature_values[value_index][row] + "+";
}
vecForCons.push_back(select_feature);
}
vecFeatAllCons.push_back(vecForCons);
}
vecAllFeatures.push_back(vecFeatAllCons);
for (int nodeID = 0; nodeID < m_dataPreProc->m_intItemNum; nodeID++)
{
int predID = m_vecPredicate[predicate_index];
//.........这里部分代码省略.........