static filter_ptr compile(string const& str,transcoder const& tr) { stack<shared_ptr<filter<FeatureT> > > filters; stack<shared_ptr<expression<FeatureT> > > exps; filter_grammar<FeatureT> grammar(filters,exps,tr); parse_info<std::string::const_iterator> info = parse(str.begin(), str.end(), grammar, space_p); if ( !info.full) { std::ostringstream os; os << "Failed to parse filter expression:\n" << str << "\nParsing aborted at '" << *info.stop << "'"; throw config_error( os.str() ); } if ( ! filters.empty()) { return filters.top(); } else { // XXX: do we ever get here? [DS] return filter_ptr(new none_filter<FeatureT>()); } }
static filter_ptr compile(string const& str) { stack<shared_ptr<filter<FeatureT> > > filters; stack<shared_ptr<expression<FeatureT> > > exps; filter_grammar<FeatureT> grammar(filters,exps); char const *text = str.c_str(); parse_info<> info = parse(text,text+strlen(text),grammar,space_p); if (info.full && !filters.empty()) { return filters.top(); } else { clog << "failed at :" << info.stop << "\n"; return filter_ptr(new none_filter<FeatureT>()); } }
CTokenFilter* CAnalyzerFactory::createStopFilter(const tchar* szIdendifier) { CParamParser pp; if(pp.parse2(szIdendifier)) { tstring iden; if(pp.getParam2(0,iden)) { if(firtex::string_utils::endsWithNoCase(iden.c_str(),_T("standard"))) { tstring file; pp.getParam2(1,file); tstring str; if(!_tcsicmp(file.c_str(),_T("stopword.stf"))) { str = GlobalConfig.General.Path + _T("\\data\\"); str += file; } else str = file; if(CMisc::dirExists(str.c_str())) { FIRTEX_CLOG(level::info) << _T("Use stopword:") << str << FIRTEX_ENDL; auto_ptr<CStandardStopFilter> filter_ptr(new CStandardStopFilter()); try { filter_ptr->load(str.c_str()); return filter_ptr.release(); } catch(...) { FIRTEX_CLOG(level::warn) << _T("Load stop word file failed:") << str << FIRTEX_ENDL; } } else FIRTEX_CLOG(level::info) << _T("Use stop word,but can't find stop word file :") << str << FIRTEX_ENDL; return NULL; } } } return NULL; }