belambert / cl-edit-distance

A Common Lisp implementation of edit distance.
Creative Commons Attribution 4.0 International
5 stars 0 forks source link

PRINT-DIFFERENCES: #<TYPE-ERROR expected-type: SEQUENCE datum: #\p> #1

Open phmarek opened 6 years ago

phmarek commented 6 years ago

Hi,

first of all, thank you for this library!

Sadly it doesn't seem to work as expected, or at least as expected by me (sorry! ;).

PRINT-DIFFERENCES says Given a 'path' as produced by the above function LEVENSTEIN-DISTANCE function above, but trying to do that I get a type error:

(edit-distance:print-differences 
  (edit-distance:levenshtein-distance
    "foo1"
    "foo2"
    :test #'eql
    :return-path t)
  )
#<TYPE-ERROR expected-type: SEQUENCE datum: #\f>

I guess I'm misunderstanding how that should be used, so perhaps the solution is a better doc-string?!

belambert commented 6 years ago

Thanks for trying it out! I haven't used this lately and was just cleaning it up.

Looks like this is a bug actually, for when the sequences are strings. I think I have a partial fix that I'm about to push. The fix will cause it to not error, but the printed diff still won't be useful to you. The print-diff function capitalizes the string elements to indicate a substitution, but that's not meaningful for numeric elements. So the diff of "foo1" and "foo2" is:

NIL: #\f #\o #\o #\1 
NIL: #\f #\o #\o #\2 

Insertions and deletions are visible:

NIL: #\f #\o #\o #\1 
NIL: #\f #\o #\o *** 

Non-numeric substitutions are visible, e.g. "Fool" vs. "Food":

NIL: #\f #\o #\o #\L 
NIL: #\f #\o #\o #\D 

Let me know if that helps for now.

In the meantime, I'll have to figure out a better way to show the errors, perhaps ANSI colors is one option.

phmarek commented 6 years ago

Well, ANSI colors aren't that easy to handle across the REPL; you could try to send them like this:

`( #\f  #\o  #\o '#\1)
`( #\f  #\o  #\o '#\2)

Ie. return two values, and highlight differences in them via (single)quoting, to have the syntax coloring do the work for you.

belambert commented 6 years ago

That's an interesting idea. I'll have to give it a little thought. In the meantime, anyone could write their own print function using the return value of diff.