Re: XQuery and music informatio retrieval

Michael Good wrote:
> 
> Say we are trying to search for "Frere Jacques" sung in the key of C. We
> just want to look for a sequence of pitches: C, D, E, C. We do not want
> to assume, though, that all these pitches are in the same measure - both
> of these XML data should be found (this is not real MusicXML, but
> simplified for this example):
> 
> <measure number="1">
>   <note>C</note>
>   <note>D</note>
>   <note>E</note>
>   <note>C</note>
> </measure>
> 
> as well as
> 
> <measure number="1">
>   <rest/>
>   <rest/>
>   <note>C</note>
>   <note>D</note>
> </measure>
> <measure number="2">
>   <note>E</note>
>   <note>C</note>
>   <rest/>
>   <rest/>
> </measure>
> 
> In both cases, we want to return the 4 notes in sequence, regardless of
> whether they are in the same parent or consecutive parents. However, the
> following would not match, since there is an F in the middle of the
> sequence:
> 
> <measure number="1">
>   <rest/>
>   <rest/>
>   <note>C</note>
>   <note>D</note>
> </measure>
> <measure number="2">
>   <note>F</note>
>   <note>E</note>
>   <note>C</note>
>   <rest/>
> </measure>
> 
> I know there are brute force ways to do this, but this is already a
> *much* simpler than real-world query example, and needs to be 1) handled
> simply and 2) retrieved quickly from an XML database.
> 
> Is there some convenient mechanism to specify that I want to match a
> sequence of elements that share, not necessarily a common parent, but a
> common grandparent, great-grandparent, or arbitrary level ancestor?
> Goodness knows there is a lot in XQuery, so please let me know if I have
> missed the easy way to handle this type of query.

Hmmm... How about this XPath:

    //note[.="C"
       and following::note[1]="D"
       and following::note[2]="E"
       and following::note[3]="C"]

That would select the first note of each occurrence of the "Frere Jacques"
melody in the current document. If (as you say) you want to select all four
notes of each occurrence of the melody, that would be more involved, I
think.

-Michael Dyck

Received on Wednesday, 18 July 2001 02:57:33 UTC