|
| 1 | +--- |
| 2 | +id: adjusting-comparison-sensitivity |
| 3 | +url: comparison/java/adjusting-comparison-sensitivity |
| 4 | +title: Adjusting comparison sensitivity |
| 5 | +weight: 2 |
| 6 | +description: "" |
| 7 | +keywords: |
| 8 | +productName: GroupDocs.Comparison for Java |
| 9 | +hideChildren: False |
| 10 | +--- |
| 11 | +**[GroupDocs.Comparison](https://products.groupdocs.com/comparison/java)** allows to adjust comparison sensitivity to achieve the necessary balance between file comparison speed and accuracy. Possible comparison sensitivity values range is from **0** to **100**. |
| 12 | + |
| 13 | +* **Minimal value** - the minimal value is **0**. Setting sensitivity to a minimal value provides the fastest comparison speed, but it may produce worst comparison quality. |
| 14 | + If there is at least one common letter in two compared words then these words will not be treated as fully inserted and deleted |
| 15 | +* **Value by default** - the default value is **75**. Comparison occurs when the percentage of deleted or inserted elements in relation to all elements does not exceed 75%. |
| 16 | +* **Maximum value** - the maximum values is **100**. Comparison occurs at any length of a common sub-sequence of two compared objects. This option provides the best quality, but slowest comparison speed. |
| 17 | + |
| 18 | +For better understanding about how comparison algorithms work let's suppose we have two strings: |
| 19 | + |
| 20 | +```java |
| 21 | +1. It is our equity poetry |
| 22 | +2. Jack is a glad calf |
| 23 | +``` |
| 24 | + |
| 25 | +*Case 1.* If **SensitivityOfComparison = 80%** comparison of these two strings will produce the next result:We will highlight removed text parts with **red **and inserted parts with **blue** color. So, these strings have two common sub-sequences: **"is "** word and 4 space symbols. |
| 26 | +Common sub-sequence is - **"is "** and its length is 6 symbols (there are 4 space symbols in it). |
| 27 | +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 + 6) \* 100 = 83% |
| 28 | + |
| 29 | +**Jack is a glad calf****It is our equity poetry** |
| 30 | + |
| 31 | +Because calculated percent of removed and inserted symbols equals **83%** and it is bigger than value of **SensitivityOfComparison** (equals **80%**) then this common sub-sequence will be not taken into account. |
| 32 | +The first string considered completely removed and the second string considered completely inserted. The same results will be produced for any calculated percent less than **83%**. |
| 33 | + |
| 34 | +*Case 2. *If**SensitivityOfComparison = 85%**, comparison of these two strings will produce the next result: |
| 35 | +**Jack****It**** is ****a****our****glad****equity****calf****poetry** |
| 36 | + |
| 37 | +Common sub-sequence was found, because **85% > 83%**. The same results will be produced for any calculated percent bigger than **83%**. |
| 38 | + |
| 39 | +Here are the steps to compare files with specific comparison sensitivity: |
| 40 | + |
| 41 | +* Instantiate [Comparer](https://apireference.groupdocs.com/comparison/java/com.groupdocs.comparison/Comparer) objectwith source file path or stream; |
| 42 | +* Call [add](https://apireference.groupdocs.com/comparison/java/com.groupdocs.comparison/Comparer#add(java.lang.String)) method and specify target file path or stream. |
| 43 | +* Instantiate [CompareOptions](https://apireference.groupdocs.com/comparison/java/com.groupdocs.comparison.options/CompareOptions) object with desired [setSensitivityOfComparison](https://apireference.groupdocs.com/comparison/java/com.groupdocs.comparison.options/CompareOptions#getSensitivityOfComparison()) value; |
| 44 | +* Call [compare](https://apireference.groupdocs.com/comparison/java/com.groupdocs.comparison/Comparer#compare(java.lang.String,%20com.groupdocs.comparison.options.CompareOptions)) method and pass [CompareOptions](https://apireference.groupdocs.com/comparison/java/com.groupdocs.comparison.options/CompareOptions) object to method; |
| 45 | + |
| 46 | + |
| 47 | +The following code snippet demonstrates how compare files with specific sensitivity: |
| 48 | + |
| 49 | +## Compare files with sensitivity adjustment |
| 50 | + |
| 51 | +```java |
| 52 | +Comparer comparer = new Comparer("C:\\source.pdf"); |
| 53 | +try { |
| 54 | + comparer.add("C:\\target.pdf"); |
| 55 | + |
| 56 | + CompareOptions compareOptions = new CompareOptions(); |
| 57 | + compareOptions.setSensitivityOfComparison(100); |
| 58 | + |
| 59 | + comparer.compare("C:\\result.pdf", compareOptions); |
| 60 | +} finally { |
| 61 | + comparer.dispose(); |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +## More resources |
| 66 | + |
| 67 | +### GitHub Examples |
| 68 | +You may easily run the code above and see the feature in action in our GitHub examples: |
| 69 | + |
| 70 | +* [GroupDocs.Comparison for Java examples, plugins, and showcase](https://github.com/groupdocs-comparison/GroupDocs.Comparison-for-Java) |
| 71 | +* [GroupDocs.Comparison for .NET examples, plugins, and showcase](https://github.com/groupdocs-comparison/GroupDocs.Comparison-for-.NET) |
| 72 | +* [Document Comparison for Java App Dropwizard UI Modern Example](https://github.com/groupdocs-comparison/GroupDocs.Comparison-for-Java-Dropwizard) |
| 73 | +* [Document Comparison for Java Spring UI Example](https://github.com/groupdocs-comparison/GroupDocs.Comparison-for-Java-Spring) |
| 74 | +* [Document Comparison for .NET MVC UI Example](https://github.com/groupdocs-comparison/GroupDocs.Comparison-for-.NET-MVC) |
| 75 | +* [Document Comparison for .NET App WebForms UI Modern Example](https://github.com/groupdocs-comparison/GroupDocs.Comparison-for-.NET-WebForms) |
| 76 | + |
| 77 | + |
| 78 | +### Free Online App |
| 79 | +Along with full-featured Java library we provide simple, but powerful free Apps. |
| 80 | +You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSGand other documents with free to use online **[GroupDocs Comparison App](https://products.groupdocs.app/comparison)**. |
0 commit comments