Adjusting comparison sensitivity

On this page

GroupDocs.Comparison allows you to adjust comparison sensitivity to achieve the necessary balance between the comparison speed and accuracy. Possible comparison sensitivity values range is from 0 to 100.

  • Minimal value (0) sets sensitivity to a minimal value provides the fastest comparison speed, but it may produce worst comparison quality. If there is at least one common letter in two compared words then these words are not treated as fully inserted and deleted
  • Value by default means 75. Comparison occurs when the percentage of deleted or inserted elements in relation to all elements does not exceed 75%
  • Maximum value (100) provides the best quality, but slowest comparison speed. Comparison occurs at any length of a common sub-sequence of two compared objects

For better understanding about how comparison algorithms work let’s suppose we have two strings:

Strings
1``. It is our equity poetry
2``. Jack is a glad calf

So, these strings have two common sub-sequences: “is” word and 4 space symbols. 
Common sub-sequence is - " is " and its length is 4 symbols (there are 2 space symbols in it).
Length of inserted sub-sequence is 13 symbols - Jackagladcalf
Removed sub-sequence length is 17 symbols - **Itourequitypoetry*_
Lets calculate percent of removed and inserted symbols: (17 + 13) / (17 + 13 + 4) * 100 = 88%

Case 1. If SensitivityOfComparison = 80% comparison of these two strings produces the next result:
Jack is a glad calfIt is our equity poetry

Because calculated percent of removed and inserted symbols equals 88% and it is bigger than value of SensitivityOfComparison equals 80% then this common sub-sequence will be not taken into account.
The first string considered completely removed and the second string considered completely inserted. The same results are produced for any calculated percent less than 83%.

Case 2. If SensitivityOfComparison = 89%, comparison of these two strings produces the next result:
JackIt is aour gladequity calfpoetry

Common sub-sequence was found, because 89% > 88%. The same results are produced for any calculated percent bigger than 88%.

To compare documents with specific comparison sensitivity, follow these steps:

  1. Instantiate the Comparer object. Specify the source document path or stream.
  2. Call the add() method. Specify the target document path or stream.
  3. Instantiate the CompareOptions object. Call the setSensitivityOfComparison() method to specify the appropriate value.
  4. Call the compare() method. Specify the CompareOptions object.

The following code snippet shows how to compare documents with specific sensitivity:

try (Comparer comparer = new Comparer(sourceFile)) {
    comparer.add(targetFile);

    CompareOptions compareOptions = new CompareOptions();
    compareOptions.setSensitivityOfComparison(100);

    final Path resultPath = comparer.compare(resultFile, compareOptions);
}

The result is as follows:

SensitivityOfComparison = 50SensitivityOfComparison = 100

On this page