how to display part of the results?

Hello!

I want to display part of the results, but don’t know what to do? For example I have the XML source :


Made by one who has spent but a couple of years in the study of birds, it must, of necessity, be incomplete. What songsters might be added to the number of some skilled ornithologist traveling the same paths as religiously as the writer might easily make him shudder with envy. There can be little doubt that in the migratory season of the warblers there are nearly a score which pass through and visit Omaha.



I want to return only the last sentence, which contains the word “Omaha”, not the whole paragraph. How should I proceed?

thanks.

Hi,
You will need to write some code to do this, but if you use XQuery4 you can get Tamino to do a lot of the work first. An XQuery like this:


declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"
for $d in input()/document
let $ref := tf:createTextReference($d/p, "Omaha")
return $ref
</pre><BR>will return a reference object like this:<BR><pre class="ip-ubbcode-code-pre"><ino:object ino:collection="documents" ino:docid="1" ino:doctype="document" ino:doctypeid="1" ino:end="411" ino:nodeid="4" ino:start="405" </pre><BR>This tells you everything you need to know to process the document. You still need to work out where the sentence starts and ends, and you probably need to think about handling multiple hits in one paragraph. How you do this depends mostly on your choice of programming language. You could also use the additional tf:highlight function to return your text with processing instructions to show your search terms:<BR><pre class="ip-ubbcode-code-pre">for $d in input()/document
let $ref := tf:createTextReference($d/p, "Omaha")
let $high := tf:highlight($d/p, $ref, "hit")
return $high
</pre> which would return:<BR><pre class="ip-ubbcode-code-pre"><p>
Made by one who has spent but a couple of years in the study of birds, it must, of necessity, be
incomplete.What songsters might be added to the number of some skilled ornithologist traveling the same paths
as religiously as the writer might easily make him shudder with envy. There can be little doubt that in the
migratory season of the warblers there are nearly a score which pass through and visit
<?hit + 1?> 
Omaha. 
<?hit - 1?>
</p> 


I hope this gives you some ideas.
Best regards
Bill

Hi Bill, thanks a lot for the hint. Do you also have any idea on how to return for example <?hit +3?> in the above example.

thanks a lot in advance,

Yu

Sir:

I have got the result telling me the ino:start and ino:end of the referenced string. However I do not know how to use these fields. For example how do I retrieve the value of ino:start from the query result in Xquery? The following code gives me an error :

declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction" 
declare namespace xs="http://www.w3.org/2001/XMLSchema"
for $a in (for $d in input()/TEI/TEI.2/:text/body/p
let $ref := tf:createTextReference($d, "Omaha")
return $ref)
return $a/ino:response/xq:result/ino:object/@ino:start

Also, if I now the ino:start and ino:end of the string, how can I display the context of the string, say for example display the words in the range of ino:start-10 and ino:end+10.

thanks a lot in advance.

How about something like this:

declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction" 
declare namespace ino="http://namespaces.softwareag.com/tamino/response2"
declare namespace xs="http://www.w3.org/2001/XMLSchema" 
for $d in input()/document 
let $ref := tf:createTextReference($d/p, "Omaha") 
let $start := xs:int($ref/@ino:start) - 10
let $end := xs:int($ref/@ino:end) + 10
return substring($d/p,$start,$end)

Note the extra namespace declarations that you need to use the xs:int function and to reference the “ino:” namespace.

Thanks a lot, Sir. However

 return xs:int($ref/@ino:start)

gives me the following error:
<ino:messagetext ino:code=“INOXQE6315”>Runtime type exception: sequence occurred where atomic value required</ino:messagetext>
</ino:message>

What shall I do?

Please post you entire XQuery - I can’t see this problem here.

Hello! The following is the query:

declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction" 
declare namespace ino="http://namespaces.softwareag.com/tamino/response2" 
declare namespace xs="http://www.w3.org/2001/XMLSchema" 
for $d in input() 
let $ref := tf:createTextReference($d//p, "Omaha") 
let $start := xs:int($ref/@ino:start) - 10 
let $end := xs:int($ref/@ino:end) + 10 
for $a in $ref
return substring($d//p,$start,$end)

and the error is:

<ino:messagetext ino:code="INOXQE6315">Runtime type exception: sequence occurred where atomic value required</ino:messagetext> 
  </ino:message>

The following refined code still receives the same error:

declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction" 
declare namespace ino="http://namespaces.softwareag.com/tamino/response2" 
declare namespace xs="http://www.w3.org/2001/XMLSchema" 
for $d in input() 
let $ref := tf:createTextReference($d//p, "Omaha")
for $a in $ref
let $start := xs:int($a/@ino:start) - 10 
let $end := xs:int($a/@ino:end) + 10 
return substring($d//p,$start,$end)

The following query works, however only for the $start part, i.e it returns 5 characters preceeding the keyword, however not 5 characters after the keyword. Do you know why?

declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction" 
declare namespace ino="http://namespaces.softwareag.com/tamino/response2" 
declare namespace xs="http://www.w3.org/2001/XMLSchema" 
for $d in input()/TEI/TEI.2/:text/body/p
let $ref := tf:createTextReference($d, "kindergarten")
let $start := xs:int($ref/@ino:start) - 5
let $end := xs:int($ref/@ino:end) + 5 
where $ref
return substring($d,$start,$end)

The result:

<xq:value>r the kindergarten tots.</xq:value> 
  <xq:value>rough kindergarten, or first grade, according to their lights, while some of the baby Robins are already in the co</xq:value> 
  <xq:value>from kindergarten to the grade schools, and thence into "high</xq:value> 
  <xq:value>n the kindergarten pupils were asked to ascertain whether a robin hops or runs while enroute to the nearest and most succulent worm. Just in passing, there is a neat little question for you grown-ups, too. But that is another affair.</xq:value> 
  </xq:result>

thanks a lot really.

Sorry I made a mistake - I should have read the doco for the substring function. It takes two arguments, start and length (not start and end). So you need:

let $start := xs:int($a/@ino:start) - 10
let $end := xs:int($a/@ino:end) + 10
let $length := $end - $start
return substring($d//p,$start,$length)

But this may not solve your problem, which is probably more connected with multiple hits? Can you please send me your schema and your data (just a small sample) because I can’t reproduce your problem here.

Hi Bill, thanks a lot. The problem is solved. The code is as follows:

declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction" 
declare namespace ino="http://namespaces.softwareag.com/tamino/response2" 
declare namespace xs="http://www.w3.org/2001/XMLSchema" 
for $d in input()/TEI/TEI.2/:text/body/p
let $ref := tf:createTextReference($d, "to")
for $each in $ref
let $start := xs:int($each/@ino:start) - 20
let $end := xs:int($each/@ino:end) + 20 
let $stringend := $end -$start 
where $each
return substring($d,$start,$stringend)