Coder Social home page Coder Social logo

javalc6 / stringdiff2 Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 32 KB

A java application that highlights text differences between two plain strings based on longest common subsequences

License: GNU General Public License v2.0

Java 100.00%
compare-strings compare-text java string-compare string-comparison string-differences strings text-compare text-comparison text-diff

stringdiff2's Introduction

StringDiff2

This java application highlights text differences between two plain strings by generating html fragment to show changes, based on longest common subsequences.

The markTextDiff2() markups changes between text1 and text2 using the longestCommonSubsequence() method.

The Hirschberg algorithm provides Longest Common Subsequence using a linear amount of memory.

Java 8 or later is required to run the application.

Compile

Run following command to build the application:

javac StringDiff2.java

Run

Just use the following command to run the application:

java StringDiff2

Example

Setting the following strings:

text1 = "Do not change this section. Please check any misqelling! Note that this section is obsolete.";
text2 = "New section added. Do not change this section. Please check any mispelling!";

running the command "java StringDiff2" will generate the following html fragment:

<ins style='background-color:#00ff66'>New section added. </ins>Do not change this section. Please check any mis<del style='background-color:#ff9933'>q</del><ins style='background-color:#00ff66'>p</ins>elling!<del style='background-color:#ff9933'> Note that this section is obsolete.</del>

If you load the html fragment with a browser, you get the following result:

html fragment in a browser

Credits

The java implementation of the longest common subsequence Hirschberg algorithm is credited to https://commons.apache.org/proper/commons-text/index.html

Caveat

This algorithm has O(n * m) complexity. In case of very long strings it is very slow.

stringdiff2's People

Contributors

javalc6 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.