Re[2]: Percentage matching of text

B

Bruce Eckel

Ah, but here's an interesting one:
0.5

So if it matches half the string it's 50% but if the last two
characters are out of order that's an additional 25%.

Other examples:
1.0

You get a different interpretation for each "speed" of ratio.

I started thinking that all I wanted was a pass-fail kind of thing so
I wondered if real_quick_ratio() might do the trick. But with the
following experiments:
1.0

It seems like there's no way to get real_quick_ratio() to say anything
except "it's a perfect match!" I'm wondering if someone didn't leave a
code stub unwritten:

def real_quick_ratio(self): return 1.0



[Bruce Eckel]
...
What I'd like to do is find an algorithm that produces the results of
a text comparison as a percentage-match. Thus I would be able to
assert that my test samples must match the control sample by at least
(for example) 83% for the test to pass.
SequenceMatcher works on sequences of hashable elements. Above, it's
working on sequence of characters (aka "strings" <wink>). Other
possibilites include sequences of lines ("files") and lists of
integers.


Bruce Eckel http://www.BruceEckel.com mailto:[email protected]
Contains electronic books: "Thinking in Java 3e" & "Thinking in C++ 2e"
Web log: http://www.mindview.net/WebLog
Subscribe to my newsletter:
http://www.mindview.net/Newsletter
My schedule can be found at:
http://www.mindview.net/Calendar

"The whole problem with the world is that fools and fanatics are always
so certain of themselves, and wiser people so full of doubts."
--Bertrand Russell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top