.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MARC::Transform 3pm" .TH MARC::Transform 3pm "2014-10-17" "perl v5.20.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MARC::Transform \- Perl module to transform a MARC record using a YAML configuration file .SH "VERSION" .IX Header "VERSION" Version 0.003005 .SH "SYNOPSIS" .IX Header "SYNOPSIS" \&\fBPerl script:\fR .PP .Vb 1 \& use MARC::Transform; \& \& # For this synopsis, we create a small record: \& my $record = MARC::Record\->new(); \& $record\->insert_fields_ordered( MARC::Field\->new( \& \*(Aq501\*(Aq, \*(Aq\*(Aq, \*(Aq\*(Aq, \& \*(Aqa\*(Aq => \*(Aqfoo\*(Aq, \& \*(Aqb\*(Aq => \*(Aq1\*(Aq, \& \*(Aqc\*(Aq => \*(Aqbar\*(Aq, \& \*(Aqd\*(Aq => \*(Aqbor\*(Aq ) ); \& \& print "\-\-init record\-\-\en". $record\->as_formatted ."\en"; \& \& # We transform our record with our YAML configuration file \& # with its absolute path (or relative if called \& # from the right path ) : \& $record = MARC::Transform\->new ( $record, "/path/conf.yaml" ); \& \& # You can also define your YAML into a variable: \& my $yaml="delete : f501d\en"; \& # and use it to transform the record: \& $record = MARC::Transform\->new ( $record, $yaml ); \& \& print "\en\-\-transformed record\-\-\en". $record\->as_formatted ."\en"; .Ve .PP \&\fBconf.yaml:\fR .PP .Vb 11 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& f502a : New 502a subfield\*(Aqs value \& update : \& $f501b : \e&LUT("$this") \& LUT : \& 1 : first \& 2 : second value in this LUT (LookUp Table) \& \-\-\- \& delete : f501c .Ve .PP \&\fBResult\fR (with \f(CW\*(C`$record\->as_formatted\*(C'\fR): .PP .Vb 6 \& \-\-init record\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& _dbor \& \& \-\-transformed record\-\- \& LDR \& 501 _afoo \& _bfirst \& 502 _aNew 502a subfield\*(Aqs value .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is a Perl module to transform a \s-1MARC\s0 record using a \s-1YAML\s0 configuration file. .PP It allows you to \fBcreate\fR , \fBupdate\fR , \fBdelete\fR , \fBduplicate\fR fields and subfields of a record. You can also use \fBscripts\fR and \fBlookup tables\fR. You can specify \fBconditions\fR to execute these actions. .PP All conditions, actions, functions and lookup tables are \fBdefined in the \s-1YAML\s0\fR. .PP MARC::Transform use MARC::Record. .SH "METHOD" .IX Header "METHOD" .SS "\fInew()\fP" .IX Subsection "new()" .Vb 1 \& $record = MARC::Transform\->new($record, "/path/conf.yaml" ); .Ve .PP This is the only method you'll use. It takes a MARC::Record object and a \s-1YAML\s0 path as arguments. You can also define your \s-1YAML\s0 into a variable and use it to transform the record like this : .PP .Vb 2 \& my $yaml="delete : f501d\en"; \& $record = MARC::Transform\->new ( $record, $yaml ); .Ve .PP \fIOptional hash reference\fR .IX Subsection "Optional hash reference" .PP As we will see in more detail below, it is possible to add a hash reference (named \f(CW$mth\fR into yaml) as the third optional argument. .PP .Vb 6 \& my $record = MARC::Record\->new(); my $hashref = {\*(Aqvar\*(Aq => \*(Aqfoo\*(Aq}; \& my $yaml = \*(Aqcreate : \& f500a : $$mth{"var"} \& \*(Aq; \& $record = MARC::Transform\->new($record,$yaml,$hashref); \& #the new 500$a subfield\*(Aqs value is "foo" .Ve .PP \fIVerbose mode\fR .IX Subsection "Verbose mode" .PP Each \s-1YAML\s0 rule (see basis below to understand what is a rule) generates a script that is evaluated, in the record, for each field and subfield specified in the condition (If there is a condition). By adding a fourth optional argument \fB1\fR to the method, it displays the generated script. This can be useful to understand what is happening: .PP .Vb 1 \& $record = MARC::Transform\->new($record,"/path/conf.yaml",0,1); .Ve .SH "YAML" .IX Header "YAML" .SS "Basis" .IX Subsection "Basis" \&\- \fB\s-1YAML\s0 is divided in rules\fR (separated by \-\-\- ), each rule is executed one after the other, rules whithout condition will allways be executed: .PP .Vb 7 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& f600a : new field value \& \-\-\- \& delete : f501c \& \-\-\- .Ve .PP \&\- \fBconditions are written in perl\fR, which allows great flexibility. They must be defined with \f(CW\*(C`condition : \*(C'\fR .PP .Vb 2 \& condition : ($f501a=~/foo/ and $f503a=~/bar/) or ($f102a eq "bib") \& # if a 501$a and 503$a contain foo and bar, or if a 102$a = bib .Ve .PP \&\- Conditions test records \fBfield by field\fR (only for fields defined in the condition) .PP For example, this means, that if we have more '501' fields in the record, if our condition is \f(CW\*(C`$f501a eq "foo" and $f501b eq "bar"\*(C'\fR, that condition will be true only if a '501' field has a 'a' subfield = \*(L"foo\*(R" \s-1AND\s0 a 'b' subfield = 'bar' (it will be false if there is a '501' field with a 'a' subfield = \*(L"foo\*(R" and \s-1ANOTHER \s0'501' field with a 'b' subfield = \*(L"bar\*(R"). .PP \&\- It's possible to run more than one different actions in a single rule: .PP .Vb 6 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& f600a : new field value \& delete : f501c \& \-\-\- .Ve .PP \&\- The order in which actions are written does not matter. Actions will always be executed in the following order: .IP "\(bu" 4 create .IP "\(bu" 4 duplicatefield .IP "\(bu" 4 forceupdate .IP "\(bu" 4 forceupdatefirst .IP "\(bu" 4 update .IP "\(bu" 4 updatefirst .IP "\(bu" 4 execute .IP "\(bu" 4 delete .PP \&\- \fBEach rule can be divided into sub-rules\fR (separated by \- ) similar to 'if,elsif' or 'switch,case' scripts. If the first sub-rule's condition is false, the following sub-rule's condition is tested. When the sub-rule's condition is true (or if a sub-rule has no condition), the following sub-rules are not read. .PP .Vb 10 \& \-\-\- \& \- \& condition : $f501a eq "foo" \& create : \& f502a : value if foo \& \- \& condition : $f501a eq "bar" \& create : \& f502a : value elsif bar \& \- \& create : \& f502a : value else \& \-\-\- \& # It is obvious that if a sub\-rule has no condition, it will be \& # considered as an \*(Aqelse\*(Aq (following sub\-rules will not be read) .Ve .PP \&\- It is not allowed to define more than one similar action into a single (sub\-)rule. However, it remains possible to execute a similar action several times in a single rule (refer to the specific syntax of each action in order to see how to do this): .PP \&. this is \fBnot\fR allowed: .PP .Vb 3 \& \-\-\- \& delete : f501b \& delete : f501c .Ve .PP \&. it works: .PP .Vb 4 \& \-\-\- \& delete : \& \- f501b \& \- f501c .Ve .PP \fIa small script to test your rules\fR .IX Subsection "a small script to test your rules" .PP \&\- \fBit is strongly recommended to test each rule on a test record before using it on a large batch of records\fR. You can create a script (e.g. \f(CW\*(C`test.pl\*(C'\fR) with the contents below (that you will adapt to test your rules) and run it with \f(CW\*(C`perl ./test.pl\*(C'\fR : .PP .Vb 10 \& #!/usr/bin/perl \& use MARC::Transform; \& my $record = MARC::Record\->new(); \& $record\->leader(\*(Aqoptionnal leader\*(Aq); \& $record\->insert_fields_ordered( MARC::Field\->new(\*(Aq005\*(Aq, \*(Aqcontrolfield_content\*(Aq)); \& $record\->insert_fields_ordered( MARC::Field\->new(\*(Aq501\*(Aq, \*(Aq\*(Aq, \*(Aq\*(Aq, \*(Aqa\*(Aq => \*(Aqfoo\*(Aq, \*(Aqb\*(Aq => \*(Aqbar\*(Aq) ); \& print "\en\-\-init record\-\-\en". $record\->as_formatted ."\en"; \& my $yaml=\*(Aq\-\-\- \& condition : $f501a eq "foo" \& create : \& f502a : condition is true \& \*(Aq; \& $record = MARC::Transform\->new($record,$yaml); \& print "\en\-\-transformed record\-\-\en". $record\->as_formatted ."\en"; .Ve .SS "Field's and subfield's naming convention" .IX Subsection "Field's and subfield's naming convention" \fIIn actions\fR .IX Subsection "In actions" .PP \&\- Field's and subfield's names are very important: .IP "\(bu" 4 They must begin with the letter \fBf\fR followed by the \fB3\-digit\fR field name (e.g. f099), followed, for the subfields, by their \fBletter or digit\fR (e.g. \fBf501b\fR). .IP "\(bu" 4 Controlfields names begin with the letter \fBf\fR followed by \fB3\-digit lower than 010\fR followed by \fBunderscore\fR (e.g. \fBf005_\fR). .IP "\(bu" 4 \&\fBIndicators\fR must begin with the letter \fBi\fR, followed by the \fB3\-digit\fR field name followed by the indicator's position (\fB1 or 2\fR) (par exemple \fBi0991\fR). .IP "\(bu" 4 In actions, you can define \fBa subfield directly\fR (or an indicator with i1 or i2). Depending on context, it refers to the condition's field (if we define only one field to be tested in the condition), or to the field currently being processed in action: .Sp .Vb 8 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& b : new \*(Aqb\*(Aq subfield\*(Aqs value in unique condition\*(Aqs field (501) \& f600 : \& i1 : 1 \& a : new subfield (a) in this new 600 field \& \-\-\- .Ve .PP \fIIn conditions\fR .IX Subsection "In conditions" .IP "\(bu" 4 In conditions, Field's and subfield's naming convention follow the \fBsame rules that actions\fR, but they must be \fBpreceded by a dollar signs $\fR (e.g. \f(CW$f110c\fR for a subfield or \f(CW$i0991\fR for an indicator). .IP "\(bu" 4 The record leader can be defined with \fB\f(CB$ldr\fB\fR. .IP "\(bu" 4 It's possible to test only one character's value in subfields or leader. To do this, you have to add the \fBthis character's position from 0 to 99\fR: .Sp .Vb 2 \& #to test the 3rd char. in leader and the 12e char. in \*(Aq501$a\*(Aq: \& condition : $ldr2 eq "t" and $f501a11 eq "z" .Ve .PP \fIRun actions only on the condition's fields\fR .IX Subsection "Run actions only on the condition's fields" .PP We have already seen that to refers to the condition's field in actions, it is possible to define subfields directly. It works only if we define only one field to be tested in the condition. If we ve'got more than one field in condition, their \fBnames must also begin with $\fR to refer them (it works also with a unique field in condition). .PP For example, if you test \f(CW$f501a\fR value's in condition: .PP \&\- this will delete 'c' subfields only in the '501' field which is true in the condition: .PP .Vb 2 \& condition : $f501a eq "foo" and defined $f501b \& delete : $f501c .Ve .PP \&\- this will delete 'c' subfields in all '501' fields: .PP .Vb 2 \& condition : $f501a eq "foo" and defined $f501b \& delete : f501c .Ve .PP \&\- this will create a new '701' field with a 'c' subfield containing '501$a' subfield's value defined in the condition: .PP .Vb 3 \& condition : defined $f501a \& create : \& f701c : $f501a .Ve .PP \&\fB\s-1WARNING\s0\fR: To get \fBsubfield's value of\fR the condition's fields, these subfields must be defined in the condition: .PP \&\- it \fBdoesn't\fR work: .PP .Vb 3 \& condition : $f501a eq "foo" \& create : \& f701a : $f501c .Ve .PP \&\- it works (create a new '701' field with a subfield 'a' containing the condition's '501$c' subfield's value ): .PP .Vb 3 \& condition : $f501a eq "foo" and defined $f501c \& create : \& f701a : $f501c .Ve .PP \&\- this restriction is true only for the subfield's values, but isn't true to specify the fields affected by an action: the example below will create a new 'c' subfield \fBin a field defined in the condition\fR. .PP .Vb 5 \& condition : $f501a eq "foo" and $f110a == 2 \& create : \& $f501c : new subfield value \& # If there are multiple \*(Aq501\*(Aq fields, only the one with a \& # subfield \*(Aqa\*(Aq=\*(Aqfoo\*(Aq will have a new \*(Aqc\*(Aq subfield created .Ve .SS "Actions" .IX Subsection "Actions" \fIcreate\fR .IX Subsection "create" .IP "\(bu" 4 As the name suggests, this action allows you to create new fields and subfields. .IP "\(bu" 4 Syntax: .Sp .Vb 3 \& # basic: \& create : \& : \& \& # to create two subfields (in one field) with same name: \& create : \& : \& \- \& \- \& \& # advanced: \& create : \& : \& : \& \- \& \- \& : .Ve .IP "\(bu" 4 Example: .Sp .Vb 10 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& b : new subfield\*(Aqs value on the condition\*(Aqs field \& f502a : this is the subfield\*(Aqs value of a new 502 field \& f502b : \& \- this is the first \*(Aqb\*(Aq value of another new 502 \& \- this is the 2nd \*(Aqb\*(Aq value of this another new 502 \& f600 : \& a : \& \- first \*(Aqa\*(Aq subfield of this new 600 field \& \- second \*(Aqa\*(Aq subfield of this new 600 field \& b : the 600b value .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-init record\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& \-\-transformed record\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& _bnew subfield\*(Aqs value on the condition\*(Aqs field \& 502 _bthis is the first \*(Aqb\*(Aq value of another new 502 \& _bthis is the 2nd \*(Aqb\*(Aq value of this another new 502 \& 502 _athis is the subfield\*(Aqs value of a new 502 field \& 600 _afirst \*(Aqa\*(Aq subfield of this new 600 field \& _asecond \*(Aqa\*(Aq subfield of this new 600 field \& _bthe 600b value .Ve .IP "\(bu" 4 be careful: You need to use lists to create several subfields with the same name in a field: .Sp .Vb 4 \& # does not work: \& create : \& f502b : value \& f502b : value .Ve .PP \fIupdate\fR .IX Subsection "update" .IP "\(bu" 4 This action allows you to update \fBexisting\fR fields. This action updates all the specified subfields of all specified fields (if the specified field is a condition's field, it will be the only one to be updated) .IP "\(bu" 4 Syntax: .Sp .Vb 3 \& # basic: \& update : \& : \& \& # advanced: \& update : \& : \& : \& : \& : \& : .Ve .IP "\(bu" 4 Example: .Sp .Vb 8 \& \-\-\- \& condition : $f502a eq "second a" \& update : \& b : updated value of all \*(Aqb\*(Aq subfields in the condition field \& f502c : updated value of all \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& f501 : \& a : updated value of all \*(Aqa\*(Aq subfields into all \*(Aq501\*(Aq fields \& b : $f502a is the 502a condition\*(Aqs field\*(Aqs value .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-init record\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _afirst a \& _asecond a \& _bbbb \& _cccc1 \& _cccc2 \& 502 _apoto \& 502 _btruc \& _cbidule \& \-\-transformed record\-\- \& LDR \& 501 _aupdated value of all \*(Aqa\*(Aq subfields into all \*(Aq501\*(Aq fields \& _bsecond a is the 502a condition\*(Aqs field\*(Aqs value \& _cbar \& 502 _afirst a \& _asecond a \& _bupdated value of all \*(Aqb\*(Aq subfields in the condition field \& _cupdated value of all \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& _cupdated value of all \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& 502 _apoto \& 502 _btruc \& _cupdated value of all \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields .Ve .PP \fIupdatefirst\fR .IX Subsection "updatefirst" .IP "\(bu" 4 This action is \fBidentical to the update\fR, except that it updates only the \fBfirst\fR subfield of the specified fields .IP "\(bu" 4 \&\fBSyntax\fR: except for the action's name, it's the \fBsame than the update\fR's syntax .IP "\(bu" 4 Example: .Sp .Vb 8 \& \-\-\- \& condition : $f502a eq "second a" \& updatefirst : \& b : updated value of first \*(Aqb\*(Aq subfields in the condition\*(Aqs field \& f502c : updated value of first \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& f501 : \& a : updated value of first \*(Aqa\*(Aq subfields into all \*(Aq501\*(Aq fields \& b : $f502a is the value of 502a conditionnal field .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-init record\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _afirst a \& _asecond a \& _bbbb \& _cccc1 \& _cccc2 \& 502 _apoto \& 502 _btruc \& _cbidule \& \-\-transformed record\-\- \& LDR \& 501 _aupdated value of first \*(Aqa\*(Aq subfields into all \*(Aq501\*(Aq fields \& _bsecond a is the value of 502a conditionnal field \& _cbar \& 502 _afirst a \& _asecond a \& _bupdated value of first \*(Aqb\*(Aq subfields in the condition\*(Aqs field \& _cupdated value of first \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& _cccc2 \& 502 _apoto \& 502 _btruc \& _cupdated value of first \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields .Ve .PP \fIforceupdate and forceupdatefirst\fR .IX Subsection "forceupdate and forceupdatefirst" .IP "\(bu" 4 If the specified \fBsubfields exist\fR: these actions are identical to the \fBupdate\fR and the updatefirst actions .IP "\(bu" 4 If the specified \fBsubfields doesn't exist\fR: these actions are identical to the \fBcreate\fR action .IP "\(bu" 4 \&\fBSyntax\fR: except for the action's name, it's the \fBsame than the update\fR's syntax .IP "\(bu" 4 Example: .Sp .Vb 8 \& \-\-\- \& condition : $f502a eq "second a" \& forceupdate : \& b : \*(Aqb\*(Aq subfield\*(Aqs value in the condition\*(Aqs field \& f502c : \*(Aq502c\*(Aq value\*(Aqs \& f503 : \& a : \*(Aq503a\*(Aq value\*(Aqs \& b : $f502a is the 502a condition\*(Aqs value .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-init record\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _btruc \& _cbidule \& 502 _apoto \& 502 _afirst a \& _asecond a \& _bbbb \& _ccc1 \& _ccc2 \& \-\-transformed record\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _btruc \& _c\*(Aq502c\*(Aq value\*(Aqs \& 502 _apoto \& _c\*(Aq502c\*(Aq value\*(Aqs \& 502 _afirst a \& _asecond a \& _b\*(Aqb\*(Aq subfield\*(Aqs value in the condition\*(Aqs field \& _c\*(Aq502c\*(Aq value\*(Aqs \& _c\*(Aq502c\*(Aq value\*(Aqs \& 503 _a\*(Aq503a\*(Aq value\*(Aqs \& _bsecond a is the 502a condition\*(Aqs value \& \-\-transformed record if we had used forceupdatefirst\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _btruc \& _c\*(Aq502c\*(Aq value\*(Aqs \& 502 _apoto \& _c\*(Aq502c\*(Aq value\*(Aqs \& 502 _afirst a \& _asecond a \& _b\*(Aqb\*(Aq subfield\*(Aqs value in the condition\*(Aqs field \& _c\*(Aq502c\*(Aq value\*(Aqs \& _ccc2 \& 503 _a\*(Aq503a\*(Aq value\*(Aqs \& _bsecond a is the value of 502a conditionnal field .Ve .PP \fIdelete\fR .IX Subsection "delete" .IP "\(bu" 4 As the name suggests, this action allows you to delete fields and subfields. .IP "\(bu" 4 Syntax: .Sp .Vb 2 \& # basic: \& delete : \& \& # advanced: \& delete : \& \- \& \- .Ve .IP "\(bu" 4 Example: .Sp .Vb 12 \& \-\-\- \& condition : $f501a eq "foo" \& delete : $f501 \& \-\-\- \& condition : $f501a eq "bar" \& delete : b \& \-\-\- \& delete : f502 \& \-\-\- \& delete : \& \- f503 \& \- f504a .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-init record\-\- \& LDR \& 501 _abar \& _bbb1 \& _bbb2 \& 501 _afoo \& 502 _apata \& 502 _apoto \& 503 _apata \& 504 _aata1 \& _aata2 \& _btbbt \& \-\-transformed record\-\- \& LDR \& 501 _abar \& 504 _btbbt .Ve .PP \fIduplicatefield\fR .IX Subsection "duplicatefield" .IP "\(bu" 4 As the name suggests, this action allows you to duplicate entire fields. .IP "\(bu" 4 Syntax: .Sp .Vb 2 \& # basic: \& duplicatefield : > \& \& # advanced: \& duplicatefield : \& \- > \& \- > .Ve .IP "\(bu" 4 Example: .Sp .Vb 12 \& \-\-\- \& condition : $f008_ eq "controlfield_contentb" \& duplicatefield : $f008 > f007 \& \-\-\- \& condition : $f501a eq "bar" \& duplicatefield : $f501 > f400 \& \-\-\- \& condition : $f501a eq "foo" \& duplicatefield : \& \- f501 > f401 \& \- $f501 > f402 \& \- f005 > f006 .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-init record\-\- \& LDR \& 005 controlfield_content2 \& 005 controlfield_content1 \& 008 controlfield_contentb \& 008 controlfield_contenta \& 501 _afoo \& 501 12 _abar \& _bbb1 \& _bbb2 \& \-\-transformed record\-\- \& LDR \& 005 controlfield_content2 \& 005 controlfield_content1 \& 006 controlfield_content1 \& 006 controlfield_content2 \& 007 controlfield_contentb \& 008 controlfield_contentb \& 008 controlfield_contenta \& 400 12 _abar \& _bbb1 \& _bbb2 \& 401 12 _abar \& _bbb1 \& _bbb2 \& 401 _afoo \& 402 _afoo \& 501 _afoo \& 501 12 _abar \& _bbb1 \& _bbb2 .Ve .PP \fIexecute\fR .IX Subsection "execute" .IP "\(bu" 4 This action allows you to to define Perl code that will be run with \f(CW\*(C`eval\*(C'\fR .Sp You can run functions written directly in the \s-1YAML \s0( for details on writing perl subs in the \s-1YAML,\s0 refer to next chapter: Use Perl functions and LookUp Tables ). .IP "\(bu" 4 Syntax: .Sp .Vb 2 \& # basic: \& execute : \& \& # advanced: \& execute : \& \- \& \- .Ve .IP "\(bu" 4 Example: .Sp .Vb 12 \& \-\-\- \& condition : $f501a eq "bar" \& execute : \& \- warn("f501a eq $f501a") \& \- warn("barbar") \& \-\-\- \& \- \& condition : $f501a eq "foo" \& execute : \e&warnfoo("f501a eq $f501a") \& \- \& subs : > \& sub warnfoo { my $string = shift;warn $string; } .Ve .Sp result (in stderr): .Sp .Vb 3 \& f501a eq bar at (eval 30) line 6, <$yamls> line 1. \& barbar at (eval 30) line 7, <$yamls> line 1. \& f501a eq foo at (eval 33) line 2, <$yamls> line 1. .Ve .SS "Use Perl functions and LookUp Tables" .IX Subsection "Use Perl functions and LookUp Tables" You can use Perl functions (\fBsubs\fR) and lookup tables (\fB\s-1LUT\s0\fR) to define with greater flexibility values that will be created or updated by the actions: create, forceupdate, forceupdatefirst, update and updatefirst. .PP These functions (and lookup tables) can be \fBwritten in a rule\fR (in this case they can be used only by this rule) \fBor after the last rule\fR ( after the last \-\-\-, can be used in all rules: \fBglobal_subs\fR and \fBglobal_LUT\fR ). .PP \fIVariables\fR .IX Subsection "Variables" .PP Four types of variables can be used: .PP \f(CW$this\fR, and condition's elements .IX Subsection "$this, and condition's elements" .IP "\(bu" 4 variables pointing on the condition's subfield's values are those we have already seen in Chapter 'Run actions only on condition fields' (e.g. \fB\f(CB$f110c\fB\fR) .IP "\(bu" 4 \&\fB\f(CB$this\fB\fR: this is the variable to use to pointing to the \fBvalue of current subfield\fR. \f(CW$this\fR can also be used outside a sub or a \s-1LUT.\s0 .Sp Example (N.B.: sub 'fromo2e' converts 'o' to 'e'): .Sp .Vb 11 \& \-\-\- \& \- \& condition : $f501a eq "foo" \& create : \& c : \e&fromo2e("$f501a") \& update : \& d : this 501d value\*(Aqs is $this \& b : \e&fromo2e("$this") \& \- \& subs: > \& sub fromo2e { my $string=shift; $string =~ s/o/e/g; $string; } .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 11 \& \-\-init record\-\- \& LDR \& 501 _afoo \& _bboo \& _ddoo \& \-\-transformed record\-\- \& LDR \& 501 _afoo \& _bbee \& _d this 501d value\*(Aqs is doo \& _cfee .Ve .PP \f(CW$mth\fR .IX Subsection "$mth" .PP \&\fB\f(CB$mth\fB\fR is the optional hashref add as third optional argument. It can be used in writing (into subs and global_subs) and reading. This allows to interact with the script that calls MARC::Transform. .IP "\(bu" 4 Syntaxe: \fB$$mth{foo}\fR .IP "\(bu" 4 Example in a perl script : .Sp .Vb 10 \& my $record = MARC::Record\->new(); \& $record\->leader(\*(Aqoptionnal leader\*(Aq); \& print "\-\-init record\-\-\en". $record\->as_formatted; \& my %mth; \& $mth{"inc"}=1; \& $mth{"var"}="a string"; \& my $yaml = \*(Aq \& \-\-\- \& condition : $$mth{"var"} eq "a string" \& forceupdate : \& f500a : $$mth{"var"} \& \-\-\- \& \- \& execute : \e&testa() \& \- \& subs: > \& sub testa { $$mth{"inc"}++; } \& \-\-\- \& forceupdate : \& f600a : \e&testb() \& \-\-\- \& global_subs: > \& sub testb { $$mth{"inc"}++;$$mth{"inc"}; } \& \*(Aq; \& $record = MARC::Transform\->new($record,$yaml,\e%mth); \& print "\en\-\-transformed record\-\- ".$mth{"inc"}." : \en". $record\->as_formatted ."\en"; .Ve .Sp result : .Sp .Vb 6 \& \-\-init record\-\- \& LDR optionnal leader \& \-\-transformed record\-\- 3 : \& LDR optionnal leader \& 500 _aa string \& 600 _a3 .Ve .PP \f(CW$record\fR .IX Subsection "$record" .PP \&\fB\f(CB$record\fB\fR is the current MARC::Record object. .PP \fIsubs\fR .IX Subsection "subs" .PP Internal rules .IX Subsection "Internal rules" .IP "\(bu" 4 Syntax: .Sp .Vb 8 \& #full rule: \& \-\-\- \& \- \& \& \- \& subs: > \& \& \-\-\- \& \& # method invokation syntax: \& \e&("") .Ve .IP "\(bu" 4 Example: .Sp .Vb 10 \& \-\-\- \& \- \& condition : $f501a eq "foo" and defined $f501d \& update : \& b : \e&convertbaddate("$this") \& c : \e&trim("$f501d") \& \- \& subs: > \& sub convertbaddate { \& #this function convert date like "21/2/98" to "1998\-02\-28" \& my $in = shift; \& if ($in =~/^(\ed{1,2})\e/(\ed{1,2})\e/(\ed{2}).*/) \& { \& my $day=$1; \& my $month=$2; \& my $year=$3; \& if ($day=~m/^\ed$/) {$day="0".$day;} \& if ($month=~m/^\ed$/) {$month="0".$month;} \& if (int($year)>12) \& {$year="19".$year;} \& else {$year="20".$year;} \& return "$year\-$month\-$day"; \& } \& else \& { \& return $in; \& } \& } \& \& sub trim { \& # This function removes ",00" at the end of a string \& my $in = shift; \& $in=~s/,00$//; \& return $in; \& } .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 12 \& \-\-init record\-\- \& LDR \& 501 _afoo \& _b8/12/10 \& _cboo \& _d40,00 \& \-\-transformed record\-\- \& LDR \& 501 _afoo \& _b2010\-12\-08 \& _c40 \& _d40,00 .Ve .PP global_subs .IX Subsection "global_subs" .IP "\(bu" 4 Syntax: .Sp .Vb 3 \& \-\-\- \& global_subs: > \& \& \& # method invokation syntax: \& \e&("") .Ve .IP "\(bu" 4 Example: .Sp .Vb 10 \& \-\-\- \& condition : $f501a eq "foo" \& update : \& b : \e&return_record_encoding() \& c : \e&trim("$this") \& \-\-\- \& global_subs: > \& sub return_record_encoding { \& $record\->encoding(); \& } \& \& sub trim { \& # This function removes ",00" at the end of a string \& my $in = shift; \& $in=~s/,00$//; \& return $in; \& } .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR ): .Sp .Vb 10 \& \-\-init record\-\- \& LDR \& 501 _afoo \& _bbar \& _c40,00 \& \-\-transformed record\-\- \& LDR \& 501 _afoo \& _bMARC\-8 \& _c40 .Ve .PP \fI\s-1LUT\s0\fR .IX Subsection "LUT" .PP If a value has no match in a LookUp Table, it isn't modified. (unless you have defined a default value with \f(CW\*(C`_default_value_\*(C'\fR ). .PP If you want to use more than one LookUp Table in a rule, you must use a global_LUT because it differentiates tables with titles. .PP Internal rules .IX Subsection "Internal rules" .IP "\(bu" 4 Syntax: .Sp .Vb 10 \& #full rule: \& \-\-\- \& \- \& \& \- \& LUT : \& : \& : \& _default_value_ : optionnal default value \& \-\-\- \& \& # LUT invokation syntax: \& \e&LUT("") .Ve .IP "\(bu" 4 Example: .Sp .Vb 12 \& \-\-\- \& \- \& condition : $f501b eq "bar" \& create : \& f604a : \e&LUT("$f501b") \& update : \& c : \e&LUT("$this") \& \- \& LUT : \& 1 : first \& 2 : second \& bar : openbar .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR ): .Sp .Vb 9 \& \-\-init record\-\- \& LDR \& 501 _bbar \& _c1 \& \-\-transformed record\-\- \& LDR \& 501 _bbar \& _cfirst \& 604 _aopenbar .Ve .PP global_LUT .IX Subsection "global_LUT" .IP "\(bu" 4 Syntax: .Sp .Vb 9 \& \-\-\- \& global_LUT: \& : \& : \& : \& _default_value_ : valeur par de\*'faut optionnelle \& : \& : \& : \& \& # global_LUT invokation syntax: \& \e&LUT("","") .Ve .IP "\(bu" 4 Example: .Sp .Vb 10 \& \-\-\- \& update : \& f501a : \e&LUT("$this","numbers") \& f501b : \e&LUT("$this","cities") \& f501c : \e&LUT("$this","cities") \& \-\-\- \& global_LUT: \& cities: \& NY : New York \& SF : San Fransisco \& TK : Tokyo \& _default_value_ : unknown city \& numbers: \& 1 : one \& 2 : two .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR ): .Sp .Vb 12 \& \-\-init record\-\- \& LDR \& 501 _a1 \& _a3 \& _bfoo \& _cSF \& \-\-transformed record\-\- \& LDR \& 501 _aone \& _a3 \& _bunknown city \& _cSan Fransisco .Ve .PP $$mth{\*(L"_defaultLUT_to_mth_\*(R"} .IX Subsection "$$mth{_defaultLUT_to_mth_}" .IP "\(bu" 4 \&\fBNote: \fRif you call MARC::Transform with the third parameter, the module filled its key named \f(CW\*(C`_defaultLUT_to_mth_\*(C'\fR in case you want to keep, in the calling script, track of the values and types (named \f(CW\*(C`lookuptableforthis\*(C'\fR for non-global's \s-1LUT\s0) unmatched. \f(CW$$mth{"_defaultLUT_to_mth_"}\fR is cleared each time MARC::Transform\->new is called. .IP "\(bu" 4 If we recall the above example with : .Sp .Vb 4 \& my %mth; \& $record = MARC::Transform\->new($record,$yaml,\e%mth); \& print $mth{"_defaultLUT_to_mth_"}\->{"cities"}[0]; \& print "\en".Data::Dumper::Dumper $mth{"_defaultLUT_to_mth_"}; .Ve .Sp will return in stdout : .Sp .Vb 9 \& foo \& $VAR1 = { \& \*(Aqnumbers\*(Aq => [ \& \*(Aq3\*(Aq \& ], \& \*(Aqcities\*(Aq => [ \& \*(Aqfoo\*(Aq \& ] \& }; .Ve .Sp try this if you want to get the content of \f(CW$mth\fR{\*(L"_defaultLUT_to_mth_\*(R"} instead of the line containing Data::Dumper::Dumper : .Sp .Vb 5 \& foreach my $k (keys(%{$mth{"_defaultLUT_to_mth_"}})) \& { \& foreach my $value(@{$mth{"_defaultLUT_to_mth_"}\->{"$k"}}) \& { print "$k : $value \en"; } \& } .Ve .SH "Latest tips and a big YAML example's" .IX Header "Latest tips and a big YAML example's" .IP "\(bu" 4 If your script return an error like \*(L"\s-1YAML\s0 Error: Stream does not end with newline character\*(R", it's easy to fix. If you define your \s-1YAML\s0 into a variable, it must end with a new blank line. If you give a path to your \s-1YAML\s0 file, it is probably not good : try with an absolut path. .IP "\(bu" 4 Restriction: the specific case of double-quotes (") and dollar signs ($): .Sp In \s-1YAML,\s0 these characters are interpreted differently. To use them in string context, you will need to replace them in \s-1YAML\s0 by \f(CW\*(C`#_dbquote_#\*(C'\fR (for ") and \f(CW\*(C`#_dollars_#\*(C'\fR (for $): .Sp \&. Example: .Sp .Vb 4 \& \-\-\- \& condition : $f501a eq "I want #_dbquote_##_dollars_##_dbquote_#" \& create : \& f604a : "#_dbquote_#$f501a#_dbquote_# contain a #_dollars_# sign" .Ve .Sp \&. result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR ): .Sp .Vb 7 \& \-\-init record\-\- \& LDR \& 501 _aI want "$" \& \-\-transformed record\-\- \& LDR \& 501 _aI want "$" \& 604 _a"I want "$"" contain a $ sign .Ve .IP "\(bu" 4 Restriction: You can test if a field or subfield exists, but it is inadvisable to test its absence. .IP "\(bu" 4 Example: feel free to copy the examples in this documentation. Be aware that I have added four space characters at the beginning of each exemple's line to make them better displayed by the \s-1POD\s0 interpreter. If you copy / paste them into your \s-1YAML\s0 configuration file, Be sure to remove the first four characters of each line (e.g. with vim, \f(CW\*(C`:%s/^\es\es\es\es//g\*(C'\fR ). .IP "\(bu" 4 This yaml was called like this: \f(CW\*(C`my %mth; $mth{"var"}="a string"; $record = MARC::Transform\->new($record,$yaml,\e%mth);\*(C'\fR .Sp .Vb 10 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& f502a : this is the value of a subfield of a new 502 field \& \-\-\- \& condition : $f401a=~/foo/ \& create : \& b : new value of the 401 condition\*(Aqs field \& f600 : \& a : \& \- first a subfield of this new 600 field \& \- second a subfield of this new 600 field \& \- $$mth{"var"} \& b : the 600b value \& execute : \e&reencodeRecordtoUtf8() \& \-\-\- \& \- \& condition : $f501a =~/foo/ and $f503a =~/bar/ \& forceupdate : \& $f503b : mandatory b in condition\*(Aqs field \& f005_ : mandatory 005 \& f006_ : \e&return_record_encoding() \& f700 : \& a : the a subfield of this mandatory 700 field \& b : \e&sub1("$f503a") \& forceupdatefirst : \& $f501b : update only the first b in condition\*(Aqs field 501 \& \- \& condition : $f501a =~/foo/ \& execute : \e&warnfoo("f501a contain foo") \& \- \& subs : > \& sub return_record_encoding { $record\->encoding(); } \& sub sub1 {my $string=shift;$string =~ s/a/e/g;return $string;} \& sub warnfoo { my $string = shift;warn $string; } \& \-\-\- \& \- \& condition : $f501b2 eq "o" \& update : \& c : updated value of all c in condition\*(Aqs field \& f504a : updated value of all 504a if exists \& f604 : \& b : \e&LUT("$this") \& c : \e&LUT("NY","cities") \& updatefirst : \& f604a : update only the first a in 604 \& \- \& condition : $f501c eq "1" \& delete : $f501 \& \- \& LUT : \& 1 : first \& 2 : second \& bar : openbar \& \-\-\- \& delete : \& \- f401a \& \- f005 \& \-\-\- \& condition : $ldr2 eq "t" \& execute : \e&SetRecordToLowerCase($record) \& \-\-\- \& condition : $f008_ eq "controlfield_content8b" \& duplicatefield : \& \- $f008 > f007 \& \- f402 > f602 \& delete : f402 \& \-\-\- \& global_subs: > \& sub reencodeRecordtoUtf8 { \& $record\->encoding( \*(AqUTF\-8\*(Aq ); \& } \& sub warnfee { \& my $string = shift;warn $string; \& } \& global_LUT: \& cities: \& NY : New York \& SF : San Fransisco \& numbers: \& 1 : one \& 2 : two .Ve .Sp result (with \f(CW\*(C`$record\->as_formatted\*(C'\fR ) : .Sp .Vb 10 \& \-\-init record\-\- \& LDR optionnal leader \& 005 controlfield_content \& 008 controlfield_content8a \& 008 controlfield_content8b \& 106 _aVaLuE \& 401 _aafooa \& 402 2 _aa402a2 \& 402 1 _aa402a1 \& 501 _c1 \& 501 _afoo \& _afoao \& _b1 \& _bbaoar \& _cbig \& 503 _afee \& _ababar \& 504 _azut \& _asisi \& 604 _afoo \& _afoo \& _bbar \& _ctruc \& \& \-\-transformed record\-\- \& LDR optionnalaleader \& 006 UTF\-8 \& 007 controlfield_content8b \& 008 controlfield_content8a \& 008 controlfield_content8b \& 106 _aVaLuE \& 401 _bnew value of the 401 condition\*(Aqs field \& 501 _c1 \& 501 _afoo \& _afoao \& _bupdate only the first b in condition\*(Aqs field 501 \& _bbaoar \& _cupdated value of all c in condition\*(Aqs field \& 502 _athis is the value of a subfield of a new 502 field \& 503 _afee \& _ababar \& _bmandatory b in condition\*(Aqs field \& 504 _aupdated value of all 504a if exists \& _aupdated value of all 504a if exists \& 600 _aa string \& _afirst a subfield of this new 600 field \& _asecond a subfield of this new 600 field \& _bthe 600b value \& 602 1 _aa402a1 \& 602 2 _aa402a2 \& 604 _aupdate only the first a in 604 \& _afoo \& _bopenbar \& _cNew York \& 700 _athe a subfield of this mandatory 700 field \& _bbeber .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 MARC::Record () .IP "\(bu" 4 MARC::Field () .IP "\(bu" 4 MARC::Loader () .IP "\(bu" 4 \&\s-1YAML \s0() .IP "\(bu" 4 Library Of Congress \s-1MARC\s0 pages () .Sp The definitive source for all things \s-1MARC.\s0 .SH "AUTHOR" .IX Header "AUTHOR" Stephane Delaune, (delaune.stephane at gmail.com) .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2011\-2013 Stephane Delaune for Biblibre.com, all rights reserved. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "===========> DOCUMENTATION FRANCAISE" .IX Header "===========> DOCUMENTATION FRANCAISE" .SH "\- NOM" .IX Header "- NOM" MARC::Transform \- Module Perl pour transformer une notice \s-1MARC\s0 en utilisant un fichier de configuration \s-1YAML\s0 .SH "\- VERSION" .IX Header "- VERSION" Version 0.003005 .SH "\- SYNOPSIS" .IX Header "- SYNOPSIS" \&\fBPerl script:\fR .PP .Vb 1 \& use MARC::Transform; \& \& # Pour ce synopsis, nous cre\*'ons une petite notice: \& my $record = MARC::Record\->new(); \& $record\->insert_fields_ordered( MARC::Field\->new( \& \*(Aq501\*(Aq, \*(Aq\*(Aq, \*(Aq\*(Aq, \& \*(Aqa\*(Aq => \*(Aqfoo\*(Aq, \& \*(Aqb\*(Aq => \*(Aq1\*(Aq, \& \*(Aqc\*(Aq => \*(Aqbar\*(Aq, \& \*(Aqd\*(Aq => \*(Aqbor\*(Aq ) ); \& \& print "\-\-notice d\*(Aqorigine\-\-\en". $record\->as_formatted ."\en"; \& \& # Nous transformons notre notice avec notre fichier de \& # configuration YAML avec son chemin absolu ( ou \& # relatif si il est appele\*' depuis le bon endroit) : \& $record = MARC::Transform\->new ( $record, "/path/conf.yaml" ); \& \& # Vous pouvez aussi e\*'crire votre YAML dans une variable: \& my $yaml="delete : f501d\en"; \& # et l\*(Aqutiliser pour transformer la notice: \& $record = MARC::Transform\->new ( $record, $yaml ); \& \& print "\en\-\-notice transforme\*'e\-\-\en". $record\->as_formatted ."\en"; .Ve .PP \&\fBconf.yaml:\fR .PP .Vb 11 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& f502a : New 502a subfield\*(Aqs value \& update : \& $f501b : \e&LUT("$this") \& LUT : \& 1 : first \& 2 : second value in this LUT (LookUp Table) \& \-\-\- \& delete : f501c .Ve .PP \&\fBRe\*'sultat\fR (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR): .PP .Vb 6 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& _dbor \& \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _afoo \& _bfirst \& 502 _aNew 502a subfield\*(Aqs value .Ve .SH "\- DESCRIPTION" .IX Header "- DESCRIPTION" C'est un module Perl pour transformer une notice \s-1MARC\s0 en utilisant un fichier de configuration \s-1YAML.\s0 .PP Il permet de \fBcre\*'er\fR , \fBmettre a\*` jour\fR , \fBsupprimer\fR , \fBdupliquer\fR les champs et les sous-champs d'une notice. Vous pouvez aussi utiliser des \fBscripts\fR et des \fBtables de correspondance\fR. Vous pouvez pre\*'ciser des \fBconditions\fR pour executer ces actions. .PP Toutes les conditions, actions, fonctions et tables de correspondance sont \fBde\*'finies dans le \s-1YAML\s0\fR. .PP MARC::Transform utilise MARC::Record. .SH "\- METHODE" .IX Header "- METHODE" .SS "\- \fInew()\fP" .IX Subsection "- new()" .Vb 1 \& $record = MARC::Transform\->new($record, "/path/conf.yaml" ); .Ve .PP C'est la seule me\*'thode que vous utiliserez. Elle prend un objet MARC::Record et le chemin vers un \s-1YAML\s0 comme arguments. Vous pouvez aussi e\*'crire votre \s-1YAML\s0 dans une variable et l'utiliser pour transformer la notice comme ceci : .PP .Vb 2 \& my $yaml="delete : f501d\en"; \& $record = MARC::Transform\->new ( $record, $yaml ); .Ve .PP \fI\- Re\*'fe\*'rence a\*` un hash optionnel\fR .IX Subsection "- Re'fe'rence a` un hash optionnel" .PP Comme nous allons le voir plus en de\*'tail plus bas, il est possible d'ajouter comme troisie\*`me argument une re\*'fe\*'rence a\*` un hash (nomme\*' \f(CW$mth\fR dans le yaml). .PP .Vb 6 \& my $record = MARC::Record\->new(); my $hashref = {\*(Aqvar\*(Aq => \*(Aqfoo\*(Aq}; \& my $yaml = \*(Aqcreate : \& f500a : $$mth{"var"} \& \*(Aq; \& $record = MARC::Transform\->new($record,$yaml,$hashref); \& #la valeur du nouveau sous\-champ 500$a est "foo" .Ve .PP \fI\- Mode verbeux\fR .IX Subsection "- Mode verbeux" .PP Chaque re\*`gle du \s-1YAML \s0(voir les bases plus bas pour comprendre ce qu'est une re\*`gle) ge\*'ne\*`re un script qui est e\*'value\*', dans la notice, pour chaque champ et sous-champ spe\*'cifie\*' dans la condition (si il y a une condition). En ajoutant un quatrie\*`me argument optionnel \fB1\fR a\*` la me\*'thode, elle affiche le script ge\*'ne\*'re\*'. Cela peut e\*^tre utile pour comprendre ce qu'il se passe: .PP .Vb 1 \& $record = MARC::Transform\->new($record,"/path/conf.yaml",0,1); .Ve .SH "\- YAML" .IX Header "- YAML" .SS "\- Bases" .IX Subsection "- Bases" \&\- \fBLe \s-1YAML\s0 est divise\*' en re\*`gle\fR (se\*'pare\*'es par \-\-\- ), chaque re\*`gle est exe\*'cute\*'e l'une apre\*`s l'autre, les re\*`gles sans condition sont toujours exe\*'cute\*'es: .PP .Vb 7 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& f600a : new field value \& \-\-\- \& delete : f501c \& \-\-\- .Ve .PP \&\- \fBles conditions sont e\*'crites en perl\fR, ce qui permet une grande flexibilite\*'. Elles doivent e\*^tre de\*'finies avec \f(CW\*(C`condition : \*(C'\fR .PP .Vb 2 \& condition : ($f501a=~/foo/ and $f503a=~/bar/) or ($f102a eq "bib") \& # si un 501$a et un 503$a contiennent foo et bar, ou si un 102$a = bib .Ve .PP \&\- Les conditions testent les notices \fBchamp par champ\fR (uniquement sur les champs de\*'finis dans la condition) .PP Cela signifie, par exemple, que si nous avons plusieurs champs '501' dans la notice, si notre condition est \f(CW\*(C`$f501a eq "foo" and $f501b eq "bar"\*(C'\fR, cette condition sera vrai uniquement si un champ '501' a un sous-champ 'a' = \*(L"foo\*(R" \s-1ET\s0 un sous-champ 'b' = 'bar' (elle sera fausse si il y a un champ '501' avec un sous-champ 'a' = \*(L"foo\*(R" et \s-1UN AUTRE\s0 champ '501' avec un sous-champ 'b' = \*(L"bar\*(R"). .PP \&\- Il est possible de lancer plusieurs actions diffe\*'rentes dans une seule re\*`gle: .PP .Vb 6 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& f600a : new field value \& delete : f501c \& \-\-\- .Ve .PP \&\- L'ordre dans lequel les actions sont e\*'crites n'a pas d'importance. Les actions seront toujours exe\*'cute\*'e dans l'ordre suivant: .IP "\(bu" 4 create .IP "\(bu" 4 duplicatefield .IP "\(bu" 4 forceupdate .IP "\(bu" 4 forceupdatefirst .IP "\(bu" 4 update .IP "\(bu" 4 updatefirst .IP "\(bu" 4 execute .IP "\(bu" 4 delete .PP \&\- \fBChaque re\*`gle peut e\*^tre divise\*'e en sous\-re\*`gles\fR (se\*'pare\*'es par \- ) similaires a\*` un 'if,elsif' ou un script 'switch,case'. Si la condition de la premie\*`re sous\-re\*`gle est fausse, la condition de la sous\-re\*`gle suivante est teste\*'e. Lorsque la condition d'une sous\-re\*`gle est vraie (ou si un sous\-re\*`gle n'a pas de condition), les sous\-re\*`gles suivantes ne sont pas lues. .PP .Vb 10 \& \-\-\- \& \- \& condition : $f501a eq "foo" \& create : \& f502a : value if foo \& \- \& condition : $f501a eq "bar" \& create : \& f502a : value elsif bar \& \- \& create : \& f502a : value else \& \-\-\- \& # Si une sous\-re\*`gle n\*(Aqa pas de condition, elle sera conside\*'re\*'e \& # comme un \*(Aqelse\*(Aq (les sous\-re\*`gles suivantes ne seront pas lues) .Ve .PP \&\- Il n'est pas permis de de\*'finir plus d'une action similaire dans une seule (sous\-)re\*`gle. Cependant, il reste possible d'exe\*'cuter une action similaire plusieurs fois dans une seule re\*`gle (se re\*'fe\*'rer a\*` la syntaxe spe\*'cifique a\*` chaque action pour voir comment faire cela): .PP \&. Cela n'est \fBpas\fR permis: .PP .Vb 3 \& \-\-\- \& delete : f501b \& delete : f501c .Ve .PP \&. cela fonctionne: .PP .Vb 4 \& \-\-\- \& delete : \& \- f501b \& \- f501c .Ve .PP \fI\- un petit script pour tester vos re\*`gles\fR .IX Subsection "- un petit script pour tester vos re`gles" .PP \&\- \fBIl est fortement recommende\*' de tester chaque re\*`gle sur une notice de test avant de l'utiliser sur un large lot de notices\fR. Vous pouvez cre\*'er un script (par exemple \f(CW\*(C`test.pl\*(C'\fR) avec le contenu ci-dessous (que vous adapterez pour tester vos re\*`gles) et le lancer avec \f(CW\*(C`perl ./test.pl\*(C'\fR : .PP .Vb 10 \& #!/usr/bin/perl \& use MARC::Transform; \& my $record = MARC::Record\->new(); \& $record\->leader(\*(Aqoptionnal leader\*(Aq); \& $record\->insert_fields_ordered( MARC::Field\->new(\*(Aq005\*(Aq, \*(Aqcontrolfield_content\*(Aq)); \& $record\->insert_fields_ordered( MARC::Field\->new(\*(Aq501\*(Aq, \*(Aq\*(Aq, \*(Aq\*(Aq, \*(Aqa\*(Aq => \*(Aqfoo\*(Aq, \*(Aqb\*(Aq => \*(Aqbar\*(Aq) ); \& print "\en\-\-init record\-\-\en". $record\->as_formatted ."\en"; \& my $yaml=\*(Aq\-\-\- \& condition : $f501a eq "foo" \& create : \& f502a : condition is true \& \*(Aq; \& $record = MARC::Transform\->new($record,$yaml); \& print "\en\-\-transformed record\-\-\en". $record\->as_formatted ."\en"; .Ve .SS "\- Convention de nommage des champs et des sous-champs" .IX Subsection "- Convention de nommage des champs et des sous-champs" \fI\- Dans les actions\fR .IX Subsection "- Dans les actions" .PP \&\- Les noms des champs et des sous-champs sont tre\*`s importants: .IP "\(bu" 4 Ils doivent commencer par la lettre \fBf\fR suivi des \fB3 chiffres\fR du nom du champ (par exemple f099), suivi, pour les sous-champs, par leur \fBlettre ou chiffre\fR (par exemple \fBf501b\fR). .IP "\(bu" 4 Les noms des champs de contro\*^le commencent par la lettre \fBf\fR suivi par \fB3 chiffres infe\*'rieur a\*` 010\fR suivi par \fBunderscore\fR (par exemple \fBf005_\fR). .IP "\(bu" 4 \&\fBLes indicateurs\fR doivent commencer par la lettre \fBi\fR, suivi des \fB3 chiffres\fR du nom du champ suivi par la position de l'indicateur(\fB1 or 2\fR) (par exemple \fBi0991\fR). .IP "\(bu" 4 Dans les actions, vous pouvez de\*'finir \fBun sous-champ directement\fR (ou un indicateur avec i1 ou i2). Selon le contexte, il se re\*'fe\*`re au champ de la condition (si nous n'avons de\*'fini qu'un seul champ a\*` tester dans la condition), ou au champ en cours de traitement dans l'action: .Sp .Vb 8 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& b : new \*(Aqb\*(Aq subfield\*(Aqs value in unique condition\*(Aqs field (501) \& f600 : \& i1 : 1 \& a : new subfield (a) in this new 600 field \& \-\-\- .Ve .PP \fI\- Dans les conditions\fR .IX Subsection "- Dans les conditions" .IP "\(bu" 4 Dans les conditions la convention de nommage des champs et des sous-champs suit les \fBme\*^mes re\*`gles que les actions\fR, mais ils doivent e\*^tre \fBpre\*'ce\*'de\*'s du symbole dollar $\fR (par exemple \f(CW$f110c\fR pour un sous-champ ou \f(CW$i0991\fR pour un indicateur). .IP "\(bu" 4 Le leader de la notice peut e\*^tre de\*'fini avec \fB\f(CB$ldr\fB\fR. .IP "\(bu" 4 Il est possible de tester la valeur d'un seul caracte\*`re dans les sous-champs ou le leader. Pour faire cela, vous devez ajouter la \fBposition de ce caracte\*`re a\*` partir de 0 et jusqu'a\*` 99\fR: .Sp .Vb 2 \& #pour tester le 3e caracte\*`re du leader et le 12e dans le 501$a: \& condition : $ldr2 eq "t" and $f501a11 eq "z" .Ve .PP \fI\- Lancer des actions uniquement sur les champs de la condition\fR .IX Subsection "- Lancer des actions uniquement sur les champs de la condition" .PP Nous avons de\*'ja\*` vu que pour se re\*'fe\*'rer au champ de la condition dans les actions, il est possible de de\*'finir les sous-champs directement. Cela fonctionne uniquement si nous avons de\*'finis seulement un champ a\*` tester dans la condition. Si nous avons plus d'un champ dans la condition, pour s'y re\*'fe\*'rer, leurs \fBnoms doivent aussi commencer par $\fR (cela fonctionne e\*'galement avec un champ unique dans la condition). .PP Par exemple, si vous testez la valeur du \f(CW$f501a\fR dans la condition: .PP \&\- cela va supprimer les sous-champs 'c' uniquement dans le champ '501' qui est vrai dans la condition: .PP .Vb 2 \& condition : $f501a eq "foo" and defined $f501b \& delete : $f501c .Ve .PP \&\- cela va supprimer les sous-champs 'c' dans tous les champs '501': .PP .Vb 2 \& condition : $f501a eq "foo" and defined $f501b \& delete : f501c .Ve .PP \&\- cela va cre\*'er un nouveau champ '701' avec un sous-champ 'c' contenant la valeur du sous-champ 501$a de\*'fini dans la condition: .PP .Vb 3 \& condition : defined $f501a \& create : \& f701c : $f501a .Ve .PP \&\fB\s-1ATTENTION\s0\fR: Pour avoir \fBla valeur\fR des sous-champs des champs de la condition, ces sous-champs doivent e\*^tre de\*'finis dans la condition: .PP \&\- cela ne fonctionne \fBpas\fR: .PP .Vb 3 \& condition : $f501a eq "foo" \& create : \& f701a : $f501c .Ve .PP \&\- cela fonctionne (cre\*'e un nouveau champ '701' avec un sous-champ 'a' contenant la valeur du sous-champ 501$c de la condition): .PP .Vb 3 \& condition : $f501a eq "foo" and defined $f501c \& create : \& f701a : $f501c .Ve .PP \&\- Cette restriction est vrai uniquement pour les valeurs des sous-champs mais pas pour spe\*'cifier les champs affecte\*'s par une action : l'exemple ci-dessous va cre\*'er un nouveau sous-champ 'c' \fBdans un champ de\*'fini dans la condition\fR. .PP .Vb 5 \& condition : $f501a eq "foo" and $f110a == 2 \& create : \& $f501c : new subfield value \& # Si il y a de multiples champs \*(Aq501\*(Aq, seuls ceux ayant un \& # sous\-champ \*(Aqa\*(Aq=\*(Aqfoo\*(Aq auront un nouveau sous\-champ \*(Aqc\*(Aq cre\*'e\*' .Ve .SS "\- Actions" .IX Subsection "- Actions" \fI\- create\fR .IX Subsection "- create" .IP "\(bu" 4 Comme son nom l'indique, cette action vous permet de cre\*'er de nouveaux champs et sous-champs. .IP "\(bu" 4 Syntaxe: .Sp .Vb 3 \& # basique: \& create : \& : \& \& # pour cre\*'er deux sous\-champs (dans un champ) avec le me\*^me nom: \& create : \& : \& \- \& \- \& \& # avance\*'e: \& create : \& : \& : \& \- \& \- \& : .Ve .IP "\(bu" 4 Exemple: .Sp .Vb 10 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& b : new subfield\*(Aqs value on the condition\*(Aqs field \& f502a : this is the subfield\*(Aqs value of a new 502 field \& f502b : \& \- this is the first \*(Aqb\*(Aq value of another new 502 \& \- this is the 2nd \*(Aqb\*(Aq value of this another new 502 \& f600 : \& a : \& \- first \*(Aqa\*(Aq subfield of this new 600 field \& \- second \*(Aqa\*(Aq subfield of this new 600 field \& b : the 600b value .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& _bnew subfield\*(Aqs value on the condition\*(Aqs field \& 502 _bthis is the first \*(Aqb\*(Aq value of another new 502 \& _bthis is the 2nd \*(Aqb\*(Aq value of this another new 502 \& 502 _athis is the subfield\*(Aqs value of a new 502 field \& 600 _afirst \*(Aqa\*(Aq subfield of this new 600 field \& _asecond \*(Aqa\*(Aq subfield of this new 600 field \& _bthe 600b value .Ve .IP "\(bu" 4 faites attention: vous devez utilisez des listes pour cre\*'er plusieurs sous-champs avec le me\*^me nom dans un champ: .Sp .Vb 4 \& # ne fonctionne pas: \& create : \& f502b : value \& f502b : value .Ve .PP \fI\- update\fR .IX Subsection "- update" .IP "\(bu" 4 Cette action vous permet de mettre a\*` jour les champs \fBexistants\fR. Cette action met a\*` jour tous les sous-champs spe\*'cifie\*'s de tous les champs spe\*'cifie\*'s (si le champ spe\*'cifie\*' est un champ de la condition, il sera le seul a\*` e\*^tre mis a\*` jour ) .IP "\(bu" 4 Syntaxe: .Sp .Vb 3 \& # basique: \& update : \& : \& \& # avance\*'e: \& update : \& : \& : \& : \& : \& : .Ve .IP "\(bu" 4 Exemple: .Sp .Vb 8 \& \-\-\- \& condition : $f502a eq "second a" \& update : \& b : updated value of all \*(Aqb\*(Aq subfields in the condition field \& f502c : updated value of all \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& f501 : \& a : updated value of all \*(Aqa\*(Aq subfields into all \*(Aq501\*(Aq fields \& b : $f502a is the 502a condition\*(Aqs field\*(Aqs value .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _afirst a \& _asecond a \& _bbbb \& _cccc1 \& _cccc2 \& 502 _apoto \& 502 _btruc \& _cbidule \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _aupdated value of all \*(Aqa\*(Aq subfields into all \*(Aq501\*(Aq fields \& _bsecond a is the 502a condition\*(Aqs field\*(Aqs value \& _cbar \& 502 _afirst a \& _asecond a \& _bupdated value of all \*(Aqb\*(Aq subfields in the condition field \& _cupdated value of all \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& _cupdated value of all \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& 502 _apoto \& 502 _btruc \& _cupdated value of all \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields .Ve .PP \fI\- updatefirst\fR .IX Subsection "- updatefirst" .IP "\(bu" 4 Cette action est \fBidentique a\*` update\fR, excepte\*' qu'elle met a\*` jour seulement le \fBpremier\fR sous-champ des champs spe\*'cifie\*'s .IP "\(bu" 4 \&\fBSyntaxe\fR: excepte\*' pour le nom de l'action, c'est la \fBme\*^me que la syntaxe de update\fR .IP "\(bu" 4 Exemple: .Sp .Vb 8 \& \-\-\- \& condition : $f502a eq "second a" \& updatefirst : \& b : updated value of first \*(Aqb\*(Aq subfields in the condition\*(Aqs field \& f502c : updated value of first \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& f501 : \& a : updated value of first \*(Aqa\*(Aq subfields into all \*(Aq501\*(Aq fields \& b : $f502a is the value of 502a conditionnal field .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _afirst a \& _asecond a \& _bbbb \& _cccc1 \& _cccc2 \& 502 _apoto \& 502 _btruc \& _cbidule \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _aupdated value of first \*(Aqa\*(Aq subfields into all \*(Aq501\*(Aq fields \& _bsecond a is the value of 502a conditionnal field \& _cbar \& 502 _afirst a \& _asecond a \& _bupdated value of first \*(Aqb\*(Aq subfields in the condition\*(Aqs field \& _cupdated value of first \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields \& _cccc2 \& 502 _apoto \& 502 _btruc \& _cupdated value of first \*(Aqc\*(Aq subfields into all \*(Aq502\*(Aq fields .Ve .PP \fI\- forceupdate et forceupdatefirst\fR .IX Subsection "- forceupdate et forceupdatefirst" .IP "\(bu" 4 Si le \fBsous-champ spe\*'cifie\*' existe\fR: ces actions sont identiques aux actions \fBupdate\fR et updatefirst .IP "\(bu" 4 Si le \fBsous-champ spe\*'cifie\*' n'existe pas\fR: ces actions sont identiques a\*` l'action \fBcreate\fR .IP "\(bu" 4 \&\fBSyntaxe\fR: excepte\*' pour le nom de l'action, c'est la \fBme\*^me que la syntaxe de update\fR .IP "\(bu" 4 Exemple: .Sp .Vb 8 \& \-\-\- \& condition : $f502a eq "second a" \& forceupdate : \& b : \*(Aqb\*(Aq subfield\*(Aqs value in the condition\*(Aqs field \& f502c : \*(Aq502c\*(Aq value\*(Aqs \& f503 : \& a : \*(Aq503a\*(Aq value\*(Aqs \& b : $f502a is the 502a condition\*(Aqs value .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _btruc \& _cbidule \& 502 _apoto \& 502 _afirst a \& _asecond a \& _bbbb \& _ccc1 \& _ccc2 \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _btruc \& _c\*(Aq502c\*(Aq value\*(Aqs \& 502 _apoto \& _c\*(Aq502c\*(Aq value\*(Aqs \& 502 _afirst a \& _asecond a \& _b\*(Aqb\*(Aq subfield\*(Aqs value in the condition\*(Aqs field \& _c\*(Aq502c\*(Aq value\*(Aqs \& _c\*(Aq502c\*(Aq value\*(Aqs \& 503 _a\*(Aq503a\*(Aq value\*(Aqs \& _bsecond a is the 502a condition\*(Aqs value \& \-\-notice transforme\*'e si nous avions utilise\*' forceupdatefirst\-\- \& LDR \& 501 _afoo \& _b1 \& _cbar \& 502 _btruc \& _c\*(Aq502c\*(Aq value\*(Aqs \& 502 _apoto \& _c\*(Aq502c\*(Aq value\*(Aqs \& 502 _afirst a \& _asecond a \& _b\*(Aqb\*(Aq subfield\*(Aqs value in the condition\*(Aqs field \& _c\*(Aq502c\*(Aq value\*(Aqs \& _ccc2 \& 503 _a\*(Aq503a\*(Aq value\*(Aqs \& _bsecond a is the value of 502a conditionnal field .Ve .PP \fI\- delete\fR .IX Subsection "- delete" .IP "\(bu" 4 Comme son nom l'indique, cette action vous permet de supprimer des champs et sous-champs. .IP "\(bu" 4 Syntaxe: .Sp .Vb 2 \& # basique: \& delete : \& \& # avance\*'e: \& delete : \& \- \& \- .Ve .IP "\(bu" 4 Exemple: .Sp .Vb 12 \& \-\-\- \& condition : $f501a eq "foo" \& delete : $f501 \& \-\-\- \& condition : $f501a eq "bar" \& delete : b \& \-\-\- \& delete : f502 \& \-\-\- \& delete : \& \- f503 \& \- f504a .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _abar \& _bbb1 \& _bbb2 \& 501 _afoo \& 502 _apata \& 502 _apoto \& 503 _apata \& 504 _aata1 \& _aata2 \& _btbbt \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _abar \& 504 _btbbt .Ve .PP \fI\- duplicatefield\fR .IX Subsection "- duplicatefield" .IP "\(bu" 4 Comme son nom l'indique, cette action vous permet de dupliquer des champs entiers. .IP "\(bu" 4 Syntaxe: .Sp .Vb 2 \& # basique: \& duplicatefield : > \& \& # avance\*'e: \& duplicatefield : \& \- > \& \- > .Ve .IP "\(bu" 4 Exemple: .Sp .Vb 12 \& \-\-\- \& condition : $f008_ eq "controlfield_contentb" \& duplicatefield : $f008 > f007 \& \-\-\- \& condition : $f501a eq "bar" \& duplicatefield : $f501 > f400 \& \-\-\- \& condition : $f501a eq "foo" \& duplicatefield : \& \- f501 > f401 \& \- $f501 > f402 \& \- f005 > f006 .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 10 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 005 controlfield_content2 \& 005 controlfield_content1 \& 008 controlfield_contentb \& 008 controlfield_contenta \& 501 _afoo \& 501 12 _abar \& _bbb1 \& _bbb2 \& \-\-notice transforme\*'e\-\- \& LDR \& 005 controlfield_content2 \& 005 controlfield_content1 \& 006 controlfield_content1 \& 006 controlfield_content2 \& 007 controlfield_contentb \& 008 controlfield_contentb \& 008 controlfield_contenta \& 400 12 _abar \& _bbb1 \& _bbb2 \& 401 12 _abar \& _bbb1 \& _bbb2 \& 401 _afoo \& 402 _afoo \& 501 _afoo \& 501 12 _abar \& _bbb1 \& _bbb2 .Ve .PP \fI\- execute\fR .IX Subsection "- execute" .IP "\(bu" 4 Cette action vous permet de de\*'finir du code Perl qui sera exe\*'cute\*' avec \f(CW\*(C`eval\*(C'\fR .Sp Vous pouvez executer des fonctions e\*'crites directement dans le \s-1YAML \s0( pour des de\*'tails sur l'e\*'criture de subs perl dans le \s-1YAML,\s0 re\*'fe\*'rez vous au chapitre suivant: Utiliser des fonctions Perl et des tables des correspondance) .IP "\(bu" 4 Syntaxe: .Sp .Vb 2 \& # basique: \& execute : \& \& # avance\*'e: \& execute : \& \- \& \- .Ve .IP "\(bu" 4 Exemple: .Sp .Vb 12 \& \-\-\- \& condition : $f501a eq "bar" \& execute : \& \- warn("f501a eq $f501a") \& \- warn("barbar") \& \-\-\- \& \- \& condition : $f501a eq "foo" \& execute : \e&warnfoo("f501a eq $f501a") \& \- \& subs : > \& sub warnfoo { my $string = shift;warn $string; } .Ve .Sp re\*'sultat (dans stderr): .Sp .Vb 3 \& f501a eq bar at (eval 30) line 6, <$yamls> line 1. \& barbar at (eval 30) line 7, <$yamls> line 1. \& f501a eq foo at (eval 33) line 2, <$yamls> line 1. .Ve .SS "\- Utiliser des fonctions Perl et des tables des correspondance" .IX Subsection "- Utiliser des fonctions Perl et des tables des correspondance" Vous pouvez utiliser des fonctions Perl (\fBsubs\fR) et des tables de correspondance (\fB\s-1LUT\s0\fR pour LookUp Tables) pour de\*'finir avec une plus grande flexibilite\*' les valeurs qui vont e\*^tre cre\*'e\*'es ou mises a\*` jour avec les actions: create, forceupdate, forceupdatefirst, update and updatefirst. .PP Ces fonctions (et tables des correspondance) peuvent e\*^tre \fBe\*'crites dans une re\*`gle\fR (dans ce cas elles ne peuvent e\*^tre utilise\*'e que par cette re\*`gle) \fBou apre\*`s la dernie\*`re re\*`gle\fR ( apre\*`s le dernier \-\-\-, elles peuvent alors e\*^tre utilise\*'es dans toutes les re\*`gles: \fBglobal_subs\fR et \fBglobal_LUT\fR ). .PP \fI\- Variables\fR .IX Subsection "- Variables" .PP Quatre types de variables peuvent e\*^tre utilise\*'s: .PP \- \f(CW$this\fR, et les e\*'le\*'ments de la condition .IX Subsection "- $this, et les e'le'ments de la condition" .IP "\(bu" 4 les variables pointant sur la valeur des sous-champs de la condition sont celles que nous avons de\*'ja\*` vu dans le chapitre 'Lancer des actions uniquement sur les champs de la condition' (par exemple \fB\f(CB$f110c\fB\fR) .IP "\(bu" 4 \&\fB\f(CB$this\fB\fR: c'est la variable a\*` utiliser pour pointer sur la \fBvaleur du sous-champ en cours\fR. \f(CW$this\fR peut aussi e\*^tre utilise\*'e dans une sub ou une \s-1LUT.\s0 .Sp Exemple (N.B.: la sub 'fromo2e' convertit les 'o' en 'e'): .Sp .Vb 11 \& \-\-\- \& \- \& condition : $f501a eq "foo" \& create : \& c : \e&fromo2e("$f501a") \& update : \& d : this 501d value\*(Aqs is $this \& b : \e&fromo2e("$this") \& \- \& subs: > \& sub fromo2e { my $string=shift; $string =~ s/o/e/g; $string; } .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 11 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _afoo \& _bboo \& _ddoo \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _afoo \& _bbee \& _d this 501d value\*(Aqs is doo \& _cfee .Ve .PP \- \f(CW$mth\fR .IX Subsection "- $mth" .PP \&\fB\f(CB$mth\fB\fR est l'e\*'ventuel hashref passe\*' comme troisie\*`me argument. Il est utilisable en e\*'criture (dans les subs et les global_subs) et en lecture. Cela permet d'inte\*'ragir avec le script qui appelle MARC::Transform. .IP "\(bu" 4 Syntaxe: \fB$$mth{foo}\fR .IP "\(bu" 4 Exemple dans un script perl : .Sp .Vb 10 \& my $record = MARC::Record\->new(); \& $record\->leader(\*(Aqoptionnal leader\*(Aq); \& print "\-\-init record\-\-\en". $record\->as_formatted; \& my %mth; \& $mth{"inc"}=1; \& $mth{"var"}="a string"; \& my $yaml = \*(Aq \& \-\-\- \& condition : $$mth{"var"} eq "a string" \& forceupdate : \& f500a : $$mth{"var"} \& \-\-\- \& \- \& execute : \e&testa() \& \- \& subs: > \& sub testa { $$mth{"inc"}++; } \& \-\-\- \& forceupdate : \& f600a : \e&testb() \& \-\-\- \& global_subs: > \& sub testb { $$mth{"inc"}++;$$mth{"inc"}; } \& \*(Aq; \& $record = MARC::Transform\->new($record,$yaml,\e%mth); \& print "\en\-\-transformed record\-\- ".$mth{"inc"}." : \en". $record\->as_formatted ."\en"; .Ve .Sp re\*'sultat : .Sp .Vb 6 \& \-\-init record\-\- \& LDR optionnal leader \& \-\-transformed record\-\- 3 : \& LDR optionnal leader \& 500 _aa string \& 600 _a3 .Ve .PP \- \f(CW$record\fR .IX Subsection "- $record" .PP \&\fB\f(CB$record\fB\fR est l'objet MARC::Record en cours de traitement. .PP \fI\- subs\fR .IX Subsection "- subs" .PP \- A l'inte\*'rieur des re\*`gles .IX Subsection "- A l'inte'rieur des re`gles" .IP "\(bu" 4 Syntaxe: .Sp .Vb 8 \& #re\*`gle entie\*`re: \& \-\-\- \& \- \& \& \- \& subs: > \& \& \-\-\- \& \& # syntaxe d\*(Aqinvocation de la me\*'thode: \& \e&("") .Ve .IP "\(bu" 4 Exemple: .Sp .Vb 10 \& \-\-\- \& \- \& condition : $f501a eq "foo" and defined $f501d \& update : \& b : \e&convertbaddate("$this") \& c : \e&trim("$f501d") \& \- \& subs: > \& sub convertbaddate { \& #convertit les dates du type "21/2/98" en "1998\-02\-28" \& my $in = shift; \& if ($in =~/^(\ed{1,2})\e/(\ed{1,2})\e/(\ed{2}).*/) \& { \& my $day=$1; \& my $month=$2; \& my $year=$3; \& if ($day=~m/^\ed$/) {$day="0".$day;} \& if ($month=~m/^\ed$/) {$month="0".$month;} \& if (int($year)>12) \& {$year="19".$year;} \& else {$year="20".$year;} \& return "$year\-$month\-$day"; \& } \& else \& { \& return $in; \& } \& } \& \& sub trim { \& # Cette fonction enle\*`ve ",00" a\*` la fin d\*(Aqune chai\*^ne \& my $in = shift; \& $in=~s/,00$//; \& return $in; \& } .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR): .Sp .Vb 12 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _afoo \& _b8/12/10 \& _cboo \& _d40,00 \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _afoo \& _b2010\-12\-08 \& _c40 \& _d40,00 .Ve .PP \- global_subs .IX Subsection "- global_subs" .IP "\(bu" 4 Syntaxe: .Sp .Vb 3 \& \-\-\- \& global_subs: > \& \& \& # syntaxe d\*(Aqinvocation de la me\*'thode \& \e&("") .Ve .IP "\(bu" 4 Exemple: .Sp .Vb 10 \& \-\-\- \& condition : $f501a eq "foo" \& update : \& b : \e&return_record_encoding() \& c : \e&trim("$this") \& \-\-\- \& global_subs: > \& sub return_record_encoding { \& $record\->encoding(); \& } \& \& sub trim { \& # Cette fonction enle\*`ve ",00" a\*` la fin d\*(Aqune chai\*^ne \& my $in = shift; \& $in=~s/,00$//; \& return $in; \& } .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR ): .Sp .Vb 10 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _afoo \& _bbar \& _c40,00 \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _afoo \& _bMARC\-8 \& _c40 .Ve .PP \fI\- \s-1LUT\s0\fR .IX Subsection "- LUT" .PP Si une valeur n'a pas de correspondance dans une table de correspondance, elle n'est pas modifie\*'e (a\*` moins que vous n'ayez de\*'finit une valeur par de\*'faut avec \f(CW\*(C`_default_value_\*(C'\fR ). .PP Si vous voulez utiliser plus d'une table de correspondance dans une re\*`gle, vous devez utiliser une global_LUT car elle diffe\*'rencie les tables avec des titres. .PP \- A l'inte\*'rieur des re\*`gles .IX Subsection "- A l'inte'rieur des re`gles" .IP "\(bu" 4 Syntaxe: .Sp .Vb 10 \& #re\*`gle entie\*`re: \& \-\-\- \& \- \& \& \- \& LUT : \& : \& : \& _default_value_ : valeur par de\*'faut optionnelle \& \-\-\- \& \& # syntaxe d\*(Aqinvocation de la LUT: \& \e&LUT("") .Ve .IP "\(bu" 4 Exemple: .Sp .Vb 12 \& \-\-\- \& \- \& condition : $f501b eq "bar" \& create : \& f604a : \e&LUT("$f501b") \& update : \& c : \e&LUT("$this") \& \- \& LUT : \& 1 : first \& 2 : second \& bar : openbar .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR ): .Sp .Vb 9 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _bbar \& _c1 \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _bbar \& _cfirst \& 604 _aopenbar .Ve .PP \- global_LUT .IX Subsection "- global_LUT" .IP "\(bu" 4 Syntaxe: .Sp .Vb 9 \& \-\-\- \& global_LUT: \& : \& : \& : \& _default_value_ : valeur par de\*'faut optionnelle \& : \& : \& : \& \& # syntaxe d\*(Aqinvocation de la global_LUT: \& \e&LUT("","") .Ve .IP "\(bu" 4 Exemple: .Sp .Vb 10 \& \-\-\- \& update : \& f501a : \e&LUT("$this","numbers") \& f501b : \e&LUT("$this","cities") \& f501c : \e&LUT("$this","cities") \& \-\-\- \& global_LUT: \& cities: \& NY : New York \& SF : San Fransisco \& TK : Tokyo \& _default_value_ : unknown city \& numbers: \& 1 : one \& 2 : two .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR ): .Sp .Vb 12 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _a1 \& _a3 \& _bfoo \& _cSF \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _aone \& _a3 \& _bunknown city \& _cSan Fransisco .Ve .PP \- $$mth{\*(L"_defaultLUT_to_mth_\*(R"} .IX Subsection "- $$mth{_defaultLUT_to_mth_}" .IP "\(bu" 4 \&\fB\s-1NB : \s0\fRsi vous appelez MARC::Transform avec le troisie\*`me parame\*`tre, le module en rempli la cle\*' nomme\*'e \f(CW\*(C`_defaultLUT_to_mth_\*(C'\fR au cas ou\*` vous souhaiteriez conserver, dans le script d'appel, une trace des valeurs et types (nomme\*' \f(CW\*(C`lookuptableforthis\*(C'\fR pour les \s-1LUT\s0 non globales) sans correspondance. \f(CW$$mth{"_defaultLUT_to_mth_"}\fR est vide\*'e a\*` chaque fois que MARC::Transform\->new est appele\*'. .IP "\(bu" 4 Si nous rappellons l'exemple ci-dessus avec : .Sp .Vb 4 \& my %mth; \& $record = MARC::Transform\->new($record,$yaml,\e%mth); \& print $mth{"_defaultLUT_to_mth_"}\->{"cities"}[0]; \& print "\en".Data::Dumper::Dumper $mth{"_defaultLUT_to_mth_"}; .Ve .Sp cela renverra sur la sortie standard : .Sp .Vb 9 \& foo \& $VAR1 = { \& \*(Aqnumbers\*(Aq => [ \& \*(Aq3\*(Aq \& ], \& \*(Aqcities\*(Aq => [ \& \*(Aqfoo\*(Aq \& ] \& }; .Ve .Sp essayez ceci si vous souhaitez re\*'cupe\*'rer le contenu de \f(CW$mth\fR{\*(L"_defaultLUT_to_mth_\*(R"} a\*` la place de la ligne contenant Data::Dumper::Dumper : .Sp .Vb 5 \& foreach my $k (keys(%{$mth{"_defaultLUT_to_mth_"}})) \& { \& foreach my $value(@{$mth{"_defaultLUT_to_mth_"}\->{"$k"}}) \& { print "$k : $value \en"; } \& } .Ve .SH "\- Dernie\*`res astuces et un gros exemple de YAML" .IX Header "- Dernie`res astuces et un gros exemple de YAML" .IP "\(bu" 4 Si votre script renvoie une erreur du type \*(L"\s-1YAML\s0 Error: Stream does not end with newline character\*(R", c'est simple a\*` corriger. Si vous avez de\*'fini votre \s-1YAML\s0 dans une variable, elle doit se terminer par une nouvelle ligne vide. Si vous avez donner un chemin vers votre fichier, il n'est vraisemblablement pas bon : essayez avec un chemin absolu. .IP "\(bu" 4 Restriction: le cas spe\*'cifique des guillemets doubles (") et du symbole dollar ($): .Sp Dans le \s-1YAML,\s0 ces caracte\*`res sont interpre\*'te\*'s diffe\*'remment. Pour les utiliser dans un contexte de chai\*^ne de caracte\*`re, vous devrez les remplacer dans le \s-1YAML\s0 par \f(CW\*(C`#_dbquote_#\*(C'\fR (pour ") et \f(CW\*(C`#_dollars_#\*(C'\fR (pour $): .Sp \&. Exemple: .Sp .Vb 4 \& \-\-\- \& condition : $f501a eq "I want #_dbquote_##_dollars_##_dbquote_#" \& create : \& f604a : "#_dbquote_#$f501a#_dbquote_# contain a #_dollars_# sign" .Ve .Sp \&. re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR ): .Sp .Vb 7 \& \-\-notice d\*(Aqorigine\-\- \& LDR \& 501 _aI want "$" \& \-\-notice transforme\*'e\-\- \& LDR \& 501 _aI want "$" \& 604 _a"I want "$"" contain a $ sign .Ve .IP "\(bu" 4 Restriction: Vous pouvez tester si un champ ou sous-champ existe, mais il est de\*'conseille\*' de tester son absence. .IP "\(bu" 4 Exemple: n'he\*'sitez pas a\*` copier les exemples de cette documentation. Faite attention car j'ai ajoute\*' quatre caracte\*`res espace au de\*'but de chaque ligne des exemples pour qu'ils soient mieux affiche\*'s par l'interpre\*'teur \s-1POD.\s0 Si vous les copiez / collez dans votre fichier de configuration \s-1YAML,\s0 n'oubliez pas de supprimer les quatres premier caracte\*`res de chaque ligne (par exemple avec vim, \f(CW\*(C`:%s/^\es\es\es\es//g\*(C'\fR ). .IP "\(bu" 4 Ce yaml a e\*'te\*' appelle\*' comme ceci: \f(CW\*(C`my %mth; $mth{"var"}="a string"; $record = MARC::Transform\->new($record,$yaml,\e%mth);\*(C'\fR .Sp .Vb 10 \& \-\-\- \& condition : $f501a eq "foo" \& create : \& f502a : this is the value of a subfield of a new 502 field \& \-\-\- \& condition : $f401a=~/foo/ \& create : \& b : new value of the 401 condition\*(Aqs field \& f600 : \& a : \& \- first a subfield of this new 600 field \& \- second a subfield of this new 600 field \& \- $$mth{"var"} \& b : the 600b value \& execute : \e&reencodeRecordtoUtf8() \& \-\-\- \& \- \& condition : $f501a =~/foo/ and $f503a =~/bar/ \& forceupdate : \& $f503b : mandatory b in condition\*(Aqs field \& f005_ : mandatory 005 \& f006_ : \e&return_record_encoding() \& f700 : \& a : the a subfield of this mandatory 700 field \& b : \e&sub1("$f503a") \& forceupdatefirst : \& $f501b : update only the first b in condition\*(Aqs field 501 \& \- \& condition : $f501a =~/foo/ \& execute : \e&warnfoo("f501a contain foo") \& \- \& subs : > \& sub return_record_encoding { $record\->encoding(); } \& sub sub1 {my $string=shift;$string =~ s/a/e/g;return $string;} \& sub warnfoo { my $string = shift;warn $string; } \& \-\-\- \& \- \& condition : $f501b2 eq "o" \& update : \& c : updated value of all c in condition\*(Aqs field \& f504a : updated value of all 504a if exists \& f604 : \& b : \e&LUT("$this") \& c : \e&LUT("NY","cities") \& updatefirst : \& f604a : update only the first a in 604 \& \- \& condition : $f501c eq "1" \& delete : $f501 \& \- \& LUT : \& 1 : first \& 2 : second \& bar : openbar \& \-\-\- \& delete : \& \- f401a \& \- f005 \& \-\-\- \& condition : $ldr2 eq "t" \& execute : \e&SetRecordToLowerCase($record) \& \-\-\- \& condition : $f008_ eq "controlfield_content8b" \& duplicatefield : \& \- $f008 > f007 \& \- f402 > f602 \& delete : f402 \& \-\-\- \& global_subs: > \& sub reencodeRecordtoUtf8 { \& $record\->encoding( \*(AqUTF\-8\*(Aq ); \& } \& sub warnfee { \& my $string = shift;warn $string; \& } \& global_LUT: \& cities: \& NY : New York \& SF : San Fransisco \& numbers: \& 1 : one \& 2 : two .Ve .Sp re\*'sultat (avec \f(CW\*(C`$record\->as_formatted\*(C'\fR ) : .Sp .Vb 10 \& \-\-notice d\*(Aqorigine\-\- \& LDR optionnal leader \& 005 controlfield_content \& 008 controlfield_content8a \& 008 controlfield_content8b \& 106 _aVaLuE \& 401 _aafooa \& 402 2 _aa402a2 \& 402 1 _aa402a1 \& 501 _c1 \& 501 _afoo \& _afoao \& _b1 \& _bbaoar \& _cbig \& 503 _afee \& _ababar \& 504 _azut \& _asisi \& 604 _afoo \& _afoo \& _bbar \& _ctruc \& \& \-\-notice transforme\*'e\-\- \& LDR optionnalaleader \& 006 UTF\-8 \& 007 controlfield_content8b \& 008 controlfield_content8a \& 008 controlfield_content8b \& 106 _aVaLuE \& 401 _bnew value of the 401 condition\*(Aqs field \& 501 _c1 \& 501 _afoo \& _afoao \& _bupdate only the first b in condition\*(Aqs field 501 \& _bbaoar \& _cupdated value of all c in condition\*(Aqs field \& 502 _athis is the value of a subfield of a new 502 field \& 503 _afee \& _ababar \& _bmandatory b in condition\*(Aqs field \& 504 _aupdated value of all 504a if exists \& _aupdated value of all 504a if exists \& 600 _aa string \& _afirst a subfield of this new 600 field \& _asecond a subfield of this new 600 field \& _bthe 600b value \& 602 1 _aa402a1 \& 602 2 _aa402a2 \& 604 _aupdate only the first a in 604 \& _afoo \& _bopenbar \& _cNew York \& 700 _athe a subfield of this mandatory 700 field \& _bbeber .Ve .SH "\- VOIR AUSSI" .IX Header "- VOIR AUSSI" .IP "\(bu" 4 MARC::Record () .IP "\(bu" 4 MARC::Field () .IP "\(bu" 4 MARC::Loader () .IP "\(bu" 4 \&\s-1YAML \s0() .IP "\(bu" 4 Library Of Congress \s-1MARC\s0 pages () .Sp The definitive source for all things \s-1MARC.\s0 .SH "\- AUTEUR" .IX Header "- AUTEUR" Ste\*'phane Delaune, (delaune.stephane at gmail.com) .SH "\- COPYRIGHT" .IX Header "- COPYRIGHT" Copyright 2011\-2013 Stephane Delaune for Biblibre.com, all rights reserved. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.