当前位置: 首页>>代码示例>>C++>>正文


C++ Sentence::get_predicates方法代码示例

本文整理汇总了C++中Sentence::get_predicates方法的典型用法代码示例。如果您正苦于以下问题:C++ Sentence::get_predicates方法的具体用法?C++ Sentence::get_predicates怎么用?C++ Sentence::get_predicates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sentence的用法示例。


在下文中一共展示了Sentence::get_predicates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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];
//.........这里部分代码省略.........
开发者ID:153370771,项目名称:ltp,代码行数:101,代码来源:SRLBaselineExt.cpp


注:本文中的Sentence::get_predicates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。