GeezerVison is showing github.com — Diff by phrase functionality? · Issue #14 · java-diff-utils/java-diff-utils
Diff by phrase functionality? #14DescriptionThanks a lot for this project. I was wondering if something can be done to achieve the following. Let's say I have 2 versions of a string:
"J. G. Feldstein, Chair" and "T. P. Pastor, Chair"
When using character level diff, I get this result:

Makes sense, of course, since it diffs by character and keeps all the ones that were there before. Id I diff by word, this happens:

Again, makes sense. However, this makes it difficult for a user to understand what happens. What would be great is if we could "whitelist" a few characters, so that they don't count on the diff, and use it in phrase level. So in that case, if we whitelist whitespace and punctuation, we could get:

Would this be feasible and/or possible? Activitywumpz commented on Nov 9, 2017 That would be possible but needed a change. At the moment there is a SPLIT_PATTERN defined to separate words. This pattern needs to be adjusted, or better a function needs to be injected to do character, word or like you call it phrase processing.
I would suggest an API change that would remove inlineDiffByWord and replace it with some kind of splitFunction to make this completely adjustable or by inlineDiffByPattern and make this SPLIT_PATTERN modifiable. wumpz commented on Nov 9, 2017 Please look at DiffRowGeneratorTest.testGeneratorIssue14. Is that what you meant? If I missunderstood you the implemented modifiable splitter is nevertheless a new feature. ;)
The output of this test is:
J. G. FeldsteinT. P. Pastor, Chair
The inline splitter is responsible for splitting the source line into blocks to compare (characters, words, phrases). Its up to you to configure it the way you want it to behave. Lilykos commented on Nov 13, 2017 Yes, working nicely! Thanks a lot for your efforts! wumpz commented on Nov 13, 2017 By the way. Did you know, it's been deployed to maven central? The-Lum commented on Mar 27, 2023 Hello @wumpz, and all,
How to make a test similar to:
|
public void testGeneratorIssue14() { |
|
DiffRowGenerator generator = DiffRowGenerator.create() |
|
.showInlineDiffs(true) |
|
.mergeOriginalRevised(true) |
|
.inlineDiffBySplitter(line -> DiffRowGenerator.splitStringPreserveDelimiter(line, Pattern.compile(","))) |
|
.oldTag(f -> "~") |
|
.newTag(f -> "**") |
|
.build(); |
In my test, I have always this error:
error: splitStringPreserveDelimiter(String,Pattern) has protected access in DiffRowGenerator
.inlineDiffBySplitter(line -> DiffRowGenerator.splitStringPreserveDelimiter(line, Pattern.compile(",")))
^
- How to proper call this method?
Regards.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|