//----------------------------------------------------------------- public CResultAErreur GetElementNiveau(string strChaine, int nNiveau) { CResultAErreur result = CResultAErreur.True; if (nNiveau == 1) { return(GetElement1(strChaine)); } ArrayList lst = (ArrayList)m_tableNiveauToMots[nNiveau]; if (lst != null) { string strRegEx = ""; foreach (string strMot in lst) { strRegEx += "(" + strMot + ")" + "|"; } strRegEx = strRegEx.Substring(0, strRegEx.Length - 1); Regex ex = new Regex(strRegEx, RegexOptions.IgnoreCase); MatchCollection matches = ex.Matches(strChaine); if (matches.Count > 0) { Match mt = matches[matches.Count - 1]; string strVal = mt.Value.ToLower(); Type tp = (Type)m_tableMotsToTypeElement[strVal]; if (tp != null) { //On a trouvé. Récupère le texte avant et après int nPos = strChaine.LastIndexOf(mt.Value); string strGauche, strDroite; strGauche = strChaine.Substring(0, nPos).Trim(); strDroite = strChaine.Substring(nPos + mt.Value.Length).Trim(); result = GetElementNiveau(strGauche, nNiveau); if (result) { CElementRechercheIntuitive eltGauche = (CElementRechercheIntuitive)result.Data; result = GetElementNiveau(strDroite, nNiveau); if (result) { CElementRechercheIntuitive eltDroite = (CElementRechercheIntuitive)result.Data; CElementRechercheIntuitive newElt = (CElementRechercheIntuitive)Activator.CreateInstance(tp); newElt.MotUtilise = mt.Value; if (eltGauche != null) { newElt.ListeParametres.Add(eltGauche); } if (eltDroite != null) { newElt.ListeParametres.Add(eltDroite); } result.Data = newElt; return(result); } } } } } return(GetElementNiveau(strChaine, nNiveau - 1)); }
public static string GetStringSysteme(CElementRechercheIntuitive elt) { string strTexte = elt.MotUtilise; if (elt.Parametres.Length != 0) { strTexte += "("; foreach (CElementRechercheIntuitive par in elt.ListeParametres) { strTexte += GetStringSysteme(par) + ";"; } strTexte = strTexte.Substring(0, strTexte.Length - 1) + ")"; } return(strTexte); }
//----------------------------------------------------------------- public CAnalyseurRequeteIntuitive() { foreach (Type tp in CAllocateurElementRecherche.TypesElements) { CElementRechercheIntuitive elt = (CElementRechercheIntuitive)Activator.CreateInstance(tp); ArrayList lst = null; foreach (CMotRecherche mot in elt.MotsPossibles) { lst = (ArrayList)m_tableNiveauToMots[mot.Niveau]; if (lst == null) { lst = new ArrayList(); m_tableNiveauToMots[mot.Niveau] = lst; } lst.Add(mot.Mot); m_tableMotsToTypeElement[mot.Mot.ToLower()] = tp; } } }
//----------------------------------------------------------------- public CResultAErreur GetElement1(string strChaine) { CResultAErreur result = CResultAErreur.True; //Recherche un opérateur de niveau 1 ArrayList lst = (ArrayList)m_tableNiveauToMots[1]; if (lst != null) { foreach (string strMot in lst) { if (strChaine.Length >= strMot.Length && strChaine.Substring(0, strMot.Length) == strMot) { Type tp = (Type)m_tableMotsToTypeElement[strMot]; if (tp != null) { CElementRechercheIntuitive elt = (CElementRechercheIntuitive)Activator.CreateInstance(tp); elt.MotUtilise = strChaine.Substring(0, strMot.Length); string strChaineDroite = strChaine.Substring(strMot.Length).Trim(); result = GetElement0(strChaineDroite); if (result) { if (result.Data != null) { elt.ListeParametres.Add(result.Data); } result.Data = elt; return(result); } } } } } return(GetElement0(strChaine)); }