Work on documentation in sgml.
[ir-tcl-moved-to-github.git] / doc / ir-tcl.sgml
1 <!doctype linuxdoc system>
2
3 <!--
4   $Id
5 -->
6
7 <article>
8 <title>IrTcl User's Guide and Reference
9 <author>Index Data, <tt/info@index.ping.dk/
10 <date>May 1995
11 <abstract>
12 This document describes IrTcl - 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 [ref 1]. 
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 --- 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 [ref 2] 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 --- useful for
42 testing purposes.
43 <item> A system which operates within the Tk environment which
44 makes it very easy to implement GUI clients.
45 </itemize>
46
47 <sect>Overview
48
49 <p>
50 Basically, <sf/IrTcl/ is a set of commands introduced to Tcl.
51 When extending Tcl there are two approaches: action-oriented commands
52 and object-oriented commands.
53
54 Action-oriented commands manipulate
55 Tcl variables and each command introduces only one action.
56 The string manipulation commands in Tcl are action oriented.
57
58 Object-oriented commands are added for every declared
59 variable (object). Object-oriented commands usually provide a set of
60 actions (methods) to manipulate the object.
61 The widgets in Tk (X objects) are examples of the object-oriented style.
62
63 <sf/IrTcl/ commands are object-oriented. The main reason
64 for this is that the data structures involved in the IR protocol
65 are not easily represented by Tcl data structures.
66 Also, the <sf/IrTcl/ objects tend to exist for a relativly long time.
67 Note that although we use the term object-oriented commands, this
68 does not mean that the programming style is strictly object-oriented. For
69 example, there is such no such thing as inheritance.
70
71 We are now ready to present the three commands introduced to Tcl by
72 <sf/IrTcl/:
73
74 <itemize>
75 <item> ir: The ir object represents a connection to a target. More
76 precisely it describes a Z-association. 
77 <item> ir-set: The ir-set describes a result set, which is
78 conceptually a collection of records returned by the target.
79 The ir-set object may retrieve records from a target by means of
80 the ir object; it may read/write records from/to a local file or it may be
81 updated with a user-edited record. 
82 <item> ir-scan: The scan object represents a list of scan lines
83 retrieved from a target.
84 </itemize>
85
86 <bf/Example/
87
88 To create a new IR object called <tt/z-assoc/ write:
89 <tscreen><verb>
90    ir z-assoc
91 </verb></tscreen>
92
93 <bf/End of example/
94
95 Each object provides a set of <em/settings/ which may either be
96 readable, writeable of both. All settings immediately follow
97 the name of the object. If a value is present the setting
98 is set to <em/value/.
99
100 <bf/Example/
101
102 We wish to set the preferred-message-size to 18000 on the
103 <tt/z-assoc/ object:
104
105 <tscreen><verb>
106    z-assoc preferredMessageSize 18000
107 </verb></tscreen>
108
109 To read the current value of preferred-message-size use:
110
111 <tscreen><verb>
112    z-assoc preferredMessageSize
113 </verb></tscreen>
114 <bf/End of example/
115
116 One important category consists of settings is those that relate to the
117 event-driven model. When <sf/IrTcl/ receives responses from the target, i.e.
118 init responses, search responses, etc., a <em/callback/ routine
119 is called. Callback routines are represented in Tcl as
120 a list, which is re-interpreted prior to invocation.
121 The method is similar to the one used in Tk to capture X events.
122
123 For each SR/Z39.50 request there is a corresponding object action. The most
124 important actions are:
125 <itemize>
126 <item> connect Establishes connection with a target
127 <item> init Sends an initialize request.
128 <item> search Sends a search request.
129 <item> present Sends a present request.
130 <item> scan Sends a scan request.
131 </itemize>
132
133 <bf/Example/
134 This example shows a complete
135 connect - init - search - present scenario. 
136
137 First an IR object, called <tt/z/, is created.
138 Also a result set <tt/z.1/ is introduced by the <tt/ir-set/ 
139 and it is specified that the result set uses <tt/z/ as its association.
140
141 The setting <tt/databaseNames/ is set to the 
142 database <tt/books/ to which the following searches are directed.
143 A connection is established to <tt/fake.com/ by the <tt/connect/ action.
144 A callback is then defined <em/before/ the init request is executed. 
145 The Tcl procedure <tt/init-response/ is called when a 
146 init-response is returned from the target.
147
148 The <tt/init-response/ procedure sets up a <tt/search-response/ 
149 callback handler and sends a search-request by using a query which
150 consists of a single word <tt/science/.
151
152 When the <tt/search-response/ procedure is called it defines
153 a variable <tt/hits/ and sets it to the value of the setting
154 <tt/resultCount/. If <tt/hits/ is positive a present-request is
155 sent --- asking for 5 records from position 1. 
156
157 Finally, a present-response is received and the number of records
158 returned is stored in the variable <tt/ret/.
159
160 <tscreen><verb>
161 ir z
162 ir-set z.1 z
163 z databaseNames books
164 z connect fake.com
165 z callback {init-response}
166 z init
167
168 proc init-response {} {
169     z.1 callback {search-response}
170     z.1 search science
171 }
172
173 proc search-response {} {
174     set hits [z.1 resultCount]
175     puts "$hits hits"
176     if {$hits > 0} {
177         z.1 callback {present-response}
178         z.1 present 1 5
179     }
180 }
181
182 proc present-response {} {
183     set ret [z.1 numberOfRecordsReturned]
184     puts "$ret records returned"
185 }
186 </verb></tscreen>
187 <bf/End of example/
188
189 The previous example program doesn't care about error conditions. 
190 If errors occur in the program they will be trapped by the Tcl error 
191 handler. This is not always appropriate. However, Tcl offers a 
192 <tt/catch/ command to support error handling by the program itself.
193
194 <sect>Associations
195
196 <p>
197 The ir object describes an association with a target.
198 This section covers the connect-init-disconnect actions provided
199 by the ir object.
200 An ir object is created by the <tt/ir/ command and the
201 created object enters a 'not connected' state, because it isn't
202 connected to a target yet. 
203
204 <sect1>Connect
205
206 <p>
207 A connection is established by the <tt/connect/ action which is
208 immediately followed by a hostname. Table ref{tab:irconnect} lists the
209 settings that affect the <tt/connect/ action. 
210 Obviously, these settings should be set <bf/before/ connecting.
211
212 <descrip>
213 <tag><tt>comstack </tt><tt>mosi|tcpip</tt></tag>
214  Comstack type
215 <tag><tt>protocol </tt><tt>Z3950|SR</tt></tag>
216  ANSI/NISO Z39.50 or ISO SR
217 <tag><tt>failback </tt><em>list</em></tag>
218  Fatal error Tcl script. Called on protocol errors or if target
219  closes connection
220 </descrip>
221
222 <sect1>Init
223
224 <p>
225 If the connect operation succeeds the <tt/init/ action should be used. 
226 Table ref{tab:irinit} lists the init related settings.
227
228 <descrip>
229 <tag><tt>preferredMessageSize </tt><em>integer</em></tag>
230  Preferred-message-size
231 <tag><tt>maximumRecordSize </tt><em>integer</em></tag>
232  Maximum-record-size
233 <tag><tt>idAuthentication </tt><em>string</em></tag>
234  Id-authentication
235 <tag><tt>implementationName </tt><em>string</em></tag>
236  Implementation-name of origin system
237 <tag><tt>implementationId </tt><em>string</em></tag>
238  Implementation-id of origin system
239 <tag><tt>options </tt><em>list</em></tag>
240  Options to be negotiated in init. The list contains the options that
241 are set.
242 <tag><tt>protocolVersion </tt><em>integer</em></tag>
243  Protocol version: 2, 3, etc.
244 <tag><tt>initResponse </tt><em>list</em></tag>
245  Init-response Tcl script
246 <tag><tt>callback </tt><em>list</em></tag>
247  General response Tcl script. Only used if initResponse is not specified
248 </descrip>
249
250 The init-response handler should inspect some of the settings in table
251 ref{tab:irinitresponse}
252
253 <descrip>
254 <tag><tt>initResult </tt><em>boolean</em></tag>
255  Init response status
256 <tag><tt>preferredMessageSize </tt><em>integer</em></tag>
257  Preferred-message-size
258 <tag><tt>maximumRecordSize </tt><em>integer</em></tag>
259  Maximum-record-size
260 <tag><tt>targetImplementationName </tt><em>string</em></tag>
261  Implementation-name of target system
262 <tag><tt>targetImplementationId </tt><em>string</em></tag>
263  Implementation-id of target system
264 <tag><tt>targetImplementationVersion </tt><em>string</em></tag>
265  Implementation-version of target system
266 <tag><tt>options </tt><em>list</em></tag>
267  Options negotiated after init. The list contains the options that are set.
268 <tag><tt>protocolVersion </tt><em>integer</em></tag>
269  Protocol version: 2, 3, etc.
270 <tag><tt>userInformationField </tt><em>string</em></tag>
271  User information field
272 </descrip>
273
274 <bf/Example/
275 Consider a client with the ability to access multiple targets.
276
277 We define a list of targets that we wish to connect to.
278 Each item in the list describes the target parameters with
279 the following four components: association-name, comstack-type,
280 protocol-type and a hostname.
281
282 The list for the two targets: ISO/SR target DANBIB and TCP/Z39.50 
283 target Data Research, will be defined as:
284 <tscreen><verb>
285 set targetList { {danbib mosi sr 0103/find2.denet.dk:4500}
286                  {drs tcpip z39 dranet.dra.com} }
287 </verb></tscreen>
288
289 The Tcl code below defines, connect and initialize the
290 targets in <tt/targetList/:
291
292 <tscreen><verb>
293 \foreach target $targetList {
294     set assoc [lindex $target 0]
295     ir $assoc
296     $assoc comstack [lindex $target 1]
297     $assoc protocol [lindex $target 2]
298     $assoc failback [list fail-response $assoc]
299     $assoc connect [lindex $target 3]
300     $assoc initResponse [list init-response $assoc]
301     $assoc init
302 }
303
304 proc fail-response {assoc} {
305     puts "$assoc closed connection or protocol error"
306 }
307
308 proc init-response {assoc} {
309     if {[$assoc initResult]} {
310         puts "$assoc initialized ok"
311     } else {
312         puts "$assoc didn't initialize"
313     }
314 }
315 </verb></tscreen>
316
317 <tt/target/ is bound to each item in the list of targets.
318 The <tt/assoc/ is set to the ir object name.
319 Then, the comstack, protocol and failback are set for the <tt/assoc/ object.
320 The ir object name is argument to the <tt/fail-response/ routine. 
321 Note the use of the Tcl <tt/list/ command which 
322 is necessary here because the argument contains variables 
323 (<tt/assoc/) that should be substituted before the handler is defined.
324 After the connect operation, the <tt/init-response/ handler
325 is defined in much the same way as the failback handler.
326 And, finally, an init request is executed.
327 <bf/End of example/
328
329 <sect1>Disconnect
330
331 <p>
332 To terminate the connection the <tt/disconnect/ action should be used. 
333 This action has no parameters. 
334 Another connection may be established by a new <tt/connect/ action on
335 the same ir object.
336
337 <sect>Result sets
338
339 <p>
340 This section covers the queries used by <sf/IrTcl/, and how searches and
341 presents are handled.
342
343 A search operation and a result set is described by the ir set object.
344 The ir set object is defined by the <tt/ir-set/ command which
345 has two parameters. The first is the name of the new ir set object, and
346 the second, which is optional, is the name of an assocation --- an ir
347 object. The second argument is required if the ir set object should be able
348 to perform searches and presents. However, it is not required if
349 only ``local'' operations is done with the ir set object.
350
351 When the ir set object is created a number of settings are inherited
352 from the ir object, such as the selected databass, query type,
353 etc. Thus, the ir object contains what we could call default
354 settings.
355
356 <sect1>Queries
357
358 <p>
359 Search requests are sent by the <tt/search/ action which
360 takes a query as parameter. There are two types of queries,
361 RPN and CCL, controlled by the setting <tt/queryType/.
362 A string representation for the query is used in <sf/IrTcl/ since
363 Tcl has reasonably powerful string manipulaton capabilities.
364 The RPN query used in <sf/IrTcl/ is the prefix query notation also used in
365 the <bf/YAZ/ test client.
366
367 The CCL query is an uninterpreted octet-string which is parsed by the target.
368 We refer to the standard: ISO 8777. Note that only a few targets
369 actually support the CCL query and the interpretation of
370 the standard may vary.
371
372 The prefix query notation (which is converted to RPN) offer a few
373 operators, shown in table ref{tab:prefixop}.
374
375 <descrip>
376 <tag><tt>@attr </tt><em>list op</em></tag>
377  The attributes in list are applied to op
378 <tag><tt>@and </tt><em>op1 op2</em></tag>
379  Boolean <em/and/ on op1 and op2
380 <tag><tt>@or </tt><em>op1 op2</em></tag>
381  Boolean <em/or/ on op1 and op2
382 <tag><tt>@not </tt><em>op1 op2</em></tag>
383  Boolean <em/not/ on op1 and op2
384 <tag><tt>@prox </tt><em>list op1 op2</em></tag>
385  Proximity operation on op1 and op2 
386 </descrip>
387
388 It is simple to build RPN queries in <sf/IrTcl/. Search terms
389 are sequences of characters, as in:
390 <tscreen><verb>
391    science
392 </verb></tscreen>
393
394 Boolean operators use the prefix notation (instead of the suffix/RPN),
395 as in:
396 <tscreen><verb>
397    @and science technology
398 </verb></tscreen>
399
400 Search terms may be associated with attributes. These
401 attributes are indicated by the <tt/@attr/ operator.
402 Assuming the bib-1 attribute set, we can set the use-attribute 
403 (type is 1) to title (value is 4):
404
405 <tscreen><verb>
406    @attr 1=4 science
407 </verb></tscreen>
408
409 Also, it is possible to apply attributes to a range of search terms.
410 In the query below, both search terms have use=title but the <tt/tech/
411 term is right truncated:
412
413 <tscreen><verb>
414    @attr 1=4 @and @attr 5=1 tech beta
415 </verb></tscreen>
416
417 <sect1>Search
418
419 <p>
420 Table ref{tab:irsearchrequest} lists settings that affect the search.
421 Setting the <tt/databaseNames/ is mandatory. All other settings
422 have reasonable defaults.
423
424 </article>
425
426 \begin{table}[htbf]
427 \begin{tabular}{l|l|p{8cm}}
428 Setting & Value & Description \\\hline
429 databaseNames        & list    & database-names \\
430 smallSetUpperBound   & integer & small set upper bound \\
431 largeSetLowerBound   & integer & large set lower bound \\
432 mediumSetPresentNumber & integer & medium set present number \\
433 replaceIndicator     & boolean & replace-indicator \\
434 setName                 & string  & name of result set \\
435 queryType               & rpn     & query type-1 \\
436                         & ccl     & query type-2 \\
437 preferredRecordSyntax   & string & preferred record syntax. 
438 See table ref{tab:recordtypes} on page \pageref{tab:recordtypes} \\
439 smallSetElementSetNames  & string  & small-set-element-set names \\
440 mediumSetElementSetNames & string  & medium-set-element-set names \\
441 searchResponse          & list    & Search-response Tcl script \\
442 callback                & list    & General response Tcl script. Only used
443 if searchResponse is not specified \\
444 \end{tabular}
445 \caption{Search request settings}
446 \label{tab:irsearchrequest}
447 \end{table}
448
449 The search-response handler, specified by the <tt/callback/ - or
450 the <tt/searchResponse/ setting, 
451 should read some of the settings shown in table ref{tab:irsearchresponse}.
452
453 \begin{table}[htbf]
454 \begin{tabular}{l|l|p{8cm}}
455 Setting & Value & Description \\\hline
456 searchStatus            & boolean & search-status \\
457 responseStatus          & list    & response status information \\
458 resultCount             & integer & result-count \\
459 numberOfRecordsReturned & integer & number of records retrieved \\
460 \end{tabular}
461 \caption{Search response settings}
462 \label{tab:irsearchresponse}
463 \end{table}
464
465 The <tt/responseStatus/ signals one of three conditions which
466 is indicated by the value of the first item in the list:
467
468 \begin{description}
469 \item[NSD] indicates that the target has returned one or more non-surrogate
470 diagnostic messages. The <tt/NSD/ item is followed by a list with
471 all non-surrogate messages. Each non-surrogate message consists
472 of three items. The first item of the three items is the error
473 code (integer); the next item is a textual representation of the error
474 code in plain english; the third item is additional information, possibly
475 empty if no additional information was returned by the target.
476
477 \item[DBOSD] indicates a successful operation where the
478 target has returned one or more records. Each record may be
479 either a database record or a surrogate diagnostic.
480
481 \item[OK] indicates a successful operation --- no records are
482 returned from the target. 
483 \end{description}
484
485 <bf/Example/
486 We continue with the multiple-targets example. 
487 The <tt/init-response/ procedure will attempt to make searches:
488
489 <tscreen><verb>
490 proc init-response {assoc} {
491     puts "$assoc connected"
492     ir-set ${assoc}.1 $assoc
493     $assoc.1 queryType rpn
494     $assoc.1 databaseNames base-a base-b
495     $assoc.1 searchResponse [list search-response $assoc ${assoc}.1]
496     $assoc.1 search "@attr 1=4 @and @attr 5=1 tech beta"
497 }
498 </verb></tscreen>
499
500 An ir set object is defined and the
501 ir object is told about the name of ir object.
502 The ir set object use the name of the ir object as prefix.
503
504 Then, the query-type is defined to be RPN, i.e. we will
505 use the prefix query notation later on.
506
507 Two databases, <tt/base-a/ and <tt/base-b/, are selected.
508
509 A <tt/search-response/ handler is defined with the
510 ir object and the ir-set object as parameters and
511 the search is executed.
512
513 The first part of the <tt/search-response/ looks like:
514 <tscreen><verb>
515 proc search-response {assoc rset} {
516     set status [$rset responseStatus]
517     set type [lindex $status 0]
518     if {$type == NSD} {
519         set code [lindex $status 1]
520         set msg [lindex $status 2]
521         set addinfo [lindex $status 3]
522         puts "NSD $code: $msg: $addinfo"
523         return
524     } 
525     set hits [$rset resultCount]
526     if {$type == DBOSD} {
527         set ret [$rset numberOfRecordsReturned]
528         ...
529     }
530 }
531 </verb></tscreen>
532 The response status is stored in variable <tt/status/ and 
533 the first element indicates the condition.
534 If non-surrogate diagnostics are returned they are displayed.
535 Otherwise, the search was a success and the number of hits
536 is read. Finally, it is tested whether the search response
537 returned records (database or diagnostic).
538
539 Note that we actually didn't inspect the search status (setting
540 <tt/searchStatus/) to determine whether the search was successful or not, 
541 because the standard specifies that one or more non-surrogate
542 diagnostics should be returned by the target in case of errors.
543 <bf/End of example/
544
545 If one or more records are returned from the target they
546 will be stored in the result set object.
547 In the case in which the search response contains records, it is
548 very similar to the present response case. Therefore, some settings
549 are common to both situations.
550
551 <sect1>Present
552
553 <p>
554 The <tt/present/ action sends a present request. The <tt/present/ is
555 followed by two optional integers. The first integer is the 
556 result-set starting position --- defaults to 1. The second integer 
557 is the number of records requested --- defaults to 10. 
558 The settings which could be modified before a <tt/present/
559 action are shown in table ref{tab:irpresentrequest}.
560
561 \begin{table}[htbf]
562 \begin{tabular}{l|l|p{8cm}}
563 Setting & Value & Description \\\hline
564 preferredRecordSyntax   & string & preferred record syntax. 
565 See table ref{tab:recordtypes} on page \pageref{tab:recordtypes} \\
566 elementSetElementSetNames & string  & element-set names \\
567 presentResponse         & list    & Present-response Tcl script \\
568 callback                & list    & General response Tcl script. Only used
569 if presentResponse is not specified \\
570 \end{tabular}
571 \caption{Present request settings}
572 \label{tab:irpresentrequest}
573 \end{table}
574
575 The present-response handler should inspect the settings
576 shown in table ref{tab:irpresentresponse}. 
577 Note that <tt/responseStatus/ and <tt/numberOfRecordsReturned/
578 settings were also used in the search-response case.
579
580 As in the search-response case, records returned from the
581 target are stored in the result set object.
582
583 \begin{table}[htbf]
584 \begin{tabular}{l|l|p{8cm}}
585 Setting & Value & Description \\\hline
586 presentStatus           & boolean & present-status \\
587 responseStatus          & list    & Response status information \\
588 numberOfRecordsReturned & integer & number of records returned \\
589 nextResultSetPosition   & integer & next result set position \\
590 \end{tabular}
591 \caption{Present response settings}
592 \label{tab:irpresentresponse}
593 \end{table}
594
595 <sect1>Records
596
597 <p>
598 Search responses and present responses may result in
599 one or more records stored in the ir set object if
600 the <tt/responseStatus/ setting indicates database or
601 surrogate diagnostics (<tt/DBOSD/). The individual
602 records, indexed by an integer position, should be 
603 inspected.
604
605 The action <tt/Type/ followed by an integer returns information 
606 about a given position in an ir set. There are three possiblities:
607
608 <itemize>
609 <item> SD The item is a surrogate diagnostic.
610 <item> DB The item is a database record.
611 <item> <em/empty/ There is no record at the specified position.
612 </itemize>
613
614 To handle the first case, surrogate diagnostic, the
615 <tt/Diag/ action should be used. It returns three
616 items: error code (integer), text representation in plain english
617 (string), and additional information (string, possibly empty).
618
619 In the second case, database record, the <tt/recordType/ action should
620 be used. It returns the record type at the given position.
621 Some record types are shown in table ref{tab:recordtypes}.
622
623 \begin{table}[htbf]
624 \begin{center}
625 \begin{tabular}{c}
626 Type \\\hline
627 UNIMARC \\
628 INTERMARC \\ 
629 CCF \\
630 USMARC \\
631 UKMARC \\
632 NORMARC \\
633 LIBRISMARC \\
634 DANMARC \\
635 FINMARC \\
636 SUTRS \\
637 \end{tabular}
638 \end{center}
639 \caption{Record types}
640 \label{tab:recordtypes}
641 \end{table}
642
643 <bf/Example/
644 We continue our search-response example. In the case,
645 <tt/DBOSD/, we should inspect the result set items. 
646 Recall that the ir set name was passed to the
647 search-response handler as argument <tt/rset/.
648
649 <tscreen><verb>
650     if {$type == DBOSD} {
651         set ret [$rset numberOfRecordsReturned]
652         for {set i 1} {$i<=$ret} {incr i} {
653             set itype [$rset Type $i]
654             if {$itype == SD} {
655                 set diag [$rset Diag $i]
656                 set code [lindex $diag 0]
657                 set msg [lindex $diag 1]
658                 set addinfo [lindex $diag 2]
659                 puts "$i: NSD $code: $msg: $addinfo"
660             } else if {$itype == DB} {
661                 set rtype [$rset RecordType $i]
662                 puts "$i: type is $rtype"
663             }
664         }
665     }
666 </verb></tscreen>
667 Each item in the result-set is examined. 
668 If an item is a diagnostic message it is displayed; otherwise
669 if it's a database record its type is displayed.
670 <bf/End of example/
671
672 <sect1>MARC records
673
674 <p>
675 In the case, where there is a MARC record at a given position we
676 want to display it somehow. The action <tt/getMarc/ is what we need.
677 The <tt/getMarc/ is followed by a position integer and the type of
678 extraction we want to make: <tt/field/ or <tt/line/.
679
680 The <tt/field/ and <tt/line/ type are followed by three
681 parameters that serve as extraction masks.
682 They are called tag, indicator and field.
683 If the mask matches a tag/indicator/field of a record the information
684 is extracted. Two characters have special meaning in masks: the
685 dot (any character) and star (any number of any character).
686
687 The <tt/field/ type returns one or more lists of field information
688 that matches the mask specification. Only the content of fields
689 is returned.
690
691 The <tt/line/ type, on the other hand, returns a Tcl list that
692 completely describe the layout of the MARC record --- including
693 tags, fields, etc.
694
695 The <tt/field/ type is sufficient and efficient in the case, where only a
696 small number of fields are extracted, and in the case where no
697 further processing (in Tcl) is necessary.
698
699 However, if the MARC record is to be edited or altered in any way, the
700 <tt/line/ extraction is more powerful --- only limited by the Tcl
701 language itself.
702
703 <bf/Example/
704 Consider the record below:
705 <tscreen><verb>
706 001       11224466 
707 003    DLC
708 005    00000000000000.0
709 008    910710c19910701nju           00010 eng  
710 010    $a    11224466 
711 040    $a DLC $c DLC
712 050 00 $a 123-xyz
713 100 10 $a Jack Collins
714 245 10 $a How to program a computer
715 260 1  $a Penguin
716 263    $a 8710
717 300    $a p. cm.
718 </verb></tscreen>
719
720 Assuming this record is at position 1 in ir-set <tt/z.1/, we
721 might extract the title-field (245 * a), with the following command:
722 <tscreen><verb>
723 z.1 getMarc 1 field 245 * a
724 </verb></tscreen>
725
726 which gives:
727 <tscreen><verb>
728 {How to program a computer}
729 </verb></tscreen>
730
731 Using the <tt/line/ instead of <tt/field/ gives:
732 <tscreen><verb>
733 {245 {10} {{a {How to program a computer}} }}
734 </verb></tscreen>
735
736 If we wish to extract the whole record as a list, we use:
737 <tscreen><verb>
738 z.1 getMarc 1 line * * *
739 </verb></tscreen>
740
741 giving:
742 <tscreen><verb>
743 {001 {} {{{} {   11224466 }} }}
744 {003 {} {{{} DLC} }}
745 {005 {} {{{} 00000000000000.0} }}
746 {008 {} {{{} {910710c19910701nju           00010 eng  }} }}
747 {010 {  } {{a {   11224466 }} }}
748 {040 {  } {{a DLC} {c DLC} }}
749 {050 {00} {{a 123-xyz} }}
750 {100 {10} {{a {Jack Collins}} }}
751 {245 {10} {{a {How to program a computer}} }}
752 {260 {1 } {{a Penguin} }}
753 {263 {  } {{a 8710} }}
754 {300 {  } {{a {p. cm.}} }}
755 </verb></tscreen>
756
757 <bf/End of example/
758
759 <bf/Example/
760 This example demonstrates how Tcl can be used to examine
761 a MARC record in the list notation.
762
763 The procedure <tt/extract-format/ makes an extraction of
764 fields in a MARC record based on a number of masks.
765 There are 5 parameters, <tt/r/: a
766 record in list notation, <tt/tag/: regular expression to
767 match the record tags, <tt/ind/: regular expression to
768 match indicators, <tt/field/: regular expression to 
769 match fields, and finally <tt/text/: regular expression to 
770 match the content of a field.
771
772 <tscreen><verb>
773 proc extract-format {r tag ind field text} {
774     foreach line $r {
775         if {[regexp $tag [lindex $line 0]] && \
776                 [regexp $ind [lindex $line 1]]} {
777             foreach f [lindex $line 2] {
778                 if {[regexp $field [lindex $f 0]]} {
779                     if {[regexp $text [lindex $f 1]]} {
780                         puts [lindex $f 1]
781                     }
782                 }
783             }
784         }
785     }
786 }
787 </verb></tscreen>
788
789 To match <tt/comput/ followed by any number of character(s) in the
790 245 fields in the record from the previous example, we could use:
791 <tscreen><verb>
792 set r [z.1 getMarc 1 line * * *]
793
794 extract-format $r 245 .. . comput
795 </verb></tscreen>
796 which gives:
797 <tscreen><verb>
798 How to program a computer
799 </verb></tscreen>
800
801 <bf/End of example/
802
803 The <tt/putMarc/ action does the opposite of <tt/getMarc/. It
804 copies a record in Tcl list notation to a ir set object and is
805 needed if a result-set must be updated by a Tcl modified (user-edited)
806 record.
807
808 <sect>Scan
809
810 <p>
811 <em/To be written/
812
813 \appendix
814 \pagebreak
815
816 <sect>References
817
818 <p>
819 \label{sec:references}
820
821 <itemize>
822 <item> <bf/Ousterhout, John K./:
823 Tcl and the Tk Toolkit. Addison-Wesley Company Inc (ISBN
824 0-201-63337-X). Source and documentation
825 can be found in <tt/URL:ftp://ftp.cs.berkeley.edu/pub/tcl/
826 and mirrors.
827 <item> <bf/Furniss, Peter/:
828 RFC 1698: Octet Sequences for Upper-Layer OSI to Support
829 Basic Communications Applications.
830 </itemize>
831
832 </article>