Giter VIP home page Giter VIP logo

vba-sequencematcher's Introduction

VBA-SequenceMatcher

Abstarct

Text diff scripts in VBA (Word), partially ported from Python difflib.SequenceMathcer.

Implemented methods:

  • set_seq1
  • set_seq2
  • set_seqs
  • find_longest_match
  • get_matching_blocks
  • sort_blocks *
  • get_opcode
  • calculate_ratio
  • ratio
  • quick_ratio
  • real_quick_ratio

* represents original method of vba version. NOTE that junk function has not benn implemented yet

This repository is under the license of PSFL.

Usage

"SequenceMather.cls" is the entity of SequenceMathcer. You can create a instance in any modules. NOTE that junk function has not benn implemented yet

Dim seq As SequenceMatcher
Dim seg1 As String, seg2 As String

Set seq = New SequenceMatcher
seg1 = "lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur"
seg2 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."

Call seq.set_seqs(seg1, seg2)

Debug.Print "---RATIO---"
Debug.Print seq.ratio
Debug.Print "---QUICK_RATIO---"
Debug.Print seq.quick_ratio
Debug.Print "---REAL_QUICK_RATIO---"
Debug.Print seq.real_quick_ratio

This code results in:

---RATIO---
 0.989505231380463 
---QUICK_RATIO---
 0.989505231380463 
---REAL_QUICK_RATIO---
 0.998500764369965 

and native python goes:

---RATIO---
0.9895052473763118
---QUICK_RATIO---
0.9895052473763118
---REAL_QUICK_RATIO---
0.9985007496251874

Applying Opcode

Another bas module "WordSeqApplyer" has a sub procedure named "apply_opcode". It can rewrite the text in document with revision according to the opcode. For more details, please see the file "test.docm", press "Alt+F8" and run "WordSeqApplyer.main".

vba-sequencematcher's People

Contributors

cpkobo avatar

Stargazers

 avatar enigma158an201 avatar monstar avatar Justin Xu avatar

Watchers

 avatar

vba-sequencematcher's Issues

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.