Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
compare nested lists
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jens Teich  
View profile  
 More options Dec 21 2008, 5:09 pm
Newsgroups: comp.lang.lisp
From: Jens Teich <spamt...@jensteich.de>
Date: Sun, 21 Dec 2008 23:09:36 +0100
Local: Sun, Dec 21 2008 5:09 pm
Subject: compare nested lists
I have different versions of nested lists generated from XML files and
want to find ('highlight') the differences. The problem is similar to
the history tag on wikipedia where differences of different versions of
the same article are displayed.

Before I get my own hands dirty I wanted to ask if there are already
solutions out there. I have problems to find useful search terms for
google. Tried 'differences nested lists trees' and stuff like
that. Hints for more specific search terms are welcome.

Jens


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xah Lee  
View profile  
 More options Dec 21 2008, 6:41 pm
Newsgroups: comp.lang.lisp
From: Xah Lee <xah...@gmail.com>
Date: Sun, 21 Dec 2008 15:41:11 -0800 (PST)
Local: Sun, Dec 21 2008 6:41 pm
Subject: Re: compare nested lists
On Dec 21, 2:09 pm, Jens Teich <spamt...@jensteich.de> wrote:

> I have different versions of nested lists generated from XML files and
> want to find ('highlight') the differences. The problem is similar to
> the history tag on wikipedia where differences of different versions of
> the same article are displayed.

> Before I get my own hands dirty I wanted to ask if there are already
> solutions out there. I have problems to find useful search terms for
> google. Tried 'differences nested lists trees' and stuff like
> that. Hints for more specific search terms are welcome.

> Jens

i don't have answer for you, but here's some thoughts.

if your xml is valid xml, then the problem is threotecially trivial.
Basically, you just have tree A and B. It is easy to compare how 2
trees differ. You can implement this by using a xml parser, then just
decent on the tree ...
This solution doesn't deal with xml “attributes”...

another simple, practical, semi solution is simply to insert a newline
char to all tags so that each tag is on a line. Then, just use diff on
them.

depending on how many such files you need to compare or whether you
need this as algorithm implemented in a program ... but if just a few
files or only need manual process, then emacs can easily handle it.

i'm suppossing you need this as a algorithm in a program... i think
asking in XML parsing communities will help.

reading Wikipedia on XML and all associated articles about XML
transformation will probably turn up helpful leads.

  Xah
http://xahlee.org/



    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Madhu  
View profile  
 More options Dec 21 2008, 10:09 pm
Newsgroups: comp.lang.lisp
From: Madhu <enom...@meer.net>
Date: Mon, 22 Dec 2008 08:39:28 +0530
Local: Sun, Dec 21 2008 10:09 pm
Subject: Re: compare nested lists

* Jens Teich <m2wsdttc2n....@jensteich.de> :
Wrote on Sun, 21 Dec 2008 23:09:36 +0100:

| I have different versions of nested lists generated from XML files and
| want to find ('highlight') the differences. The problem is similar to
| the history tag on wikipedia where differences of different versions of
| the same article are displayed.
|
| Before I get my own hands dirty I wanted to ask if there are already
| solutions out there. I have problems to find useful search terms for
| google. Tried 'differences nested lists trees' and stuff like
| that. Hints for more specific search terms are welcome.

You might try to find `mytrie.lisp' for a prototype of how I tried
dealing with this problem by using a prefix tree datastructure.
Specifically the COMM-TRIE function.  I use this for implementing
functions that compare trees for display and manipulation, especially
directory trees.

--
Madhu


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
budden  
View profile  
 More options Dec 22 2008, 7:47 am
Newsgroups: comp.lang.lisp
From: budden <budden-l...@mail.ru>
Date: Mon, 22 Dec 2008 04:47:37 -0800 (PST)
Local: Mon, Dec 22 2008 7:47 am
Subject: Re: compare nested lists
Hi!

> I have different versions of nested lists generated from XML files and
> want to find ('highlight') the differences. The problem is similar to
> the history tag on wikipedia where differences of different versions of
> the same article are displayed.

Try this:

(defmacro let1 (defvar defparameter &body progn) "Shortcut for (let
((a b)) c) "
          `(let ((,defvar ,defparameter)) ,@progn))

