Esempio n. 1
0
        public MainView DoTextMatch(string text, string subtext)
        {
            try
            {
                reset();

                if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(subtext))
                {
                    createInputEmptyMatchView(text, subtext);
                    return _mainView;
                }

                var textMatcher = new TextMatcher(text, subtext);
                textMatcher.Match();

                if (textMatcher.GetMatches().Count() == 0)
                {
                    createNoMatchView(text, subtext);
                    return _mainView;
                }

                createMatchView(text, subtext, textMatcher);
                return _mainView;

            }
            catch (SubtextLongerThanTextException)
            {

                createSubtextTooLongMatchView(text, subtext);
                return _mainView;
            }

        }
Esempio n. 2
0
        private Task <List <SystemMatch> > ScanText(string text)
        {
            AddTestData();

            var matcher = new TextMatcher(new RandomSystemApi(new HttpClient()));

            return(matcher.FindSystemMatches(text));
        }
Esempio n. 3
0
        public void GetMatches_MatchWasNotCalled_EmptyListReturned()
        {
            var textMatcher = new TextMatcher("Not Important", "Not Important");

            var matches = textMatcher.GetMatches();

            Assert.True(matches.Count() == 0);
        }
Esempio n. 4
0
        public void Match_TextContainsThreeInstancesOfSingleCharacterSubtext_ListContainsThreeMatches()
        {
            const string text = "abcabcabc";
            const string subtext = "a";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();

            Assert.True(matches.Count() == 3);
        }
Esempio n. 5
0
        public void Match_TextContainsOneInstanceOfSingleCharacterSubtext_MatchHasCorrectStartPosition()
        {
            const string text = "abc";
            const string subtext = "a";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();

            Assert.True(matches.First().StartPosition == 1);
        }
Esempio n. 6
0
        public async Task Text_NoMatch()
        {
            var message = new Messages.Message();

            message.Text = "hello world";

            var matcher = new TextMatcher("test");
            var matches = await matcher.GetMatches(message);

            Assert.Null(matches);
        }
Esempio n. 7
0
        public async Task Text_Match()
        {
            var message = new Messages.Message();

            message.Text = "hello world";

            var matcher = new TextMatcher("hello world");
            var matches = await matcher.GetMatches(message);

            Assert.Equal(1, matches.Length);
            Assert.Equal("hello world", matches[0].Text);
        }
