public void Migrate(string code)
        {
            string jsonFilePath       = Path.Combine(Configuration.DictionariesDirectoryPath, $"{code}");
            var    jsonDictionary     = ReadJsonObject <JsonDictionary>(jsonFilePath + ".json");
            var    jsonDictionaryMeta = ReadJsonObject <DictionaryMeta>(jsonFilePath + "-meta.json");

            WriteDictionary(code, jsonDictionary.Name, jsonDictionaryMeta.Copyright);
            int index = 0;

            foreach (var entry in jsonDictionary.Entries)
            {
                index++;
                string root            = ArabicHelper.Substitute(entry.Name);
                string rootLetterNames = ArabicHelper.ArabicToLetterNames(root);
                string html            = entry.Text;
                html = HeaderRegex.Replace(entry.Text, "");
                html = EmptyElementRegex.Replace(html, m => m.Groups[1].Value + m.Groups[2].Value);
                html = html.Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ");
                if (jsonDictionaryMeta.RemoveNewLines)
                {
                    html = NewLineRegex.Replace(html, " ");
                }
                else
                {
                    html = NewLineRegex.Replace(html, "\r");
                }
                //TODO: Not until we know we are not already inside a html element
                //html = ArabicRegex.Replace(html, m => $"<span class=\"arabic\">{m.Value}</span>");
                string[] htmlLines       = html.Split('\r');
                var      dictionaryEntry = new DictionaryEntry(
                    dictionaryCode: code,
                    word: root,
                    entryIndex: index,
                    html: htmlLines);
                DictionaryEntryWriteRepository.Write(dictionaryEntry);

                if (index % 100 == 0)
                {
                    Logger.Debug($"{code} {rootLetterNames}");
                }
            }
        }
Beispiel #2
0
 public static string GetIndexForArabic(string word)
 => ArabicHelper.ArabicToLetterNames(ArabicHelper.SubstituteAndOmit(word)).Replace('-', 'x');