Example #1
0
        private static int FindBestMatch(int firstIndex, int secondCount, Func <int, int, CompareRowResult> compares)
        {
            CompareRowResult best = null;
            int bestIndex         = 0;

            // secondCount + 1 allows us to get to the Missing Record Section
            for (int secondIndex = 0; secondIndex < secondCount; secondIndex++)
            {
                var compare = compares(firstIndex, secondIndex);
                if (compare == null)
                {
                    continue;
                }
                if (best == null)
                {
                    best      = compare;
                    bestIndex = secondIndex;
                    continue;
                }
                if (compare.totalErrors < best.totalErrors)
                {
                    best      = compare;
                    bestIndex = secondIndex;
                    continue;
                }
            }

            // no matching records return matching
            if (best == null)
            {
                return(secondCount);
            }

            return(bestIndex);
        }
Example #2
0
        private void AddFinalMatch(int tableRowIndex, int dataIndex, CompareRowResult rowResult, MatchQuality matchQuality)
        {
            // Missing TableRows are not added to final
            if (tableRowIndex != _tableRowsCount)
            {
                // A Match calls us to action.
                // We need to remove previous compares.
                // So, that when we finalize... Matches won't get confused with other Match Data
                for (int dataForIndex = 0; dataForIndex < _dataItemsCount; dataForIndex++)
                {
                    tableRowToDataCompares[tableRowIndex, dataForIndex] = null;
                }

                var tableRowCompareMatchResult = new CompareRowFinalResult();
                tableRowCompareMatchResult.compareRowResult   = rowResult;
                tableRowCompareMatchResult.matchQuality       = matchQuality;
                tableRowCompareMatchResult.index              = dataIndex;
                TableRowToDataCompareRowFinals[tableRowIndex] = tableRowCompareMatchResult;
            }

            // Missing Datas are not added to final
            if (dataIndex != _dataItemsCount)
            {
                for (int tableRowForIndex = 0; tableRowForIndex < _tableRowsCount; tableRowForIndex++)
                {
                    tableRowToDataCompares[tableRowForIndex, dataIndex] = null;
                }

                var dataCompareMatchResult = new CompareRowFinalResult();
                dataCompareMatchResult.compareRowResult   = rowResult;
                dataCompareMatchResult.matchQuality       = matchQuality;
                dataCompareMatchResult.index              = tableRowIndex;
                DataToTableRowCompareRowFinals[dataIndex] = dataCompareMatchResult;
            }
        }
Example #3
0
        // Used by TableAid to Add a new Result.
        public void AddRowResult(
            int tableRowIndex,
            int dataItemIndex,
            CompareRowResult rowResult,
            bool isMatch)
        {
            // These are for No Matches...
            // We left a little space in the table to make these...
            if (tableRowIndex == int.MaxValue)
            {
                tableRowIndex = _tableRowsCount;
            }

            if (dataItemIndex == int.MaxValue)
            {
                dataItemIndex = _dataItemsCount;
            }

            if (isMatch == true)
            {
                AddFinalMatch(tableRowIndex, dataItemIndex, rowResult, MatchQuality.PerfectMatch);
            }
            else
            {
                _tableRowToDataCompares[tableRowIndex, dataItemIndex] = rowResult;
            }
        }
        // Used by TableAid to Add a new Result.
        public void AddRowResult(int tableRowIndex, int dataItemIndex, CompareRowResult rowResult, bool isMatch)
        {
            // These are for No Matches...
            // We left a little space in the table to make these...
            if (tableRowIndex == int.MaxValue)
                tableRowIndex = _tableRowsCount;

            if (dataItemIndex == int.MaxValue)
                dataItemIndex = _dataItemsCount;

            if (isMatch == true)
            {
                AddFinalMatch(tableRowIndex, dataItemIndex, rowResult, MatchQuality.PerfectMatch);
            }
            else
            {
                tableRowToDataCompares[tableRowIndex, dataItemIndex] = rowResult;
            }
        }