Esempio n. 8
0
 /// <summary>
 /// Determines whether [contains] [the specified text].
 /// </summary>
 /// <param name="text">The text.</param>
 /// <returns>
 ///   <c>true</c> if [contains] [the specified text]; otherwise, <c>false</c>.
 /// </returns>
 public bool Contains(string text)
 {
     if (!string.IsNullOrEmpty(text))
     {
         var matchResult = new TextMatcher(this).Match(text);
         return(matchResult != null && matchResult.MatchedCount == text.Length);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 9
0
        public MatchShouldBase(DataFixture dataFixture)
        {
            DataFixture = dataFixture;
            DataFixture.Init();

            Matcher =
                new TextMatcher(DataFixture.Companies, DataFixture.Localities, DataFixture.Classifiers)
            {
                UseCache = false
            };
            // _analyser.FlushCache();
        }
Esempio n. 10
0
        public void ProcGen_Potential_Confusion_test_2()
        {
            var textMatcher = new TextMatcher(new RandomSystemApi(new HttpClient()));
            var result      = textMatcher.FindNamedSectorCandidates("North America Sector AA-Q b5-0 and Madeup Sector AA-Q b5-0");

            Assert.Equal(2, result.Count);

            var match = result.First();

            Assert.Equal("North America Sector AA-Q b5-0", match);
            match = result.Last();
            Assert.Equal("Madeup Sector AA-Q b5-0", match);
        }
Esempio n. 11
0
        /// <summary>
        /// Searches for specified text within the tree and returns the list of matching starting positions.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="matchList">The match list.</param>
        /// <returns></returns>
        public IEnumerable <int> Search(string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                var matchResult = new TextMatcher(this).Match(text);

                if (matchResult != null && matchResult.MatchingSuffixes != null && matchResult.MatchedCount == text.Length)
                {
                    foreach (var suffixNode in matchResult.MatchingSuffixes)
                    {
                        yield return(suffixNode.LeafNumber);
                    }
                }
            }
        }
Esempio n. 12
0
        private void buildMatchesMessage(TextMatcher textMatcher)
        {
            foreach (var match in textMatcher.GetMatches())
            {
                _matchesMessage.Append(match.StartPosition + ",");
            }

            if (_matchesMessage.Length > 0)
            {
                const int arrayOffset = 1;
                var lastCharacterPosition = _matchesMessage.Length - arrayOffset;
                const int numberOfCharacters = 1;
                _matchesMessage.Remove(lastCharacterPosition, numberOfCharacters);
            }
        }
Esempio n. 13
0
            public void Then_the_output_should_be_1_26_51()
            {

                const string subtext = "polly";
                var output = new[] { 1, 26, 51 };

                var textMatcher = new TextMatcher(_text, subtext);
                textMatcher.Match();

                var matches = textMatcher.GetMatches();
                matches.should_have_count(3);
                foreach (var match in matches)
                {
                    output.should_contain(match.StartPosition);
                }

            }
Esempio n. 14
0
            public void Then_the_output_should_be_3_28_53_78_82()
            {

                const string subtext = "ll";
                var output = new[] { 3, 28, 53, 78, 82 };

                var textMatcher = new TextMatcher(_text, subtext);
                textMatcher.Match();

                var matches = textMatcher.GetMatches();
                matches.should_have_count(5);
                foreach (var match in matches)
                {
                    output.should_contain(match.StartPosition);
                }

            }
Esempio n. 15
0
        protected internal override YqlCompiledNode CompileNode(YqlCompiler compiler)
        {
            if (SourceString == null)
            {
                throw new ArgumentNullException("SourceString");
            }

            YqlCompiledNode sourceStringNode = SourceString.CompileNode(compiler);

            // Get the body text
            TextMatcher textMatcher = new TextMatcher(this.searchText, this.WholeWords, this.MatchAllWords);

            Expression expression = Expression.Call(Expression.Constant(textMatcher),
                                                    TextMatcher.Info_IsMatch,
                                                    sourceStringNode.Expression);

            return(new YqlCompiledNode(this, expression, new[] { sourceStringNode }));
        }
Esempio n. 16
0
        public void Match_TextContainsOneInstanceOfMultiCharacterSubtext_ListContainsOneMatch()
        {
            const string text = "abcxyzabc";
            const string subtext = "xyz";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();

            Assert.True(matches.Count() == 1);            
        }
Esempio n. 17
0
            public void Then_there_should_be_no_matches()
            {

                const string subtext = "aaa";

                var textMatcher = new TextMatcher(_text, subtext);
                textMatcher.Match();

                var matches = textMatcher.GetMatches();
                matches.should_have_count(0);
            }
Esempio n. 18
0
        public void Match_AttemptToMatchPastLastCharacterOfText_ListContainsNoMatches()
        {
            const string text = "abcxyzabc";
            const string subtext = "ccc";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();
            matches.Count().should_equal(0);
        }
Esempio n. 19
0
        public void Match_UpperCaseTextContainsOneInstanceOfLowerCaseSubtext_CaseInsensitiveMatchOccurs()
        {
            const string text = "abcXYZabc";
            const string subtext = "xyz";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();

            Assert.True(matches.First().StartPosition == 4);   
        }
Esempio n. 20
0
 private void createMatchView(string text, string subtext, TextMatcher textMatcher)
 {
     buildMatchesMessage(textMatcher);
     createMainView(text, subtext);
 }
Esempio n. 21
0
        public void Match_TextContainsThreeInstancesOfSingleCharacterSubtext_MatchesHaveCorrectStartPositions()
        {
            const string text = "abcabcabc";
            const string subtext = "a";
            var output = new[] { 1, 4, 7 };
            

            var textMatcher = new TextMatcher(text, subtext);
            textMatcher.Match();
            
            var matches = textMatcher.GetMatches();
            const int outputNotFoundValue = 0;
            foreach (int foundInOutput in matches.Select(match => (from o in output
                                                                         where o == match.StartPosition
                                                                         select o).SingleOrDefault()))
            {                
                Assert.AreNotEqual(outputNotFoundValue,foundInOutput);
            }





        }
Esempio n. 22
0
 public ScanText(ILogger <ScanText> logger, TextMatcher matcher)
 {
     _logger  = logger;
     _matcher = matcher;
 }
Esempio n. 23
0
        public void Convert(ICollection<CuttingScheme> output, StreamReader tr)
        {
            // сканирование dxf, загрузка линий и текстов
            int typeCode;
            string data;
            while (true)
            {
                typeCode = int.Parse(tr.ReadLine());
                data = tr.ReadLine();
                if (typeCode == 0 && data == "SECTION")
                {
                    typeCode = int.Parse(tr.ReadLine());
                    data = tr.ReadLine();
                    if (typeCode == 2 && data == "ENTITIES")
                    {
                        break;
                    }
                }
            }

            List<Line> lines = new List<Line>();
            _texts = new LinkedList<Text>();

            while (!tr.EndOfStream)
            {
                typeCode = int.Parse(tr.ReadLine());
                data = tr.ReadLine();
                if (typeCode == 0 && data == "LINE")
                {
                    Line line = new Line();
                    line.Read(tr);
                    lines.Add(line);
                }
                else if (typeCode == 0 && data == "TEXT")
                {
                    Text text = new Text();
                    text.Read(tr);
                    _texts.AddLast(text);
                }
            }

            // составляем список резов, выбирая линии со стилем HIDDEN
            LinkedList<Line> buffer = new LinkedList<Line>(lines);
            _cuts = new LinkedList<Line>();
            BazUtils.TakeFrom(buffer, _cuts, BazUtils.CutsPredicate);

            // составляем список прямоугольноков, собирая их из линий
            List<Line> otherLines = new List<Line>();
            LinkedList<Rectangle> rects = new LinkedList<Rectangle>();
            while (buffer.Count > 0)
            {
                Line line1 = buffer.First.Value;
                buffer.RemoveFirst();
                Line line2 = BazUtils.FindContLine(line1, buffer);
                if (line2 == null)
                {
                    otherLines.Add(line1);
                    continue;
                }
                buffer.Remove(line2);
                Line line3 = BazUtils.FindContLine(line2, buffer);
                if (line3 == null)
                {
                    otherLines.Add(line1);
                    otherLines.Add(line2);
                    continue;
                }
                buffer.Remove(line3);
                Line line4 = BazUtils.FindContLine(line2, buffer);
                if (line4 != null)
                {
                    otherLines.Add(line1);
                    otherLines.Add(line2);
                    otherLines.Add(line3);
                    continue;
                }
                buffer.Remove(line4);

                Rectangle rect = new Rectangle();
                rect.LeftBottom.X = Math.Min(line1.P1.X, line2.P2.X);
                rect.LeftBottom.Y = Math.Min(line1.P1.Y, line2.P2.Y);
                rect.RightTop.X = Math.Max(line1.P1.X, line2.P2.X);
                rect.RightTop.Y = Math.Max(line1.P1.Y, line2.P2.Y);
                rects.AddLast(rect);
            }

            BazUtils.BubbleSort<Rectangle>(rects, Rectangle.SquareDescending);
            while (rects.Count > 0)
            {
                // находим прямоугольники листа и его обрезанной части
                Rectangle sheetRect = rects.First.Value;
                rects.RemoveFirst();
                List<Rectangle> internals = new List<Rectangle>();
                BazUtils.TakeFrom<Rectangle>(rects, internals, sheetRect.IsContains);
                if (internals.Count == 0)
                {
                    break;
                }
                Rectangle cutoffRect = internals[0];

                // определяем ширину реза и направление первого реза
                CutMatcher matcher = new CutMatcher();
                CuttingDirection firstCut;
                matcher.Bounds = cutoffRect;
                Line match = BazUtils.Lookup(_cuts, matcher.MatchHorizontalCut);
                if (match == null)
                {
                    match = BazUtils.Lookup(_cuts, matcher.MatchVerticalCut);
                    _cutterThick = (cutoffRect.LeftBottom.Y - match.P1.Y) * 2;
                    firstCut = CuttingDirection.Vertical;
                }
                else
                {
                    _cutterThick = (cutoffRect.LeftBottom.X - match.P1.X) * 2;
                    firstCut = CuttingDirection.Horizontal;
                }

                // заполняем полученные параметры раскроя
                ParametersCollection pars = new ParametersCollection();
                pars.CutterThickness = (decimal)(_cutterThick * 10.0);
                pars.CutOffLeft = (decimal)((cutoffRect.LeftBottom.X - sheetRect.LeftBottom.X) * 10.0);
                pars.CutOffBottom = (decimal)((cutoffRect.LeftBottom.Y - sheetRect.LeftBottom.Y) * 10.0);
                pars.CutOffRight = (decimal)((sheetRect.RightTop.X - cutoffRect.RightTop.X) * 10.0);
                pars.CutOffTop = (decimal)((sheetRect.RightTop.Y - cutoffRect.RightTop.Y) * 10.0);
                _scheme = new CuttingScheme();
                _scheme.Parameters = pars;
                _scheme.Sheet = new Sheet();
                _scheme.Sheet.Thickness = 16;
                _scheme.Height = (decimal)((sheetRect.RightTop.Y - sheetRect.LeftBottom.Y) * 10.0);
                _scheme.Width = (decimal)((sheetRect.RightTop.X - sheetRect.LeftBottom.X) * 10.0);
                _scheme.Sheet.Width = _scheme.Width;
                _scheme.Sheet.Height = _scheme.Height;

                // составляем сам раскрой
                if (firstCut == CuttingDirection.Vertical)
                {
                    CutHorizontalStrip(_scheme.RootSection, cutoffRect);
                }
                else
                {
                    CutVerticalStrip(_scheme.RootSection, cutoffRect);
                }
                
                // получаем количество листов из строчки под раскроем
                List<Text> sheetInfo = new List<Text>();
                TextMatcher textMatcher = new TextMatcher();
                textMatcher.Bounds = sheetRect.HorizStrip(sheetRect.LeftBottom.Y - 30, sheetRect.LeftBottom.Y);
                BazUtils.TakeFrom<Text>(_texts, sheetInfo, textMatcher.IsInside);
                sheetInfo.Sort(Text.PosYAscending);
                string sheetsCountStr = sheetInfo[0].Value;
                int eqPos = sheetsCountStr.LastIndexOf('=');
                _scheme.Repetitions = int.Parse(sheetsCountStr.Substring(eqPos + 1, sheetsCountStr.Length - eqPos - 1));

                output.Add(_scheme);
            }
        }
Esempio n. 24
0
        public void Convert(ICollection <CuttingScheme> output, StreamReader tr)
        {
            // сканирование dxf, загрузка линий и текстов
            int    typeCode;
            string data;

            while (true)
            {
                typeCode = int.Parse(tr.ReadLine());
                data     = tr.ReadLine();
                if (typeCode == 0 && data == "SECTION")
                {
                    typeCode = int.Parse(tr.ReadLine());
                    data     = tr.ReadLine();
                    if (typeCode == 2 && data == "ENTITIES")
                    {
                        break;
                    }
                }
            }

            List <Line> lines = new List <Line>();

            _texts = new LinkedList <Text>();

            while (!tr.EndOfStream)
            {
                typeCode = int.Parse(tr.ReadLine());
                data     = tr.ReadLine();
                if (typeCode == 0 && data == "LINE")
                {
                    Line line = new Line();
                    line.Read(tr);
                    lines.Add(line);
                }
                else if (typeCode == 0 && data == "TEXT")
                {
                    Text text = new Text();
                    text.Read(tr);
                    _texts.AddLast(text);
                }
            }

            // составляем список резов, выбирая линии со стилем HIDDEN
            LinkedList <Line> buffer = new LinkedList <Line>(lines);

            _cuts = new LinkedList <Line>();
            BazUtils.TakeFrom(buffer, _cuts, BazUtils.CutsPredicate);

            // составляем список прямоугольноков, собирая их из линий
            List <Line>            otherLines = new List <Line>();
            LinkedList <Rectangle> rects      = new LinkedList <Rectangle>();

            while (buffer.Count > 0)
            {
                Line line1 = buffer.First.Value;
                buffer.RemoveFirst();
                Line line2 = BazUtils.FindContLine(line1, buffer);
                if (line2 == null)
                {
                    otherLines.Add(line1);
                    continue;
                }
                buffer.Remove(line2);
                Line line3 = BazUtils.FindContLine(line2, buffer);
                if (line3 == null)
                {
                    otherLines.Add(line1);
                    otherLines.Add(line2);
                    continue;
                }
                buffer.Remove(line3);
                Line line4 = BazUtils.FindContLine(line2, buffer);
                if (line4 != null)
                {
                    otherLines.Add(line1);
                    otherLines.Add(line2);
                    otherLines.Add(line3);
                    continue;
                }
                buffer.Remove(line4);

                Rectangle rect = new Rectangle();
                rect.LeftBottom.X = Math.Min(line1.P1.X, line2.P2.X);
                rect.LeftBottom.Y = Math.Min(line1.P1.Y, line2.P2.Y);
                rect.RightTop.X   = Math.Max(line1.P1.X, line2.P2.X);
                rect.RightTop.Y   = Math.Max(line1.P1.Y, line2.P2.Y);
                rects.AddLast(rect);
            }

            BazUtils.BubbleSort <Rectangle>(rects, Rectangle.SquareDescending);
            while (rects.Count > 0)
            {
                // находим прямоугольники листа и его обрезанной части
                Rectangle sheetRect = rects.First.Value;
                rects.RemoveFirst();
                List <Rectangle> internals = new List <Rectangle>();
                BazUtils.TakeFrom <Rectangle>(rects, internals, sheetRect.IsContains);
                if (internals.Count == 0)
                {
                    break;
                }
                Rectangle cutoffRect = internals[0];

                // определяем ширину реза и направление первого реза
                CutMatcher       matcher = new CutMatcher();
                CuttingDirection firstCut;
                matcher.Bounds = cutoffRect;
                Line match = BazUtils.Lookup(_cuts, matcher.MatchHorizontalCut);
                if (match == null)
                {
                    match        = BazUtils.Lookup(_cuts, matcher.MatchVerticalCut);
                    _cutterThick = (cutoffRect.LeftBottom.Y - match.P1.Y) * 2;
                    firstCut     = CuttingDirection.Vertical;
                }
                else
                {
                    _cutterThick = (cutoffRect.LeftBottom.X - match.P1.X) * 2;
                    firstCut     = CuttingDirection.Horizontal;
                }

                // заполняем полученные параметры раскроя
                ParametersCollection pars = new ParametersCollection();
                pars.CutterThickness = (decimal)(_cutterThick * 10.0);
                pars.CutOffLeft      = (decimal)((cutoffRect.LeftBottom.X - sheetRect.LeftBottom.X) * 10.0);
                pars.CutOffBottom    = (decimal)((cutoffRect.LeftBottom.Y - sheetRect.LeftBottom.Y) * 10.0);
                pars.CutOffRight     = (decimal)((sheetRect.RightTop.X - cutoffRect.RightTop.X) * 10.0);
                pars.CutOffTop       = (decimal)((sheetRect.RightTop.Y - cutoffRect.RightTop.Y) * 10.0);
                _scheme                 = new CuttingScheme();
                _scheme.Parameters      = pars;
                _scheme.Sheet           = new Sheet();
                _scheme.Sheet.Thickness = 16;
                _scheme.Height          = (decimal)((sheetRect.RightTop.Y - sheetRect.LeftBottom.Y) * 10.0);
                _scheme.Width           = (decimal)((sheetRect.RightTop.X - sheetRect.LeftBottom.X) * 10.0);
                _scheme.Sheet.Width     = _scheme.Width;
                _scheme.Sheet.Height    = _scheme.Height;

                // составляем сам раскрой
                if (firstCut == CuttingDirection.Vertical)
                {
                    CutHorizontalStrip(_scheme.RootSection, cutoffRect);
                }
                else
                {
                    CutVerticalStrip(_scheme.RootSection, cutoffRect);
                }

                // получаем количество листов из строчки под раскроем
                List <Text> sheetInfo   = new List <Text>();
                TextMatcher textMatcher = new TextMatcher();
                textMatcher.Bounds = sheetRect.HorizStrip(sheetRect.LeftBottom.Y - 30, sheetRect.LeftBottom.Y);
                BazUtils.TakeFrom <Text>(_texts, sheetInfo, textMatcher.IsInside);
                sheetInfo.Sort(Text.PosYAscending);
                string sheetsCountStr = sheetInfo[0].Value;
                int    eqPos          = sheetsCountStr.LastIndexOf('=');
                _scheme.Repetitions = int.Parse(sheetsCountStr.Substring(eqPos + 1, sheetsCountStr.Length - eqPos - 1));

                output.Add(_scheme);
            }
        }