Re: list of speakers

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
  • list of speakers
    • Jim_Albright - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id TAA28284Sat, 18 Jul 1998 19:27:16 -0400 (EDT)
      • Brandon Ibach - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id NAA17179Sun, 19 Jul 1998 13:01:52 -0400 (EDT)
      • <Possible follow-ups>
      • Paul Prescod - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id QAA20795Sun, 19 Jul 1998 16:03:47 -0400 (EDT) <=
      • Jim_Albright - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id XAA11956Mon, 20 Jul 1998 23:46:42 -0400 (EDT)
        • Paul Prescod - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id CAA16649Tue, 21 Jul 1998 02:59:37 -0400 (EDT)