bool ModelTagMatcher::Match( const Word_Form & wf, Solarix::Dictionary & dict ) const { if( !lexeme.empty() ) { if( !lexeme.eqi( *wf.GetName() ) ) return false; } else if( !id_lemma.empty() ) { bool m=false; for( lem::Container::size_type i=0; i<id_lemma.size(); ++i ) if( id_lemma[i] == wf.GetEntryKey() ) { m=true; break; } if( !m ) return false; } else if( !pos.empty() ) { bool m=false; const int ekey = wf.GetEntryKey(); const SG_Entry & e = dict.GetSynGram().GetEntry(ekey); const int wf_pos = e.GetClass(); for( lem::Container::size_type i=0; i<pos.size(); ++i ) if( pos[i]==wf_pos ) { m=true; break; } if( !m ) return false; } if( !pairs.empty() ) { for( lem::Container::size_type i=0; i<pairs.size(); ++i ) { const GramCoordPair & p = pairs[i]; if( wf.GetPairs().FindOnce(p)!=UNKNOWN ) continue; // для бистабильных координат - состояние 0 равнозначно отсутствию вообще такой пары if( dict.GetSynGram().coords()[ p.GetCoord().GetIndex() ].IsBistable() ) { if( wf.GetPairs().FindOnce( p.GetCoord().GetIndex() ) != UNKNOWN ) return false; } else return false; } } return true; }
SegmentingSentenceTokenizer::SegmentingSentenceTokenizer(const Solarix::Dictionary &dict, int language) : SentenceTokenizer(dict, language) { lookup = lem::Ptr<Solarix::CharNode>((Solarix::CharNode*)&dict.GetSynGram().GetPrefixTree(), null_deleter()); seeker = dict.seeker; const SG_Language &lang = dict.GetSynGram().languages()[language]; int ipar = lang.FindParam(L"WordDelimiters"); if (ipar != UNKNOWN) delimiters += lang.params[ipar]->values.front().c_str(); return; }
void TreeDimension::PrintXML( lem::OFormatter & xml, const Solarix::Dictionary & dict ) const { xml.printf( "<dimension>\n" ); xml.printf( "<name>%us</name>\n", name.c_str() ); xml.printf( "<trees count=\"%d\">\n", CastSizeToInt(nodes.size()) ); for( lem::Container::size_type i=0; i<nodes.size(); ++i ) { xml.printf( "<tree n=\"%d\">\n", CastSizeToInt(i) ); nodes[i]->PrintXML( xml, dict.GetSynGram() ); xml.printf( "</tree>\n" ); } xml.printf( "</trees>\n" ); xml.printf( "</dimension>\n" ); return; }
void TreeDimension::Print( const Solarix::Dictionary & dict, lem::OFormatter & out, bool detailed ) const { if( !nodes.empty() ) { out.printf( "%vf6<<%vn%vfB%us%vn%vf6>>:%vn", name.c_str() ); if( nodes.size()>1 ) out.printf( "%vf6{%vn" ); for( lem::Container::size_type i=0; i<nodes.size(); ++i ) { out.printf( ' ' ); nodes[i]->Print( out, dict.GetSynGram(), 0, detailed ); } if( nodes.size()>1 ) out.printf( " %vf6}%vn" ); } return; }
void KB_Facts::LoadTxt(Solarix::Dictionary &dict, lem::Iridium::Macro_Parser &txtfile) { name = txtfile.read().string(); txtfile.read_it(B_LANGUAGE); txtfile.read_it(B_EQUAL); lem::Iridium::BethToken lang = txtfile.read(); id_language = dict.GetSynGram().Find_Language(lang.string()); if (id_language == UNKNOWN) { lem::Iridium::Print_Error(lang, txtfile); dict.GetIO().merr().printf("Unknown language name %us\n", lang.c_str()); throw lem::E_BaseException(); } txtfile.read_it(B_OFIGPAREN); n_ret = 0; while (!txtfile.eof()) { if (txtfile.probe(B_CFIGPAREN)) break; lem::Iridium::BethToken t = txtfile.read(); if (t.string().eqi(L"arity")) { txtfile.read_it(B_EQUAL); n_arg = txtfile.read_int(); } else if (t.string().eqi(L"return")) { txtfile.read_it(B_EQUAL); lem::Iridium::BethToken t_ret = txtfile.read(); if (t_ret.eqi(L"boolean")) { n_ret = 1; ret_type = 0; } else if (t_ret.eqi(L"integer")) { n_ret = 1; ret_type = 1; } else { lem::Iridium::Print_Error(t_ret, txtfile); dict.GetIO().merr().printf("Unknown return type %us\n", t_ret.c_str()); throw lem::E_BaseException(); } } else if (t.string().eqi(L"violation_score")) { txtfile.read_it(B_EQUAL); if (txtfile.probe(B_SUB)) violation_score = -txtfile.read_int(); else violation_score = txtfile.read_int(); } else if (t.string().eqi(L"violation_handler")) { txtfile.read_it(B_EQUAL); violation_handler = new PredicateTemplate(); PredicateTemplateParams_KB params(n_arg); violation_handler->LoadTxt(dict, txtfile, params); } else if (t.string().eqi(L"generic")) { allow_generic = true; } else { lem::Iridium::Print_Error(t, txtfile); dict.GetIO().merr().printf("Unknown property %us\n", t.c_str()); throw lem::E_BaseException(); } } return; }