This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 5829 - [FTUC] xquery full text use case document has WRONG xpath solutions
Summary: [FTUC] xquery full text use case document has WRONG xpath solutions
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Full Text 1.0 Use Cases (show other bugs)
Version: Working drafts
Hardware: All Windows XP
: P1 critical
Target Milestone: ---
Assignee: Jim Melton
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-02 19:17 UTC by zhen hua liu
Modified: 2008-09-29 21:20 UTC (History)
2 users (show)

See Also:


Attachments

Description zhen hua liu 2008-07-02 19:17:54 UTC
In http://www.w3.org/TR/xpath-full-text-10-use-cases/ Working Draft 16 May 2008 version (including its previous drafts), there is a fundamental mistake in the xpath solutions for majority of the use case examples.
For example, in section 3.2.1, the xpath solution IS NOT correct.
Solution in XPath:
===================
doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//chapter ftcontains "one of 
the best known lists of heuristics is Ten Usability 
Heuristics")>0]

The count() function in the predicates counts the ftcontains expression result,
which is always a single boolean value of "true" or "false". Therefore, count() function here always return 1 and since 1 > 0, so the 'book' element is always returned. 

The correct solution is 

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//chapter [. ftcontains "one of 
the best known lists of heuristics is Ten Usability 
Heuristics"] )>0]

Here count() function counts number of 'chapter' element nodes which satisfies the ftcontains expression. Note we use another predicate [] to surround the ftcontains expression. 
This incorrect solution is everywhere in the use case document when the xpath solution with count() is used as solution. 

