示例#1
0
        public ImportLexiconCommand(AppOptions options, string inputDir, string database,
                                    string profile, bool preflight)
        {
            _config            = options.Configuration;
            _repositoryService = new RepositoryService(_config);
            _inputDir          = inputDir ?? throw new ArgumentNullException(nameof(inputDir));
            _database          = database ?? throw new ArgumentNullException(nameof(database));
            _profileText       = profile ?? throw new ArgumentNullException(nameof(profile));
            _preflight         = preflight;
            _ud = new UniData();

            _tAllowedChildren = new HashSet <string>
            {
                "hi", "qf", "x", "xr"
            };
            _exAllowedChildren = new HashSet <string>
            {
                "hi", "q", "x"
            };
            _extAllowedChildren = new HashSet <string>
            {
                "hi", "x"
            };

            _lemmaHomRegex     = new Regex(@"^(?<l>[^(]+)(?:\s*\((?<h>\d+)\))?");
            _tagRegex          = new Regex("<[^>]+>");
            _wsRegex           = new Regex(@"\s+");
            _textCutterOptions = new TextCutterOptions
            {
                LimitAsPercents = false,
                LineFlattening  = true,
                MaxLength       = 200,
                Ellipsis        = "\u2026"
            };
        }
示例#2
0
        public void Apply(StringBuilder text)
        {
            if (text is null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            // find the index and length of each Greek span in text
            // and process it via the transliterator
            int i = 0;

            while (i < text.Length)
            {
                if (UniData.IsInGreekRange(text[i]))
                {
                    int j = i + 1;
                    while (j < text.Length &&
                           (char.IsWhiteSpace(text[j]) ||
                            UniData.IsInGreekRange(text[j])))
                    {
                        j++;
                    }
                    string greek = text.ToString(i, j - i);
                    string roman = Transliterator.Transliterate(greek);
                    text.Remove(i, j - i);
                    text.Insert(i, roman);
                    i += roman.Length;
                }
                else
                {
                    i++;
                }
            }
        }
        private void LoadConfigurable(Type configurable)
        {
            string            path                      = null;
            ConfigurationList configurations            = null;
            Dictionary <Type, IConfigurable> dictionary = null;
            IConfigurable cfg = (IConfigurable)Activator.CreateInstance(configurable);

            path           = cfg.ConfigurationDirectory;
            configurations = cfg.Configurations;
            dictionary     = cfg.ConfigurationDictionary;
            if (dictionary != null)
            {
                dictionary.Add(configurable, cfg);
            }

            UniversalData UniData;

            if (_SavedConfigs.ContainsKey(cfg))
            {
                UniData = _SavedConfigs[cfg];
            }
            else
            {
                UniData = new UniversalData(PointBlankServer.ConfigurationsPath + "/" + (string.IsNullOrEmpty(path) ? "" : path + "/") + configurable.Name);
            }
            JsonData JSON = UniData.GetData(EDataType.JSON) as JsonData;

            if (!_SavedConfigs.ContainsKey(cfg))
            {
                _SavedConfigs.Add(cfg, UniData);
            }
            if (UniData.CreatedNew)
            {
                foreach (KeyValuePair <string, object> kvp in configurations)
                {
                    if (JSON.CheckKey(kvp.Key))
                    {
                        JSON.Document[kvp.Key] = JToken.FromObject(kvp.Value);
                    }
                    else
                    {
                        JSON.Document.Add(kvp.Key, JToken.FromObject(kvp.Value));
                    }
                }
            }
            else
            {
                foreach (JProperty property in JSON.Document.Properties())
                {
                    if (configurations[property.Name] == null)
                    {
                        continue;
                    }

                    configurations[property.Name] = property.Value.ToObject(configurations[property.Name].GetType());
                }
            }
            UniData.Save();
        }
        private void LoadTranslatable(Type translatable)
        {
            string          path         = null;
            TranslationList translations = null;
            Dictionary <Type, ITranslatable> dictionary = null;
            ITranslatable translater = (ITranslatable)Activator.CreateInstance(translatable);

            path         = translater.TranslationDirectory;
            translations = translater.Translations;
            dictionary   = translater.TranslationDictionary;
            if (dictionary != null)
            {
                dictionary.Add(translatable, translater);
            }

            UniversalData UniData;

            if (_SavedTranslations.ContainsKey(translater))
            {
                UniData = _SavedTranslations[translater];
            }
            else
            {
                UniData = new UniversalData(PointBlankServer.TranslationsPath + "/" + (string.IsNullOrEmpty(path) ? "" : path + "/") + translatable.Name);
            }
            JsonData JSON = UniData.GetData(EDataType.JSON) as JsonData;

            if (!_SavedTranslations.ContainsKey(translater))
            {
                _SavedTranslations.Add(translater, UniData);
            }
            if (UniData.CreatedNew)
            {
                foreach (KeyValuePair <string, string> kvp in translations)
                {
                    if (JSON.CheckKey(kvp.Key))
                    {
                        JSON.Document[kvp.Key] = kvp.Value;
                    }
                    else
                    {
                        JSON.Document.Add(kvp.Key, kvp.Value);
                    }
                }
            }
            else
            {
                foreach (JProperty property in JSON.Document.Properties())
                {
                    if (translations[property.Name] == null)
                    {
                        continue;
                    }

                    translations[property.Name] = (string)property.Value;
                }
            }
            UniData.Save();
        }
示例#5
0
 /// <summary>
 /// Multiplies the specified token.
 /// </summary>
 /// <param name="token">The token.</param>
 /// <returns>The original token and eventually its transliterated form.
 /// </returns>
 public IEnumerable <string> Multiply(string token)
 {
     if (!string.IsNullOrEmpty(token) &&
         token.Any(c => UniData.IsInGreekRange(c)))
     {
         return(new[] { token, Transliterator.Transliterate(token) });
     }
     return(new[] { token });
 }
示例#6
0
        /// <summary>
        /// Apply this filter to the specified text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>The filtered text.</returns>
        public static string Apply(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(text);
            }

            if (_ud == null)
            {
                _ud = new UniData();
            }

            StringBuilder sb     = new StringBuilder();
            bool          prevWs = false;

            foreach (char c in text)
            {
                if (char.IsWhiteSpace(c))
                {
                    if (prevWs || sb.Length == 0)
                    {
                        continue;
                    }
                    sb.Append(' ');
                    prevWs = true;
                }
                else
                {
                    prevWs = false;
                    switch (c)
                    {
                    case '\u2019':
                    case '\'':
                        sb.Append('\'');
                        break;

                    default:
                        if (char.IsLetter(c))
                        {
                            sb.Append(_ud.GetSegment(
                                          char.ToLowerInvariant(c), true));
                        }
                        else
                        {
                            if (char.IsDigit(c))
                            {
                                sb.Append(c);
                            }
                        }
                        break;
                    }
                }
            }
            return(sb.ToString().TrimEnd());
        }
        /// <summary>
        /// Builds the sort key from the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="repository">The repository.</param>
        /// <returns>Sort key.</returns>
        /// <exception cref="ArgumentNullException">item</exception>
        public string BuildKey(IItem item, ICadmusRepository repository)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            if (_ud == null)
            {
                _ud = new UniData();
            }

            StringBuilder sb = new StringBuilder();

            foreach (char c in item.Title ?? "")
            {
                if (char.IsWhiteSpace(c))
                {
                    if (sb.Length > 0 && (sb[sb.Length - 1] != ' '))
                    {
                        sb.Append(' ');
                    }
                }
                else
                {
                    if (char.IsDigit(c) || c == '\'')
                    {
                        sb.Append(c);
                        continue;
                    }
                    if (char.IsLetter(c))
                    {
                        char seg = _ud.GetSegment(char.ToLowerInvariant(c), true);
                        if (seg != '\0')
                        {
                            sb.Append(seg);
                        }
                    }
                }
            }

            return(sb.ToString().TrimEnd());
        }