From: ab talebi
Subject: loop problem
Date: 
Message-ID: <3c4d539e.83460833@news.uio.no>
Sorry people, after a hard drive crash I don't know if I have posted
this before or not, but let me try again:
------------------------------------------------------------
this iteration is very complex and hard to understand for me maybe
some one else can help me?

I have this list that consists of two (but it can be more) strings

my-list:
(("car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
ska) (noun ako hui)) blue ((adj hji hui))" "strong ((adj hji hui) (adv
ly hui)) is ((verb hji ska) (verb kos hji)) man ((noun ako hui) (prop
hui))"))

what I need is this list:
(
((noun noun) (verb noun) (adj))
((adj adv) (verb verb) (noun prop)))

we don't know how many strings we have in my-list but I guess
 (length (car test)) 
can tell us that

(caar my-list) wil give me the first string:
"car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
ska) (noun ako hui)) blue ((adj hji hui))"

I have a function called sting-to-list that simply gets a "string" and
turns it to a (list) I use it to get this:

(defun string-to-list (str &optional (pos 0) (list nil))
  (multiple-value-bind (obj newpos)
       (read-from-string str nil :end-of-string :start pos)
    (if (eql obj :end-of-string)
       (nreverse list)
       (string-to-list str newpos (cons obj list)))))

