Module Kwmarc

module Kwmarc: sig .. end

ISO 2709 MARC Records

Functions to read and parse MARC (ISO 2709) records. Also includes a MARC to Dublin Core crosswalk.

Missing functionality: lots, but most notably, MARC-8 character set handling; all strings from field values are simply octets.
Author(s): Keith Waclena


module L: Kwlookup.Alist(String)
exception Bad of string
Exception raised when a bad MARC record is encountered.
type leader = {
   reclen : int;
   status : string option * char;
   typeof : string option * char;
   biblevel : string option * char;
   control : string option * char;
   charset : string option * char;
   indcnt : string option * char;
   sfccnt : string option * char;
   base : int;
   enclevel : string option * char;
   desccat : string option * char;
   multipart : string option * char;
   lof : string option * char;
   scp : string option * char;
   id : string option * char;
   undefined : string option * char;
}
val leader_field_of_offset : string array
type data = {
   indicator : string;
   subs : string L.t;
}
type field = 
| Control of string
| Data of data
type marc = {
   leader : leader;
   fields : field L.t;
   raw : string;
}
val string_of_marc : marc -> string
val parse : string -> marc
val leader : marc -> leader
val field : L.key -> marc -> field
val subfield : L.key -> field -> string
val indicator : 'a -> field -> 'b
val read : Pervasives.in_channel -> string option
val fold : ('a -> string -> 'a) -> 'a -> Pervasives.in_channel -> 'a

MARC Crosswalks

The Kwmarc.crosswalk function can convert a MARC record into other formats. We only provide one crosswalk (Unqualified Dublin Core) but more are possible.

exception BadFF
Bad fixed field (ff) substring in crosswalk
val crosswalk : ('a * spec list) list -> marc -> ('a * string) list
crosswalk cw record: generate a translation of this MARC record according to the crosswalk cw.

This function generates a list of repeatable named elements, each of which is mapped to values of a MARC field (which may be restricted to particular subfields); subfields are joined together with spaces between them. This is suitable to generate simple XML (for, say, Dublin Core), where the names could be XML elements and the values, CDATA.
Returns an alist of (name, value) pairs

record : a parse MARC record

Functions to build crosswalks


val df : ?subs:char list -> string -> spec
df ?subs f: content of variable data field, with optional subfield restrictions.
subs : restricted subfield names
f : field name
val cf : string -> int -> int -> spec
cf f a b: content of control field characters a-b.
f : field name
a : index of first character of data
b : index of last character of data
val except : int list -> int list -> int list
except ex list: exclude (eliminate) all fields numbered in ex from list.

For example, to specify all 5xx fields except for 506, 530, 540, and 546, you could say

500--599 |> except [506; 530; 540; 546] |> map (df & string_of_int)

ex : field numbers to exclude
val ($) : int -> char -> spec
f$s: content of field f, subfield s

Predefined Crosswalks


module DC: sig .. end
Dublin Core Crosswalks.