Project

Profile

Help

Invalid QName error

Added by Anonymous over 19 years ago

Legacy ID: #2928031 Legacy Poster: amitabh ojha (amitabhojha)

Researchers Jacky W.W. Wan and Gillian Dobbie (ACM, Jan 2004) have implemented the well known Apriori Association Rule Mining Algorithm on XML data through XQuery, using X-Hive/DB 4.1. My research work involves extending their published work. As a starting point, I just tried to run their original XQuery on Saxon (after updating the syntax). The XQuery code which is as follows, is contained in a single file &#8220;apriori.xql&#8221; :- declare namespace my = "urn:foo"; declare function my:join ($X, $Y) { let $items := for $item in $Y where every $i in $X satisfies $i != $item return $item return $X union $items }; declare function my:commonIts ($X, $Y) { for $item in $X where some $i in $Y satisfies $i = $item return $item }; declare function my:removeIts ($X, $Y) { for $item in $X where every $i in $Y satisfies $i != $item return $item }; declare function my:removeDuplicate ($C) { for $itemset1 in $C let $items1 := $itemset1/* let $items :=(for $itemset2 in $C let $items2 := $itemset2/* where $itemset2>>$itemset1 and count($items1) = count (my:commonIts ($items1, $items2)) return $items2) where count ($items) = 0 return $itemset1 }; declare function my:prune ($X, $Y) { every $item in $X satisfies some $items in $Y//items satisfies count (my:commonIts (my:removeIts ($X, $item), $items/)) = count ($X) - 1 }; declare function my:getLargeItemsets ($C, $minsup, $total, $src) { for $items in $C let $trans := (for $tran in $src where every $item1 in $items/ satisfies some $item2 in $tran/* satisfies $item1 = $item2 return $tran) let $sup := (count ($trans) * 1.00) div $total where $sup >= $minsup return <largeItemset> {$items} <support> {$sup} </support> </largeItemset> }; declare function my:candidateGen ($l) { for $freqSet1 in $l let $items1 := $freqSet1//items/* for $freqSet2 in $l let $items2 := $freqSet2//items/* where $freqSet2 >> $freqSet1 and count ($items1) + 1 = count ($items1 union $items2) and my:prune (my:join($items1,$items2), $l) return <items> {my:join ($items1, $items2)} </items> }; declare function my:apriori ($l, $L, $minsup, $total, $src) { let $C := my:removeDuplicate (my:candidateGen ($l)) let $l := my:getLargeItemsets ($C, $minsup, $total, $src) let $L := $l union $L return if (empty ($l)) then $L else my:apriori($l, $L, $minsup, $total, $src) }; let $src := doc (&#8220;transactions.xml&#8221;)//items let $minsup := 0.4 let $total := count ($src) * 1.00 let $C := distinct-values ($src/) let $l := (for $itemset in $C let $items := (for $item in $src/ where $itemset = $item return $item) let $sup := (count($items) * 1.00) div $total where $sup >= $minsup return <largeItemset> <items> {$itemset} </items> <support> {$sup} </support> </largeItemset>) let $L := $l return <largeItemsets> {my:apriori($l, $L,$minsup, $total, $src)} </largeItemsets> The file &#8220;transactions.xml&#8221; is as follows :- <transactions> <transaction id="1"> <items> <item>a</item> <item>d</item> <item>e</item> </items> </transaction> <transaction id="2"> <items> <item>b</item> <item>c</item> <item>d</item> </items> </transaction> <transaction id="3"> <items> <item>a</item> <item>c</item> </items> </transaction> <transaction id="4"> <items> <item>b</item> <item>c</item> <item>d</item> </items> </transaction> <transaction id="5"> <items> <item>a</item> <item>b</item> </items> </transaction> </transactions> On running this Xquery with Java SDK 1.4.2_04, using saxon7.jar (and also with saxon8.jar and the JAXP 1.3 .jar files), the following error message shows up (even as the files transactions.xml and the above XQuery are in the same sub-directory) : &#8220;XQuery syntax error on line 82 in &#8216; &#8230; := doc (o^transactions.xmlö)// : Invalid Qname {o^transactions.xmlö} Except the recursive apriori function, I have already tested all functions separately and found them ok. The recursive apriori function is hard to test in isolation. Particularly worrying is that once the above error shows up, thereafter even if you edit the portion of XQuery calling code and make it only execute doc(&#8220;transactions.xml&#8221;), the same error message comes up again. Will be really grateful if you could please test-run this query and help me with further guidance.


Replies (4)

Please register to reply

RE: Invalid QName error - Added by Anonymous over 19 years ago

Legacy ID: #2928072 Legacy Poster: Michael Kay (mhkay)

The let $src := doc (&#8220;transactions.xml&#8221;)//items should surely be let $src := doc("transactions.xml")//items It looks as if you were using one of those too-clever-by-half editors that replaces straight quotes by typographical quotes, which of course are not recognized as XQuery delimiters. Sorry about the poor error message: any non-ASCII characters found in query, outside a comment or string literal, are assumed to be part of a QName, and the parser then checks whether the supposed QName is valid, which in this case it isn't. Michael Kay

RE: Invalid QName error - Added by Anonymous over 19 years ago

Legacy ID: #2928235 Legacy Poster: amitabh ojha (amitabhojha)

But this XQuery was created with notepad editor that comes with windows. I look forward to your further help on this.

RE: Invalid QName error - Added by Anonymous over 19 years ago

Legacy ID: #2928313 Legacy Poster: Michael Kay (mhkay)

I didn't know that Notepad had been infected with the Microsoft smart-quotes disease. But the query evidently contains Unicode typographical left and right quotation marks instead of normal ASCII typewriter quotes, and you need to correct this. Michael Kay

RE: Invalid QName error - problem solved - Added by Anonymous over 19 years ago

Legacy ID: #2933596 Legacy Poster: amitabh ojha (amitabhojha)

The problem was exactly what you had indicated. I had copied the said XQuery code directly from the ACM paper (which was in a .pdf file), pasted it directly onto a windows notepad file and then made necessary corrections in that notepad file. And yes, the double quote symbol (copy-pasted from .pdf file) that was visually appearing ok in notepad file was actually something else - this fact I discovered when I opened this file in linux using gedit editor. Thanks very much indeed for your help. Amitabh Ojha

    (1-4/4)

    Please register to reply