(mapcar #'car (cadr (string-to-list (caar my-list))))
(NOUN NOUN)

but I don't know how to use this information to iterate the list and
get what I need

tnx
ab talebi

From: Nils Goesche
Subject: Re: loop problem
Date: 
Message-ID: <a2k1j7$11dmbm$2@ID-125440.news.dfncis.de>
In article <·················@news.uio.no>, ab talebi wrote:

> I have a function called sting-to-list that simply gets a "string" and
> turns it to a (list) I use it to get this:
 
[snip]

> (mapcar #'car (cadr (string-to-list (caar my-list))))
> (NOUN NOUN)
> 
> but I don't know how to use this information to iterate the list and
> get what I need

Could you try to formulate your question more clearly?  You already
have string-to-list, so consider that done.  Now what do you still
need?  A function that apparently gets some kind of list as input
and should output a somewhat transformed list.  Could you give one
or more examples for possible input lists and your desired output?

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9
From: ab talebi
Subject: Re: loop problem
Date: 
Message-ID: <6b58a68e.0201221458.29fbb5d9@posting.google.com>
Nils Goesche <······@cartan.de> wrote in message news:<···············@ID-125440.news.dfncis.de>...
> In article <·················@news.uio.no>, ab talebi wrote:
> 
> > I have a function called sting-to-list that simply gets a "string" and
> > turns it to a (list) I use it to get this:
>  
> [snip]
> 
> > (mapcar #'car (cadr (string-to-list (caar my-list))))
> > (NOUN NOUN)
> > 
> > but I don't know how to use this information to iterate the list and
> > get what I need
> 
> Could you try to formulate your question more clearly?  You already
> have string-to-list, so consider that done.  Now what do you still
> need?  A function that apparently gets some kind of list as input
> and should output a somewhat transformed list.  Could you give one
> or more examples for possible input lists and your desired output?
> 
> Regards,


what I need is a function (say "analyse") that takes this my-list:

(("car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
ska) (noun ako hui)) blue ((adj hji hui))" "strong ((adj hji hui) (adv
ly hui)) is ((verb hji ska) (verb kos hji)) man ((noun ako hui) (prop
hui))"))

and gives me this list:

(
((noun noun) (verb noun) (adj))
((adj adv) (verb verb) (noun prop)))

this is the first word of each inner-parantes
we don't know how many strings we have in my-list so we have to use something like

for i=1 to (length (car my-list))

to go throught the list. hope that helps clearify the question

tnx
ab talebi
From: Coby Beck
Subject: Re: loop problem
Date: 
Message-ID: <Kjm38.16061$XG4.674903@news2.calgary.shaw.ca>
"ab talebi" <············@yahoo.com> wrote in message
·································@posting.google.com...
> Nils Goesche <······@cartan.de> wrote in message
news:<···············@ID-125440.news.dfncis.de>...
> > In article <·················@news.uio.no>, ab talebi wrote:
> >
> > > I have a function called sting-to-list that simply gets a "string" and
> > > turns it to a (list) I use it to get this:
> >
> > [snip]
> >
> > > (mapcar #'car (cadr (string-to-list (caar my-list))))
> > > (NOUN NOUN)
> > >
> > > but I don't know how to use this information to iterate the list and
> > > get what I need
> >
> > Could you try to formulate your question more clearly?  You already
> > have string-to-list, so consider that done.  Now what do you still
> > need?  A function that apparently gets some kind of list as input
> > and should output a somewhat transformed list.  Could you give one
> > or more examples for possible input lists and your desired output?
> >
> > Regards,
>
>
> what I need is a function (say "analyse") that takes this my-list:
>
> (("car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
> ska) (noun ako hui)) blue ((adj hji hui))" "strong ((adj hji hui) (adv
> ly hui)) is ((verb hji ska) (verb kos hji)) man ((noun ako hui) (prop
> hui))"))
>
> and gives me this list:
>
> (
> ((noun noun) (verb noun) (adj))
> ((adj adv) (verb verb) (noun prop)))
>

(loop for string in mylist
         collect (mapcar #'car (cadr (string-to-list (car string)))))

or something....

--
Coby
···········@101yboc
From: ab talebi
Subject: Re: loop problem
Date: 
Message-ID: <6b58a68e.0201231328.56659091@posting.google.com>
"Coby Beck" <·····@mercury.bc.ca> wrote in message news:<······················@news2.calgary.shaw.ca>...
> "ab talebi" <············@yahoo.com> wrote in message
> ·································@posting.google.com...
> > Nils Goesche <······@cartan.de> wrote in message
>  news:<···············@ID-125440.news.dfncis.de>...
> > > In article <·················@news.uio.no>, ab talebi wrote:
> > >
> > > > I have a function called sting-to-list that simply gets a "string" and
> > > > turns it to a (list) I use it to get this:
> > >
> > > [snip]
> > >
> > > > (mapcar #'car (cadr (string-to-list (caar my-list))))
> > > > (NOUN NOUN)
> > > >
> > > > but I don't know how to use this information to iterate the list and
> > > > get what I need
> > >
> > > Could you try to formulate your question more clearly?  You already
> > > have string-to-list, so consider that done.  Now what do you still
> > > need?  A function that apparently gets some kind of list as input
> > > and should output a somewhat transformed list.  Could you give one
> > > or more examples for possible input lists and your desired output?
> > >
> > > Regards,
> >
> >
> > what I need is a function (say "analyse") that takes this my-list:
> >
> > (("car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
> > ska) (noun ako hui)) blue ((adj hji hui))" "strong ((adj hji hui) (adv
> > ly hui)) is ((verb hji ska) (verb kos hji)) man ((noun ako hui) (prop
> > hui))"))
> >
> > and gives me this list:
> >
> > (
> > ((noun noun) (verb noun) (adj))
> > ((adj adv) (verb verb) (noun prop)))
> >
> 
> (loop for string in mylist
>          collect (mapcar #'car (cadr (string-to-list (car string)))))
> 
> or something....

(setf my-list '(("car ((noun automoblie sks hui)(noun vehicle sks
hui)) is ((verb hji ska) (noun ako hui)) blue ((adj hji hui))" "strong
((adj hji hui) (adv ly hui)) is ((verb hji ska) (verb kos hji)) man
((noun ako hui) (prop hui))")))

the function analyse:

(defun analyse ()
  (loop for string in my-list
        collect (mapcar #'car (cadr (string-to-list (car string))))))

gives me:

((NOUN NOUN)) 

which is just fine. I wrote the function analyse-all that I was hoping
would give me:

(((NOUN NOUN) (VERB NOUN) (ADJ)) ((ADJ ADV) (VERB VERB) (NOUN PROP)))

 which is all the categories of all the words.

(defun analyse-all (list)
  (cond ((null list) list)
        (t (cons (analyse (car list))
                 (analyse (cdr list))))))

all I get is "function analyse has the wrong number of arguments"
I know that car/cdr can not be right because with car/cdr we can not
find the next word of the string in my-list (is, blue). so the
question what shall we use to find "the next word of the string" and
how shall we iterate the list so the function analyse-all gives us:

(((NOUN NOUN) (VERB NOUN) (ADJ)) ((ADJ ADV) (VERB VERB) (NOUN PROP)))

tnx

ab talebi
From: Nils Goesche
Subject: Re: loop problem
Date: 
Message-ID: <a2nact$12bmra$1@ID-125440.news.dfncis.de>
In article <····························@posting.google.com>, ab talebi wrote:

> "Coby Beck" <·····@mercury.bc.ca> wrote in message news:<······················@news2.calgary.shaw.ca>...

>> (loop for string in mylist
>>          collect (mapcar #'car (cadr (string-to-list (car string)))))
>> 
>> or something....
> 
> (setf my-list '(("car ((noun automoblie sks hui)(noun vehicle sks
> hui)) is ((verb hji ska) (noun ako hui)) blue ((adj hji hui))" "strong
> ((adj hji hui) (adv ly hui)) is ((verb hji ska) (verb kos hji)) man
> ((noun ako hui) (prop hui))")))
> 
> the function analyse:
> 
> (defun analyse ()
>    (loop for string in my-list
>         collect (mapcar #'car (cadr (string-to-list (car string))))))

Try (defun analyse (list)
       (loop for string in list
             collect (mapcar #'car (cadr (string-to-list (car string))))))

and test it with (analyse my-list).
 
> gives me:
> 
> ((NOUN NOUN)) 
> 
> which is just fine. I wrote the function analyse-all that I was hoping
> would give me:
> 
> (((NOUN NOUN) (VERB NOUN) (ADJ)) ((ADJ ADV) (VERB VERB) (NOUN PROP)))
> 
>  which is all the categories of all the words.
> 
> (defun analyse-all (list)
>   (cond ((null list) list)
>         (t (cons (analyse (car list))
>                  (analyse (cdr list))))))
> 
> all I get is "function analyse has the wrong number of arguments"

It does, doesn't it?  Maybe you want another (mapcar #'analyse ...)
here, I am not sure.

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9
From: Thomas A. Russ
Subject: Re: loop problem
Date: 
Message-ID: <ymivgdsyfpq.fsf@sevak.isi.edu>
············@yahoo.com (ab talebi) writes:

> what I need is a function (say "analyse") that takes this my-list:
> 
> (("car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
> ska) (noun ako hui)) blue ((adj hji hui))" "strong ((adj hji hui) (adv
> ly hui)) is ((verb hji ska) (verb kos hji)) man ((noun ako hui) (prop
> hui))"))

Well, the first thing that I would do would be to transform the
representation from strings to objects.  The simplest such
transformation would just be to use strings for the words and list
structure for the attributes.

(("car" ((noun automoblie sks hui)(noun vehicle sks hui))
  "is" ((verb hji ska) (noun ako hui))
  "blue" ((adj hji hui)))
 ("strong" ((adj hji hui) (adv ly hui))
  "is" ((verb hji ska) (verb kos hji))
  "man" ((noun ako hui) (prop hui))))

Once you have done this transformation, using list processing operations
to extract parts of the representation become much easier.  Then it
becomes a bit easier to see how to get to

> and gives me this list:
> 
> (
> ((noun noun) (verb noun) (adj))
> ((adj adv) (verb verb) (noun prop)))

We can then break this down into constituent parts, which will make
things even easier.

Assume *SENTENCES* is set to the modified list above

(loop for sentence in *sentences*
      collect (collect-attribute-heads sentence))

(defun collect-attribute-heads (sentence)
  (when sentence
     (cons (mapcar #'first (second sentence))
           (collect-attribute-heads (cddr sentence)))))

The key to designing things like this is to break the task down into
manageable pieces, and then package those pieces into functions.

Now if I were really doing this, I would choose a (slightly) more
complicated data structure than what is shown above.  In particular,
instead of relying on the alternating word-attribute pairs in the
sentence, I would probably make them be defstructs and use accessors to
get the lexeme and its parse information.

At the very least I would introduce yet another level of nested lists
and then define accessors (using defmacro) so that I wouldn't need to
use names like FIRST, etc. to do the access.  The only drawback to
using macros is that one would not be able to funcall or map them over
the data structures.

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: ab talebi
Subject: Re: loop problem
Date: 
Message-ID: <3c4fe817.84337084@news.uio.no>
On 23 Jan 2002 12:28:33 -0800, ···@sevak.isi.edu (Thomas A. Russ)
wrote:

>············@yahoo.com (ab talebi) writes:
>
>> what I need is a function (say "analyse") that takes this my-list:
>> 
>> (("car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
>> ska) (noun ako hui)) blue ((adj hji hui))" "strong ((adj hji hui) (adv
>> ly hui)) is ((verb hji ska) (verb kos hji)) man ((noun ako hui) (prop
>> hui))"))
>
>Well, the first thing that I would do would be to transform the
>representation from strings to objects.  The simplest such
>transformation would just be to use strings for the words and list
>structure for the attributes.
>
>(("car" ((noun automoblie sks hui)(noun vehicle sks hui))
>  "is" ((verb hji ska) (noun ako hui))
>  "blue" ((adj hji hui)))
> ("strong" ((adj hji hui) (adv ly hui))
>  "is" ((verb hji ska) (verb kos hji))
>  "man" ((noun ako hui) (prop hui))))
>
>Once you have done this transformation, using list processing operations
>to extract parts of the representation become much easier.  Then it
>becomes a bit easier to see how to get to
>

I agree with you, but the question is how we can get from

(("car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
ska) (noun ako hui)) .....

notion to what you sugested:

(("car" ((noun automoblie sks hui)(noun vehicle sks hui)) "is" ((verb
hji ska) (noun ako hui)) ...

string-to-list takes one big string 
"car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
ska) (noun ako hui)) blue ((adj hji hui))" and gives us a list of that
string.

actually the story behind string-to-list is our original datafile
which is in this format:

c:\corpus.txt

LEXEME	things
CATALOGUE	dxol
DEF	car ((noun automoblie sks hui)(noun vehicle sks hui)) is
((verb hji ska) (noun ako hui)) blue ((adj hji hui))" 
DEF	strong ((adj hji hui) (adv ly hui)) is ((verb hji ska) (verb
kos hji)) man ((noun ako hui) (prop hui))
=

We put this into a more lisp-friendly way by read-database

(defun read-entry (stream)
  (loop
      for line = (read-line stream nil nil)
      when (null line)
      return stream
      until  (string-equal line "=")
      collect 
	(multiple-value-bind (key position) (let ((*read-eval* nil))
					      (read-from-string line))
	  (loop 
	      while (eq #\tab (char line position))
	      do (incf position))	; skip multiple tabs
	  (list key
		(subseq line position)))))

(defun read-database (pathname)
  (with-open-file (stream pathname :direction :input)
    (loop
	for address = (read-entry stream)
	until (eq address stream)
	collect address)))


read-database converts values into strings so it's here that we get
the strings to begin with.

(setf corpus (read-database "c:\corpus.txt"))


the function extract does the job of extractiong the DEF-part, which
is the part of interest:

(defun find-category-values (category record)
  (loop for (current-category value) in record
    when (eq current-category category) collect value))

(defun extract (category value list)
  (if (null list) 
      '()
      (let ((record (first list)))
        (if (equal (cadr (assoc 'lexeme record)) value)
            (cons (find-category-values category record)
                  (extract category value (rest list)))
          (extract category value (rest list))))))

(defun get-def (x)
  (extract 'def x corpus))


so that is why get-def will give us:

(("car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
ska) (noun ako hui)) blue ((adj hji hui))" "strong ((adj hji hui) (adv
ly hui)) is ((verb hji ska) (verb kos hji)) man ((noun ako hui) (prop
hui))"))


so what do we have to do to get what you sugested, namely:

(("car" ((noun automoblie sks hui)(noun vehicle sks hui))
  "is" ((verb hji ska) (noun ako hui))
  "blue" ((adj hji hui)))
 ("strong" ((adj hji hui) (adv ly hui))
  "is" ((verb hji ska) (verb kos hji))
  "man" ((noun ako hui) (prop hui))))


tnx

ab talebi