دوستان این قطعه کد با فایل xml بالا داره چه کار می کنه
كد:
public static Dictionary LoadFromFile(string DictionaryLanguage)
{
string dictionaryFile = string.Format(@"{1}\dics\{0}.xml", DictionaryLanguage,
Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6));
if(!File.Exists(dictionaryFile))
{
throw new FileNotFoundException("Could Not Load Dictionary: " + dictionaryFile);
}
Dictionary dict = new Dictionary();
XElement doc = XElement.Load(dictionaryFile);
dict.Step1PrefixRules = LoadKeyValueRule(doc, "stemmer", "step1_pre");
dict.Step1SuffixRules = LoadKeyValueRule(doc, "stemmer", "step1_post");
dict.ManualReplacementRules = LoadKeyValueRule(doc, "stemmer", "manual");
dict.PrefixRules = LoadKeyValueRule(doc, "stemmer", "pre");
dict.SuffixRules = LoadKeyValueRule(doc, "stemmer", "post");
dict.SynonymRules = LoadKeyValueRule(doc, "stemmer", "synonyms");
dict.LinebreakRules = LoadValueOnlyRule(doc, "parser", "linebreak");
dict.NotALinebreakRules = LoadValueOnlyRule(doc, "parser", "linedontbreak");
dict.DepreciateValueRule = LoadValueOnlyRule(doc, "grader-syn", "depreciate");
dict.TermFreqMultiplierRule = LoadValueOnlySection(doc, "grader-tf");
List<string> unimpwords = new List<string>();
dict.UnimportantWords = new List<Word>();
unimpwords = LoadValueOnlySection(doc, "grader-tc");
foreach (string unimpword in unimpwords)
{
dict.UnimportantWords.Add(new Word(unimpword));
}
return dict;
}
كد:
private static List<string> LoadValueOnlySection(XElement doc, string section)
{
List<string> list = new List<string>();
IEnumerable<XElement> step1pre = doc.Elements(section);
foreach (var x in step1pre.Elements())
{
list.Add(x.Value);
}
return list;
}
كد:
private static Dictionary<string, string> LoadKeyValueRule(XElement doc, string section, string container)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
IEnumerable<XElement> step1pre = doc.Elements(section).Elements(container);
foreach (var x in step1pre.Elements())
{
string rule = x.Value;
string[] keyvalue = rule.Split('|');
if (!dictionary.ContainsKey(keyvalue[0]))
dictionary.Add(keyvalue[0], keyvalue[1]);
}
return dictionary;
}
اصلا برای چی داره این فایل xml رو می خونه و هی قسمت های مختلفش رو از هم جدا می کنه .(متوجه شدم داره چی کار می کنه اما علتش رو نمی فهمم)