Utilisateur:LoveBot/Sources/Obsolete.cs
Apparence
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using DotNetWikiBot;
namespace LoveBot
{
//
// Classe FilterManager
//
class FilterManager
{
// Constructeur.
public FilterManager()
{
m_groups = new List<FilterGroup>();
CreateFilterGroups();
}
// Création d'un FilterGroup.
private FilterGroup CreateFilterGroup(int n, string context)
{
return (new FilterGroup(n, context));
}
// SearchAndSolveObsoleteModels.
public bool SearchAndSolveObsoleteModels(ref string article, string title)
{
for (int ii = 0; ii < m_groups.Count; ii++)
{
FilterGroup currentFilterGroup = m_groups[ii];
ObsoleteModelDescription obsoleteModel = SearchFirstObsoleteModel(article, currentFilterGroup);
while (obsoleteModel != null && ii < m_groups.Count)
{
int beginIndex = obsoleteModel.GetModelBeginIndex();
int length = obsoleteModel.GetModelLength();
string separator = obsoleteModel.GetModelSeparator();
MODEL_FR_WIKIPEDIA id = obsoleteModel.GetModelType();
string type = currentFilterGroup.GetNameFromId(id);
switch (id)
{
case MODEL_FR_WIKIPEDIA.Classe_monument_historique_France:
case MODEL_FR_WIKIPEDIA.Classe_monument_historique_France_nocat:
case MODEL_FR_WIKIPEDIA.Inscrit_monument_historique_France:
case MODEL_FR_WIKIPEDIA.Inscrit_monument_historique_France_nocat:
{
bool isNoCat = false;
if (id == MODEL_FR_WIKIPEDIA.Classe_monument_historique_France_nocat
|| id == MODEL_FR_WIKIPEDIA.Inscrit_monument_historique_France_nocat)
isNoCat = true;
bool isInscrit = true;
if (id == MODEL_FR_WIKIPEDIA.Classe_monument_historique_France
|| id == MODEL_FR_WIKIPEDIA.Classe_monument_historique_France_nocat)
isInscrit = false;
article = writeNewMH(article, title, beginIndex, length, type, separator, isNoCat, isInscrit);
}
break;
case MODEL_FR_WIKIPEDIA.Commonscat_simple:
article = writeNewCommonsInline(article, title, beginIndex, length, type, separator);
break;
case MODEL_FR_WIKIPEDIA.Commonscat:
case MODEL_FR_WIKIPEDIA.Commons_category:
article = writeNewData(article, title, beginIndex, length, type, separator, true, "commons");
break;
case MODEL_FR_WIKIPEDIA.Commons:
article = writeNewData(article, title, beginIndex, length, type, separator, false, "commons");
break;
case MODEL_FR_WIKIPEDIA.Wikt:
case MODEL_FR_WIKIPEDIA.Wiktionnaire:
case MODEL_FR_WIKIPEDIA.Wiktionnaire_cat:
article = writeNewFromWiktionnaire(article, title, beginIndex, length, type, separator, (id == MODEL_FR_WIKIPEDIA.Wiktionnaire_cat));
break;
case MODEL_FR_WIKIPEDIA.wiktionnaire_langue:
article = writeNewFromWiktionnaireLangue(article, title, beginIndex, length, type, separator);
break;
case MODEL_FR_WIKIPEDIA.Livre_de_cuisine:
article = writeNewFromLivreDeCuisine(article, title, beginIndex, length, type, separator);
break;
case MODEL_FR_WIKIPEDIA.Wikibooks:
article = writeNewData(article, title, beginIndex, length, type, separator, false, "wikibooks");
break;
case MODEL_FR_WIKIPEDIA.Wikiquote:
article = writeNewData(article, title, beginIndex, length, type, separator, false, "wikiquote");
break;
case MODEL_FR_WIKIPEDIA.Wikispecies:
article = writeNewData(article, title, beginIndex, length, type, separator, false, "wikispecies");
break;
case MODEL_FR_WIKIPEDIA.Wikisource_XY:
case MODEL_FR_WIKIPEDIA.Wikisourcetexte:
case MODEL_FR_WIKIPEDIA.Wikisourceauteur:
case MODEL_FR_WIKIPEDIA.Wikisource_œuvre:
case MODEL_FR_WIKIPEDIA.Wikisource:
article = writeNewData(article, title, beginIndex, length, type, separator, false, "wikisource");
break;
case MODEL_FR_WIKIPEDIA.Wikisource_langue:
article = writeNewFromWikisourceLangue(article, title, beginIndex, length, type, separator);
break;
case MODEL_FR_WIKIPEDIA.Wikinews:
article = writeNewFromWikinews(article, title, beginIndex, length, type, separator);
break;
case MODEL_FR_WIKIPEDIA.Wikiversity:
article = writeNewData(article, title, beginIndex, length, type, separator, false, "wikiversity");
break;
default:
break;
}
obsoleteModel = SearchFirstObsoleteModel(article, currentFilterGroup);
}
}
return true;
}
// trashParseMH.
string trashParseMH(string dataParsing, string key)
{
int index = dataParsing.ToLower().IndexOf(key);
if (index != -1)
{
int indexBegin = dataParsing.IndexOf("=", index);
indexBegin++;
int start = 0;
int index1 = dataParsing.IndexOf("[[", indexBegin);
int index2 = dataParsing.IndexOf("]]", indexBegin);
int index3 = dataParsing.IndexOf("=", indexBegin);
int indexEnd = dataParsing.IndexOf("|", indexBegin);
while (indexEnd > index1 && indexEnd < index2)
{
start = index2 + 2;
index1 = dataParsing.IndexOf("[[", start);
index2 = dataParsing.IndexOf("]]", start);
indexEnd = dataParsing.IndexOf("|", start);
}
if (indexEnd != -1)
return dataParsing.Substring(indexBegin, indexEnd - indexBegin);
else
return dataParsing.Substring(indexBegin);
}
return "";
}
// writeNewMH.
string writeNewMH(string article, string title, int beginIndex, int length, string type, string sep, bool isNoCat, bool isInscrit)
{
string dataLeft = article.Substring(0, beginIndex);
int endIndex = beginIndex + length;
string dataRight = article.Substring(endIndex + 1);
string newData = "{{Monument historique (France)\r\n";
string dataParsing = article.Substring(beginIndex + type.Length + 1, length - type.Length - 2);
// Premier nettoyage.
dataParsing = dataParsing.Replace('\n', ' ');
// Rustine à recycler : gère les cas date ... = {{date|4|aout|1799}} par {{date 4 aout 1799}}.
int testIndexBegin = 0;
while ((testIndexBegin = dataParsing.IndexOf('{', testIndexBegin)) != -1)
{
int testIndexEnd = dataParsing.IndexOf('}', testIndexBegin);
if (testIndexEnd == -1)
break;
string subDataParsing = dataParsing.Substring(testIndexBegin, testIndexEnd - testIndexBegin);
subDataParsing = subDataParsing.Replace('|', ' ');
dataParsing = dataParsing.Substring(0, testIndexBegin) + subDataParsing + dataParsing.Substring(testIndexEnd);
testIndexBegin++;
}
string monumentType = "";
string date = "";
string merimee = "";
date = trashParseMH(dataParsing, "date_inscription");
if (date == "")
date = trashParseMH(dataParsing, "date_classement");
merimee = trashParseMH(dataParsing, "code_mérimée");
if (merimee == "")
merimee = trashParseMH(dataParsing, "lien_mérimée");
if (merimee.Length > 15) // 10 + 5 sécurité
merimee = "code mérimée<!-- à remplacer par le code adéquate -->";
monumentType = trashParseMH(dataParsing, "type_monument");
// Type
if (monumentType.Length > 0)
{
newData += "| type = " + monumentType + "\r\n";
}
// Inscrit ou classé
if (isInscrit)
{
newData += "| protection = inscrit" + "\r\n";
}
else
{
newData += "| protection = classé" + "\r\n";
}
// Mérimée
newData += "| base = Mérimée" + "\r\n";
newData += "| référence = " + merimee + "\r\n";
// Catégories
if (isNoCat)
{
newData += "| nocat = oui" + "\r\n";
}
else
{
newData += "| nocat = non" + "\r\n";
}
// Parsing date.
bool parsableDate = false;
char[] parsingDate = new char[4];
parsingDate[0] = '/';
parsingDate[1] = '{';
parsingDate[2] = '}';
parsingDate[3] = ' ';
string[] parseResultDate = date.Split(parsingDate, StringSplitOptions.RemoveEmptyEntries);
int dayIndex = 0;
if (parseResultDate.Length >= 3)
{
dayIndex = 0;
for (int ii = 0; ii < parseResultDate.Length; ii++)
{
int res;
if (int.TryParse(parseResultDate[ii], out res) == true)
{
dayIndex = ii;
break;
}
}
if (dayIndex + 2 < parseResultDate.Length)
{
int result;
int.TryParse(parseResultDate[dayIndex], out result);
newData += "| jour = " + result + "\r\n";
bool test = int.TryParse(parseResultDate[dayIndex + 1], out result);
if (test)
newData += "| mois = {{MONTHNAME|" + result + "}}\r\n";
else
newData += "| mois = " + parseResultDate[dayIndex + 1] + "\r\n";
int.TryParse(parseResultDate[dayIndex + 2], out result);
newData += "| année = " + result + "\r\n";
parsableDate = true;
}
}
else if (parseResultDate.Length > 0)
{
// On suppose que c'est l'année...
for (int ii = parseResultDate.Length - 1; ii >= 0; ii--)
{
int annee;
if (int.TryParse(parseResultDate[ii], out annee) == true)
{
newData += "| année = " + annee + "\r\n";
parsableDate = true;
break;
}
}
}
newData += "}}";
// On fait qquechose seulement si la date est analysable (ici risque de blocage car le modèle obsolète est tjrs en place).
// Réfléchir à aller pointer plus loin.
if (parsableDate)
{
// Rustine à recycler : remet les modeles type {{s| |}}en place
int localIndexBegin = 3;
while ((localIndexBegin = newData.IndexOf('{', localIndexBegin)) != -1)
{
int testIndexEnd = newData.IndexOf('}', localIndexBegin);
if (testIndexEnd == -1)
break;
string subnewData = newData.Substring(localIndexBegin, testIndexEnd - localIndexBegin);
subnewData = subnewData.Replace(' ', '|');
newData = newData.Substring(0, localIndexBegin) + subnewData + newData.Substring(testIndexEnd);
localIndexBegin++;
}
article = dataLeft + newData + dataRight;
}
return article;
}
// writeNewFromWikisourceLangue.
string writeNewFromWikisourceLangue(string data, string title, int beginIndex, int length, string type, string sep)
{
string dataLeft = data.Substring(0, beginIndex);
int endIndex = beginIndex + length;
string dataRight = data.Substring(endIndex + 1);
string newData = "{{Autres projets\r\n";
string dataParsing = data.Substring(beginIndex + type.Length + 1, length - type.Length - 2);
newData += "| " + "wikisource = ";
string[] parseResult = dataParsing.Split('|');
if (parseResult.Length > 1)
{
newData += parseResult[1];
}
newData += "\r\n";
if (parseResult.Length > 2)
{
newData += "| " + "wikisource titre = ";
newData += parseResult[2];
newData += "\r\n";
}
newData += "}}";
data = dataLeft + newData + dataRight;
return data;
}
// writeNewFromWiktionnaireLangue.
string writeNewFromWiktionnaireLangue(string article, string title, int beginIndex, int length, string type, string sep)
{
string tag = "wiktionary";
string dataLeft = article.Substring(0, beginIndex);
int endIndex = beginIndex + length;
string dataRight = article.Substring(endIndex + 1);
string newData = "{{Autres projets\r\n";
string dataParsing = article.Substring(beginIndex + type.Length + 1, length - type.Length - 2);
newData += "| " + tag.ToLower() + " = ";
string[] parseResult = dataParsing.Split('|');
if (parseResult.Length > 1)
{
newData += parseResult[1];
newData += ":";
newData += "\r\n";
}
newData += "| " + tag.ToLower() + " titre = ";
newData += "Wiktionnaire en ";
if (parseResult.Length > 2)
newData += parseResult[2];
else
newData += title.ToLower();
newData += "\r\n";
newData += "}}";
article = dataLeft + newData + dataRight;
return article;
}
// writeNewFromWiktionnaire.
string writeNewFromWiktionnaire(string article, string title, int beginIndex, int length, string type, string sep, bool isCategory)
{
string tag = "wiktionary";
string dataLeft = article.Substring(0, beginIndex);
int endIndex = beginIndex + length;
string dataRight = article.Substring(endIndex + 1);
string newData = "{{Autres projets\r\n";
string dataParsing = article.Substring(beginIndex + type.Length + 1, length - type.Length - 2);
newData += "| " + tag.ToLower() + " = ";
string[] parseResult = dataParsing.Split('|');
if (isCategory)
{
newData += "Catégorie:";
}
if (parseResult.Length == 1)
{
newData += title.ToLower();
}
else if (parseResult.Length > 1)
{
newData += parseResult[1] + "\r\n";
newData += "| " + tag.ToLower() + " titre = " + parseResult[1];
}
newData += "\r\n}}";
article = dataLeft + newData + dataRight;
return article;
}
// writeNewFromLivreDeCuisine.
string writeNewFromLivreDeCuisine(string article, string title, int beginIndex, int length, string type, string sep)
{
string dataLeft = article.Substring(0, beginIndex);
int endIndex = beginIndex + length;
string dataRight = article.Substring(endIndex + 1);
string newData = "{{Autres projets\r\n";
newData += "| " + "wikibooks = ";
newData += "Livre de cuisine/";
string typeRecette = "";
string recette = "";
string titreRecette = title;
string dataParsing = article.Substring(beginIndex + type.Length + 1, length - type.Length - 2);
if (dataParsing.Length <= 1)
{
// {{Livre de cuisine}}
recette = title;
}
else
{
string[] parseResult = dataParsing.Split('|');
if (parseResult.Length == 1) // (dataParsing.IndexOf('|') == -1)
{
// {{Livre de cuisine/toto}}
recette = dataParsing;
}
else
{
int indexSlash = -1;
for (int jj = 0; jj < parseResult.Length; jj++)
{
indexSlash = parseResult[jj].IndexOf("/");
if (indexSlash != -1)
{
recette = parseResult[jj].Substring(indexSlash + 1);
break;
}
}
if (parseResult.Length > 1)
{//{{Livre de cuisine|...|toto}}
int indexParameter = -1;
for (int jj = 0; jj < parseResult.Length; jj++)
{
indexParameter = parseResult[jj].IndexOf("recette");
if (indexParameter != -1)
{
indexParameter = parseResult[jj].IndexOf("=", indexParameter);
titreRecette = parseResult[jj].Substring(indexParameter + 1);
recette = titreRecette;
}
else
{
indexParameter = parseResult[jj].IndexOf("type");
if (indexParameter != -1)
{
indexParameter = parseResult[jj].IndexOf("=", indexParameter);
typeRecette = parseResult[jj].Substring(indexParameter + 1) + "/";
}
}
}
if (recette == "")
{
recette = parseResult[1];
}
}
}
}
if (recette == "")
{
recette = title;
}
newData += typeRecette + recette;
newData += "\r\n";
newData += "| " + "wikibooks titre = ";
newData += titreRecette;
newData += "\r\n";
newData += "}}";
article = dataLeft + newData + dataRight;
return article;
}
// writeNewCommonsInline.
string writeNewCommonsInline(string article, string title, int beginIndex, int length, string type, string sep)
{
string dataLeft = article.Substring(0, beginIndex);
int endIndex = beginIndex + length;
string dataRight = article.Substring(endIndex + 1);
string newData = "{{Commons-inline\r\n";
string dataParsing = article.Substring(beginIndex + type.Length + 1, length - type.Length - 2);
string[] parseResult = dataParsing.Split('|');
if (parseResult.Length > 1)
{
newData += "|";
newData += parseResult[1];
}
if (parseResult.Length > 2)
{
newData += "|";
newData += parseResult[2];
}
newData += "}}";
article = dataLeft + newData + dataRight;
return article;
}
// writeNewFromWikinews
string writeNewFromWikinews(string data, string title, int beginIndex, int length, string type, string sep)
{
string tag = "wikinews";
string dataLeft = data.Substring(0, beginIndex);
int endIndex = beginIndex + length;
string dataRight = data.Substring(endIndex + 1);
string newData = "{{Autres projets\r\n";
string dataParsing = data.Substring(beginIndex + type.Length + 1, length - type.Length - 2);
newData += "| " + tag.ToLower() + " = ";
string[] parseResult = dataParsing.Split('|');
if (parseResult.Length == 1)
{
newData += title;
newData += "\r\n";
}
else if (parseResult.Length > 1)
{
newData += parseResult[1];
newData += "| " + tag.ToLower() + " titre = ";
newData += parseResult[1];
newData += "\r\n";
}
newData += "}}";
data = dataLeft + newData + dataRight;
return data;
}
// writeNewData.
string writeNewData(string data, string title, int beginIndex, int length, string type, string sep, bool isCategory, string tag)
{
string dataLeft = data.Substring(0, beginIndex);
int endIndex = beginIndex + length;
string dataRight = data.Substring(endIndex + 1);
string newData = "{{Autres projets\r\n";
string dataParsing = data.Substring(beginIndex + type.Length + 1, length - type.Length - 2);
newData += "| " + tag.ToLower() + " = ";
string[] parseResult = dataParsing.Split('|');
if (isCategory)
{
newData += "Category:";
}
if (parseResult.Length == 1)
{
newData += title;
}
else if (parseResult.Length > 1)
{
newData += parseResult[1];
}
newData += "\r\n";
if (parseResult.Length > 2)
{
newData += "| " + tag.ToLower() + " titre = ";
newData += parseResult[2];
newData += "\r\n";
}
newData += "}}";
data = dataLeft + newData + dataRight;
return data;
}
// Pré recherche.
// Recherche du premier modèle obsolète sur un FilterGroup donnée.
// Renvoit null si aucun.
public ObsoleteModelDescription SearchFirstObsoleteModel(string article, FilterGroup group)
{
ObsoleteModelDescription wikipediaModel = null;
int beginIndex = 0;
while (wikipediaModel == null && beginIndex != -1)
{
beginIndex = article.IndexOf(group.GetMainFilter(), beginIndex, StringComparison.InvariantCultureIgnoreCase);
if (beginIndex != -1)
{
wikipediaModel = CreateObsoleteModelDescription(article, group, beginIndex);
if (wikipediaModel != null)
{
if (wikipediaModel.IsObsolete() == true)
return wikipediaModel;
}
beginIndex++;
}
}
return null;
}
private int SpecialSearchEndIndex(char endChar, char beginChar, string data, int beginIndex)
{
// beginIndex : '{'{.
int indexEnd = data.IndexOf(endChar, beginIndex);
int indexBegin = data.IndexOf(beginChar, beginIndex);
if (indexEnd < indexBegin || indexBegin == -1)
{
// C'est le cas facile.
return indexEnd;
}
else
{
// Ici on a des endBegin avant d'avoir des beginChar.
// Genre : | { | { beginIndex | ......... | { | { }} }}
// Ici on a déjà un ouvrant à fermer.
int cmp = -2 - 1;
int start = indexBegin + 1;
while (cmp != 0)
{
indexEnd = data.IndexOf(endChar, start);
indexBegin = data.IndexOf(beginChar, start);
if (indexEnd > indexBegin)
{
cmp--;
start = indexBegin + 1;
}
else
{
cmp++;
start = indexEnd + 1;
}
}
}
return indexEnd - 1;
}
// CreateObsoleteModelDescription.
public ObsoleteModelDescription CreateObsoleteModelDescription(string article, FilterGroup group, int beginIndex)
{
ObsoleteModelDescription wikipediaModel = null;
for (int zz = 0; zz < group.GetNumber(); zz++)
{
string wikipediaModelString = group.GetStringValue(zz);
MODEL_FR_WIKIPEDIA id = group.GetId(zz);
bool isObsolete = group.IsObsolete(zz);
if (article.Substring(beginIndex, wikipediaModelString.Length).ToUpper() == wikipediaModelString.ToUpper())
{
int endIndex = 0;
if (article[beginIndex - 1] == '<')
{
/*
beginIndex = beginIndex - 1;
endIndex = article.IndexOf('>', beginIndex);
int length = endIndex - beginIndex;
if (article[beginIndex + wikipediaModelString.Length + 1] == '|' ||
article[beginIndex + wikipediaModelString.Length + 1] == '>' ||
(article[beginIndex + wikipediaModelString.Length + 1] == ' ' && article[beginIndex + wikipediaModelString.Length + 2] == '|'))
{
wikipediaModel = new ObsoleteModelDescription(beginIndex, length, id, "<");
}
break;
*/
}
else if (article[beginIndex - 2] == '{')
{
endIndex = SpecialSearchEndIndex('}', '{', article, beginIndex);
endIndex = endIndex + 1;
beginIndex = beginIndex - 2;
int length = endIndex - beginIndex;
wikipediaModel = new ObsoleteModelDescription(beginIndex, length, id, "{", isObsolete);
break;
}
}
}
return wikipediaModel;
}
// Création du FilterGroups des modèles obsolètes supportées.
// CreateFilterGroups.
public void CreateFilterGroups()
{
if (m_groups.Count > 0)
return;
FilterGroup group;
group = CreateFilterGroup(2, "Classé monument historique");
group.AddStringValue("Classé monument historique (France)/nocat", MODEL_FR_WIKIPEDIA.Classe_monument_historique_France_nocat, true);
group.AddStringValue("Classé monument historique (France)", MODEL_FR_WIKIPEDIA.Classe_monument_historique_France, true);
m_groups.Add(group);
group = CreateFilterGroup(2, "Inscrit monument historique");
group.AddStringValue("Inscrit monument historique (France)/nocat", MODEL_FR_WIKIPEDIA.Inscrit_monument_historique_France_nocat, true);
group.AddStringValue("Inscrit monument historique (France)", MODEL_FR_WIKIPEDIA.Inscrit_monument_historique_France, true);
m_groups.Add(group);
group = CreateFilterGroup(5, "Commons");
group.AddStringValue("Commons category", MODEL_FR_WIKIPEDIA.Commons_category, true);
group.AddStringValue("Commonscat simple", MODEL_FR_WIKIPEDIA.Commonscat_simple, true);
group.AddStringValue("Commonscat", MODEL_FR_WIKIPEDIA.Commonscat, true);
group.AddStringValue("Commons-inline", MODEL_FR_WIKIPEDIA.Commons_inline, false);// Modèle non obsolète.
group.AddStringValue("Commons", MODEL_FR_WIKIPEDIA.Commons, true);
m_groups.Add(group);
group = CreateFilterGroup(1, "Livre de cuisine");
group.AddStringValue("Livre de cuisine", MODEL_FR_WIKIPEDIA.Livre_de_cuisine, true);
m_groups.Add(group);
group = CreateFilterGroup(2, "Wikibooks");
group.AddStringValue("wikibookspar", MODEL_FR_WIKIPEDIA.Wikibookspar, false);
group.AddStringValue("Wikibooks", MODEL_FR_WIKIPEDIA.Wikibooks, true);
m_groups.Add(group);
group = CreateFilterGroup(4, "Wikt");
group.AddStringValue("Wiktionnaire - cat", MODEL_FR_WIKIPEDIA.Wiktionnaire_cat, true);
group.AddStringValue("Wiktionnaire langue", MODEL_FR_WIKIPEDIA.wiktionnaire_langue, true);
group.AddStringValue("Wiktionnaire", MODEL_FR_WIKIPEDIA.Wiktionnaire, true);
group.AddStringValue("Wikt", MODEL_FR_WIKIPEDIA.Wikt, true);
m_groups.Add(group);
group = CreateFilterGroup(1, "Wikiquote");
group.AddStringValue("Wikiquote", MODEL_FR_WIKIPEDIA.Wikiquote, true);
m_groups.Add(group);
group = CreateFilterGroup(1, "Wikispecies");
group.AddStringValue("Wikispecies", MODEL_FR_WIKIPEDIA.Wikispecies, true);
m_groups.Add(group);
group = CreateFilterGroup(1, "Wikiversity");
group.AddStringValue("Wikiversity", MODEL_FR_WIKIPEDIA.Wikiversity, true);
m_groups.Add(group);
group = CreateFilterGroup(1, "Wikinews");
group.AddStringValue("Wikinews", MODEL_FR_WIKIPEDIA.Wikinews, true);
m_groups.Add(group);
group = CreateFilterGroup(6, "Wikisource");
group.AddStringValue("Wikisource XY", MODEL_FR_WIKIPEDIA.Wikisource_XY, true);
group.AddStringValue("Wikisource œuvre", MODEL_FR_WIKIPEDIA.Wikisource_œuvre, true);
group.AddStringValue("Wikisourceauteur", MODEL_FR_WIKIPEDIA.Wikisourceauteur, true);
group.AddStringValue("Wikisourcetexte", MODEL_FR_WIKIPEDIA.Wikisourcetexte, true);
group.AddStringValue("Wikisource", MODEL_FR_WIKIPEDIA.Wikisource, true);
group.AddStringValue("Wikisourcelang", MODEL_FR_WIKIPEDIA.Wikisource_langue, true);
m_groups.Add(group);
}
private List<FilterGroup> m_groups;
}
//
// enum MODEL_FR_WIKIPEDIA
//
public enum MODEL_FR_WIKIPEDIA
{
Commons_category = 0,
Commonscat_simple,
Commonscat,
Commons_inline,
Commons,
Livre_de_cuisine,
Wikibookspar,
Wikibooks,
Wiktionnaire_cat,
wiktionnaire_langue,
Wiktionnaire,
Wikt,
Wikiquote,
Wikispecies,
Wikiversity,
Wikinews,
Wikisource_XY,
Wikisource_œuvre,
Wikisourceauteur,
Wikisourcetexte,
Wikisource_langue,
Wikisource,
Classe_monument_historique_France,
Classe_monument_historique_France_nocat,
Inscrit_monument_historique_France,
Inscrit_monument_historique_France_nocat
};
//
// Class ObsoleteModelDescription
//
class ObsoleteModelDescription
{
// Constructeur.
public ObsoleteModelDescription(int beginIndex, int length, MODEL_FR_WIKIPEDIA id, string sep, bool isObsolete)
{
m_beginIndex = beginIndex;
m_length = length;
m_id = id;
m_separator = sep;
m_isObsolete = isObsolete;
}
// Accesseurs 'get'.
public int GetModelBeginIndex() { return m_beginIndex; }
public int GetModelLength() { return m_length; }
public MODEL_FR_WIKIPEDIA GetModelType() { return m_id; }
public string GetModelSeparator() { return m_separator; }
public bool IsObsolete() { return m_isObsolete; }
private int m_beginIndex;
private int m_length;
private MODEL_FR_WIKIPEDIA m_id;
private string m_separator;
private bool m_isObsolete;
}
//
// Classe Filter
//
class Filter
{
public Filter(string name, MODEL_FR_WIKIPEDIA id, bool isObsolete)
{
m_id = id;
m_name = name;
m_isObsolete = isObsolete;
}
public string GetName()
{
return m_name;
}
public MODEL_FR_WIKIPEDIA GetId()
{
return m_id;
}
public bool IsObsolete()
{
return m_isObsolete;
}
private string m_name;
private MODEL_FR_WIKIPEDIA m_id;
private bool m_isObsolete;
};
//
// Classe FilterGroup
//
class FilterGroup
{
// Constructeur.
public FilterGroup(int n, string mainFilter)
{
m_mainFilter = mainFilter;
m_number = n;
m_currentNumber = 0;
m_collection = new Filter[m_number];
}
// GetNameFromId.
public string GetNameFromId(MODEL_FR_WIKIPEDIA id)
{
for (int ii = 0; ii < m_currentNumber; ii++)
{
if (m_collection[ii].GetId() == id)
return m_collection[ii].GetName();
}
return "";
}
// Ajoute une valeur de filtre.
public void AddStringValue(string stringValue, MODEL_FR_WIKIPEDIA id, bool isObsolete)
{
m_collection[m_currentNumber] = new Filter(stringValue, id, isObsolete);
m_currentNumber++;
}
// Obtient la valeur d'enum.
public MODEL_FR_WIKIPEDIA GetId(int index)
{
return m_collection[index].GetId();
}
// Is Obsolete ?
public bool IsObsolete(int index)
{
return m_collection[index].IsObsolete();
}
// Obtient une valeur de filtre.
public string GetStringValue(int index)
{
return m_collection[index].GetName();
}
// Obtient la valeur principale de filtre.
public string GetMainFilter()
{
return m_mainFilter;
}
// Détermine si la construction d l'objet est terminée et donc si il est valide ou non.
public bool IsValid()
{
if (m_number != m_currentNumber)
{
return false;
}
return true;
}
// Retourne le nombre théorique d'éléments.
public int GetNumber()
{
return m_number;
}
private int m_number;// Nombre finale de valeurs de filtres incluses ; nombre théorique.
private int m_currentNumber;// Nombre courant de valeurs de filtres incluses.
private Filter[] m_collection;// Collection de valeurs de filtres incluses.
private string m_mainFilter;// Décrit le contexte de collections de filtres.
};
}