* [patch] Incorrect result of org-babel-edit-distance
@ 2012-12-06 15:46 Nicolas Richard
2012-12-07 19:43 ` Eric Schulte
0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Richard @ 2012-12-06 15:46 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
Hello,
(org-babel-edit-distance "foo" "ffoo") returns 0, whereas 1 seems
appropriate. I don't know much about computing the levenshtein distance,
but it seems that part of the algorithm (which i found explained on
fr.wikipedia) is missing from the code. Please find a patch below trying
to address the issue.
--
Nico.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-Fix-org-babel-edit-distance-for-insertion-deletio.patch --]
[-- Type: text/x-patch, Size: 1686 bytes --]
From 448cecaf3d6618274719fc6fa96f278b7202b784 Mon Sep 17 00:00:00 2001
From: "nrichard (geodiff-mac3)" <nrichard@ulb.ac.be>
Date: Thu, 6 Dec 2012 16:38:44 +0100
Subject: [PATCH] ob: Fix org-babel-edit-distance for insertion/deletion
* lisp/ob.el (org-babel-edit-distance): When insertion or deletion are
needed, make sure the distance is incremented. In addition, the now
obsolete mmin function was removed.
---
lisp/ob.el | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/lisp/ob.el b/lisp/ob.el
index c030a7f..0aba523 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -629,16 +629,19 @@ arguments and pop open the results in a preview buffer."
(l2 (length s2))
(dist (vconcat (mapcar (lambda (_) (make-vector (1+ l2) nil))
(number-sequence 1 (1+ l1)))))
- (in (lambda (i j) (aref (aref dist i) j)))
- (mmin (lambda (&rest lst) (apply #'min (remove nil lst)))))
+ (in (lambda (i j) (aref (aref dist i) j))))
(setf (aref (aref dist 0) 0) 0)
+ (dolist (j (number-sequence 1 l2))
+ (setf (aref (aref dist 0) j) j))
(dolist (i (number-sequence 1 l1))
+ (setf (aref (aref dist i) 0) i)
(dolist (j (number-sequence 1 l2))
(setf (aref (aref dist i) j)
- (+ (if (equal (aref s1 (1- i)) (aref s2 (1- j))) 0 1)
- (funcall mmin (funcall in (1- i) j)
- (funcall in i (1- j))
- (funcall in (1- i) (1- j)))))))
+ (min
+ (1+ (funcall in (1- i) j))
+ (1+ (funcall in i (1- j)))
+ (+ (if (equal (aref s1 (1- i)) (aref s2 (1- j))) 0 1)
+ (funcall in (1- i) (1- j)))))))
(funcall in l1 l2)))
(defun org-babel-combine-header-arg-lists (original &rest others)
--
1.8.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [patch] Incorrect result of org-babel-edit-distance
2012-12-06 15:46 [patch] Incorrect result of org-babel-edit-distance Nicolas Richard
@ 2012-12-07 19:43 ` Eric Schulte
0 siblings, 0 replies; 2+ messages in thread
From: Eric Schulte @ 2012-12-07 19:43 UTC (permalink / raw)
To: Nicolas Richard; +Cc: emacs-orgmode
"Nicolas Richard" <theonewiththeevillook@yahoo.fr> writes:
> Hello,
>
> (org-babel-edit-distance "foo" "ffoo") returns 0, whereas 1 seems
> appropriate. I don't know much about computing the levenshtein distance,
> but it seems that part of the algorithm (which i found explained on
> fr.wikipedia) is missing from the code. Please find a patch below trying
> to address the issue.
>
Applied. Thanks!,
--
Eric Schulte
http://cs.unm.edu/~eschulte
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-12-07 19:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-06 15:46 [patch] Incorrect result of org-babel-edit-distance Nicolas Richard
2012-12-07 19:43 ` Eric Schulte
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.