MARC::Record question: How to update created records before writing?

2005-08-03 Thread KEVIN ZEMBOWER
I'm a newbie trying to wrap my computer science mind around MARC, and at the 
same time write a program to translate a database of reproductive health 
behavior change communication materials (i.e., posters to encourage condom use) 
into MARC records. My ultimate goal is to import them into Koha to manage the 
collection.

I have fields like these in my existing database:
PROD - Producer's name
ADP - Producer's address
CTYP - Producer's city
etc.

Any or all of these could be missing.

I'd like to create a 270 record (I think) from this information. I'd like to do 
something similar to this pseudo-code:
my $mprod = MARC::Record->new('270', ' ', ' ',); #Base record
$mprod = MARC::Record->update($mprod, a=>$ADP) if $ADP;
$mprod = MARC::Record->update($mprod, b=>$CTYP) if $CTYP;
$mprod = MARC::Record->update($mprod, c=>$CTYP) if $CTYP;


Can anyone help me out with a way of doing this efficiently? Thanks for your 
advice and suggestions.

-Kevin Zembower  

-
E. Kevin Zembower
Internet Systems Group manager
Johns Hopkins University
Bloomberg School of Public Health
Center for Communications Programs
111 Market Place, Suite 310
Baltimore, MD  21202
410-659-6139


Re: MARC::Record question: How to update created records before writing?

2005-08-03 Thread Paul POULAIN

KEVIN ZEMBOWER a écrit :

My ultimate goal is to import them into Koha to manage the collection.


good goal ;-)


Can anyone help me out with a way of doing this efficiently? Thanks for your 
advice and suggestions.


You should do this in 2 steps :
my $newRecord = MARC::Record->new(); # 1st to create the record
$newField = MARC::Field->new( # 2nd to create the field
'011','','',
'a' => $resul{ISSN},
);
# to happend the record to the field.
$newRecord->insert_fields_ordered($newField);

If you have empty values, just say 'a' => "".$resul{ISSN}

(Perl dislike a lot hashes with empty values)

when you will bulkmarcimport your biblio in Koha, empty subfields will 
be ignored, so don't bother ;-)


HTH
--
Paul POULAIN
Consultant indépendant en logiciels libres
responsable francophone de koha (SIGB libre http://www.koha-fr.org)


Re: MARC::Record question: How to update created records before writing?

2005-08-03 Thread Jonathan Gorman




On Wed, 3 Aug 2005, KEVIN ZEMBOWER wrote:


I'm a newbie trying to wrap my computer science mind around MARC


Don't know what you're using for learning marc, but you might want to keep 
http://www.loc.gov/marc.  Just remember it's based off of flat file 
processing and your computer science mind shouldn't have to horrible of a 
time with the technical manipulation of records even if some of the 
cataloging issues aren't clear.




I'd like to create a 270 record (I think) from this information.



It looks like you're confusing records with fields.  A record can contain 
any number of fields, and fields will contain two indicators and certain 
subfields.  So you probably want at a record with at least the 
address field (270), and title (245).



MARC::Record has some documentation on how to add fields to a marc record 
after it's been created (see the add_fields()).



Jonathan T. Gorman
Visiting Research Information Specialist
University of Illinois at Champaign-Urbana
216 Main Library - MC522
1408 West Gregory Drive
Urbana, IL 61801
Phone: (217) 244-7839




Re: MARC::Record question: How to update created records before writing?

2005-08-03 Thread KEVIN ZEMBOWER
Jonathan, thanks for your suggestions. Sorry for my sloppy use of terminology. 
You're right, I want to create a single MARC record for each item in my 
collection, and each MARC record will have fields like 245 and 270.

I think that what I would like to do is something like this:
if ($ADP) {
   my $madp = MARC::Field->new('270',' ', '4', a=>$ADP);
   $marcrecord->append_fields($madp);
}

if ($CTPY)
   my $mctpy = MARC::Field->new('270',' ', '4', b=>$CTPY);
   $marcrecord->append_fields($mctpy);
}

