GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Diff by phrase functionality? · Issue #14 · java-diff-utils/java-diff-utils

Diff by phrase functionality? #14

New issue
Copy link
New issue
Copy link
Closed
Closed
Diff by phrase functionality?#14
Copy link

Description

@Lilykos
Lilykos
opened on Nov 9, 2017
Issue body actions

Thanks 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:
image

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:
image

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:
image

Would this be feasible and/or possible?

Activity

  1. wumpz commented on Nov 9, 2017

    @wumpz
    wumpz
    on Nov 9, 2017
    Collaborator
    More actions

    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.

  2. wumpz
    closed this as completedin 4f6f8dbon Nov 9, 2017
  3. wumpz
    reopened this on Nov 9, 2017
  4. wumpz commented on Nov 9, 2017

    @wumpz
    wumpz
    on Nov 9, 2017
    Collaborator
    More actions

    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.

  5. Lilykos commented on Nov 13, 2017

    @Lilykos
    Lilykos
    on Nov 13, 2017
    Author
    More actions

    Yes, working nicely! Thanks a lot for your efforts!

  6. wumpz commented on Nov 13, 2017

    @wumpz
    wumpz
    on Nov 13, 2017
    Collaborator
    More actions

    By the way. Did you know, it's been deployed to maven central?

  7. wumpz
    closed this as completedon Nov 13, 2017
  8. The-Lum commented on Mar 27, 2023

    @The-Lum
    The-Lum
    on Mar 27, 2023
    More actions

    Hello @wumpz, and all,

    How to make a test similar to:

    java-diff-utils/java-diff-utils/src/test/java/com/github/difflib/text/DiffRowGeneratorTest.java

    Lines 285 to 292 in 02532a9

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.