Example #5
0
        private void CompleteFinal()
        {
            // Build Final
            var killLoop = false;

            while (!killLoop)
            {
                killLoop = true;

                var bestFinalMisMatchDataIndex     = 0;
                var bestFinalMisMatchTableRowIndex = 0;
                CompareRowResult bestFinalMisMatch = null;

                for (int tableRowIndex = 0; tableRowIndex < _tableRowsCount; tableRowIndex++)
                {
                    // It a Final Match is already set, then skip.
                    if (TableRowToDataCompareRowFinals[tableRowIndex] != null)
                    {
                        continue;
                    }

                    // No Match... find one.
                    var bestDataIndex = FindBestMatch(tableRowIndex, _dataItemsCount, TableRowToDataRetrieval);
                    var bestDataFinal = tableRowToDataCompares[tableRowIndex, bestDataIndex];

                    // Missing Record (add and continue)
                    if (bestDataIndex == _dataItemsCount)
                    {
                        AddFinalMatch(tableRowIndex, bestDataIndex, bestDataFinal, MatchQuality.None);
                        killLoop = false;
                        continue;
                    }

                    var bestTableRowIndexForData = FindBestMatch(bestDataIndex, _tableRowsCount, DataToTableRowRetrieval);

                    // Verify the Data believe that the it is also the closes Match
                    if (tableRowIndex != bestTableRowIndexForData)
                    {
                        continue;
                    }

                    // At this point we have a Match...
                    // And we will reloop
                    // But really is this match combo better than the last ???
                    if (bestFinalMisMatch == null || bestFinalMisMatch.totalErrors < bestDataFinal.totalErrors)
                    {
                        bestFinalMisMatchDataIndex     = bestDataIndex;
                        bestFinalMisMatchTableRowIndex = tableRowIndex;
                        bestFinalMisMatch = bestDataFinal;
                        killLoop          = false;
                        continue;
                    }
                }

                // if there is a Match Add it.
                if (bestFinalMisMatch != null)
                {
                    AddFinalMatch(bestFinalMisMatchTableRowIndex, bestFinalMisMatchDataIndex, bestFinalMisMatch, MatchQuality.Partial);
                }
            }

            for (int dataItemIndex = 0; dataItemIndex < _dataItemsCount; dataItemIndex++)
            {
                if (DataToTableRowCompareRowFinals[dataItemIndex] != null)
                {
                    continue;
                }

                var MissingRow = tableRowToDataCompares[_tableRowsCount, dataItemIndex];

                AddFinalMatch(_tableRowsCount, dataItemIndex, MissingRow, MatchQuality.None);
            }
        }
        private void AddFinalMatch(int tableRowIndex, int dataIndex, CompareRowResult rowResult, MatchQuality matchQuality)
        {
            // Missing TableRows are not added to final
            if (tableRowIndex != _tableRowsCount)
            {
                // A Match calls us to action.
                // We need to remove previous compares.
                // So, that when we finalize... Matches won't get confused with other Match Data
                for (int dataForIndex = 0; dataForIndex < _dataItemsCount; dataForIndex++)
                {
                    tableRowToDataCompares[tableRowIndex, dataForIndex] = null;
                }

                var tableRowCompareMatchResult = new CompareRowFinalResult();
                tableRowCompareMatchResult.compareRowResult = rowResult;
                tableRowCompareMatchResult.matchQuality = matchQuality;
                tableRowCompareMatchResult.index = dataIndex;
                TableRowToDataCompareRowFinals[tableRowIndex] = tableRowCompareMatchResult;
            }

            // Missing Datas are not added to final
            if (dataIndex != _dataItemsCount)
            {
                for (int tableRowForIndex = 0; tableRowForIndex < _tableRowsCount; tableRowForIndex++)
                {
                    tableRowToDataCompares[tableRowForIndex, dataIndex] = null;
                }

                var dataCompareMatchResult = new CompareRowFinalResult();
                dataCompareMatchResult.compareRowResult = rowResult;
                dataCompareMatchResult.matchQuality = matchQuality;
                dataCompareMatchResult.index = tableRowIndex;
                DataToTableRowCompareRowFinals[dataIndex] = dataCompareMatchResult;
            }
        }