/// <summary> /// Loads the lexic resource. /// </summary> /// <param name="output">The output.</param> /// <param name="resourceFilePath">The resource file path.</param> public void LoadLexicResource(ILogBuilder output, String resourceFilePath) { List <String> lines = new List <String>(); // <---------------------------------------------- [ if (isLoaded) { return; } String pt = ""; if (!localCache.isNullOrEmpty()) { pt = localCache; lines.AddRange(File.ReadLines(localCache)); } if (lines.Count < 100) { pt = resourceFilePath; lines = new List <string>(); lines.AddRange(File.ReadAllLines(resourceFilePath)); } Int32 i = 0; Int32 iCycle = lines.Count() / 20; Int32 l = lines.Count(); Int32 c = 0; Double p = 0; output.logStartPhase("Loading", "Loading the lexic resource - with mode: " + mode.ToString()); output.log("Start of loading lexic resource [" + pt + "]"); // Parallel.ForEach(lines, new ParallelOptions { MaxDegreeOfParallelism=1 }, (line) => Parallel.ForEach(lines, new ParallelOptions { MaxDegreeOfParallelism = 1 }, (line) => // Parallel.ForEach(lines, (line) => { string inflectForm = ""; string lemma = ""; string gramTag = ""; SelectFromLine(line, out inflectForm, out lemma, out gramTag); lexicInflection inflect = null; if (!inflectForm.isNullOrEmpty()) { if (!ContainsKey(inflectForm)) { inflect = new lexicInflection(line); inflect.lemmaForm = lemma; inflect.name = inflectForm; inflect.inflectedForm = inflectForm; inflect.lexicalDefinitionLine = line; if (spellAlternator.IsInitiated) { String altInflectedForm = spellAlternator.ConvertFromAtoB(inflectForm); spellAlternatives.GetOrAdd(altInflectedForm, inflectForm); } Add(inflectForm, inflect); } else { inflect = base[inflectForm]; } lexicGrammarCase gramCase = null; if (mode == textResourceIndexResolveMode.resolveOnLoad) { var gramTagColl = grammTagConverter.ConvertFromString(gramTag); gramCase = inflect.AddGrammarCase(gramTagColl); gramCase.lexicalDefinitionLine = gramTag; } else { gramCase = new lexicGrammarCase(); gramCase.lexicalDefinitionLine = gramTag; gramCase.name = "gc" + i.ToString(); inflect.Add(gramCase); } // <----------------- construction of Lemma centered dictionary lexicGraphSetWithLemma lxSet = null; if (!registratedLemmaIndex.ContainsKey(lemma)) { lock (LemmaIndexLock) { if (!registratedLemmaIndex.ContainsKey(lemma)) { lxSet = new lexicGraphSetWithLemma(); lxSet.lemmaForm = lemma; registratedLemmaIndex.TryAdd(lemma, lxSet); } } } lxSet = registratedLemmaIndex[lemma]; if (!lxSet.ContainsKey(inflectForm)) { lock (SetLock) { if (!lxSet.ContainsKey(inflectForm)) { lxSet.TryAdd(inflect.name, inflect); } } } Interlocked.Increment(ref c); Interlocked.Increment(ref i); if (c > iCycle) { lock (loadStatusLock) { if (c > iCycle) { c = 0; p = i.GetRatio(l); output.AppendLine("Done: _" + p.ToString("P2") + "_"); } } } } }); output.logEndPhase(); output.log("End of loading process"); isLoaded = true; }