Parsing MARC Directory Info

I expected a record that looked like this:

LEADER 00000nas  2200000Ia 4500
001    18971047
008    890105c19079999mau u p       0uuua0eng
010    07023955 /rev
040    DLC|cAUG
049    PSMM
050    F41.5|b.A64
090    F41.5|b.A64
110 2  Appalachian Mountain Club
245 14 The A.M.C. White Mountain guide :| ba guide to trails in
       the mountains of New Hampshire and adjacent parts of Maine
246 13 AMC White Mountain guide
246 13 White Mountain guide
246 13 A.M.C. White Mountain guide
260    Boston,|bThe Club,
300    v. :| bill., maps (some fold., some col.) ;|c16 cm
362 0  1st-     ed.; 1907-
500    Title varies slightly
651  0 White Mountains (N.H. and Me.)|xGuidebooks

but instead got a record that looked like this:

00939cas  2200265Ia 4500001001300000003000700013005001700020008004100037020001500078040001800093050001600111110003100127245012200158246003000280246002600310246003200336246003000368260005500398300005700453362003600510500002700546650001100573651007300584999001600657
ocm18971047
OCoLC
20020918102844.0
890105c19079999mau u p       0   a0eng
  a0910146489
  aDLCcAUGdNHS
  aF41.5b.A64
2 aAppalachian Mountain Club.
14aThe A. M. C. White Mountain guide :ba guide to trails in the mountains of New Hampshire and adjacent parts of Maine.
13aAMC White Mountain guide.
13aWhite Mountain guide.
13aA.M.C. White Mountain guide
13aAMC White Mountain guide.
  aBoston, Mass. :bAppalachian Mountain Club,c1983.
  a550 p.bill., maps (some fold., some col.) ;c16 cm.
0 a1st- ed.; 1907- ; 25th ed. 1992
  aTitle varies slightly.
  aHiking
0aWhite Mountains (N.H. and Me.)xDescription and travelxGuide-books.
  aCL000018321

(some of the non-printable characters have been replaced with newlines for readability.)

After staring at that record for entirely too long, forgetting about it for a while, then returning again to think about how unreadable it was, then forgetting about it again, then taking one last look, I had that *duh* moment that made me realize what I should have seen on first glance: this is a MARC record that hasn’t had its directory parsed.

So here’s my short-but-handy-and-hopefully-usefull-to-somebody-sometime code to parse the directory and then the rest of the record. It assumes $records is an array of records.


foreach($records as $record){
	$temp = explode('', $record);
	$dir = $temp[0];
	$record = substr($record, (strlen($dir) + 1));

	$dir = substr($dir, 24);
	$dir_field = NULL;
	while($dir){
		$dir_field[] = substr($dir, 0, 12);
		$dir = substr($dir, 12);
	}

	$record = str_replace('', '|', $record);
	$marc = NULL;
	foreach($dir_field as $field){
		if(ereg_replace('[^0-9]', '', $field)){
			unset($temp);
			$len = substr($field, 3, 4);
			$pos = substr($field, 7, 5);
			$field = substr($field, 0, 3);
			$temp = substr($record, $pos, $len);
			if($field < 10)
				$temp = '  |'. $temp;
			$marc .= trim($field .'|'. $temp) .ā€œ\nā€;
			$marc_array[$field] = $temp;
		}
	}
	echo $marc;
}

The actual output of that code on that record is this:

001|  |ocm18971047
003|  |OCoLC
005|  |20020918102844.0
008|  |890105c19079999mau u p       0   a0eng
020|  |a0910146489
040|  |aDLC|cAUG|dNHS
050|  |aF41.5|b.A64
110|2 |aAppalachian Mountain Club.
245|14|aThe A. M. C. White Mountain guide :| ba guide to trails in the mountains of New Hampshire and adjacent parts of Maine.
246|13|aAMC White Mountain guide.
246|13|aWhite Mountain guide.
246|13|aA.M.C. White Mountain guide
246|13|aAMC White Mountain guide.
260|  |aBoston, Mass. :| bAppalachian Mountain Club,|c1983.
300|  |a550 p.|bill., maps (some fold., some col.) ;|c16 cm.
362|0 |a1st- ed.; 1907- ; 25th ed. 1992
500|  |aTitle varies slightly.
650|  |aHiking
651| 0|aWhite Mountains (N.H. and Me.)|xDescription and travel|xGuide-books.
999|  |aCL000018321

