Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: [OT] Finding similar program code

by bliako (Monsignor)
on Aug 27, 2021 at 12:35 UTC ( [id://11136132]=note: print w/replies, xml ) Need Help??


in reply to [OT] Finding similar program code

I would first try to make the code look as simple as possible (from the point of view of a pattern matching algorithm. Not a human). For example, why have all kind of whitespace instead of just one, a newline say (EDIT: or none at all)? You can compress the code a bit by replacing repeated, small chunks of it with a word from compression-vocabulary. So that pattern matchings can be faster. For example ActiveSheet.Cells can become _ASC_.

If there was a VBA-to-bytecode, it could be used instead of the above (perhaps). (EDIT: no, unless you can convert it back to VBA code.)

After that, your task may be similar to DNA matching. And there exist efficient algorithms (implemented) for doing that and spotting common sections between 2 DNA sequences. See Boyer–Moore_string-search_algorithm. And also this for more food for thought: https://www.hindawi.com/journals/bmri/2019/7074387/

Of course there are linguistic approaches to this too (but code is NOT human-text): https://www.baeldung.com/cs/ml-similarities-in-text and https://towardsdatascience.com/the-best-document-similarity-algorithm-in-2020-a-beginners-guide-a01b9ef8cf05 will give you ideas.

bw, bliako

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11136132]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-20 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found