I think that this would create two 270 fields, one with an 'a' subfield and one 
with a 'b' subfield. Is this a problem in MARC records? Does this imply that 
there are two separate, different addresses? Is this the way it's supposed to 
be done? I thought that I had to create a single 270 field, with the various 
subfields. Will this import okay into Koha?

270 is a repeating field. Would this still work okay on a non-repeating field?

Thanks, again, for your suggestions and your continuing help.

-Kevin

>>> Jonathan Gorman <[EMAIL PROTECTED]> 08/03/05 12:52PM >>>



On Wed, 3 Aug 2005, KEVIN ZEMBOWER wrote:

> I'm a newbie trying to wrap my computer science mind around MARC

Don't know what you're using for learning marc, but you might want to keep 
http://www.loc.gov/marc.  Just remember it's based off of flat file 
processing and your computer science mind shouldn't have to horrible of a 
time with the technical manipulation of records even if some of the 
cataloging issues aren't clear.

>
> I'd like to create a 270 record (I think) from this information.


It looks like you're confusing records with fields.  A record can contain 
any number of fields, and fields will contain two indicators and certain 
subfields.  So you probably want at a record with at least the 
address field (270), and title (245).


MARC::Record has some documentation on how to add fields to a marc record 
after it's been created (see the add_fields()).


Jonathan T. Gorman
Visiting Research Information Specialist
University of Illinois at Champaign-Urbana
216 Main Library - MC522
1408 West Gregory Drive
Urbana, IL 61801
Phone: (217) 244-7839



Re: MARC::Record question: How to update created records before writing?

2005-08-03 Thread KEVIN ZEMBOWER
Paul, thank you so much for your reply. Looking at my example again, I see I've 
really botched it up. It should have been:
 
I have fields like these in my existing database:
ADP - Producer's address
CTYP - Producer's city
STP - Producer's state or province
etc.

Any or all of these could be missing.

I'd like to create a 270 field (I think) from this information. I'd like to do 
something similar to this pseudo-code:
my $mprod = MARC::Field->new('270', ' ', ' ',); #Base record
$mprod = MARC::Field->update($mprod, a=>$ADP) if $ADP;
$mprod = MARC::Field->update($mprod, b=>$CTYP) if $CTYP;
$mprod = MARC::Field->update($mprod, c=>$STP) if $STP;


In other words, I want to conditionally construct the subfields based on the 
available information in my existing DB.

My problem is that to construct a single 270 field, the number of 'if' clauses 
grows as the square of the variables. For instance, if I just have A or B:
if (A && B) do version 1
else if (A && ! B) do version 2
else if (B && ! A) do version 3
else do version 4

I'm not sure how I would apply your advice about empty values. 

Paul, thanks for your reply and your patience with me.

-Kevin

>>> Paul POULAIN <[EMAIL PROTECTED]> 08/03/05 12:39PM >>>
KEVIN ZEMBOWER a écrit :
> My ultimate goal is to import them into Koha to manage the collection.

good goal ;-)

> Can anyone help me out with a way of doing this efficiently? Thanks for your 
> advice and suggestions.

You should do this in 2 steps :
my $newRecord = MARC::Record->new(); # 1st to create the record
$newField = MARC::Field->new( # 2nd to create the field
'011','','',
'a' => $resul{ISSN},
);
# to happend the record to the field.
$newRecord->insert_fields_ordered($newField);

If you have empty values, just say 'a' => "".$resul{ISSN}

(Perl dislike a lot hashes with empty values)

when you will bulkmarcimport your biblio in Koha, empty subfields will 
be ignored, so don't bother ;-)

HTH
-- 
Paul POULAIN
Consultant indépendant en logiciels libres
responsable francophone de koha (SIGB libre http://www.koha-fr.org)



Re: MARC::Record question: How to update created records before writing?

2005-08-03 Thread Jonathan Gorman

On Wed, 3 Aug 2005, KEVIN ZEMBOWER wrote:



I think that what I would like to do is something like this:
if ($ADP) {
  my $madp = MARC::Field->new('270',' ', '4', a=>$ADP);
  $marcrecord->append_fields($madp);
}

if ($CTPY)
  my $mctpy = MARC::Field->new('270',' ', '4', b=>$CTPY);
  $marcrecord->append_fields($mctpy);
}