This needs to be fixed. Also part of the full text conformance tests include these use case examples. So we need to make sure the test case does NOT have the same mistake.  I checked the lastest CVS for xquery full text conformance tests, the following queries have already inherited the same mistakes:
./UseCase/UseCase-ACROSS/across-queries-results-q1b.xq
./UseCase/UseCase-ACROSS/across-queries-results-q2b.xq
./UseCase/UseCase-ACROSS/across-queries-results-q3b.xq
./UseCase/UseCase-ELEMENT/element-queries-results-q6b.xq
./UseCase/UseCase-ELEMENT/element-queries-results-q7b.xq
Comment 1 zhen hua liu 2008-07-02 19:19:46 UTC
seem to be a showstopper bug for the usecase document.
Comment 2 Michael Dyck 2008-07-02 20:06:47 UTC
(In reply to comment #0)
> 
> The correct solution is 
> 
> doc("http://bstore1.example.com/full-text.xml")
> /books/book[count(.//chapter [. ftcontains "one of 
> the best known lists of heuristics is Ten Usability 
> Heuristics"] )>0]

I believe the following simpler expression would be equivalent:
    doc("http://bstore1.example.com/full-text.xml")
    /books/book[.//chapter ftcontains "..."]

However, neither these nor the ones (XQuery + XPath) in the usecase doc seem to be solving the right problem. They're all looking for books that have some chapter containg the phrase, but the problem asks for all book chapters containing the phrase. So I think the proper solution is more like:
    doc("http://bstore1.example.com/full-text.xml")
    /books/book//chapter[. ftcontains "..."]
or just:
    doc("http://bstore1.example.com/full-text.xml")
    //chapter[. ftcontains "..."]

(Or, we could change the problem statement.)
Comment 3 zhen hua liu 2008-07-03 16:08:17 UTC
in general, there are quite a few places where using the count() in xquery/xpath is unnecessary. I recommend we shall change these example solutions to be correct and simple.
Comment 4 zhen hua liu 2008-08-06 23:09:09 UTC
here is xpath solutions which removes unnecessary count() and fixes numerous issues:
(:: 2.2.4  ::)
doc('http://bstore1.example.com/full-text.html')
/books/book[./metadata/title[. ftcontains "usability tests"]
or ./content/part/chapter/title[. ftcontains "usability tests"]]


(:: 2.2.5 ::)
doc('http://bstore1.example.com/full-text.html')
/books/book[metadata/subjects/subject
ftcontains "usability testing"]/metadata/(title|author)



(:: 2.2.6 ::)
doc('http://bstore1.example.com/full-text.html')/books/book/metadata/title[. ftcontains
"improving" ftand "usability" ordered distance at most 2 words  at start]


(:: 2.2.7 ::)
doc('http://bstore1.example.com/full-text.html')/books/book/metadata/title[. ftcontains
"improv.* the usability of a web site through expert
reviews and usability testing" entire content]




(:: 3.2.1 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[.//chapter ftcontains "one of
the best known lists of heuristics is Ten Usability Heuristics"]


(:: 3.2.2 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[content/part/introduction ftcontains "prototypes"]


(:: 3.2.3 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[content ftcontains "tests"]



(:: 3.2.4 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[.//content ftcontains "usability testing once the problems"]

(:: 3.2.5 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[
content/introduction ftcontains "identif.*" with wildcards and
content/part/introduction ftcontains "identif.*" with wildcards]




(:: 3.2.6 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[. ftcontains "mouse"]




(:: 4.2.1 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[ metadata/title/@shortTitle
 ftcontains "improve" ftand "web" ftand "usability" with stemming
distance at most 2 words  ]/metadata/title



(:: 4.2.2 ::)
(:: no xpaths solution ::)
(:: 5.2.1 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[content ftcontains "test." with wildcards]


(:: 5.2.2 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[ .//content ftcontains ".?way" with wildcards]


(:: 5.2.3 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[.//content
 ftcontains "serv.*e" with wildcards]/fn:concat(@number, ", " , metadata/title)


(:: 5.2.4 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[.//content ftcontains "us.+ testing"
   with wildcards]/fn:concat(@number, ", ", metadata/title)




(:: 5.2.5 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[content ftcontains "test.{3,4}"
   with wildcards]
Comment 5 zhen hua liu 2008-08-06 23:11:11 UTC
(:: 6.2.1 ::)
doc('http://bstore1.example.com/full-text.html')/books/book[.//content ftcontains "test" with stemming]



(:: 6.2.2 ::)
doc("http://bstore1.example.com/full-text.html")/books/book[.//content
ftcontains (("usable" with stemming)
ftand ("testing" phrase)) ftor (("use" with stemming )
ftand ("testing" phrase))]



(:: 7.2.1 ::)

doc("http://bstore1.example.com/full-text.html")
/books/book[.//introduction ftcontains "quote"
with thesaurus at
"http://bstore1.example.com/UsabilityThesaurus.xml"
relationship "synonyms"]





(:: 7.2.2 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[content ftcontains "web site components"
with thesaurus at
"http://bstore1.example.com/UsabilityThesaurus.xml"
relationship "narrower terms" at most 2 levels]



(:: 7.2.3 ::)

doc("http://bstore1.example.com/full-text.html")
/books/book[content ftcontains "letters"
ftor "holiday cards" with thesaurus at
"http://bstore1.example.com/UsabilityThesaurus.xml"
relationship "BT" exactly 1 levels]

(:: 7.2.4 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[. ftcontains "Merrygould"
with thesaurus at
"http://bstore1.example.com/UsabilitySoundex.xml"
relationship "sounds like"]



(:: 7.2.5 ::)

doc("http://bstore1.example.com/full-text.html")
/books/book[. ftcontains "sucessfull"
with thesaurus at
"http://bstore1.example.com/spellcheck.xml"
relationship "misspelling of"]



(:: 7.2.6 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[@number="3" and .//component ftcontains "AIDS"
uppercase with thesaurus at
"http://bstore1.example.com/OurTaxonomy.xml"
relationship "disease in this category"]


(:: 8.2.1 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[.//content ftcontains "planning then conducting" with stop words at
"http://bstore1.example.com/StopWordList.xml"]



(:: 8.2.2 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[.//content ftcontains "planning then
conducting" without stop words]



(:: 8.2.3 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[content ftcontains "not been
approved" with stop words at
"http://bstore1.example.com/StopWordList.xml"
except ("not")]/(metadata/title, content)

(:: 9.2.1 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[.//content ftcontains "résumé."
with wildcards diacritics sensitive]



(:: 9.2.2 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[.//content ftcontains "resume."
with wildcards diacritics insensitive]



(:: 9.2.3 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[. ftcontains "AIDS" uppercase]



(:: 9.2.4::)
doc("http://bstore1.example.com/full-text.html")
/books/book[. ftcontains "AIDS" case insensitive]


(:: 10.2.1 ::)

doc('http://bstore1.example.com/full-text.html')/books/book[.//content ftcontains "web"
   ftor "software"]



(:: 10.2.2 ::)

doc('http://bstore1.example.com/full-text.html')/books/book [.//content ftcontains "web"
   ftand "software"]





(:: 10.2.3 ::)

doc('http://bstore1.example.com/full-text.html')/books/book[.//content ftcontains "goal"
   ftand "obstacles" ftand "task" ordered]





(:: 10.2.4 ::)

doc('http://bstore1.example.com/full-text.html')/books/book[. ftcontains ftnot "us.* testing" with wildcards]

(:: 10.2.5 ::)

doc('http://bstore1.example.com/full-text.html')/books/book
[./metadata ftcontains "usability" ftand ftnot "plan"]






(:: 10.2.6 ::)


doc('http://bstore1.example.com/full-text.html')/books/book
[ content ftcontains
   (("résumés" diacritics sensitive) ftor "drafts"
   ftor "correspondence") ftand ftnot "book drafts"]





(:: 10.2.7 ::)

doc('http://bstore1.example.com/full-text.html')/books/book[.//content ftcontains 
   (("résumés" diacritics sensitive) ftor "drafts"
   ftor "correspondence") not in "book drafts"]

Comment 6 zhen hua liu 2008-08-06 23:13:18 UTC
(:: 11.2.1 ::)

doc("http://bstore1.example.com/full-text.html")/books/book
[ metadata/subjects/subject ftcontains "web site" ftand "usability"]


(:: 11.2.2 ::)

doc("http://bstore1.example.com/full-text.html")/books/book                       
[(some $s1 in ./metadata/subjects/subject satisfies $s1
 ftcontains "web site")
   and
(some $s2 in ./metadata/subjects/subject satisfies $s2 ftcontains "usability")]


(:: 11.2.3 ::)

doc("http://bstore1.example.com/full-text.html")/books/book[
  every $pub in .//publisher satisfies
   $pub ftcontains "ersatz" ftand "publications"]



(:: 11.2.4 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//content ftcontains "expert review methods" occurs at least 2 times]

(:: 12.2.1 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//content ftcontains
   "software" ftand "developer" with stemming
   distance at most 3 words]


(:: 12.2.2 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//content ftcontains
   "efficient" ftand "task" ftand "completion"
   ordered distance at most 10 words]


(:: 12.2.3 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//content ftcontains
   "users" ftand "feeling" ftand ("well served" ftor "well-served")
   with stemming ordered window 15 words]




(:: 12.2.4 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//content ftcontains
   "users" ftand "would" ftand "know" ftand "step"
   with stemming same sentence]


(:: 12.2.5 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//content ftcontains
   "usability" ftand "web site" ftand "efficiency"
   ftand "satisfaction" same paragraph]

(:: 13.2.1 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//p ftcontains "computer workstation"
and .//p/footnote ftcontains "comfortable"]
/(metadata/title , .//p)


(:: 13.2.2 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//chapter/p ftcontains "usability" ftand "test" with
stemming ]/(metadata/title, .//chapter/p/step[1], .//chapter/p/step[2])


(:: 13.2.3 ::)
doc("http://bstore1.example.com/full-text.html")/books/book[@number="3"
and
 content/part/component/(subComponent |subComponent/subsubComponent)/
   componentTitle ftcontains "flow diagram"
and
./ancestor::node()[.//componentTitle
  ftcontains "human computer interaction"]]
/(metadata/title, content)



(:: 13.2.4 ::)
(:: no xpath solution ::)
(:: 14.2.1 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[.//p [. ftcontains "testing"
   ftand ("guidance" ftor "correct") distance at
   most 60 words without content ./*] ]



(:: 14.2.2 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//chapter ftcontains
   "users can be tested at any computer workstation
   or in a lab" without content .//footnote ]
/(metadata/title, .//chapter)



(:: 14.2.3 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//chapter[. ftcontains
   "at any computer workstation or in a lab"
   without content (.//footnote[. ftcontains
   "workstation." with wildcards])] ]
/(metadata/title, .//chapter)


(:: 14.2.4 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[ .//chapter/p | .//chapter/p/footnote
   [. ftcontains "workstation" ftand "lab"
   distance at most 6 words without content ./footnote]]
/(metadata/title, .//chapter/p | .//chapter/p/footnote)

(:: 15.2.1 ::)
(:: no xpaths solution ::)

(:: 15.2.2 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[content//p ftcontains
   ("task" ftand "performance" with stemming distance
   at most 3 words) ftand "expert review" with stemming]
/(metadata/title, content)


(:: 15.2.3 ::)
doc("http://bstore1.example.com/full-text.html")/books/book
[.//content ftcontains (("millicent"
   ftand "marigold" ordered distance at most 3 words)
   ftand "quote.{0-5}" with wildcards with thesaurus at
   "http://bstore1.example.com/UsabilityThesaurus.xml"
   relationship "synonyms" distance at most 3 words)
   ftand "usability testing" ftand "iterate" with stemming
   distance at most 50 words]



(:: 15.2.4 ::)
(:: no xpaths solution ::)

(:: 15.2.5 ::)
(:: no xpaths solution ::)


(:: 16.2.1 - 16:2.8 ::)
(:: no xpaths solution ::)

(:: 16.2.9 ::)

doc("http://bstore1.example.com/full-text.html")
/books/book[content ftcontains ("successfully"
ftand "completing" ftand "tasks") with stemming
window  (count(content/part/chapter) * 3) words]/(metadata/title , content)

(:: 17.2.1 ::)
(:: no xpaths solution ::)

(:: 17.2.2 ::)
(:: no xpaths solution ::)

(:: 17.2.3 ::)
doc("http://bstore1.example.com/full-text.html")
/books/book[for $i score $s in .[. ftcontains "usability"] where $s > 0.1
return $s ]/metadata/title




(:: 17.2.4 - 17.2.6 ::)
(:: no xpaths solution ::)
Comment 7 Pat Case 2008-08-11 14:13:56 UTC
First installment of XQuery solutions rewritten without count().  Sections 2-10. Sections 11-17 to follow. Pat Case

2.2.4 Q4 Query in Different Elements
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $title := $book/(metadata|content/part/chapter)/title
where $title ftcontains "usability tests"
return $book

2.2.6 Q6 Starts-with Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $title := $book/metadata/title 
where $title ftcontains "improving" ftand "usability" 
   ordered distance at most 2 words at start
return $title

2.2.7 Q7 Entire Element Content Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $exactTitle := $book/metadata/title
where $exactTitle ftcontains "improv.* the usability of a 
   web site through expert reviews and usability testing" 
   with wildcards entire content
return $exactTitle

3.2.1 Q1 Query Across Descendant Elements (No Element Content)
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $chap := $book//chapter
where $chap ftcontains "one of the best known lists of 
   heuristics is Ten Usability Heuristics"
return $book

3.2.2 Q2 Query Across Descendant Elements (Highlighting Tags)
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $intro := $book/content/part/introduction
where $intro ftcontains "prototypes"
return $book

3.2.3 Q3 Query Across Descendant Elements (Substantive Tags)
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content
where $cont ftcontains "tests"
return $book

3.2.4 Q4 Query Across Siblings
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content 
where $cont ftcontains "usability testing once the 
   problems"
return $book

3.2.5 Q5 Query in Different Sub-Trees
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $intro := $book/content/(introduction|part/introduction)   
where $intro [./p ftcontains "identif.*" with wildcards
return $book

3.2.6 Q6 Query on Entire Document
no change

4.2.1 Q1 Query on Attribute
no change

4.2.2 Q2 Query on Element and Attribute
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $stitle := $book/metadata/title/@shortTitle    
let $cont := $book//componentTitle  
where $stitle ftcontains "manuscript guides"
   with stemming and $cont ftcontains "user profiling" 
   with stemming
return data($book/metadata/title/@shortTitle)

5.2.1 Q1 One Character Suffix Wildcard Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content 
where $cont ftcontains "test." with wildcards
return $book

5.2.2  Q2 Zero or One Character Prefix Wildcard Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains ".?way" with wildcards
return $book

5.2.3-5.2.5 done in document

6.2.1 Q1 Query Stemming on Word Root
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "test" with stemming
return $book

6.2.2 done in document

7.2.1 Q1 Query on Synonyms Identified by a Thesaurus
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $intro := $book//introduction 
where $intro ftcontains "quote" with thesaurus at
   "http://bstore1.example.com/UsabilityThesaurus.xml" 
   relationship "synonyms"
return $book

7.2.2 Q2 Query on Narrower Terms Identified by a Thesaurus
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content
where $cont ftcontains "web site components" 
   with thesaurus at 
   "http://bstore1.example.com/UsabilityThesaurus.xml" 
   relationship "narrower terms" at most 2 levels
return $book

7.2.3 Q3 Query on Broader Terms Identified by a Thesaurus
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[@number="3"]
let $cont := $book/content 
where $cont ftcontains 
   ("letters" ftor "holiday cards") with thesaurus at 
   "http://bstore1.example.com/UsabilityThesaurus.xml" 
   relationship "BT" exactly 1 levels
return $book

7.2.4 Q4 Query on Word Which Sounds Like Other Words
no change

7.2.5 Q5 Query on Word Spelled Similarly to Other Words
no change

7.2.6 Q6 Query on Subordinate Terms Identified by a Taxonomy
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[@number="3"]
let $comp := $book//component
where $comp ftcontains "AIDS" uppercase with thesaurus at 
   "http://bstore1.example.com/OurTaxonomy.xml" 
   relationship "disease in this category"
return $book

8.2.1 Q1 Query on Stop Word Treated as a Stop Word
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "planning then conducting" 
   with stop words 
   at "http://bstore1.example.com/StopWordList.xml"
return $book

8.2.2 Q2 Query on Stop Word Not Treated as a Stop Word
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "planning then conducting" 
   without stop words
return $book

9.2.1 Q1 Diacritics Sensitive Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "résumé." with wildcards 
   diacritics sensitive
return $book

9.2.2 Q2 Diacritics Insensitive Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "resume." with wildcards 
   diacritics insensitive
return $book

9.2.3 Q3 Query on Word with Upper Case Characters
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book  
where $book[. ftcontains "AIDS" uppercase] 
return $book

9.2.4 Q4 Query on Word with Upper Case and Lower Case Characters
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book  
where $book ftcontains "AIDS" case insensitive
return $book

10.2.1 Q1 Or Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "web" ftor "software"
return $book

10.2.2 Q2 And Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "web" ftand "software"
return $book

10.2.3 Q3 And Query Ordered
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "goal" ftand "obstacles" 
   ftand "task" ordered
return $book

10.2.4 Q4 Unary Not Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
where $book ftcontains ftnot "us.* testing" with 
   wildcards
return $book

10.2.5 Q5 And Not Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $up := $book/metadata
where $up ftcontains "usability" ftand ftnot "plan"
return $book

10.2.6 Q6 And Not Query Where Second Operand Is a Subset of the First Operand
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content
where $cont ftcontains ("résumés" diacritics sensitive 
   ftor "drafts" ftor "correspondence") ftand ftnot 
   "book drafts"
return $book

10.2.7 Q7 Mild Not Query Where Second Operand Is a Subset of the First Operand
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains ("résumés" diacritics sensitive 
   ftor "drafts" ftor "correspondence") not in "book 
   drafts"
return $book
Comment 8 Pat Case 2008-08-12 20:45:13 UTC
XQuery solutions for Sections 11-17. Pat

11.2.1 Q1 Query in Same Instance of an Element
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $subj := $book/metadata/subjects/subject
where $subj ftcontains "web site" ftand "usability"
return $book

11.2.2 Q2 no change

11.2.3 Q3 Query in Every Instance of an Element (Universal Quantification)
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
where every $pub in $book//publisher satisfies 
   $pub ftcontains "ersatz" ftand "publications"
return $book
--Removed parentheses.

11.2.4 Q4 Occurrence Count Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "expert review methods" 
   occurs at least 2 times
return $book

12.2.1 Q1 Unordered Distance Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "software" ftand "developer" 
   with stemming distance at most 3 words
return $book

12.2.2 Q2 Ordered Distance Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "efficient" ftand "task" ftand 
   "completion" ordered distance at most 10 words
return $book

12.2.3 Q3 Ordered Window Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "users" ftand "feeling" ftand 
   ("well served" ftor "well-served") with stemming 
   ordered window 15 words
return $book

12.2.4 Q4 Unordered Within a Sentence Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "users" ftand "would" ftand "know" 
   ftand "step" with stemming same sentence
return $book

12.2.5 Q5 Unordered Within a Paragraph Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content
where $cont ftcontains "usability" ftand "web site" 
   ftand "efficiency" ftand "satisfaction" same paragraph
return $book

13.2.1 Q1 Query on Element and Its Children
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $para := $book//p
let $fn := $para/footnote
where $para ftcontains "computer workstation" 
   and $fn ftcontains "comfortable"
return ($book/metadata/title, $para)

13.2.2 Q2 Query on Element Returning Its First Two Children
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $para := $book//chapter/p
where $para ftcontains "usability" ftand "test" 
   with stemming
return ($book/metadata/title, $para/step[1], $para/step[2])

13.2.3 Q3 Query on Element and Its Ancestors
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[@number="3"]
let $comp := $book/content/part/component/
   (subComponent|subComponent/subsubComponent)/
   componentTitle
let $parentComp := $comp[ancestor::node()
where $comp ftcontains "flow diagram.?" 
   with wildcards and $parentComp [. /content/
   part/component/
   (subComponent|subComponent/subsubComponent)/
   componentTitle ftcontains "human computer 
   interaction"]
return ($book/metadata/title, $book/content)

13.2.4 Q4 Query on Element and Its Right Siblings
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $chapters := $book//chapter
where $chapters [./p ftcontains "usability 
   testing" and ./p/following-sibling::p ftcontains 
   "information architecture"]
return ($book/metadata/title, $chapters)

14.2.1 Q1 Distance Query Ignoring Content of All Descendant Elements
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $p := $book//p 
where $p ftcontains "testing" ftand "guidance" ftor 
   "correct" distance at most 60 words without content *
return $book
--Removed parentheses.

14.2.2 Q2 Phrase Query Ignoring Content of Descendant Element Specified by XPath Expression
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $chap := $book//chapter
where $chap ftcontains "users can be tested at any 
   computer workstation or in a lab" without content 
   .//footnote] 
return ($book/metadata/title, $chap)

14.2.3 Q3 Phrase Query Ignoring Content of Descendant Element Specified by Full-Text Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $chap := $book//chapter 
where $chap ftcontains  "at any computer workstation 
   or in a lab" without content (.//footnote[. ftcontains 
   "workstation." with wildcards])
return ($book/metadata/title, $chap)

14.2.4 Q4 Distance Query Ignoring Content of Descendant Elements Level by Level
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $where := $book//chapter/(p|p/footnote)
where $where ftcontains "workstation" ftand "lab" 
   distance at most 6 words without content ./footnote
return ($book/metadata/title, $where)
--Shortened xpath in let statement.

15.2.1 Q1 Query on Words and Phrases in Two Languages
no change

15.2.2 Q2 Phrase and Distance Query in an Instance of an Element with Stemming
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $para := $book/content//p
where $para ftcontains ("task" ftand "performance" 
   with stemming distance at most 3 words) ftand 
   "expert review" with stemming
return ($book/metadata/title, $book//content)

15.2.3 Q3 Nested Distance Query with Wildcards, Stemming, and Thesaurus Support
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $quote := $book//content
where $quote ftcontains (("millicent" 
   ftand "marigold" ordered distance at most 3 words)
   ftand "quote.{0-5}" with wildcards with thesaurus at  
   "http://bstore1.example.com/UsabilityThesaurus.xml"
   relationship "synonyms" distance at most 3 words) 
   ftand "usability testing" ftand "iterations" with stemming 
   distance at most 50 words
return $book

15.2.4 Q4 Window Query with Wildcards and Stemming Ignoring Content of a Descendant Element
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $au := $book/metadata/author
let $co := $book//content
where $au ftcontains ftnot ("montana" ftand "marigold")
   and $co ftcontains "correct" ftor "comment" with 
   stemming ftor "guidance" ftor "assistance" 
   ftor "help" ftand "usability test.*" with wildcards 
   window 80 words without content .//footnote
return <book number="{$book/@number}"> 
          {$book/metadata/title, 
          $book//content}
          </book>
--Removed 3 sets of parentheses in 2nd ftcontains.

15.2.5 Q5 Query on Different Elements in Different Sub-Trees with Conditional Return
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $title := $book/metadata/title
let $in := $book/content/introduction
let $pin := $book/content/part/introduction
where $title ftcontains "usability" and $in ftcontains 
   "satisfaction" and $pin ftcontains "identify 
   problems"
return <book number="{$book/@number}"> 
          {$title} 
          if (count($book/metadata/author) > 0)
          then {$book/metadata/author, $in, $pin}
          else {$book/metadata/publicationInfo/publisher, $in, $pin}
          </book> 
 
16.2.1  Q1 Full-Text Query Constructing New Element
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $var := $book/metadata/title
where $var ftcontains "usability"
return <result> 
          {$book/metadata/title, $book/metadata/author} 
           </result>

16.2.2 Q2 Full-Text Query Returning Count of Descendant Element Occurrences
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $ct := $book/content/part/chapter/title
where $ct ftcontains "usability" ftand "test" 
   with stemming
return <book number="{$book/@number}"> 
          {$book/metadata/title,
          for $title in $ct
          return 
             ($title, 
             <number-of-steps> 
                {count($title/..//step)}
             </number-of-steps>)}
       </book>
 --Removed parentheses on "test" with stemming
 
16.2.3 no change
 
16.2.4 no change
 
16.2.5 Q5 Full-Text Query with Character String Query
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[.//publicationInfo/place/text() 
   = "Washington, D.C."]
let $intro := $book/content/introduction
where $intro ftcontains "résumés" diacritics sensitive
   ftand "drafts" ftand "correspondence"
return <book number="{$book/@number}"> 
           {$book/metadata/title, $intro}
           </book>
--Removed parentheses around résumés" diacritics sensitive

16.2.6 no change

16.2.7 Q7 Full-Text Query with Date Comparison and Element Occurrence Count
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[./metadata/publicationInfo/dateIssued > 
   "2000-12-31" or ./metadata/publicationInfo/dateRevised 
   > "2000-12-31" and count(./metadata/author) > 1]
let $subj := $book//subject
where $subj ftcontains "usability test.*" with wildcards
return <book number="{$book/@number}"> 
          {$book/metadata/title, $book/metadata/author, $subj}
           </book>
--Removed parentheses.

16.2.8 no change.

16.2.9 Q9 Query Using an XQuery Expression to Determine the Number of Words Allowed in a Window
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content
where $cont ftcontains ("successfully" 
   ftand "completing" ftand "tasks"
   window (count(./part/chapter) * 3) 
   words) with stemming
return ($book/metadata/title, $cont)
--Moved parentheses.

17.2.1-17.2.5 no change.

17.2.6 Q6 Query with Weight Declaration
for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $booktext := $book/content ftcontains ("conduct" 
   ftand "usability" ftand "tests" distance at most 
   10 words) with stemming 
let score $s := $booktext ftcontains 
   ("measuring" ftand "success" distance
   at most 4 words weight 0.8) with stemming 
order by $s
return ($book/metadata/title, $booktext)
--Not sure of this one. Added parentheses.
Comment 9 Pat Case 2008-08-19 19:17:46 UTC
Zhen,

Thanks for all the XPath Solutions.

I have one problem I can't fix on my own.

17.2.3 Q3 Query Filtering on Scores

Find all books that focus on "usability".

This query performs a word query and filters on scores.
 
The XQuery is:
 
<eg role="xquery" xml:space="preserve">for $book score $s in 
   doc(" http://bstore1.example.com/full-text.xml")
   /books/book[. ftcontains "usability"]
where $s &gt; 0.1
return $book/metadata/title</eg>

The existing XPath is:

<eg role="xpath" xml:space="preserve">doc(" http://bstore1.example.com/full-text.xml")
/books/book[(for $i score $s in .[. ftcontains "usability"]
return $s) &gt; 0.1]/metadata/title</eg>
 
The revised XPath from you is:
 
(:: 17.2.3 ::)
doc(" http://bstore1.example.com/full-text.html")
/books/book[for $i score $s in .[. ftcontains "usability"] where $s > 0.1
return $s ]/metadata/title
 
--I didn't think XPath had where statements. Might it be that what is in the Use Cases now is correct?

Pat
Comment 10 zhen hua liu 2008-08-19 19:58:48 UTC
Pat, you are right that xpath 2.0 does not have where clause, so then I could not find a pure XPath solution for this use case.
Comment 11 Pat Case 2008-08-20 11:18:34 UTC
Could someone tell me why the existing XPath for 17.2.3 Q3 Query Filtering on Scores is wrong?

Existing XPath is:

<eg role="xpath" xml:space="preserve">doc("
http://bstore1.example.com/full-text.xml")
/books/book[(for $i score $s in .[. ftcontains "usability"]
return $s) &gt; 0.1]/metadata/title</eg>

Pat
Comment 12 Pat Case 2008-09-29 19:16:43 UTC
I have updated the XQuery and XPath queries in the use case document and in the test suite.

The FTTF accepted changes at the 9/29/2008 meeting.

We left original solution for 17.2.3 Q3 Query Filtering on
Scores.

I am marking the bug fixed.

Zhen, if you approve the changes, please make the bug closed.

Pat Case, Library of Congress, member FTTF