[libcatmandu-marc-perl] 197/208: Adding more POD in the tutorial
Jonas Smedegaard
dr at jones.dk
Sat Oct 28 03:42:50 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag upstream/1.19
in repository libcatmandu-marc-perl.
commit f78321cc5e54206b183d276733d65309af7fa2bc
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date: Sun Jul 23 10:47:38 2017 +0200
Adding more POD in the tutorial
---
lib/Catmandu/MARC.pm | 2 +
lib/Catmandu/MARC/Tutorial.pod | 85 ++++++++++++++++++------------------------
2 files changed, 39 insertions(+), 48 deletions(-)
diff --git a/lib/Catmandu/MARC.pm b/lib/Catmandu/MARC.pm
index 7b9920a..9a137a7 100644
--- a/lib/Catmandu/MARC.pm
+++ b/lib/Catmandu/MARC.pm
@@ -1342,6 +1342,8 @@ Catmandu::MARC - Catmandu modules for working with MARC data
=over
+=item * L<Catmandu::MARC::Tutorial>
+
=item * L<Catmandu::Importer::MARC>
=item * L<Catmandu::Exporter::MARC>
diff --git a/lib/Catmandu/MARC/Tutorial.pod b/lib/Catmandu/MARC/Tutorial.pod
index 0e97114..75c20ec 100644
--- a/lib/Catmandu/MARC/Tutorial.pod
+++ b/lib/Catmandu/MARC/Tutorial.pod
@@ -49,18 +49,36 @@ The C<marc_map> Fix can get one or more subfields to extract from MARC:
In the example below the 650a field can be repeated in some marc records.
We will join all the repetitions in an comma delimited list for each record.
-First we create a Fix file containing all the Fixes, then we execute the
-catmandu command.
+ $ catmandu convert MARC to CSV --fix 'marc_map(650a,subject,join:","); retain(subject)' < data.mrc
-Open a text editor and create the C<myfix.fix> file with content:
+=head2 Create a list of all ISBN numbers in the data
- marc_map(650a,subject.$append)
- join_field(subject,",")
- retain(subject)
+In the previous example we saw how all subjects can be printed using a few Fix commands.
+When a subject is repeated in a record, it will be written on one line joined by a comma:
-And execute the command:
+ subject1
+ subject2, subject3
+ subject4
- $ catmandu convert MARC to CSV --fix myfix.fix < data.mrc
+In the example over record 1 contained 'subject1', record 2 'subject2' and 'subject3' and
+record 3 'subject4'. What should we use when we want a list of all values in a long list?
+
+In the example below we'll print all ISBN numbers in a batch of MARC records in one long list
+using the Text exporter:
+
+ $ catmandu convert MARC to Text --field_sep "\n" --fix 'marc_map(020a,isbn.\$append); retain(isbn)' < data.mrc
+
+The first new thing is the C<$append> in the marc_map. This will create in C<isbn> a
+list of all ISBN numbers found in the C<020a> field. Because C<$> signs have a special meaning on
+the command line they need to be escaped with a backslash C<\>. The C<Text> exporter with the C<field_sep>
+option will make use all the list in the C<isbn> field are written on a new line.
+
+=head2 Create a list of all unique ISBN numbers in the data
+
+Given the result of the previous command, it is now easy to create a unique list of ISBN numbers
+with the UNIX C<uniq> command:
+
+ $ catmandu convert MARC to Text --field_sep "\n" --fix 'marc_map(020a,isbn.\$append); retain(isbn)' < data.mrc | uniq
=head2 Create a list of the number of subjects per record
@@ -68,6 +86,9 @@ We will create a list of subjects (650a) and count the number of items
in this list for each record. The CSV file will contain the C<_id> (record
identifier) and C<subject> the number of 650a fields.
+Writing all Fixes on the command line can become tedious. In Catmandu it is possible
+to create a Fix script which contains all the Fix commands.
+
Open a text editor and create the C<myfix.fix> file with content:
marc_map(650a,subject.$append)
@@ -78,37 +99,6 @@ And execute the command:
$ catmandu convert MARC to CSV --fix myfix.fix < data.mrc
-=head2 Create a list of all ISBN numbers in the data
-
-We will create first a Fix script which C<select>s only the records
-that contain an ISBN field (022$a). All the isbns found we will
-print inline using the C<add_to_exporter> Fix.
-
-Open a text editor and create the C<myfix.fix> file with content:
-
- marc_map(020a,isbn.$append)
-
- select exists(isbn)
-
- # Loop over the ISBNs and print them to a CSV exporter
- do list(path:isbn,var:c)
- move_field(c,result.isbn)
- add_to_exporter(result,CSV)
- end
-
-Execute the following catmandu command, notice that we ignore the normal
-output with help of the C<Null> exporter (all output will be generated)
-by the Fix script:
-
- $ catmandu convert MARC to Null --fix myfix.fix < data.mrc
-
-=head2 Create a list of all unique ISBN numbers in the data
-
-Here we can use the Fix script as in the previous example and use the
-UNIX "sort -u" command:
-
- $ catmandu convert MARC to Null --fix myfix.fix < data.mrc | sort -u
-
=head2 Create a list of all ISBN numbers for records with type 920a == book
In the example we need an extra condition for match the content of the
@@ -119,18 +109,16 @@ Open a text editor and create the C<myfix.fix> file with content:
marc_map(020a,isbn.$append)
marc_map(920a,type)
- select all_match(type,"book")
- select exists(isbn)
+ select all_match(type,"book") # select only the books
+ select exists(isbn) # select only the records with ISBN numbers
- # Loop over the ISBNs and print them to a CSV exporter
- do list(path:isbn,var:c)
- move_field(c,result.isbn)
- add_to_exporter(result,CSV)
- end
+ retain(isbn) # only keep this field
+
+All the text after the C<#> sign are inline code comments.
And run the command:
- $ catmandu convert MARC to Null --fix myfix.fix < data.mrc
+ $ catmandu convert MARC to Text --field_sep "\n" --fix myfix.fix < data.mrc
=head2 Show which MARC record don't contain a 900a field matching some list of values
@@ -168,7 +156,8 @@ And now run the command:
=head1 Create a CSV file of all ISSN numbers found at any MARC field
To process this information we need to create a Fix script like the
-one below (line numbers are added here to explain the working of this script):
+one below (line numbers are added here to explain the working of this script
+but don't need to be included in the script):
01: marc_map('***',text.$append)
02:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-marc-perl.git
More information about the Pkg-perl-cvs-commits
mailing list