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. Comment by bibliophile on November 17, 2006 3:49 pm

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

    :-)

  2. Comment by Kyle Banerjee on November 29, 2006 7:56 pm

    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:

vidioarab (25) - sextv2.info (23) - marc directory (20) - mountain (10) - parsing MARC records (7) - MARC parser (6) - parse MARC record (6) - p.1 sex.com (5) - parsing MARC in PHP (4) - fotoblog sex (4) - marc 21 parser (4) - parse marc (4) - marc21 parser (4) - www.sex.col (4) - sex photoblog (4) - parse marc records (3) - vidioarab sex (3) - sex fotoblog (3) - php marc parser (3) - scriblio marcedit (3) - parsing MARC (3) - php marc record parser (2) - cache 0q5vXU0jzyYJ libworm com rss search php qu web 2  (2) - how to parse marc record (2) - marcedit (2) - php parse marc records (2) - php marc (2) - guide to marc records (2) - clib vidioarab (2) - F (2) - photoblog dir (2) - italia felm (2) - amc parser (2) - printable (2) - directory parsing (2) - www.italia sex.com (2) - marc tag 246 (2) - marc records php (2) - directory parser (2) - maps of fold mountains (2) - parse for nude pics (2) - marc21 php (1) - marc parser open source (1) - sex.photoblog (1) - MARc21 parser perl (1) - marcs directory (1) - php parsing directory (1) - marc records 650 tag (1) - sex-photoblog (1) - MARC record parser in PHP (1) - 449 tag (1) - Marc record parser (1) - marc null (1) - marc tag parser php (1) - library marc parser open source php (1) - marc directory info (1) - pono.sex (1) - marcedit add field arrays (1) - marc php (1) - www.xxxl qu (1) - www.sex col. (1) - Wii remote bluetooth parsing (1) - www italia pono sex com (1) - muvie sex vidioarab (1) - privat sex fotoblog (1) - marc tag 362 (1) - a1st edition amc guide (1) - www.italia sexe (1) - www.sex 300 col (1) - fotoblogsex (1) - marc record game controller (1) - 300 marc tag (1) - parsing raw MARC records (1) - parse a marc record (1) - sex photolog (1) - marc records 246 (1) - php parser  (1) - marc 005 tag (1) - marc php parser directory (1) - MARC parser library (1) - sex photoblog or movie (1) - enter maps folded in MArc records (1) - MARC parser written in PHP (1) - parser directory (1) - what do mean by leader in MARC record? (1) - parsing a directory (1) - www.Italia.Sex.Com (1) - ww.com.89 (1) - directory parse php (1) - Unicorn marc 005 library (1) - parse MARC mysql (1) - marc records 449 tag (1) - 362 marc record (1) - how to parse MARC records (1) - amc records posting (1) - php marc parse inurl kelkoo|bizrate|pixmania|dealtime|p (1) - marc record php parser (1) - php marc records (1) - 1907 white mountains guide to (1) - php parse marc library record (1) - marc records tag 449 (1) - birth of c16 caboose (1) - php parse marc (1) - marc (1) - sex photo blog (1) - marc parse (1) - A M C White Mountain Guide (1) - 449 tag marc record (1) - mark directory 2006 (1) - library marc record parse (1) - MARC parsing (1) - substr dir (1) - amc c16 (1) - marc records and maps and UNH (1) - Marc Field 500 title varies (1) - parse marc record library (1) - marc record php (1) - mark directory in mc (1) - marc record parsing (1) - Marc Record Ipod (1) - sex photoblog directories (1) - php parse directory (1) - parse clup (1) - parsing code hack bluetooth (1) - marc21 php parser (1) - Parser MARC Record PHP (1) - MARC record parsing code (1) - green** info ???? ??? (1) - marc 300 map fold cataloging (1) - marc 300 map fold cataloging (fold ) (1) - parsing marc record (1) - substr bsuite (1) - php parse directory as fields (1) - white mountains nh november 2006 (1) - directory info (1) - marc foreach records as record (1) - marc tag 449 (1) - MARC records RSS (1) - club 300 amc italia (1) - marc field 300 parser (1) - marc amc related records tag (1) - parsing mark (1) - php mark records (1) - mmmm ?????? (1) - Aappalachian Mountain Club (1) - marc records movie (1) - php directory parse (1) -