substring() problem

Hello! I am doing text retrieval and encountered the following problem:

The xml source has the following part:


<TEI.2>
.......
<p>
The Situation of this place which we Call 
  <hi rend="italic">Council Bluff</hi> 
  which is handsom ellevated a Spot well Calculated for a Tradeing establishment
</p>
.......
</TEI.2>

I used different approaches to retrieve the text “Call Council Bluff” . Xquery 1:


let $keyword := "Call Council Bluff"
for $d in input()/p//text()
let $ref := tf:createTextReference($d, $keyword)
for $refeach in $ref
return substring($d, $refeach/@ino:start, string-length($keyword))

From Xquery1 I get empty result, because “Call” and “Council Bluff” are contained in two text nodes and none of the two text nodes contain the keyword.

Second approach:

 let $keyword := "Call Council Bluff"
for $d in input()/p
let $ref := tf:createTextReference($d, $keyword)
for $refeach in $ref
return substring($d//text(), $refeach/@ino:start, string-length($keyword))

From the second query, I got the following error:
Runtime type exception: sequence occurred where atomic value required.
I think it is because $d//text() is not atomic. So I tried the last Xquery:

let $keyword := "Call Council Bluff"
for $d in input()/p
let $ref := tf:createTextReference($d, $keyword)
for $refeach in $ref
for $a in $d//text()
return substring($a, $refeach/@ino:start, string-length($keyword))

Then I get empty result. What shall I do? I have been working on this for two weeks now!! BTW, from the second and third Xquery, I can get the correct reference descriptions (i.e., tf:createTextReference works).

thanks a lot.

problem solved, thanks.

There was another problem which solved in the mean time I accidentally marked this as solved. This one is still not solved. Please help!

Look in the “XQuery 4 User Guide”->“Text Retrieval”->“Pattern Matching”.

But I cannot find solution from “XQuery 4 User Guide”->“Text Retrieval”->“Pattern Matching”. Can anyone help?

I was thinking of the function tf:containsNearText.

It did not help. Please let me reiterate my problem:

I have a node ($p) which contains two children nodes ($c1 and $c2). The desired text($keyword) is contained in the two children nodes. Therefore my problem is when I use tf:createTextReference($p, $keyword), it returns the start postion and end position of the desired text reference, but if I use substring($p, reference/start postion, length), I get the error message that $p is not atomic. How can I get along with problem?

Hi,

the following code does the job (in principle, see below). The trick is not to split teh paragraph into text nodes, but view it as a whole:

let $keyword := “Call Council Bluff”
for $d in input()/p
let $ref := tf:createTextReference($d, $keyword)
for $refeach in $ref
return substring($d, $refeach/@ino:start, string-length($keyword))

Caveat: you get more than one text reference for the keyword (one for each word). So you have to discard those where ino:start is less than a previous ino:start+string-length($keyword)

Regards

harald