Exemplo n.º 1
0
        protected void GetDocumentText(double documentID, string columnName = "NOTE_TEXT")
        {
            if (_cachedNoteDocuments.Keys.Contains(documentID) && _cachedNoteDocuments[documentID].Keys.Contains(columnName))
            {
                _lastDocumentID   = documentID;
                _lastDocumentText = _cachedNoteDocuments[documentID][columnName];

                _lastNoteColumnName = columnName;

                _lastDocumentText = RegExpBase.CleanupDocumentText(_lastDocumentText);
            }
            else
            {
                var cmd = _connection.CreateCommand();

                cmd.CommandText = String.Format("SELECT {0} FROM Documents WHERE ED_ENC_NUM = @ED_ENC_NUM", columnName);

                cmd.Parameters.AddWithValue("@ED_ENC_NUM", documentID);

                _lastDocumentText = cmd.ExecuteScalar() as string ?? string.Empty;
                _lastDocumentID   = documentID;

                _lastNoteColumnName = columnName;

                _lastDocumentText = RegExpBase.CleanupDocumentText(_lastDocumentText);
            }

            SendResponse(new IpcResponse
            {
                ResponseType = IpcResponseType.Success,
                DocumentID   = documentID,
                DocumentText = _lastDocumentText
            });
        }
 protected void RaiseModifiedEvent(RegExpBase regExp)
 {
     if (this.Modified != null)
     {
         this.Modified(regExp, EventArgs.Empty);
     }
 }
Exemplo n.º 3
0
        protected int CalcRegExpScore(RegExpBase regExp, string text, out bool isMatch)
        {
            var scoreResult = 0;

            isMatch = false;

            try
            {
                var matches = regExp.GetFilteredMatches(text);
                if (matches.Any())
                {
                    isMatch = true;

                    var totalMatches = matches.Count;

                    regExp.IncrementTotalDocuments();
                    regExp.AddTotalMatches(totalMatches);

                    ///////////////////////////////////////////////////////////////////////////////

                    var score  = regExp.Score ?? 0;
                    var factor = regExp.Factor ?? 0;

                    scoreResult  = totalMatches * score;
                    scoreResult += (totalMatches / 2) * (totalMatches - 1) * factor;
                }
            }
            catch (Exception ex)
            {
                Logger.HandleException(ex);
            }

            return(scoreResult);
        }
Exemplo n.º 4
0
        public RegExpMatchResult(RegExpBase regExp, int position, int start, int length, int columnIndex = 0)
        {
            this.RegExp      = regExp;
            this.Position    = position;
            this.ColumnIndex = columnIndex;

            _start  = start;
            _length = length;
        }
Exemplo n.º 5
0
        public RegExpMatchResult(RegExpBase regExp, int position, Match match, int columnIndex = 0)
        {
            this.RegExp      = regExp;
            this.Position    = position;
            this.Match       = match;
            this.ColumnIndex = columnIndex;

            _start  = -1;
            _length = -1;
        }
Exemplo n.º 6
0
        protected RegExpMatchResult Navigate_Document(RegExpBase regExp, int totalDocsCount, List <double> documents, int blockStartPosition, int position, bool forward)
        {
            var increment = forward ? 1 : -1;

            _position = position + increment;

            _unique = false;

            ///////////////////////////////////////////////////////////////////////////////

            if (forward && _position >= totalDocsCount)
            {
                _position = 0;
            }
            else if (!forward && _position < 0)
            {
                _position = totalDocsCount - 1;
            }

            ///////////////////////////////////////////////////////////////////////////////

            while (_position >= 0 && _position < totalDocsCount)
            {
                _matches.Clear();
                _matches = new List <RegExpMatchResult>();
                for (int columnIndex = 0; columnIndex < _noteColumnCount; columnIndex++)
                {
                    string documentText;
                    if (!GetDocumentTextByPosition(documents, blockStartPosition, _position, forward, out documentText, columnIndex))
                    {
                        return(RegExpMatchResult.NeedMoreDataResult());
                    }

                    ///////////////////////////////////////////////////////////////////////////////

                    _matches.AddRange(regExp.GetFilteredMatches(documentText)
                                      .Select(x => new RegExpMatchResult(regExp, _position, x, columnIndex))
                                      .ToList());
                }
                if (_matches.Count > 0)
                {
                    _currentMatchIndex = 0;

                    return(_matches[_currentMatchIndex]);
                }
                ///////////////////////////////////////////////////////////////////////////////

                _position += increment;
            }

            ///////////////////////////////////////////////////////////////////////////////

            return(RegExpMatchResult.EmptyResult());
        }