Well, one option is to follow what Paul sent to you earlier and don't 
bother to check for empty references.  Also check out the docs on 
MARC::Field.  You could always create the field and add the subfields 
later.


I should warn you I haven't used MARC::Record extensively, but when I have 
it's been pretty straight forward.



I think that this would create two 270 fields, one with an 'a' subfield 
and one with a 'b' subfield. Is this a problem in MARC records? Does 
this imply that there are two separate, different addresses? Is this the 
way it's supposed to be done? I thought that I had to create a single 
270 field, with the various subfields. Will this import okay into Koha?


Wow, lot of questions.  Most of them seem to be the aspects same one: can 
I have two fields of the same type?  Yes, if they are repeatable, but 
that's not what you want in this case.  You do need to create one single 
field, which is why the approach above won't work.  Create one field, then 
add subfields, or just add empty fields when creating it like Paul 
suggested.


(My apologies to Paul if I'm not applying his suggestion correctly)
So a quick example might be


$record = MARC::Record->new():
$field = MARC::Field->new('270','','',
   a => $ADP,
   b => $CTYP,
   c => $STP);
$record->append_fields($field)

So if the variables are empty, it doesn't matter because it will just lead 
to an empty subfield, which Kola should ignore anyhow.  (I don't know if 
it does or not, but I suppose it doesn't hurt to try).


Jon Gorman


Re: MARC::Record question: How to update created records before writing?

2005-08-03 Thread KEVIN ZEMBOWER
Jon, now I'm beginning to see the light. My problem with your suggestion:
$record = MARC::Record->new():
$field = MARC::Field->new('270','','',
   a => $ADP,
   b => $CTYP,
   c => $STP);
$record->append_fields($field)

was that if, for instance, $CTYP hadn't been defined, I'd get an error here. 
Now that I'm thinking about your solution, I can make sure that $CTYP is 
defined (as empty) initially, then fill it conditionally if I have the data, 
then put them all in the MARC field, filled or not.

I think that this will work for me. Thank you, and Paul, for your help and 
advice.

-Kevin

>>> Jonathan Gorman <[EMAIL PROTECTED]> 08/03/05 02:27PM >>>
On Wed, 3 Aug 2005, KEVIN ZEMBOWER wrote:

>
> I think that what I would like to do is something like this:
> if ($ADP) {
>   my $madp = MARC::Field->new('270',' ', '4', a=>$ADP);
>   $marcrecord->append_fields($madp);
> }
>
> if ($CTPY)
>   my $mctpy = MARC::Field->new('270',' ', '4', b=>$CTPY);
>   $marcrecord->append_fields($mctpy);
> }
>

Well, one option is to follow what Paul sent to you earlier and don't 
bother to check for empty references.  Also check out the docs on 
MARC::Field.  You could always create the field and add the subfields 
later.

I should warn you I haven't used MARC::Record extensively, but when I have 
it's been pretty straight forward.


> I think that this would create two 270 fields, one with an 'a' subfield 
> and one with a 'b' subfield. Is this a problem in MARC records? Does 
> this imply that there are two separate, different addresses? Is this the 
> way it's supposed to be done? I thought that I had to create a single 
> 270 field, with the various subfields. Will this import okay into Koha?

Wow, lot of questions.  Most of them seem to be the aspects same one: can 
I have two fields of the same type?  Yes, if they are repeatable, but 
that's not what you want in this case.  You do need to create one single 
field, which is why the approach above won't work.  Create one field, then 
add subfields, or just add empty fields when creating it like Paul 
suggested.

(My apologies to Paul if I'm not applying his suggestion correctly)
So a quick example might be


$record = MARC::Record->new():
$field = MARC::Field->new('270','','',
   a => $ADP,
   b => $CTYP,
   c => $STP);
$record->append_fields($field)

So if the variables are empty, it doesn't matter because it will just lead 
to an empty subfield, which Kola should ignore anyhow.  (I don't know if 
it does or not, but I suppose it doesn't hurt to try).

Jon Gorman


RE: MARC::Record question: How to update created records before w riting?

2005-08-03 Thread Bryan Baldus
On Wednesday, August 03, 2005 12:31 PM, KEVIN ZEMBOWER wrote:
>I'd like to create a 270 field (I think) from this information. I'd like to
do something similar to this pseudo-code:
>my $mprod = MARC::Field->new('270', ' ', ' ',); #Base record
>$mprod = MARC::Field->update($mprod, a=>$ADP) if $ADP;
>$mprod = MARC::Field->update($mprod, b=>$CTYP) if $CTYP;
>$mprod = MARC::Field->update($mprod, c=>$STP) if $STP;
>

Unless I'm mistaken, you should be able to do something similar to the above
(using the suggestions already provided by others) by building an array of
subfield code+data pairs:

push @subfields, 'a', $ADP if $ADP;
#... for each subfield element

Then, once all subfields have been added to @subfields:

$field = MARC::Field->new('270','','', @subfields);
$record->append_fields($field)


Please correct me if I am wrong,
Bryan Baldus
[EMAIL PROTECTED]
[EMAIL PROTECTED]
http://home.inwave.com/eija
  


RE: MARC::Record question: How to update created records before writing?

2005-08-03 Thread KEVIN ZEMBOWER
Bryan, man, that worked like a champ. Thank you so much for suggesting it. I 
like its clean-ness and efficiency.

If someone else is following this in the archives, here's the final version of 
my code:
   #Producer information and address.
   #Another field 270 could also be used for Distributor info.
   if ($record{"PROD"}) { #If there's a producer's name...
  my $pr = MARC::Field->new('260', ' ', ' ',
 b=>$record{"PROD"},
);
  $marcrecord->insert_fields_ordered($pr);
   } #if there's a producer's name

   #All the rest of the producer's information...
   if ($record{"CONP"} ||
   $record{"ADP"}  ||
   $record{"CTYP"} ||
   $record{"STP"}  ||
   $record{"ZIPP"} ||
   $record{"CNP"}  ||
   $record{"PHP"}  ||
   $record{"FAXP"} ||
   $record{"PRODUCER_EMAIL"}
  ) {
  my @sf; #subfields container for data
  push @sf, 'a', $record{"ADP"} if $record{"ADP"};
  push @sf, 'b', $record{"CTYP"}if $record{"CTYP"};
  push @sf, 'c', $record{"STP"} if $record{"STP"};
  push @sf, 'd', $record{"CNP"} if $record{"CNP"};
  push @sf, 'e', $record{"ZIPP"}if $record{"ZIPP"};
  push @sf, 'k', $record{"PHP"} if $record{"PHP"};
  push @sf, 'l', $record{"FAXP"}if $record{"FAXP"};
  push @sf, 'p', $record{"CONP"}if $record{"CONP"};
  push @sf, 'm', $record{"PRODUCER_EMAIL"}  if $record{"PRODUCER_EMAIL"};

  my $marc270 = MARC::Field->new('270', '1', ' ', @sf);
  $marcrecord->insert_fields_ordered($marc270);

   } #If there's any producer information


Thanks, again, Bryan.

-Kevin

>>> Bryan Baldus <[EMAIL PROTECTED]> 08/03/05 03:00PM >>>
On Wednesday, August 03, 2005 12:31 PM, KEVIN ZEMBOWER wrote:
>I'd like to create a 270 field (I think) from this information. I'd like to
do something similar to this pseudo-code:
>my $mprod = MARC::Field->new('270', ' ', ' ',); #Base record
>$mprod = MARC::Field->update($mprod, a=>$ADP) if $ADP;
>$mprod = MARC::Field->update($mprod, b=>$CTYP) if $CTYP;
>$mprod = MARC::Field->update($mprod, c=>$STP) if $STP;
>

Unless I'm mistaken, you should be able to do something similar to the above
(using the suggestions already provided by others) by building an array of
subfield code+data pairs:

push @subfields, 'a', $ADP if $ADP;
#... for each subfield element

Then, once all subfields have been added to @subfields:

$field = MARC::Field->new('270','','', @subfields);
$record->append_fields($field)


Please correct me if I am wrong,
Bryan Baldus
[EMAIL PROTECTED] 
[EMAIL PROTECTED] 
http://home.inwave.com/eija