Esempio n. 1
0
 /// <summary>
 /// Замена юнитов из цепочки однородных сущностей на саму сущность
 /// </summary>
 /// <param name="unitCollection">коллекция, содержащие юниты цепочки однородных сущностей</param>
 public void ReplaceUnits(IList <UnitTextBase> unitCollection)
 {
     if (_units.Any())
     {
         int    index       = unitCollection.IndexOf(_units.First());
         Entity homogeneous = new Entity(_units.GetText(), _units.First().PositionInfo.Start, new HomogeneousEntityInfo()
         {
             Pretext = _pretext
         });
         SimpleStringBuilder value = new SimpleStringBuilder();
         foreach (UnitTextBase unit in _units)
         {
             unitCollection.RemoveAt(index);
             if (unit.IsEntity)
             {
                 Entity entity = (Entity)unit;
                 homogeneous.AddChild(entity);
                 value.Append(entity.Value);
             }
             else
             {
                 value.Append(unit.Text);
             }
         }
         homogeneous.EntityInfo.Value  = value.TrueValue;
         homogeneous.EntityInfo.Morpho = GetChainMorphoInformation();
         unitCollection.Insert(index, homogeneous);
     }
 }
Esempio n. 2
0
        public void Test_EmptyStringBuilder()
        {
            var sb = new SimpleStringBuilder();

            Assume.That(sb.IsDisposed, Is.True);
            Assert.That(() => sb.Capacity, Throws.InstanceOf <NullReferenceException>());
            Assert.That(() => sb.Dispose(), Throws.Nothing);
        }
 public string SimpleStringBuilder()
 {
     using (var builder = new SimpleStringBuilder(s.Length + 1))
     {
         builder.Append(c);
         builder.Append(s);
         return(builder.ToString());
     }
 }
        /// <summary>
        /// Проверка, что заданный текст начинается с обстоятельственного слова
        /// </summary>
        /// <param name="text">текст</param>
        /// <returns>результат проверки</returns>
        public static bool IsStartWithAdjunct(string text)
        {
            string simpleText = new SimpleStringBuilder(text).LowerValue;

            foreach (string adjunct in _adjuncts)
            {
                if (simpleText.StartsWith(adjunct))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
        public void SimpleStringBuilder_AppendChar()
        {
            using var builder = new SimpleStringBuilder(N + 4);
            var c = X;

            for (var i = 0; i < N; i++)
            {
                // ReSharper disable once PossiblyImpureMethodCallOnReadonlyVariable
                builder.Append(c);
            }

            _str = builder.ToString();
        }
            /// <summary>
            /// Замена исключений в заданном тексте
            /// </summary>
            /// <param name="sourceText">текст</param>
            /// <returns>результирующая строка</returns>
            private string ReplaceExclusions(string sourceText)
            {
                StringBuilder       text    = new StringBuilder(sourceText);
                SimpleStringBuilder builder = new SimpleStringBuilder(text.ToString());

                foreach (Match match in _conjunctionExclusionsRegex.Matches(builder.LowerValue))
                {
                    if (IsPossibleNearSymbols(builder.LowerValue, match))
                    {
                        int start  = builder.GetRealPosition(match.Index);
                        int length = builder.GetRealPosition(match.Index + match.Length) - start;
                        text.Replace(sourceText.Substring(start, length), new string('_', length), start, length);
                    }
                }
                return(text.ToString());
            }
Esempio n. 7
0
        public void Test_StringBuilder()
        {
            using var sb = new SimpleStringBuilder(100);
            sb.Append(' ');
            sb.Append('1');
            sb.Append('2');
            sb.Append('3');
            sb.Append('4');
            sb.Append("Some text");
            sb.Append(ReadOnlySpan <char> .Empty);
            sb.Append((string)null);
            sb.Append('W', 'T', 'F');

            var s = sb.ToString();

            Assert.AreEqual(" 1234Some textWTF", s);

            Assert.IsFalse(sb.View().IsEmpty);
            sb.Clear();
            Assert.IsTrue(sb.View().IsEmpty);
        }
Esempio n. 8
0
        /// <summary>
        /// Проверка, что точка стоит перед именем собственным
        /// </summary>
        /// <param name="pointIndex">индекс точки</param>
        /// <returns>результат проверки</returns>
        private bool IsPointBeforeProper(int pointIndex)
        {
            SimpleStringBuilder builder = new SimpleStringBuilder();

            for (int i = pointIndex + 1; i < Text.Length; ++i)
            {
                char symbol = Text[i];
                if (Char.IsLetter(symbol))
                {
                    if (Char.IsUpper(symbol))
                    {
                        string value = builder.LowerValue.Trim();
                        return(string.IsNullOrEmpty(value) || _tokenSelector.Dictionaries.GetDictionaryElements(DictionaryType.FamilyPrefixes).Contains(value));
                    }
                }
                else if (!symbol.IsSpace())
                {
                    break;
                }
                builder.Append(symbol);
            }
            return(false);
        }
        /// <summary>
        /// Кодирование заданной коллекции юнитов
        /// </summary>
        /// <param name="unitCollection">коллекция юнитов</param>
        /// <returns>закодированная строка</returns>
        public string CodeUnits(IEnumerable <UnitTextBase> unitCollection)
        {
            _codedUnits = new List <CodedUnit>();
            SimpleStringBuilder result = new SimpleStringBuilder();

            foreach (UnitTextBase unit in unitCollection)
            {
                bool isNotEmpty = !unit.IsEmptyText();
                if (isNotEmpty)
                {
                    result.Append(' ');
                }
                _codedUnits.Add(new CodedUnit()
                {
                    Unit = unit, Position = result.Length
                });
                if (isNotEmpty)
                {
                    result.Append(CodeUnit(unit));
                }
            }
            return(result.LowerValue);
        }
 /// <summary>
 /// Инициализация внутренних свойств из заданной коллекции юнитов
 /// </summary>
 /// <param name="units">коллекция юнитов</param>
 private void Initialize(IEnumerable <UnitTextBase> units)
 {
     _sourceText       = ReplaceExclusions(units.GetText());
     _conjunctionShift = units.First().PositionInfo.Start;
     _sourceBuilder    = new SimpleStringBuilder(_sourceText);
 }
Esempio n. 11
0
        private static string CodeByText(UnitTextBase unit)
        {
            var simpleValue = new SimpleStringBuilder(unit.IsEntity ? ((Entity)unit).Value : unit.Text).LowerValue;

            if ((simpleValue == "не") || (simpleValue == "not") || (simpleValue == "no"))
            {
                return("not");
            }
            else if ((simpleValue == "или") || (simpleValue == "либо") || (simpleValue == "or"))
            {
                return("or");
            }
            else if ((simpleValue == "и") || (simpleValue == "and"))
            {
                return("and");
            }
            else if ((simpleValue == "-") || (simpleValue == "–") || (simpleValue == "—"))
            {
                return("-");
            }
            else if (simpleValue == "+")
            {
                return("+");
            }
            else if ((simpleValue == "…") || (simpleValue == "..."))
            {
                return("...");
            }
            else if ((simpleValue == "≥") || (simpleValue == "›") || (simpleValue == ">") || (simpleValue == "≫"))
            {
                return(">");
            }
            else if ((simpleValue == "≤") || (simpleValue == "‹") || (simpleValue == "<") || (simpleValue == "≪"))
            {
                return("<");
            }
            else if ((simpleValue == "±") || (simpleValue == "÷") ||
                     (simpleValue == ".") || (simpleValue == ",") ||
                     (simpleValue == "(") || (simpleValue == ")"))
            {
                return(simpleValue);
            }
            else if (simpleValue == "between")
            {
                return("between");
            }
            else if ((simpleValue == "около") || (simpleValue == "about"))
            {
                return("about");
            }
            else if ((simpleValue == "ниже") || (simpleValue == "менее") || (simpleValue == "меньше") ||
                     (simpleValue == "less") || (simpleValue == "fewer") || (simpleValue == "few") || (simpleValue == "small") || (simpleValue == "below") ||
                     (simpleValue == "at most") || (simpleValue == "max.") || (simpleValue == "lower") || (simpleValue == "shorter"))
            {
                return("less");
            }
            else if ((simpleValue == "больше") || (simpleValue == "более") || (simpleValue == "выше") ||
                     (simpleValue == "more") || (simpleValue == "great") || (simpleValue == "higher") || (simpleValue == "above") ||
                     (simpleValue == "at least") || (simpleValue == "min.") || (simpleValue == "longer") || (simpleValue == "large"))
            {
                return("great");
            }
            else if ((simpleValue == "равно") || (simpleValue == "equal"))
            {
                return("equal");
            }
            else if ((simpleValue == "от") || (simpleValue == "с") || (simpleValue == "from") || (simpleValue == "of"))
            {
                return("from");
            }
            else if ((simpleValue == "до") || (simpleValue == "to"))
            {
                return("to");
            }
            else if (simpleValue == "по")
            {
                return("po");
            }
            else if (simpleValue == "than")
            {
                return("than");
            }
            return(null);
        }