xml question to allegro-cl

Gunn Inger Lyse <[email protected]> Mon, 12 Jun 2006 15:56:27 +0200
Newsgroups gmane.lisp.allegro
Message-ID <[email protected]>
Hi,

I would like to submit to the Allegro CL User Forum.

In particular, I have the following question.

------------------------

I want to read an xml file in lisp, using the Sax XML Parser for 
Allegro Common Lisp. I need to write a program which says, more or less 
that (see xml sample below, it is a corpus of words) "if the lemma = 
"også" (or any other input word) , then print the two words before and 
after this token"

But I cannot figure out how to actually get started in parsing my 
corpus, and how to express that only when A, then B. (for instace, only 
when lemma = "test", then print its surrounding words). I want to test 
the sax parser, using the test-sax-parser class: 
http://www.franz.com/support/documentation/8.0/doc/sax.htm . I have the 
following successfully loaded:
(require :sax)
(use-package :net.xml.sax)

Since the given "testsuite" only has classes and methods, I assume that 
the class instance must be my file. So I have:
(defparameter *xmlfile* (make-instance 'test-sax-parser :reader 
"lisp:projects;semantic-mirrors;testxmlfile.xml"))
Trying START-DOCUMENT and END-DOCUMENT seems to work fine, but I cannot 
see what I give as the arguments of the next method, START-ELEMENT. It 
takes five arguments:
(parser test-sax-parser) iri localname qname attrs . The first argument 
is my file *xmlfile*, but what are the remaining four?

In short: I don't get it; could anyone provide test expressions for 
each of the method defined? Or even better, help me getting started by 
showing a method which looks for at particular lemma in the corpus and 
only does something when encountering this lemma?

Here is a sample of my xml corpus:
<xml><text><body>
<struct type='p-level' id='p_1'><struct type='s-level' id='s_1'><struct 
type='t-level' id='t_1_1'><feat type='token'>1</feat><feat 
type='position'>1</feat><feat type='pos'>NU</feat><feat 
type='lemma'>1</feat></struct></struct></struct>
<struct type='p-level' id='p_2'><struct type='s-level' id='s_2'>
<struct type='t-level' id='t_2_1'><feat 
type='token'>Hartmann</feat><feat type='position'>1</feat><feat 
type='pos'>N</feat><feat type='lemma'>Hartmann</feat><feat 
type='sense'>1/2</feat><struct>
<struct type='t-level' id='t_2_2'><feat type='token'>,</feat><feat 
type='position'>2</feat><feat type='pos'>PU</feat><feat 
type='lemma'>,</feat></struct>
<struct type='t-level' id='t_2_3'><feat type='token'>en</feat><feat 
type='position'>3</feat><feat type='pos'>NU</feat><feat 
type='lemma'>en</feat></struct>
<struct type='t-level' id='t_2_4'><feat type='token'>riktig</feat><feat 
type='position'>4</feat><feat type='pos'>AJ</feat><feat 
type='lemma'>riktig</feat></struct>
<struct type='t-level' id='t_2_5'><feat 
type='token'>levemann</feat><feat type='position'>5</feat><feat 
type='pos'>N</feat><feat type='lemma'>levemann</feat></struct>
<struct type='t-level' id='t_2_6'><feat type='token'>,</feat><feat 
type='position'>6</feat><feat type='pos'>PU</feat><feat 
type='lemma'>,</feat></struct>
<struct type='t-level' id='t_2_7'><feat type='token'>lot</feat><feat 
type='position'>7</feat><feat type='pos'>V</feat><feat 
type='lemma'>late</feat></struct>
</struct></struct>
</body></text></xml>



---------------------------------------------------
Gunn Inger Lyse
PhD Student Computational Linguistics

Section for Linguistic Studies
University of Bergen		Ph. office:	+47 55582464
Sydnesplass 7			Ph. mobile:	+47 47632349
N-5007 Bergen, Norway	E-mail: [email protected]