blog.humaneguitarist.org

XQuery and MusicXML

[Sun, 13 Sep 2009 00:11:47 +0000]
Earlier today, I posted about my first experience with XQuery [http://blog.humaneguitarist.org/?p=152]. I'd mentioned that I wanted to get my feet wet before I started trying to run queries on MusicXML documents. Well, I'm an incredibly impatient person. I couldn't wait to take a couple of simple queries for a test run, especially after reading the following paper from the 2008 International Conference on Music Information Retrieval hosted by ISMIR [http://www.ismir.net/], the International Society for Music Information Retrieval: Using XQuery on MusicXML Databases for Musicological Analysis [http://ismir2008.ismir.net/papers/ISMIR2008_217.pdf] Joachim Ganseman, Paul Scheunders and Wim D’haes Now, I've known for a while the tests have been done using XQuery on MusicXML documents, but this paper was getting at something that's been on my mind for a long time now: the day we can have digital libraries of sheet music, not as image files, but as encoded documents, allowing musicians and the like to have the same online ability to query music in the way that users of prose and literary documents now take for granted. Anyway, on to my first XQuery and MusicXML experience ... For testing, I used a very silly little ditty I wrote called "MusicXML: I Heart Thee". Here are its various manifestations: * MusicXML [http://blog.humaneguitarist.org/uploads/i_heart_thee.xml] * JPEG [http://blog.humaneguitarist.org/uploads/i_heart_thee.jpg] * MP3 [http://blog.humaneguitarist.org/uploads/i_heart_thee.mp3] The first query demonstrated in the paper [http://ismir2008.ismir.net/papers/ISMIR2008_217.pdf#page=3] (see page 3) is one to count the total notes in a digital library, in this case the Wikifonia [http://www.wikifonia.org/] collection of MusicXML docs. I couldn't get it to work as written even after I adjusted the query to work on my test document. This is likely due to my own ignorance, but in the end it was a good thing because it forced me to write my own, simpler queries. I'm using the Saxon [http://saxon.sourceforge.net/] query processor as described in my earlier post [http://blog.humaneguitarist.org/?p=152]. 1. This query (in red) counts all the notes in my piece: <ul> { for $i in doc("i_heart_thee.xml")/score-partwise let $j :=count($i/part/measure/note) return $j } </ul> A line-by-line translation: * Open an unordered list. * Open the query syntax with the "{" character. * Let there be a variable called "i" that will start at the root element, , of the document "i_heart_thee.xml". * Let there be a variable, "j", that executes the Count function on "i" for the element which is a child of and a grandchild of . * Print the value of "j". * Close the query syntax with the "}" character. * Close the unordered list. 2. This query (in red) counts all the notes in the vocal part (there are 3 parts altogether: voice, guitar, bass): <ul> { for $i in doc("i_heart_thee.xml")/score-partwise let $j :=count($i/part[@id='P1']/measure/note) return $j } </ul> A line-by-line translation: * Open an unordered list. * Open the query syntax with the "{" character. * Let there be a variable called "i" that will start at the root element, , of the document "i_heart_thee.xml". * Let there be a variable, "j", that executes the Count function on "i" for the element which is a child of and a grandchild of , where the "ID" attribute of is = to "P1". This is the vocal part of the score. * Print the value of "j". * Close the query syntax with the "}" character. * Close the unordered list. If you run the first query you get the result "137" as in 137 notes, including rests - even the hidden rests in measures 1,5, and 9 that exist because both voices in the guitar part have rests, though it only displays as one rest each time on the image version of the score [http://blog.humaneguitarist.org/uploads/i_heart_thee.jpg]. If you run the second query, you get 43 notes including rests and the tied notes. I'm sure there are ways to subtract rests and tied notes, but I have to start somewhere, right? :)

COMMENTS

  1. nitin [2009-09-21 02:29:19]

    Hey Dr. M, Good point: nowhere would be worse. :) I dunno if I said that, but one day it would definitely be nice to attend. This is definitely the thing I want to know the most about in terms of IR. Gotta learn a ton more as well as some programming skills ...

  2. slm [2009-09-17 15:53:17]

    I'm glad you're starting somewhere and not nowhere :D Good work! Do I remember you saying (or writing) something about knowing a conference covering musicIR that you might present some of your findings over time? (and meet like minded folks ;) )

  3. Jody DeRidder [2009-09-14 18:01:48]

    Nitin, this is terrific! Yes, everyone must start somewhere. I don't think I've ever seen anyone document so clearly each part of a query for other beginners -- this will be very helpful to others. You *rock*! Your inquisitive nature and passion for your work is inspiring. --jody