/* regle.cpp */ /* * This file is part of PRAELECTOR. * PRAELECTOR is free software; you can redistribute it and/or modify * it * under the terms of the GNU General Public License as published by * the Free * Software Foundation; either version 2 of the License, or * (at your option) * any later version. * * COLLATINVS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * * This file is part of PRAELECTOR. * * PRAELECTOR is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * PRAELECTOR is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with PRAELECTOR; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * © Yves Ouvrard, 2009 - 2017 */ // TODO // - Ajouter dans Regle le moyen de fixer la morpho française de // et , au moyen de deux nouvelles clés // frsup: et frsub:. Il faudra overloader MotFlechi::tr() et // MotFlechi::trGroupe(). #include #include #include QStringList const clesR = QStringList() <<"accord" // 0 <<"aff" <<"conflit" <<"contig" <<"doc" <<"id" // 5 <<"filtre" <<"lemmeSub" <<"lemmeSup" <<"lsSub" <<"lsSup" // 10 <<"morphoSub" <<"morphoSup" <<"poids" <<"posSub" <<"posSup" // 15 <<"sens" <<"subEstSup" <<"supEstSub" <<"supEstSup" <<"tr" // 20 <<"x"; ////////////////////////////// // Classe Regle // ////////////////////////////// Regle::Regle(QStringList ll) { _contig = 0; for (int i=0;i "); // analyse des filtres _antepos = 0; for (int i=0;i<_filtre.count();++i) { QString f = _filtre.at(i); if (f.startsWith("antep")) _antepos = f.mid(5).toInt(); } _multi = _filtre.contains("multi"); } QString Regle::accord() { return _accord; } QString Regle::aff() { if (_aff.isEmpty()) return _id; return _aff; } int Regle::antepos() { return _antepos; } bool Regle::conflit(QString id) { return _conflits.contains(id); } /** Regle::compatibleSu?Su? Quatre fonctions qui disent si deux requêtes qui ont un noeud en commun ont au moin un pos compatible pour ce noeud. */ bool Regle::compatibleSubSub(Regle* r) { if (_posSub.isEmpty() || r->posSub().isEmpty()) return true; QSet st = QSet::fromList(_posSub.split(',')); QSet sr = QSet::fromList(r->posSub().split(',')); return !(st.intersect(sr).empty()); } bool Regle::compatibleSubSup(Regle* r) { if (_posSub.isEmpty() || r->posSup().isEmpty()) return true; QSet st = QSet::fromList(_posSub.split(',')); QSet sr = QSet::fromList(r->posSup().split(',')); return !(st.intersect(sr).empty()); } bool Regle::compatibleSupSub(Regle* r) { if (_posSup.isEmpty() || r->posSub().isEmpty()) return true; QSet st = QSet::fromList(_posSup.split(',')); QSet sr = QSet::fromList(r->posSub().split(',')); return !(st.intersect(sr).empty()); } bool Regle::compatibleSupSup(Regle* r) { if (_posSup.isEmpty() || r->posSup().isEmpty()) return true; QSet st = QSet::fromList(_posSup.split(',')); QSet sr = QSet::fromList(r->posSup().split(',')); return !(st.intersect(sr).empty()); } int Regle::contig() { return _contig; } QString Regle::doc() { return _id + " " + _doc; } bool Regle::estSub(MotFlechi* mf) { // lemme Lemme* l = mf->lemme(); QString cle = l->cle(); if (subExclu(cle)) return false; if (!_lemmeSub.empty() && !_lemmeSub.contains(cle)) return false; // pos if (!_posSub.isEmpty() && !_posSub.contains(mf->pos()) && !_posSub.contains(mf->posO())) return false; // morpho QString m = mf->morpho(); bool okm = _morphoSub.empty(); if (!okm) for (int i=0;i<_morphoSub.count();++i) okm = okm || inclus(_morphoSub.at(i), m); if (!okm) return false; // lexicosyntaxe if (!_lsSub.empty()) { for (int i=0;i<_lsSub.count();++i) { if (l->synt(_lsSub.at(i))) { return true; } } return false; } return true; } bool Regle::estSuper(MotFlechi* mf) { // lemme Lemme* l = mf->lemme(); QString cle = l->cle(); // déf de lemme if (!_lemmeSup.empty() && !_lemmeSup.contains(cle)) return false; // exclusions if (_lSupExclus.contains(cle)) return false; // pos if (!_posSup.isEmpty() && !_posSup.contains(mf->pos()) && !_posSup.contains(mf->posO()) && !(_posSup.contains("w") && mf->lemme()->synt("attr"))) { return false; } // morpho QString m = mf->morpho(); bool okm = _morphoSup.empty(); if (!okm) for (int i=0;i<_morphoSup.count();++i) { okm = okm || inclus(_morphoSup.at(i), m); } if (!okm) return false; // lexicosyntaxe if (!_lsSup.empty()) { for (int i=0;i<_lsSup.count();++i) { if (l->synt(_lsSup.at(i))) return true; } return false; } return true; } bool Regle::exclut(QString id) { return _exclus.contains(id); } QString Regle::id() { return _id; } QStringList Regle::filtre() { return _filtre; } // tous les traits demandés par a doivent être dans b bool Regle::inclus(QString a, QString b) { QStringList la = a.split(QRegularExpression("\\W")); for (int i=0;i