Some version doc changed.
[ir-tcl-moved-to-github.git] / doc / ir-tcl.sgml
1 <!doctype linuxdoc system>
2
3 <!--
4   $Id: ir-tcl.sgml,v 1.12 1995-08-28 12:21:52 adam Exp $
5 -->
6
7 <article>
8 <title>IrTcl User's Guide and Reference
9 <author>Index Data, <tt/info@index.ping.dk/
10 <date>$Revision: 1.12 $
11 <abstract>
12 This document describes IrTcl &mdash; an information retrieval toolkit for
13 Tcl and Tk that provides access to the Z39.50/SR protocol.
14 </abstract>
15
16 <toc>
17
18 <sect>Introduction
19
20 <p>
21 This document describes the <sf/IrTcl/ information retrieval toolkit,
22 which offers a high-level, client interface to the Z39.50 and SR protocols.
23 The toolkit is based on the Tcl/Tk toolkit developed by Prof. John
24 K. Ousterhout at the University of California &lsqb;ref 1&rsqb;. 
25 Tcl is a simple, somewhat shell-like, interpreted language. What
26 makes Tcl attractive is that it also offers a C API, which makes
27 extensions to the language possible. The most important Tcl extension is
28 probably Tk &mdash; A Motif look-and-feel interface to the X window
29 system.
30
31 To interface the Z39.50/SR protocol <sf/IrTcl/ uses <bf/YAZ/.
32 <bf/YAZ/ offers two transport types: RFC1729/BER on TCP/IP and the mOSI
33 protocol stack.
34 However, the mOSI transport is only an option, and hence it is not
35 needed unless you wish to communicate within an OSI environment.
36 See &lsqb;ref 2&rsqb; for more information about the XTI/mOSI implementation.
37
38 <sf/IrTcl/ provides two system environments:
39
40 <itemize>
41 <item> A simple command line shell &mdash; useful for
42 testing purposes.
43 <item> A simple command line shell which operates within the Tk
44  environment &mdash; makes it very easy to implement GUI clients.
45 </itemize>
46
47 <sect>Compilation and installation
48
49 <p>
50 In order to compile you need:
51 <itemize>
52 <item> An ANSI C compiler such as GNU C.
53 <item> Tcl. Version 7.3 and 7.4 has been tested.
54 <item> YAZ version 1.0b3 or higher.
55 </itemize>
56
57 As an option you may want:
58 <itemize>
59 <item> Tk. Version 3.6 and 4.0 has been tested.
60 <item> XTI/mOSI
61 </itemize>
62
63 Unpack the <sf/IrTcl/ package at the same directory level as <bf/YAZ/. 
64
65 Type:
66 <tscreen><verb>
67 $ ./configure
68 </verb></tscreen>
69
70 This command tries to configure <sf/IrTcl/ for your system and creates
71 a <tt>Makefile</tt>.
72
73 If the <tt>configure</tt> command cannot locate Tcl and Tk in your standard
74 locations for libraries searched by your C compiler it will guess 
75 that the libraries are located in <tt>/usr/local/lib</tt> and that 
76 the header files are located in <tt>/usr/local/include</tt>. 
77 If this is incorrect you will have to modify the <tt>Makefile</tt> yourself.
78
79 Compile <sf/IrTcl/ by typing:
80 <tscreen><verb>
81 $ make
82 </verb></tscreen>
83
84 If you don't have Tk you will only be able to create the <tt>ir-tcl</tt>
85 program and you must type <tt>make ir-tcl</tt> instead.
86
87 If successful, this will make <tt>ir-tcl</tt>, <tt>ir-tk</tt> (if
88 Tk is present) and a library called <tt>libirtcl.a</tt>.
89
90 To install the programs and support files type:
91 <tscreen><verb>
92 $ make install
93 </verb></tscreen>
94
95 Summary of files installed (the names refer to the Makefile variables):
96
97 <descrip>
98 <tag><tt>ir-tk</tt></tag> The <sf/IrTcl/ shell for Tk.
99  Installed in <tt>BINDIR</tt> &mdash; defaults to
100  <tt>/usr/local/bin</tt>. <tt>ir-tk</tt> works like
101  <tt>wish</tt> &mdash without arguments it reads commands from stdin.
102  A source file may be specified by option <tt>-f</tt>. <tt>ir-tk</tt>
103  accept the same set of options as <tt>wish</tt>.
104 <tag><tt>ir-tcl</tt></tag> The <sf/IrTcl/ shell for Tcl. Installed in
105  <tt>BINDIR</tt> &mdash; defaults to <tt>/usr/local/bin</tt>.
106 <tag><tt>client.tcl</tt></tag> A graphical client for <tt>ir-tk</tt>.
107  The client is installed as an executable script called <tt>irclient</tt> in
108  <tt>BINDIR</tt>. This client needs a number of files, bitmaps, etc.
109  The client looks for the files in the current directory &mdash if
110  this fails it tries to look in the directory <tt>IRTCLDIR</tt>
111  &mdash; defaults to <tt>/usr/local/lib/irtcl</tt>.
112 <tag><tt>libirtcl.a</tt></tag> The <sf/IrTcl/ library. 
113  Installed in <tt>LIBDIR</tt> &mdash; defaults to <tt>/usr/local/lib</tt>.
114 <tag><tt>ir-tcl.h</tt></tag> The <sf/IrTcl/ header file.
115  Installed in <tt>INCDIR</tt> &mdash; defaults to <tt>/usr/local/include</tt>.
116 <tag><tt>clientrc.tcl</tt></tag> A setup file with definitions
117  of target and queries. Read and updated by <tt>client.tcl</tt>. Installed
118  in <tt>IRTCLDIR</tt> &mdash; defaults to <tt>/usr/local/lib/irtcl</tt>.
119 <tag><tt>formats/*</tt></tag> Display format files written
120  in Tk. Read by <tt>client.tcl</tt>. Installed 
121  in <tt>IRTCLDIR</tt> &mdash; defaults to <tt>/usr/local/lib/irtcl</tt>.
122 <tag><tt>bitmaps/*</tt></tag> Various bitmap files. Read by
123  <tt>client.tcl</tt>. Installed 
124  in <tt>IRTCLDIR</tt> &mdash; defaults to <tt>/usr/local/lib/irtcl</tt>.
125 <tag><tt>LICENSE</tt></tag> LICENSE file. Read by
126  <tt>client.tcl</tt>. Installed 
127  in <tt>IRTCLDIR</tt> &mdash; defaults to <tt>/usr/local/lib/irtcl</tt>.
128 </descrip>
129
130 <sect1>ir-tcl
131
132 <p>
133 The <tt>ir-tcl</tt> program is a shell like <tt>tclsh</tt> except that
134 <tt>ir-tcl</tt> features the new set of information retrieval commands. 
135 Normally <tt>ir-tcl</tt> waits on <tt/stdin/ (for you to type commands) and
136 on sockets events (connected to Z39.50/SR targets).
137 You simply type the Tcl commands line by line. A filename may be specified as 
138 argument to <tt>ir-tcl</tt> in which case the file specified is evaluated 
139 as a script.
140
141 <sect1>ir-tk
142
143 <p>
144 <tt>ir-tk</tt> is a program that works like <tt>wish</tt> except that
145 <tt>ir-tk</tt> include the new set of commands. All options accepted
146 by <tt>wish</tt> are also accepted by <tt>ir-tk</tt>. 
147
148 The enclosed script <tt>client.tcl</tt> for <tt>ir-tk</tt> is a graphical 
149 client which demonstates an example of a user interface for the Z39.50/SR 
150 protocols. 
151 At first the script was relatively small but it has grown since the 
152 beginning. At present it is about 3000 lines. 
153
154 The client can be started directly from the top level directory 
155 of <sf/IrTcl/ by typing:
156 <tscreen><verb>
157 $ ir-tk -f client.tcl
158 </verb></tscreen>
159
160 Or, if you have installed <sf/IrTcl/ you may also type:
161 <tscreen><verb>
162 $ irclient
163 </verb></tscreen>
164
165 The client lets up define targets and query types within the interface.
166 Hence, you will not need to modify configation files. 
167
168 Stuff concerning targets can be found in the pull down menu 'Target'
169 with the following options:
170 <descrip>
171 <tag>Connect</tag> Establishes connection to a target.
172 <tag>Disconnect</tag> Closes a target connection.
173 <tag>About</tag> Shows implementation Id, implementation Version, etc 
174  for the current target.
175 <tag>Setup</tag> Pops up a target definition window. You may alter
176  a target definition.
177 <tag>Setup new</tag> Lets you define a new target.
178 </descrip> 
179
180 The term query type refers to a collection of search fields. The
181 pull down menu Options|Query deals with queries. You may
182 insert/modify/remove query types.
183
184 <sect>Overview of the API
185
186 <p>
187 Basically, <sf/IrTcl/ is a set of commands introduced to Tcl.
188 When extending Tcl there are two approaches: action-oriented commands
189 and object-oriented commands.
190
191 Action-oriented commands manipulate
192 Tcl variables and each command introduces only one action.
193 The string manipulation commands in Tcl are action oriented.
194
195 Object-oriented commands are added for every declared
196 variable (object). Object-oriented commands usually provide a set of
197 actions (methods) to manipulate the object.
198 The widgets in Tk (X objects) are examples of the object-oriented style.
199
200 <sf/IrTcl/ commands are object-oriented. The main reason
201 for this is that the data structures involved in the IR protocol
202 are not easily represented by Tcl data structures.
203 Also, the <sf/IrTcl/ objects tend to exist for a relativly long time.
204 Note that although we use the term object-oriented commands, this
205 does not mean that the programming style is strictly object-oriented. For
206 example, there is such no such thing as inheritance.
207
208 We are now ready to present the three commands introduced to Tcl by
209 <sf/IrTcl/:
210
211 <descrip>
212 <tag/ir/ The ir object represents a connection to a target. More
213 precisely it describes a Z-association. 
214 <tag/ir-set/ The ir-set describes a result set, which is
215 conceptually a collection of records returned by the target.
216 The ir-set object may retrieve records from a target by means of
217 the ir object; it may read/write records from/to a local file or it may be
218 updated with a user-edited record. 
219 <tag/ir-scan/ The scan object represents a list of scan lines
220 retrieved from a target.
221 </descrip>
222
223 <bf/Example/
224
225 To create a new IR object called <tt/z-assoc/ write:
226 <tscreen><verb>
227    ir z-assoc
228 </verb></tscreen>
229
230 <bf/End of example/
231
232 Each object provides a set of <em/settings/ which may either be
233 readable, writeable of both. All settings immediately follow
234 the name of the object. If a value is present the setting
235 is set to <em/value/.
236
237 <bf/Example/
238
239 We wish to set the preferred-message-size to 18000 on the
240 <tt/z-assoc/ object:
241
242 <tscreen><verb>
243    z-assoc preferredMessageSize 18000
244 </verb></tscreen>
245
246 To read the current value of preferred-message-size use:
247
248 <tscreen><verb>
249    z-assoc preferredMessageSize
250 </verb></tscreen>
251 <bf/End of example/
252
253 One important category consists of settings is those that relate to the
254 event-driven model. When <sf/IrTcl/ receives responses from the target, i.e.
255 init responses, search responses, etc., a <em/callback/ routine
256 is called. Callback routines are represented in Tcl as
257 a list, which is re-interpreted prior to invocation.
258 The method is similar to the one used in Tk to capture X events.
259
260 For each SR/Z39.50 request there is a corresponding object action. The most
261 important actions are:
262 <descrip>
263 <tag/connect/ Establishes connection with a target
264 <tag/init/ Sends an initialize request.
265 <tag/search/ Sends a search request.
266 <tag/present/ Sends a present request.
267 <tag/scan/ Sends a scan request.
268 </descrip>
269
270 <bf/Example/
271
272 This example shows a complete connect - init - search - present scenario. 
273
274 First an IR object, called <tt/z/, is created.
275 Also a result set <tt/z.1/ is introduced by the <tt/ir-set/ 
276 and it is specified that the result set uses <tt/z/ as its association.
277
278 The setting <tt/databaseNames/ is set to the 
279 database <tt/books/ to which the following searches are directed.
280 A callback is then defined and a connection is established to
281 <tt/fake.com/ by the <tt/connect/ action.
282 If the connect succeeds the <tt/connect-response/ is called.
283
284 In the Tcl procedure, <tt/connect-response/, a callback is defined
285 <em/before/ the init request is executed. 
286 The Tcl procedure <tt/init-response/ is called when a 
287 init response is returned from the target.
288
289 The <tt/init-response/ procedure sets up a <tt/search-response/ 
290 callback handler and sends a search-request by using a query which
291 consists of a single word <tt/science/.
292
293 When the <tt/search-response/ procedure is called it defines
294 a variable <tt/hits/ and sets it to the value of the setting
295 <tt/resultCount/. If <tt/hits/ is positive a present-request is
296 sent &mdash; asking for 5 records from position 1. 
297
298 Finally, a present response is received and the number of records
299 returned is stored in the variable <tt/ret/.
300
301 <tscreen><verb>
302 ir z
303 z databaseNames books
304 ir-set z.1 z
305 z callback {connect-response}
306 z connect fake.com
307
308 proc connect-response {} {
309     z callback {init-response}
310     z init
311 }
312
313 proc init-response {} {
314     z.1 callback {search-response}
315     z.1 search science
316 }
317
318 proc search-response {} {
319     set hits [z.1 resultCount]
320     puts "$hits hits"
321     if {$hits > 0} {
322         z.1 callback {present-response}
323         z.1 present 1 5
324     }
325 }
326
327 proc present-response {} {
328     set ret [z.1 numberOfRecordsReturned]
329     puts "$ret records returned"
330 }
331 </verb></tscreen>
332 <bf/End of example/
333
334 The previous example program doesn't care about error conditions. 
335 If errors occur in the program they will be trapped by the Tcl error 
336 handler. This is not always appropriate. However, Tcl offers a 
337 <tt/catch/ command to support error handling by the program itself.
338
339 <sect>Associations
340
341 <p>
342 The ir object describes an association with a target.
343 This section covers the connect-init-disconnect actions provided
344 by the ir object.
345 An ir object is created by the <tt/ir/ command and the
346 created object enters a 'not connected' state, because it isn't
347 connected to a target yet. 
348
349 <sect1>Connect
350
351 <p>
352 A connection is established by the <tt/connect/ action which is
353 immediately followed by a hostname. A number of settings affect the
354 <tt/connect/ action. Obviously, these settings should be set
355 <bf/before/ connecting. The settings are:
356
357 <descrip>
358 <tag><tt>comstack </tt><tt>mosi|tcpip</tt></tag>
359  Comstack type.
360 <tag><tt>protocol </tt><tt>Z39|SR</tt></tag>
361  Protocol type - ANSI/NISO Z39.50 or ISO SR.
362 <tag><tt>callback </tt><em>list</em></tag>
363  Tcl script called when the connection is established
364 <tag><tt>failback </tt><em>list</em></tag>
365  Fatal error Tcl script. Called on protocol errors or if target
366  closes connection
367 </descrip>
368
369 If the connect is unsuccessful either the connect action itself
370 will return an error code or the failback handler is invoked.
371
372 <sect1>Init
373
374 <p>
375 If the connect operation succeeds the <tt/init/ action should be used. 
376 The init related settings are:
377
378 <descrip>
379 <tag><tt>preferredMessageSize </tt><em>integer</em></tag>
380  Preferred-message-size. Default value is 30000.
381 <tag><tt>maximumRecordSize </tt><em>integer</em></tag>
382  Maximum-record-size. Default value is 30000.
383 <tag><tt>idAuthentication </tt><em>string</em> ...</tag>
384  Id-authentication. There are three forms. If any empty is
385  given, the Id-authentication is not used.  If one non-empty string
386  is given, the 'open' authentication is used. If three strings are 
387  specified, the version 'id-pass' authentication (version 3 only) 
388  is used in which case the first string is groupId; the second string 
389  is userId and the third string is password.
390 <tag><tt>implementationName </tt><em>string</em></tag>
391  Implementation-name of origin system. 
392 <tag><tt>implementationId</tt></tag>
393  Implementation-id of origin system. This setting is read-only.
394 <tag><tt>implementationVersion</tt></tag>
395  Implementation-version of origin system. This settings is read-only.
396 <tag><tt>options </tt><em>list</em></tag>
397  Options to be negotiated in the init service. The list contains 
398  the options that are set. Possible values are <tt>search</tt>, 
399  <tt>present</tt>, <tt>delSet</tt>, <tt>resourceReport</tt>, 
400  <tt>triggerResourceCtrl</tt>, <tt>resourceCtrl</tt>,
401  <tt>accessCtrl</tt>, <tt>scan</tt>, <tt>sort</tt>, 
402  <tt>extendedServices</tt>, <tt>level-1Segmentation</tt>, 
403  <tt>level-2Segmentation</tt>, <tt>concurrentOperations</tt> and
404  <tt>namedResultSets</tt>. Currently the default options are:
405  <tt>search</tt>, <tt>present</tt>, <tt>scan</tt> and 
406  <tt>namedResultSets</tt>. The <tt>options</tt> setting is set to its default
407  value when an ir object is created and when a <tt>disconnect</tt>
408  action is performed.
409 <tag><tt>protocolVersion </tt><em>integer</em></tag>
410  Protocol version: 2, 3, etc. Default is 2.
411 <tag><tt>initResponse </tt><em>list</em></tag>
412  Init-response Tcl script. Note: not implemented - use <tt>callback</tt>
413  instead.
414 <tag><tt>callback </tt><em>list</em></tag>
415  General response Tcl script. Only used if <tt>initResponse</tt>
416  is not specified.
417 </descrip>
418
419 The init-response handler should inspect some of the settings shown
420 below:
421
422 <descrip>
423 <tag><tt>initResult </tt><em>boolean</em></tag>
424  Init response status. True if init operation was successful; 
425  false otherwise.
426 <tag><tt>preferredMessageSize </tt><em>integer</em></tag>
427  Preferred-message-size.
428 <tag><tt>maximumRecordSize </tt><em>integer</em></tag>
429  Maximum-record-size.
430 <tag><tt>targetImplementationName </tt><em>string</em></tag>
431  Implementation-name of target system.
432 <tag><tt>targetImplementationId </tt><em>string</em></tag>
433  Implementation-id of target system.
434 <tag><tt>targetImplementationVersion </tt><em>string</em></tag>
435  Implementation-version of target system.
436 <tag><tt>options </tt><em>list</em></tag>
437  Options negotiated in init. The list contains the options that are set.
438 <tag><tt>protocolVersion </tt><em>integer</em></tag>
439  Protocol version: 2, 3, etc.
440 <tag><tt>userInformationField </tt><em>string</em></tag>
441  User information field.
442 </descrip>
443
444 <bf/Example/
445
446 Consider a client with the ability to access multiple targets.
447
448 We define a list of targets that we wish to connect to.
449 Each item in the list describes the target parameters with
450 the following four components: association-name, comstack-type,
451 protocol-type and a hostname.
452
453 The list for the two targets: ISO/SR target DANBIB and TCP/Z39.50 
454 target Data Research, will be defined as:
455 <tscreen><verb>
456 set targetList { {danbib mosi SR 0103/find2.denet.dk:4500}
457                  {drs tcpip Z39 dranet.dra.com} }
458 </verb></tscreen>
459
460 The Tcl code below defines, connect and initialize the
461 targets in <tt/targetList/:
462
463 <tscreen><verb>
464 foreach target $targetList {
465     set assoc [lindex $target 0]
466     ir $assoc
467     $assoc comstack [lindex $target 1]
468     $assoc protocol [lindex $target 2]
469     $assoc failback [list fail-response $assoc]
470     $assoc callback [list connect-response $assoc]
471     $assoc connect [lindex $target 3]
472 }
473
474 proc connect-response {assoc} {
475     $assoc callback [list init-response $assoc]
476     $assoc init
477 }
478
479 proc fail-response {assoc} {
480     puts "$assoc closed connection or protocol error"
481 }
482
483 proc init-response {assoc} {
484     if {[$assoc initResult]} {
485         puts "$assoc initialized ok"
486     } else {
487         puts "$assoc didn't initialize"
488     }
489 }
490 </verb></tscreen>
491
492 <tt/target/ is bound to each item in the list of targets.
493 The <tt/assoc/ is set to the ir object name.
494 Then, the comstack, protocol and failback are set for the <tt/assoc/ object.
495 The ir object name is argument to the <tt/fail-response/ and 
496 <tt/connect-response/ routines. 
497 Note the use of the Tcl <tt/list/ command which 
498 is necessary here because the argument contains variables 
499 (<tt/assoc/) that should be substituted before the handler is defined.
500 After the connect operation, the <tt/init-response/ handler
501 is defined in much the same way as the failback handler.
502 And, finally, an init request is executed.
503
504 <bf/End of example/
505
506 <sect1>Disconnect
507
508 <p>
509 To terminate the connection the <tt/disconnect/ action should be used. 
510 This action has no parameters. 
511 Another connection may be established by a new <tt/connect/ action on
512 the same ir object.
513
514 <sect>Result sets
515
516 <p>
517 This section covers the queries used by <sf/IrTcl/, and how searches and
518 presents are handled.
519
520 A search operation and a result set is described by the ir set object.
521 The ir set object is defined by the <tt/ir-set/ command which
522 has two parameters. The first is the name of the new ir set object, and
523 the second, which is optional, is the name of an assocation &mdash; an ir
524 object. The second argument is required if the ir set object should be able
525 to perform searches and presents. However, it is not required if
526 only ``local'' operations is done with the ir set object.
527
528 When the ir set object is created a number of settings are inherited
529 from the ir object, such as the selected databass, query type,
530 etc. Thus, the ir object contains what we could call default
531 settings.
532
533 <sect1>Queries
534
535 <p>
536 Search requests are sent by the <tt/search/ action which
537 takes a query as parameter. There are two types of queries,
538 RPN and CCL, controlled by the setting <tt/queryType/.
539 A string representation for the query is used in <sf/IrTcl/ since
540 Tcl has reasonably powerful string manipulaton capabilities.
541 The RPN query used in <sf/IrTcl/ is the prefix query notation also used in
542 the <bf/YAZ/ test client.
543
544 The CCL query is an uninterpreted octet-string which is parsed by the target.
545 We refer to the standard: ISO 8777. Note that only a few targets
546 actually support the CCL query and the interpretation of
547 the standard may vary.
548
549 The prefix query notation (which is converted to RPN) offer a few
550 operators. They are:
551
552 <descrip>
553 <tag><tt>@attr </tt><em>list op</em></tag>
554  The attributes in list are applied to op
555 <tag><tt>@and </tt><em>op1 op2</em></tag>
556  Boolean <em/and/ on op1 and op2
557 <tag><tt>@or </tt><em>op1 op2</em></tag>
558  Boolean <em/or/ on op1 and op2
559 <tag><tt>@not </tt><em>op1 op2</em></tag>
560  Boolean <em/not/ on op1 and op2
561 <tag><tt>@prox </tt><em>list op1 op2</em></tag>
562  Proximity operation on op1 and op2. Not implemented yet.
563 <tag><tt>@set </tt><em>name</em></tag>
564  Result set reference
565 </descrip>
566
567 It is simple to build RPN queries in <sf/IrTcl/. Search terms
568 are sequences of characters, as in:
569 <tscreen><verb>
570    science
571 </verb></tscreen>
572
573 Boolean operators use the prefix notation (instead of the suffix/RPN),
574 as in:
575 <tscreen><verb>
576    @and science technology
577 </verb></tscreen>
578
579 Search terms may be associated with attributes. These
580 attributes are indicated by the <tt/@attr/ operator.
581 Assuming the bib-1 attribute set, we can set the use-attribute 
582 (type is 1) to title (value is 4):
583
584 <tscreen><verb>
585    @attr 1=4 science
586 </verb></tscreen>
587
588 Also, it is possible to apply attributes to a range of search terms.
589 In the query below, both search terms have use=title but the <tt/tech/
590 term is right truncated:
591
592 <tscreen><verb>
593    @attr 1=4 @and @attr 5=1 tech beta
594 </verb></tscreen>
595
596 <sect1>Search
597
598 <p>
599 The settings that affect the search are listed below:
600
601 <descrip>
602 <tag><tt>databaseNames </tt><em>list</em></tag>
603  database-names.
604 <tag><tt>smallSetUpperBound </tt><em>integer</em></tag>
605  small set upper bound. Default 0.
606 <tag><tt>largeSetLowerBound </tt><em>integer</em></tag>
607  large set lower bound. Default 2.
608 <tag><tt>mediumSetPresentNumber </tt><em>integer</em></tag>
609  medium set present number. Default 0.
610 <tag><tt>replaceIndicator </tt><em>boolean</em></tag>
611  replace-indicator.
612 <tag><tt>setName </tt><em>string</em></tag>
613  name of result set.
614 <tag><tt>queryType rpn|ccl</tt></tag>
615  query type-1 or query type-2 
616 <tag><tt>preferredRecordSyntax </tt><em>string</em></tag>
617  preferred record syntax &mdash; UNIMARC, USMARC, etc. 
618 <tag><tt>smallSetElementSetNames </tt><em>string</em></tag>
619  small-set-element-set names. Not implemented yet.
620 <tag><tt>mediumSetElementSetNames </tt><em>string</em></tag>
621  medium-set-element-set names. Not implemented yet.
622 <tag><tt>searchResponse </tt><em>list</em></tag>
623  Search-response Tcl script. Not implemented yet. Use <tt>callback</tt>
624  instead.
625 <tag><tt>callback </tt><em>list</em></tag>
626  General response Tcl script. Only used if searchResponse is not specified 
627 </descrip>
628
629 Setting the <tt/databaseNames/ is mandatory. All other settings
630 have reasonable defaults.
631 The search-response handler, specified by the <tt/callback/ - or
632 the <tt/searchResponse/ setting, 
633 should read some of the settings shown below:
634
635 <descrip>
636 <tag><tt>searchStatus </tt><em>boolean</em></tag>
637  search-status. True if search operation was successful; false
638  otherwise.
639 <tag><tt>responseStatus </tt><em>list</em></tag>
640  response status information.
641 <tag><tt>resultCount </tt><em>integer</em></tag>
642  result-count
643 <tag><tt>numberOfRecordsReturned </tt><em>integer</em></tag>
644  number of records returned.
645 </descrip>
646
647 The <tt/responseStatus/ signals one of three conditions which
648 is indicated by the value of the first item in the list:
649
650 <descrip>
651 <tag><tt>NSD</tt></tag> indicates that the target has returned one or 
652 more non-surrogate diagnostic messages. The <tt/NSD/ item is followed by 
653 a list with all non-surrogate messages. Each non-surrogate message consists
654 of three items. The first item of the three items is the error
655 code (integer); the next item is a textual representation of the error
656 code in plain english; the third item is additional information, possibly
657 empty if no additional information was returned by the target.
658
659 <tag><tt>DBOSD</tt></tag> indicates a successful operation where the
660 target has returned one or more records. Each record may be
661 either a database record or a surrogate diagnostic.
662
663 <tag><tt>OK</tt></tag> indicates a successful operation &mdash; no records are
664 returned from the target. 
665 </descrip>
666
667 <bf/Example/
668
669 We continue with the multiple-targets example. 
670 The <tt/init-response/ procedure will attempt to make searches:
671
672 <tscreen><verb>
673 proc init-response {assoc} {
674     puts "$assoc connected"
675     ir-set ${assoc}.1 $assoc
676     $assoc.1 queryType rpn
677     $assoc.1 databaseNames base-a base-b
678     $assoc.1 callback [list search-response $assoc ${assoc}.1]
679     $assoc.1 search "@attr 1=4 @and @attr 5=1 tech beta"
680 }
681 </verb></tscreen>
682
683 An ir set object is defined and the
684 ir object is told about the name of ir object.
685 The ir set object use the name of the ir object as prefix.
686
687 Then, the query-type is defined to be RPN, i.e. we will
688 use the prefix query notation later on.
689
690 Two databases, <tt/base-a/ and <tt/base-b/, are selected.
691
692 A <tt/search-response/ handler is defined with the
693 ir object and the ir-set object as parameters and
694 the search is executed.
695
696 The first part of the <tt/search-response/ looks like:
697 <tscreen><verb>
698 proc search-response {assoc rset} {
699     set status [$rset responseStatus]
700     set type [lindex $status 0]
701     if {$type == "NSD"} {
702         set code [lindex $status 1]
703         set msg [lindex $status 2]
704         set addinfo [lindex $status 3]
705         puts "NSD $code: $msg: $addinfo"
706         return
707     } 
708     set hits [$rset resultCount]
709     if {$type == "DBOSD"} {
710         set ret [$rset numberOfRecordsReturned]
711         ...
712     }
713 }
714 </verb></tscreen>
715 The response status is stored in variable <tt/status/ and 
716 the first element indicates the condition.
717 If non-surrogate diagnostics are returned they are displayed.
718 Otherwise, the search was a success and the number of hits
719 is read. Finally, it is tested whether the search response
720 returned records (database or diagnostic).
721
722 Note that we actually didn't inspect the search status (setting
723 <tt/searchStatus/) to determine whether the search was successful or not, 
724 because the standard specifies that one or more non-surrogate
725 diagnostics should be returned by the target in case of errors.
726
727 <bf/End of example/
728
729 If one or more records are returned from the target they
730 will be stored in the result set object.
731 In the case in which the search response contains records, it is
732 very similar to the present response case. Therefore, some settings
733 are common to both situations.
734
735 <sect1>Present
736
737 <p>
738 The <tt/present/ action sends a present request. The <tt/present/ is
739 followed by two optional integers. The first integer is the 
740 result-set starting position &mdash; defaults to 1. The second integer 
741 is the number of records requested &mdash; defaults to 10. 
742 The settings which could be modified before a <tt/present/
743 action are:
744
745 <descrip>
746 <tag><tt>preferredRecordSyntax </tt><em>string</em></tag>
747  preferred record syntax &mdash; UNIMARC, USMARC, etc.
748 <tag><tt>elementSetElementSetNames </tt><em>string</em></tag>
749  element-set names 
750 <tag><tt>presentResponse </tt><em>list</em></tag>
751  Present-response Tcl script. Not implemented yet. Use <tt>callback</tt>
752  instead.
753 <tag><tt>callback </tt><em>list</em></tag>
754  General response Tcl script. Only used if presentResponse is not specified 
755 </descrip>
756
757 The present-response handler should inspect the settings
758 shown in table below.
759 Note that <tt/responseStatus/ and <tt/numberOfRecordsReturned/
760 settings were also used in the search-response case.
761
762 As in the search response case, records returned from the
763 target are stored in the result set object.
764
765 <descrip>
766 <tag><tt>presentStatus </tt><em>boolean</em></tag>
767  present-status 
768 <tag><tt>responseStatus </tt><em>list</em></tag>
769  Response status information 
770 <tag><tt>numberOfRecordsReturned </tt><em>integer</em></tag>
771  number of records returned 
772 <tag><tt>nextResultSetPosition </tt><em>integer</em></tag>
773  next result set position
774 </descrip>
775
776 <sect1>Records
777
778 <p>
779 Search responses and present responses may result in
780 one or more records stored in the ir set object if
781 the <tt/responseStatus/ setting indicates database or
782 surrogate diagnostics (<tt/DBOSD/). The individual
783 records, indexed by an integer position, should be 
784 inspected.
785
786 The action <tt/type/ followed by an integer returns information 
787 about a given position in an ir set. There are three possiblities:
788
789 <descrip>
790 <tag><tt/SD/</tag> The item is a surrogate diagnostic record.
791 <tag><tt/DB/</tag> The item is a database record.
792 <tag><em/empty/</tag> There is no record at the specified position.
793 </descrip>
794
795 To handle the first case, surrogate diagnostic record, the
796 <tt/Diag/ action should be used. It returns three
797 items: error code (integer), text representation in plain english
798 (string), and additional information (string, possibly empty).
799
800 In the second case, database record, the <tt/recordType/ action should
801 be used. It returns the record type at the given position.
802 Some record types are:
803
804 <tscreen>
805 UNIMARC
806 INTERMARC
807 CCF
808 USMARC
809 UKMARC
810 NORMARC
811 LIBRISMARC
812 DANMARC
813 FINMARC
814 SUTRS
815 </tscreen>
816
817 <bf/Example/
818
819 We continue our search-response example. In the case,
820 <tt/DBOSD/, we should inspect the result set items. 
821 Recall that the ir set name was passed to the
822 search-response handler as argument <tt/rset/.
823
824 <tscreen><verb>
825     if {$type == "DBOSD"} {
826         set ret [$rset numberOfRecordsReturned]
827         for {set i 1} {$i<=$ret} {incr i} {
828             set itype [$rset type $i]
829             if {$itype == "SD"} {
830                 set diag [$rset Diag $i]
831                 set code [lindex $diag 0]
832                 set msg [lindex $diag 1]
833                 set addinfo [lindex $diag 2]
834                 puts "$i: NSD $code: $msg: $addinfo"
835             } elseif {$itype == "DB"} {
836                 set rtype [$rset recordType $i]
837                 puts "$i: type is $rtype"
838             }
839         }
840     }
841 </verb></tscreen>
842 Each item in the result set is examined. 
843 If an item is a diagnostic message it is displayed; otherwise
844 if it's a database record its type is displayed.
845
846 <bf/End of example/
847
848 <sect1>MARC records
849
850 <p>
851 In the case, where there is a MARC record at a given position we
852 want to display it somehow. The action <tt/getMarc/ is what we need.
853 The <tt/getMarc/ is followed by a position integer and the type of
854 extraction we want to make: <tt/field/ or <tt/line/.
855
856 The <tt/field/ and <tt/line/ type are followed by three
857 parameters that serve as extraction masks.
858 They are called tag, indicator and field.
859 If the mask matches a tag/indicator/field of a record the information
860 is extracted. Two characters have special meaning in masks: the
861 dot (any character) and star (any number of any character).
862
863 The <tt/field/ type returns one or more lists of field information
864 that matches the mask specification. Only the content of fields
865 is returned.
866
867 The <tt/line/ type, on the other hand, returns a Tcl list that
868 completely describe the layout of the MARC record &mdash; including
869 tags, fields, etc.
870
871 The <tt/field/ type is sufficient and efficient in the case, where only a
872 small number of fields are extracted, and in the case where no
873 further processing (in Tcl) is necessary.
874
875 However, if the MARC record is to be edited or altered in any way, the
876 <tt/line/ extraction is more powerful &mdash; only limited by the Tcl
877 language itself.
878
879 <bf/Example/
880
881 Consider the record below:
882 <tscreen><verb>
883 001       11224466 
884 003    DLC
885 005    00000000000000.0
886 008    910710c19910701nju           00010 eng  
887 010    $a    11224466 
888 040    $a DLC $c DLC
889 050 00 $a 123-xyz
890 100 10 $a Jack Collins
891 245 10 $a How to program a computer
892 260 1  $a Penguin
893 263    $a 8710
894 300    $a p. cm.
895 </verb></tscreen>
896
897 Assuming this record is at position 1 in ir-set <tt/z.1/, we
898 might extract the title-field (245 * a), with the following command:
899 <tscreen><verb>
900 z.1 getMarc 1 field 245 * a
901 </verb></tscreen>
902
903 which gives:
904 <tscreen><verb>
905 {How to program a computer}
906 </verb></tscreen>
907
908 Using the <tt/line/ instead of <tt/field/ gives:
909 <tscreen><verb>
910 {245 {10} {{a {How to program a computer}} }}
911 </verb></tscreen>
912
913 If we wish to extract the whole record as a list, we use:
914 <tscreen><verb>
915 z.1 getMarc 1 line * * *
916 </verb></tscreen>
917
918 giving:
919 <tscreen><verb>
920 {001 {} {{{} {   11224466 }} }}
921 {003 {} {{{} DLC} }}
922 {005 {} {{{} 00000000000000.0} }}
923 {008 {} {{{} {910710c19910701nju           00010 eng  }} }}
924 {010 {  } {{a {   11224466 }} }}
925 {040 {  } {{a DLC} {c DLC} }}
926 {050 {00} {{a 123-xyz} }}
927 {100 {10} {{a {Jack Collins}} }}
928 {245 {10} {{a {How to program a computer}} }}
929 {260 {1 } {{a Penguin} }}
930 {263 {  } {{a 8710} }}
931 {300 {  } {{a {p. cm.}} }}
932 </verb></tscreen>
933
934 <bf/End of example/
935
936 <bf/Example/
937
938 This example demonstrates how Tcl can be used to examine
939 a MARC record in the list notation.
940
941 The procedure <tt/extract-format/ makes an extraction of
942 fields in a MARC record based on a number of masks.
943 There are 5 parameters, <tt/r/: a
944 record in list notation, <tt/tag/: regular expression to
945 match the record tags, <tt/ind/: regular expression to
946 match indicators, <tt/field/: regular expression to 
947 match fields, and finally <tt/text/: regular expression to 
948 match the content of a field.
949
950 <tscreen><verb>
951 proc extract-format {r tag ind field text} {
952     foreach line $r {
953         if {[regexp $tag [lindex $line 0]] && \
954                 [regexp $ind [lindex $line 1]]} {
955             foreach f [lindex $line 2] {
956                 if {[regexp $field [lindex $f 0]]} {
957                     if {[regexp $text [lindex $f 1]]} {
958                         puts [lindex $f 1]
959                     }
960                 }
961             }
962         }
963     }
964 }
965 </verb></tscreen>
966
967 To match <tt/comput/ followed by any number of character(s) in the
968 245 fields in the record from the previous example, we could use:
969 <tscreen><verb>
970 set r [z.1 getMarc 1 line * * *]
971
972 extract-format $r 245 .. . comput
973 </verb></tscreen>
974 which gives:
975 <tscreen><verb>
976 How to program a computer
977 </verb></tscreen>
978
979 <bf/End of example/
980
981 The <tt/putMarc/ action does the opposite of <tt/getMarc/. It
982 copies a record in Tcl list notation to a ir set object and is
983 needed if a result-set must be updated by a Tcl modified (user-edited)
984 record.
985
986 <sect1>SUTRS
987
988 <p>
989 In <sf/IrTcl/ a SUTRS record is treated as one single string. To retrieve
990 a SUTRS record use the <tt>getSutrs</tt> followed by an index.
991
992 <sect>Scan
993
994 <p>
995 To perform scan, a scan object must be created by the <tt>ir-scan</tt>
996 command. This command has two arguments - name of the scan object and
997 name of the ir object. Basically, the scan object, provides one <tt>scan</tt>
998 action which sends a scan request to the target. The <tt>action</tt>
999 is followed by a string describing starting point of the term list. The
1000 format used is a simple subset of the query used in search requests. Only
1001 <tt>@attr</tt> specifications and simple terms are allowed.
1002 The settings that affect the scan are:
1003
1004 <descrip>
1005 <tag><tt>stepSize </tt><em>integer</em></tag>
1006  Step size. Default is 0.
1007 <tag><tt>numberOfTermsRequested </tt><em>integer</em></tag>
1008  Number of terms requested. Default is 20.
1009 <tag><tt>preferredPositionInResponse </tt><em>integer</em></tag>
1010  Preferred position in response. Default is 1.
1011 <tag><tt>databaseNames </tt><em>list</em></tag>
1012  Database names. Note that this setting is not (yet) supported for
1013  the scan object. You must set this for the ir object instead.
1014 <tag><tt>callback </tt><em>list</em></tag>
1015  General response Tcl script. This setting is not (yet) supported for
1016  the scan object. You must set this for the ir object instead.
1017 </descrip>
1018
1019 The scan object normally holds one or more scan line entries upon
1020 successful completion. The table below summarizes the settings
1021 that should be used in a response handler.
1022
1023 <descrip>
1024 <tag><tt>scanStatus</tt></tag>
1025  Scan status. An integer between 0 and 6.
1026 <tag><tt>numberOfTermsReturned </tt><em>integer</em></tag>
1027  Number of terms returned. 
1028 <tag><tt>positionOfTerm</tt></tag>
1029  An integer describing the position of term.
1030 <tag><tt>scanLine </tt> <em>integer</em></tag>
1031  This function returns information about a given scan line (entry) at a given
1032  index specified by the integer. The first scan line is numbered zero;
1033  the second 1 and so on. A list is returned by the <tt>scanLine</tt>
1034  setting. The first element is <tt>T</tt> if the scan line
1035  is a normal term and <tt>SD</tt> if the scan line is a surrogate 
1036  diagnostic. In the first case (normal) the scan term is second element 
1037  in the list and the number of occurences is the third element.
1038  In the other case (surrogate diagnostic), the second element
1039  is the diagnostic code, the third a text representation of the error
1040  code and the fourth element is additional information.
1041 </descrip>
1042
1043 <bf/Example/
1044
1045 We will scan for the terms after <tt>science</tt> in the Title index.
1046 We will assume that an ir object called <tt>z-assoc</tt> has already
1047 been created.
1048
1049 <tscreen><verb>
1050    z-assoc callback {scan-response}
1051    ir-scan z-scan z-assoc
1052    z-scan scan "@attr 1=4 science"
1053   
1054    proc scan-response {} {
1055        set status [z-scan status]
1056        if {$status == 0} {
1057            set no [z-scan numberOfTermsReturned]
1058            for {set i 0} {$i < $no} {incr i} {
1059                set line [z-scan scanLine $i]
1060                set type [lindex $line 0]
1061                if {$type == "T"} {
1062                    puts [lindex $line 1]
1063                } elseif {$type == "SD"} {
1064                    puts [lindex $line 1]
1065                }
1066            }
1067        }
1068    }
1069 </verb></tscreen>
1070 <bf/End of examle/
1071
1072 <sect>License
1073
1074 <p>
1075 Copyright &copy; 1995, Index Data.
1076
1077 Permission to use, copy, modify, distribute, and sell this software and
1078 its documentation, in whole or in part, for any purpose, is hereby granted,
1079 provided that:
1080
1081 1. This copyright and permission notice appear in all copies of the
1082 software and its documentation. Notices of copyright or attribution
1083 which appear at the beginning of any file must remain unchanged.
1084
1085 2. The names of Index Data or the individual authors may not be used to
1086 endorse or promote products derived from this software without specific
1087 prior written permission.
1088
1089 THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
1090 EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
1091 WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1092 IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
1093 INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
1094 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
1095 NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
1096 LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
1097 OF THIS SOFTWARE.
1098
1099 <sect>About Index Data
1100
1101 <p>
1102 Index Data is a consulting and software-development enterprise that
1103 specialises in library and information management systems. Our
1104 interests and expertise span a broad range of related fields, and one
1105 of our primary, long-term objectives is the development of a powerful
1106 information management
1107 system with open network interfaces and hypermedia capabilities.
1108
1109 We make this software available free of charge, on a fairly unrestrictive
1110 license; as a service to the networking community, and to further the
1111 development of quality software for open network communication.
1112
1113 We'll be happy to answer questions about the software, and about ourselves
1114 in general.
1115
1116 <tscreen>
1117 Index Data&nl
1118 Ryesgade 3&nl
1119 2200 K&oslash;benhavn N&nl
1120 DENMARK
1121 </tscreen>
1122
1123 <p>
1124 <tscreen><verb>
1125 Phone: +45 3536 3672
1126 Fax  : +45 3536 0449
1127 Email: info@index.ping.dk
1128 </verb></tscreen>
1129
1130 <sect>References
1131
1132 <p>
1133
1134 <descrip>
1135 <tag>1 Ousterhout, John K.:</tag>
1136 Tcl and the Tk Toolkit. Addison-Wesley Company Inc (ISBN
1137 0-201-63337-X). Source and documentation
1138 can be found in <tt>URL:ftp://ftp.cs.berkeley.edu/pub/tcl</tt>
1139 and mirrors.
1140 <tag>2 Furniss, Peter:</tag>
1141 RFC 1698: Octet Sequences for Upper-Layer OSI to Support
1142 Basic Communications Applications.
1143 </descrip>
1144
1145 </article>