Exemplo n.º 7
0
        protected void Navigate(long navigationContextID, MatchNavigationMode mode, RegExpBase regExp, int totalDocsCount, List <double> documentsBlock, int position)
        {
            RegExpMatchResult result = null;

            if (navigationContextID != _navigationContextID || _lastRegExpression != regExp.BuiltExpression)
            {
                CleanupNavigationContext();

                _navigationContextID     = navigationContextID;
                _navigationStartPosition = position;
                _lastRegExpression       = regExp.BuiltExpression;
            }

            switch (mode)
            {
            case MatchNavigationMode.Refresh:
                SendErrorResponse("Invalid navigation mode");
                return;

            case MatchNavigationMode.NextDocument:
                result = Navigate_Document(regExp, totalDocsCount, documentsBlock, position, position, true);
                break;

            case MatchNavigationMode.PrevDocument:
                result = Navigate_Document(regExp, totalDocsCount, documentsBlock, position, position, false);
                break;

            case MatchNavigationMode.NextMatch:
                result = Navigate_Match(regExp, totalDocsCount, documentsBlock, position, position, true);
                break;

            case MatchNavigationMode.PrevMatch:
                result = Navigate_Match(regExp, totalDocsCount, documentsBlock, position, position, false);
                break;

            case MatchNavigationMode.NextUniqueMatch:
                result = Navigate_UniqueMatch(regExp, totalDocsCount, documentsBlock, position, position, true);
                break;

            case MatchNavigationMode.PrevUniqueMatch:
                result = Navigate_UniqueMatch(regExp, totalDocsCount, documentsBlock, position, position, false);
                break;
            }

            SendResponse(new IpcResponse
            {
                ResponseType = IpcResponseType.Success,
                MatchResult  = result
            });
        }
        public RegExpMatchResult Navigate(long navigationContextID, RegExpBase regExp, MatchNavigationMode mode, int totalDocumentsCount, double[] documentsBlock, int position)
        {
            lock (myLock)
            {
                try
                {
                    OpenPipe();

                    SendRequest(new IpcRequest
                    {
                        RequestType         = IpcRequestType.Navigate,
                        NavigationContextID = navigationContextID,
                        NavigationMode      = mode,
                        DocumentsBlock      = documentsBlock,
                        TotalDocumentsCount = totalDocumentsCount,
                        Position            = position,
                        RegExp = regExp
                    });

                    var response = GetResponse();

                    ///////////////////////////////////////////////////////////////////////////////

                    if (response.ResponseType == IpcResponseType.Success)
                    {
                        return(response.MatchResult);
                    }

                    throw new Exception(response.ErrorMessage, response.Exception);
                }
                finally
                {
                    ClosePipe();
                }
            }
        }
Exemplo n.º 9
0
 public void HandleRegExpException(DataRow row)
 {
     HandleRegExpException(RegExpBase.GetRegExpValue(row));
 }
Exemplo n.º 10
0
 public SingleStatisticsCalculator(Logger logger, RegExpBase regExp)
 {
     _logger = logger;
     _regExp = regExp;
 }
Exemplo n.º 11
0
        protected RegExpMatchResult Navigate_UniqueMatch(RegExpBase regExp, int totalDocsCount, List <double> documentsBlock, int blockStartPosition, int position, bool forward)
        {
            var increment = forward ? 1 : -1;

            if (_position != position)
            {
                _matches           = null;
                _currentMatchIndex = -1;

                _position = position;
                _navigationStartPosition = _position;
            }

            if (!_unique)
            {
                _matches           = null;
                _currentMatchIndex = -1;

                _unique = true;
            }

            ///////////////////////////////////////////////////////////////////////////////

            if (_matches != null)
            {
                if (_currentMatchIndex == -1)
                {
                    _currentMatchIndex = forward ? 0 : _matches.Count - 1;
                }

                _currentMatchIndex += increment;

                if (_currentMatchIndex >= 0 && _currentMatchIndex < _matches.Count)
                {
                    _position = _matches[_currentMatchIndex]
                                .Position;

                    _navigationStartPosition = _position;

                    return(_matches[_currentMatchIndex]);
                }

                _position += increment;
            }

            if (forward && _position >= totalDocsCount || !forward && _position < 0)
            {
                _position = position;
                _navigationStartPosition = _position;

                if (_matches != null)
                {
                    _currentMatchIndex = forward ? _matches.Count - 1 : 0;
                }

                return(RegExpMatchResult.EmptyResult());
            }

            ///////////////////////////////////////////////////////////////////////////////

            var comparer = new MatchEqualityComparer();

            ///////////////////////////////////////////////////////////////////////////////

            while (_position >= 0 && _position < totalDocsCount)
            {
                var hasUniqueMatches = false;

                for (int columnIndex = 0; columnIndex < _noteColumnCount; columnIndex++)
                {
                    string documentText;
                    if (!GetDocumentTextByPosition(documentsBlock, blockStartPosition, _position, forward, out documentText, columnIndex))
                    {
                        return(RegExpMatchResult.NeedMoreDataResult());
                    }

                    var matches = regExp.GetFilteredMatches(documentText)
                                  .Distinct(comparer)
                                  .ToList();
                    if (matches.Any())
                    {
                        if (_matches != null)
                        {
                            foreach (var match in matches)
                            {
                                if (_matches.All(x => x.Match.Value != match.Value))
                                {
                                    if (forward)
                                    {
                                        _matches.Add(new RegExpMatchResult(regExp, _position, match, columnIndex));
                                    }
                                    else
                                    {
                                        _matches.Insert(0, new RegExpMatchResult(regExp, _position, match, columnIndex));
                                    }

                                    hasUniqueMatches = true;
                                }
                            }
                        }
                        else
                        {
                            _matches = matches.Select(x => new RegExpMatchResult(regExp, _position, x, columnIndex))
                                       .ToList();

                            hasUniqueMatches = true;
                        }
                    }
                    ///////////////////////////////////////////////////////////////////////////////
                }

                if (hasUniqueMatches)
                {
                    if (_currentMatchIndex == -1)
                    {
                        if (forward)
                        {
                            _currentMatchIndex = 0;
                        }
                        else
                        {
                            _currentMatchIndex = _matches.Count - 1;
                        }
                    }
                    else if (_currentMatchIndex < 0)
                    {
                        _currentMatchIndex = 0;
                    }
                    else if (_currentMatchIndex >= _matches.Count)
                    {
                        _currentMatchIndex = _matches.Count - 1;
                    }

                    _position = _matches[_currentMatchIndex]
                                .Position;
                    _navigationStartPosition = _position;

                    return(_matches[_currentMatchIndex]);
                }

                ///////////////////////////////////////////////////////////////////////////////

                _position += increment;
            }

            ///////////////////////////////////////////////////////////////////////////////

            _currentMatchIndex = -1;
            _position          = _navigationStartPosition;

            return(RegExpMatchResult.EmptyResult());
        }