Subject: Re: list of speakers From: Paul Prescod <papresco@xxxxxxxxxxxxxxxx> Date: Sun, 19 Jul 1998 16:01:35 -0400 (EDT) |
On Sat, 18 Jul 1998 Jim_Albright@xxxxxxx wrote: > Is it possible to extract the unique list of speakers in a play? > Is it possible to sort by number of times they speakers? Not just possible, but easy once you grok the tao of SDQL. > Assume that each speech is marked with > <VOICE>name of person who speaks</VOICE> > <TEXT>what the person says</TEXT> Here's the basic code: ; given a name and a nodelist, counts the number of elements that have ; the name as their data (define (count-occurs name nl) (node-list-reduce nl (lambda (count node) (if (string=? name (data node)) (+ count 1) count)) 0)) ; given a nodelist, looks at each node's data content and returns a list ; of unique data contents (define (unique-data-content nl) (node-list-reduce nl (lambda (result node) (if (member (data node) result) result (cons (data node) result))) '())) (element SPEAKERS (let ((speakers (unique-data-content (q-element "VOICE")))) (apply sosofo-append (map (lambda (x) (literal x " " (number->string (count-occurs x (descendants (current-node)))) " ")) speakers)))) Invoke it like this: e:\bin\jade\jade -d Jim.dsl -t sgml Jim.sgm on data like this: <!DOCTYPE SPEAKERS[ <!ELEMENT SPEAKERS O O (VOICE|SPEECH)+> <!ELEMENT VOICE O O (#PCDATA)+> <!ELEMENT SPEECH O O (#PCDATA)+> ]> <SPEAKERS> <VOICE>Paul</VOICE> <SPEECH>Paul Blah1</SPEECH> <VOICE>Paul</VOICE> <SPEECH>Paul Blah2</SPEECH> <VOICE>Lilia</VOICE> <SPEECH>Lilia Blah1</SPEECH> <VOICE>Paul</VOICE> <SPEECH>Paul Blah3</SPEECH> <VOICE>Lilia</VOICE> <SPEECH>Lilia Blah2</SPEECH> <VOICE>Jim</VOICE> <SPEECH>Jim's Voice</SPEECH> <VOICE>Paul</VOICE> <SPEECH>Paul Blah4</SPEECH> <VOICE>Paul</VOICE> <SPEECH>Paul Blah5</SPEECH> <VOICE>Lilia</VOICE> <SPEECH>Lilia Blah3</SPEECH> </SPEAKERS> Note that you will need many standard DSSSL functions that are not implemented in Jade. You can get them from the DSSSL procedure library at Mulberry Technologies: http://www.mulberrytech.com/dsssl/dsssldoc/procedures/c01.html Paul Prescod DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: list of speakers, Brandon Ibach | Thread | Re: list of speakers, Jim_Albright |
On that last post..., Brandon Ibach | Date | Re: speakers, Paul Prescod |
Month |