It includes a little bit of fudging that my other MARC parsing code demands, but works and is readable.

code, libraries, library, marc, marc directory, parsing, php, raw marc

2 Comments

  1. Mmmm…. Perl. Have you tried parsing that wonky record with the MARC::Record module (get it from
    the CPAN
    .

    :-)

  2. Not sure if you already knew about this, but Terry Reese’s MarcEdit program http://oregonstate.edu/~reeset/marcedit/html/index.php
    can do just about anything you want with MARC records. It’s blazingly fast, can do all kinds of conversions, and you can talk to it with other programs.


Comments RSS TrackBack Identifier URI

Leave a comment

 

User contributed tags for this post:

marc directory (32) - mountain (19) - video google italiasex (16) - MARC parser (9) - parsing MARC records (7) - sexclup (6) - parse MARC record (6) - marc21 parser (5) - parse marc (4) - parsing MARC in PHP (4) - marc 21 parser (4) - marc parse (4) - marcedit os x (3) - php marc parser (3) - parse marc records (3) - php marc (3) - parsing MARC (3) - scriblio marcedit (3) - marc tag 449 (2) - F (2) - photoblog dir (2) - cache 0q5vXU0jzyYJ libworm com rss search php qu web 2  (2) - club 300 amc (2) - amc parser (2) - 449 tag marc record (2) - php marc record parser (2) - italia felm (2) - marc records php (2) - directory parser (2) - 449 marc tag (2) - directory parsing (2) - marc21 php parser (2) - parse for nude pics (2) - marc tag 246 (2) - MARC2 codeing (2) - maps of fold mountains (2) - MARC parsing (2) - printable (2) - php parse marc records (2) - how to parse marc record (2) - guide to marc records (2) - marc record php (2) - marcedit (2) - marc parsen (1) - MARC record tem (1) - marc tag 362 (1) - marc tag 005 (1) - a1st edition amc guide (1) - marc ķŒŒģ‹± (1) - amc parcing (1) - bluetooth parsing wii (1) - trim marc fields (1) - Wii remote bluetooth parsing (1) - parser directory (1) - what do mean by leader in MARC record? (1) - parsing a directory (1) - parsing code hack bluetooth (1) - MARC parser library (1) - parsing raw MARC records (1) - 300 marc tag (1) - marc field 449 (1) - sexclup photo (1) - marcedit add field arrays (1) - php marc21 (1) - marc php (1) - marc record game controller (1) - MARC parser written in PHP (1) - italia sex felm (1) - marc parsers (1) - sexfotoblog (1) - AMC PASER (1) - MARC records 449 field (1) - 449 MARC field (1) - 001 in raw MARC (1) - parser directory with php (1) - 246 MARC record (1) - marcedit marc tag (1) - marc 449 field (1) - parsing marc 21 (1) - mark parsing (1) - MARCPHP Parser (1) - marc record* wii (1) - marc21 newline (1) - SEXFOTOBLOG.C (1) - what is the purpose of the MARC directory? (1) - Marc GEERINCK directory (1) - library music mysql marc 21 (1) - parsing php MARC 21 (1) - Parsing of website directories (1) - what do I enter for marc tag 005 (1) - marc21 php code (1) - library marc directories (1) - ipod marc record (1) - marc (1) - white mountains nh november 2006 (1) - mark directory in mc (1) - marc records tag 449 (1) - php parse marc library record (1) - 1907 white mountains guide to (1) - php marc records (1) - marc record php parser (1) - php marc parse inurl kelkoo|bizrate|pixmania|dealtime|p (1) - directory info (1) - marc foreach records as record (1) - php mark records (1) - parsing mark (1) - marc records 650 tag (1) - marc amc related records tag (1) - marc field 300 parser (1) - club 300 amc italia (1) - MARC records RSS (1) - amc records posting (1) - how to parse MARC records (1) - marc records and maps and UNH (1) - amc c16 (1) - substr dir (1) - library marc record parse (1) - mark directory 2006 (1) - A M C White Mountain Guide (1) -