(defun struct-to-alist (struct)
  (error
  "If you want compare structures, you need to write one using your
implementation's introspection. Consult SLIME source"))

(defun tree-to-atree-2 (tree) "let tree contain lists, alists and
structs. tree-to-atree-2 makes alist where: structures are converted
to alist with keys=slot names. Lists are converted to alist with
keys=item indices. For proper alists, keys are kept and values are
processed recursively"
  (cond
   ((typep (class-of tree) 'structure-class)
    (tree-to-atree-2 (struct-to-alist tree)))
   ((alistp tree) (mapcar (lambda (x) `(,(car x) . ,(tree-to-atree-2
(cdr x)))) tree))
   ((consp tree) (tree-to-atree-2 (list-to-alist-2 tree)))
   ((numbers-in-string-p tree) (cons '(:nums . :nuums) (tree-to-
atree-2 (read-from-string (str+ "(" tree ")")))))
   (t tree)))

(defun tree-weight (tree)
  (cond
   ((atom tree) 0)
   (t (+ 1 (tree-weight (car tree)) (tree-weight (cdr tree))))))

(defvar *compare-atrees-context* nil)

(defun compare-atrees (left right &key (test #'equalp))
"return nil if atrees are 'equal' (keys are the same and corresponding
values satisfy the test). Otherwise, returns mismatch-map"
  (cond
   ((and (atom left) (atom right))
    (let1 the-same (funcall test left right)
      (if the-same nil
        (if (and (numberp left) (numberp right) (/= 0 (* left right)))
            (let1 err
                (let ((left (abs left)) (right (abs right))) (- (/
(max left right) (min left right)) 1))
              (setf *max-error* (max err *max-error*))
            `(:l ,left :r ,right :err ,err))))))
   (t
    (let*
        ((lkeys (mapcar #'car left))
         (rkeys (mapcar #'car right))
         (keys-missing-on-right
          (set-difference lkeys rkeys :test #'equalp))
         (keys-missing-on-left
          (set-difference rkeys lkeys :test #'equalp))
         (kvs-different
          (loop for key in (intersection lkeys rkeys :test #'equalp)
                for lv = (cdr (assoc key left :test #'equalp))
                for rv = (cdr (assoc key right :test #'equalp))
                for mismatch = (compare-atrees lv rv :test test)
                when (and (eq key 'cllib::name) ;
                          (equalp lv "Value")) ;
                do (setf *compare-atrees-context* (mapcar (lambda (x) `
(,(car x) ,(cdadr x))) (cdr (assoc 'cllib::args left)))) ;
                if mismatch
                if (> (tree-weight mismatch) 10)  ;
                collect `(,key ,mismatch)
                else  ;
                collect `(,*compare-atrees-
context* ,key ,mismatch))) ;
         (result nil)
         )
      (when keys-missing-on-left
        (push `(:miss-left ,@keys-missing-on-left) result))
      (when keys-missing-on-right
        (push `(:miss-right ,@keys-missing-on-right) result))
      (when kvs-different
        (push `(:diff ,@kvs-different) result))
      (nreverse result)))))

This is cutted from "production" code, some bits may be missing. Write
if you have problems.

-----------------
$5/hour cl freelancer


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
budden  
View profile  
 More options Dec 22 2008, 7:52 am
Newsgroups: comp.lang.lisp
From: budden <budden-l...@mail.ru>
Date: Mon, 22 Dec 2008 04:52:51 -0800 (PST)
Local: Mon, Dec 22 2008 7:52 am
Subject: Re: compare nested lists
One missing thing is
(defun str+ (&rest args) (apply 'concatenate 'string (mapcar 'string
args))) (export 'str+)

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Madhu  
View profile  
 More options Dec 22 2008, 10:43 am
Newsgroups: comp.lang.lisp
From: Madhu <enom...@meer.net>
Date: Mon, 22 Dec 2008 21:13:50 +0530
Local: Mon, Dec 22 2008 10:43 am
Subject: Re: compare nested lists
* Jens Teich <m2wsdttc2n....@jensteich.de> :
Wrote on Sun, 21 Dec 2008 23:09:36 +0100:

| I have different versions of nested lists generated from XML files and
| want to find ('highlight') the differences. The problem is similar to
| the history tag on wikipedia where differences of different versions of
| the same article are displayed.
|
| Before I get my own hands dirty I wanted to ask if there are already
| solutions out there.

Or, you may be able to just use

<URL:http://www.foldr.org/~michaelw/lisp/diff-sexp.lisp>

--
Madhu


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Albert Krewinkel  
View profile  
 More options Dec 22 2008, 5:01 pm
Newsgroups: comp.lang.lisp
From: Albert Krewinkel <krewin...@gmx.net>
Date: Mon, 22 Dec 2008 14:01:11 -0800
Local: Mon, Dec 22 2008 5:01 pm
Subject: Re: compare nested lists

Jens Teich <spamt...@jensteich.de> writes:
> I have different versions of nested lists generated from XML files and
> want to find ('highlight') the differences. The problem is similar to
> the history tag on wikipedia where differences of different versions of
> the same article are displayed.

> Before I get my own hands dirty I wanted to ask if there are already
> solutions out there. I have problems to find useful search terms for
> google. Tried 'differences nested lists trees' and stuff like
> that. Hints for more specific search terms are welcome.

> Jens

http://lemonodor.com/archives/001226.html

HTH
Albert


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jens Teich  
View profile  
 More options Dec 22 2008, 6:25 pm
Newsgroups: comp.lang.lisp
From: Jens Teich <spamt...@jensteich.de>
Date: Tue, 23 Dec 2008 00:25:36 +0100
Local: Mon, Dec 22 2008 6:25 pm
Subject: Re: compare nested lists

Madhu <enom...@meer.net> writes:
> | I have different versions of nested lists generated from XML files and
> | want to find ('highlight') the differences. The problem is similar to
> | the history tag on wikipedia where differences of different versions of
> | the same article are displayed.
> |
> | Before I get my own hands dirty I wanted to ask if there are already
> | solutions out there.

> Or, you may be able to just use

> <URL:http://www.foldr.org/~michaelw/lisp/diff-sexp.lisp>

This does exactly what I was looking for, thanx!

Jens


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jens Teich  
View profile  
 More options Dec 22 2008, 6:47 pm
Newsgroups: comp.lang.lisp
From: Jens Teich <spamt...@jensteich.de>
Date: Tue, 23 Dec 2008 00:47:35 +0100
Local: Mon, Dec 22 2008 6:47 pm
Subject: Re: compare nested lists

budden <budden-l...@mail.ru> writes:
> This is cutted from "production" code, some bits may be missing. Write
> if you have problems.

Thanks for your code. I get some undefined variables:

*COMPARE-ATREES- *MAX-ERROR* ATREE-2

Jens


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jens Teich  
View profile  
 More options Dec 22 2008, 6:52 pm
Newsgroups: comp.lang.lisp
From: Jens Teich <spamt...@jensteich.de>
Date: Tue, 23 Dec 2008 00:52:43 +0100
Local: Mon, Dec 22 2008 6:52 pm
Subject: Re: compare nested lists

Albert Krewinkel <krewin...@gmx.net> writes:
> http://lemonodor.com/archives/001226.html

Hallo Albert !

That is the same as the link already posted. But thanks anyway.

Jens


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
budden  
View profile  
 More options Dec 23 2008, 3:16 am
Newsgroups: comp.lang.lisp
From: budden <budden-l...@mail.ru>
Date: Tue, 23 Dec 2008 00:16:00 -0800 (PST)
Subject: Re: compare nested lists
*Compare-atrees-
and
atree-2
are due to line auto-wrapping. It is easy to fix just by removing some
extra newlines:

... (tree-to-<PASTE>
atree-2 (read-from-string (str+ "(" tree ")")))))

collect `(,*compare-atrees-<PASTE>
context*

You can set *MAX-ERROR* to 0 prior to comparing and then
it will return maximum mismatch between corresponding numeric values
(this code was used to compare results of numeric calculations which
were
loaded from XML)


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jens Teich  
View profile  
 More options Dec 23 2008, 7:24 am
Newsgroups: comp.lang.lisp
From: Jens Teich <spamt...@jensteich.de>
Date: Tue, 23 Dec 2008 13:24:08 +0100
Local: Tues, Dec 23 2008 7:24 am
Subject: Re: compare nested lists

I see, thank you again.

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google