Skip to content

Toolchain: CSV books

Mark Jordan edited this page Feb 11, 2020 · 19 revisions

Overview

This toolchain allows the creation of Islandora import packages from book-level metadata in a CSV file and master (TIFF or JPEG2000) page images. The resulting Islandora import packages can then be ingested into Islandora using the Islandora Book Batch module.

Preparing the metadata

Requirements of the CSV file used as the input for this toolchain are that

  • the first row of the CSV file contains column labels/headings
    • all column headings must be unique, and the heading row cannot contain any empty headings
  • the records are separated by a single type of field delimiter (the record separator is defined in the [FETCHER] section's "field_delimiter" configuration setting, as described below)
  • each record in the CSV file corresponds to one book
  • one of the fields contains a unique identifier for each row in the file (this column is defined in the [FETCHER] section's "record_key" configuration setting, as described below), and
  • one of the fields contains the name of the directory where the books's page files are located (this column is defined in the [FILE_GETTER] section's "file_name_field" configuration setting, as described below).
  • you can comment out problematic records in CSV input files.

A sample metadata CSV file, each row describing a single book, looks like this:

Identifier,Directory,Title,Author,Publication Date
sfubooks0001,book0001,"Animal Carvings from Mounds of the Mississippi Valley","Henshaw, Henry W.",1883
sfubooks0002,book0002,"Cave Regions of the Ozarks and Black Hills","Owen, Luella Agnes",1897
sfubooks0003,book0003,"Marvels of Pond-life: A Year's Microscopic Recreations","Slack, Henry J.",1859

Preparing the master page images

In addition to book-level metadata, you must prepare the corresponding page images for use with MIK. The way these images are arranged is important because MIK uses information embedded in the images' file names to identify which image corresponds to which page. Some general requirements for how you prepare the page image files are:

  • All page files for a book are grouped together in one subdirectory, which is named in the CSV file's "Directory" column.
  • Allowed extensions for page image files are 'tiff', 'tif', or 'jp2', although others can be added using the allowed_file_extensions_for_OBJ configuration option.

Each filename contains a page number, which must be the final hyphen-separated segment of the filename. Leading zeros in page numbers are stripped. Two (8-page) examples of book-level directories and files that follow these requirements are:

csvbookstestinput/
├── book0001
│   ├── page-01.tif
│   ├── page-02.tif
│   ├── page-03.tif
│   ├── page-04.tif
│   ├── page-05.tif
│   ├── page-06.tif
│   ├── page-07.tif
│   └── page-08.tif
└── book0002
    ├── books_owen-01.tif
    ├── books_owen-02.tif
    ├── books_owen-03.tif
    ├── books_owen-04.tif
    ├── books_owen-05.tif
    ├── books_owen-06.tif
    ├── books_owen-07.tif
    └── books_owen-08.tif

Both book-level directories are valid since:

  • The book's content is in a directory whose name exists in the CSV file's "Directory" column,
  • the segments of the page filenames are separated by hyphens (-) (although this is configurable), and
  • the last segment of each filename contains the page number.

The book-level directories do not need to be arranged in any particular way, other than they do need to be within a single top-level directory (which is defined in the .ini file in the [FILE_GETTER]input_directory setting).

Including page-level OCR files

Optionally, you can add OCR files to input directories, which MIK will then add to the Islandora ingest packages. If these files are present, Islandora will use them as the OCR datastreams on page objects instead of having Islandora generate OCR.

To include page-level OCR in your input, name the OCR files the same as the corresponding page images, but give them extension .txt. Extending examples used above, the files would look like this:

csvbookstestinput/
├── book0001
│   ├── page-01.tif
│   ├── page-01.txt
│   ├── page-02.tif
│   ├── page-02.txt
│   ├── page-03.tif
│   ├── page-03.txt
│   ├── page-04.tif
│   ├── page-04.txt
│   ├── page-05.tif
│   ├── page-05.txt
│   ├── page-06.tif
│   ├── page-06.txt
│   ├── page-07.tif
│   ├── page-07.txt
│   └── page-08.tif
│   ├── page-08.txt
└── book0002
    ├── books_owen-01.tif
    ├── books_owen-01.txt
    ├── books_owen-02.tif
    ├── books_owen-02.txt
    ├── books_owen-03.tif
    ├── books_owen-03.txt
    ├── books_owen-04.tif
    ├── books_owen-04.txt
    ├── books_owen-05.tif
    ├── books_owen-05.txt
    ├── books_owen-06.tif
    ├── books_owen-06.txt
    ├── books_owen-07.tif
    ├── books_owen-07.txt
    ├── books_owen-08.tif
    └── books_owen-08.txt

If you include these files, you may also want to set the [WRITER] log_missing_ocr_files configuration setting to TRUE as documented below. If some of your page images do not have corresponding .txt files, you will get input validation errors. To work around this, add [FILE_GETTER] validate_input = false to your .ini file.

Preparing the configuration file

All MIK configuration files are standard INI files which contain the following sections: [SYSTEM], [CONFIG], [FETCHER], [METADATA_PARSER], [FILE_GETTER], [WRITER], [MANIPULATORS], and [LOGGING]. Entries are required unless indicated otherwise below.

Commented lines begin with a semicolon. Values that contain whitespace or special characters (equals, semicolon, etc.) should be wrapped in double quotation marks. If in doubt, use the quotation marks. The order of the sections and the entries within each section do not matter.

The SYSTEM section

This section of the configuration file sets or overrides configuration settings for PHP and the various third-party PHP components used by MIK. It can contain the following entries:

  • date_default_timezone: Optional. Provide a default timezone if date.timezone is null in the the PHP INI. You will know if you need to use this setting because Monolog will throw MIK exceptions and halt MIK. Set to one of the valid PHP timezone values listed at http://php.net/manual/en/timezones.php.
  • verify_ca: Optional. OSX's default PHP configuration use Apple's Secure Transport rather than OpenSSL, causing issues with Certificate Authority verification in Guzzle requests against websites that use HTTPS. This setting allows Guzzle to override CA verification. You will know if you need to use this setting because Guzzle will write entries in your mik.log complaining about CA verification. Set to false to ignore CA verification.

Example

[SYSTEM]
date_default_timezone = 'America/Vancouver'

The CONFIG section

Key-value pairs of configuration entries in this section are simply written to the top of the log file specified in the [LOGGING] section's path_to_log setting. You can add whatever values you want, but they are static (that is, they can't be dynamically derived at runtime). Therefore, all entries in this section are optional.

Example

[CONFIG]
config_id = csv_book_test
last_updated_on = "2016-05-14"
last_update_by = "mj"

The FETCHER section

This section of the configuration file contains the following entries:

  • class: Required. Must be 'Csv'.
  • input_file: Required. Full path to the CSV file that contains the data describing the objects you are ingesting into Islandora
  • temp_directory: Required. Full path to the directory where the fetchers write data for use later in the toolchain.
  • field_delimiter: Optional. Default is a comma (,). The string or character used in the CSV file to delimit fields. To read a tab-delimited file, use an actual tab character enclosed in quotation marks, not \t.
  • field_enclosure: Optional. Default is double quotation mark ("). The string or character used in the CSV file to wrap values of fields that contain spaces.
  • escape_character: Optional. Default is backslash (\). The string or character used in the CSV file to escape field delimiters or field enclosure characters within field values.
  • use_cache: Optional. Set to false in automated tests (in other words, you will not need to use this unless you are writing automated tests for this fetcher).
  • record_key: Required. The column label identifying the field that contains each record's unique identifier within the CSV file.

Example

[FETCHER]
class = Csv
input_file = '/home/mark/Downloads/csv_book_test.csv'
temp_directory = "/tmp/csv_book_temp"
; The column heading in the CSV file that contains the name of the unique ID for each row.
record_key = Identifier

The METADATA_PARSER section

This section of the CSV Book toolchain's configuration file contains the following entries:

  • class: Required. Must be 'mods\CsvToMods' or 'templated\Templated'. Use the former if simple source field-to-MODS-element mappings are sufficient for your needs, the latter if your source metadata requires complex logic to be converted to MODS.
  • mapping_csv_path: Required. The path, either full or relative to the mik script, where the metadata mapppings file is located.
  • repeatable_wrapper_elements: Optional. By default MIK reduces repeated top-level wrapper MODS elements (same element name with the same attributes) down to a single instance of the element. This setting lets you indicate which elements you want to be repeated (i.e, have multiple of) in your MODS. The most common use for this setting is to allow repeated <extension> elements.

Example

[METADATA_PARSER]
class = mods\CsvToMods
mapping_csv_path = "book_test_mappings.csv"

The FILE_GETTER section

This section of the CSV Book toolchain's configuration file contains the following entries:

  • class: Required. Must be 'CsvBooks'.
  • input_directory: Required. The full path to the directory where the page files are located. The files should be named as described in the "Preparing the content files" section above. Giving this option an empty value (e.g., input_directory = ) and specifying MODS as the only datastream (e.g., [WRITER]datastreams[] = MODS) allows testing the generation of MODS without requiring access to the content files.
  • temp_directory: Required. Full path to the directory where the file getter will write data for use later in the toolchain. Can be the same as the temp_directory value used in the [FETCHER] section.
  • file_name_field: Required. The column label identifying the field that contains the name of the directory that corresponds to each book.
  • validate_input: Optional. Set to false if you do not want MIK to validate the files and directories under input_directory. Defaults to true. See this Cookbook entry for more detail.
  • validate_input_type: Optional. Set to strict if you want MIK to validate the files and directories under input_directory before moving on to generate ingest packages. Defaults to realtime. See this Cookbook entry for more detail.
  • allowed_file_extensions_for_OBJ: optional. Array option defining what file extensions MIK should allow for page image files. If not specified, valid extensions are 'tiff', 'tif', 'jp2'.

Example

[FILE_GETTER]
class = CsvBooks
temp_directory = "/tmp/csv_book_temp"
input_directory = "/home/mark/Downloads/csv_book_samples"
; The column heading in the CSV file that contains the name of the directory where the page files for the book are.
file_name_field = Directory
allowed_file_extensions_for_OBJ[] = jpg

The WRITER section

This section of the CSV Book toolchain's configuration file contains the following entries:

  • class: Required. Must be 'CsvBooks'.
  • output_directory: Required. The full path to the directory where output packages are written.
  • generate_page_modsxml: Optional. Set to false if you do not want MIK to generate page-level MODS.xml files. Additional detail is provided below.
  • metadata_filename: Required. Must be 'MODS.xml'.
  • postwritehooks: Optional. A multivalued list of post-write hook scripts. Values have two parts, the full path to the PHP, Python, or shell executable, and the full path to the script itself.
  • datastreams: Optional. A multivalued list of datastream files that you want MIK to create. If not included, MIK will create a MODS.xml file for each page plus an OBJ.tiff (or other extension) file for each page. If included, only the indicated datastream files will be generated. Useful for testing metadata generation, for example datastreams[] = "MODS", which would tell MIK to generate only a MODS.xml file for each page.
  • page_sequence_separator: Optional. Default is a hypen (-). Character used to separate the segments of page-level filenames so the the last segment can be used to determine the page order/sequence.

Example

[WRITER]
class = CsvBooks
metadata_filename = MODS.xml
output_directory = "/tmp/csv_books_output"
postwritehooks[] = "php extras/scripts/postwritehooks/validate_mods.php"
postwritehooks[] = "php extras/scripts/postwritehooks/object_timer.php"
datastreams[] = MODS
; datastreams[] = OBJ

The MANIPULATORS section

This section of the CSV Book toolchain's configuration file defines which manipulators should be used. Multiple manipulators can be defined for each type (fetchermanipulators, filegettermanipulators, metadatamanipulators) as illustrated below. The value of each entry is the manipulator class name plus any pip-separated parameters that the manipulator may require. Entries in this section are optional.

Example

[MANIPULATORS]
; fetchermanipulators[] = "RandomSet|50"
fetchermanipulators[] = "SpecificSet|books.txt"
metadatamanipulators[] = "FilterModsTopic|subject"
metadatamanipulators[] = "AddUuidToMods"
metadatamanipulators[] = "AddCsvData"

The LOGGING section

This section of the CSV Book toolchain's configuration file contains the following entries:

  • path_to_log: Required. The full path to the standard log generated by MIK.
  • path_to_manipulator_log: Required. The full path to the log that the manipulators write status and error messages to.

Example

[LOGGING]
path_to_log = "/tmp/csv_books_output"/mik.log"
path_to_manipulator_log = "/tmp/csv_books_output/manipulator.log"

Creating page-level MODS.xml files

The CSV metadata file contains rows describing books, not pages. However, MIK provides an option to generate page-level MODS files, the purpose of which is to provide a descriptive title for each page and also to provide a <dataIssued> value to be used in searches. These page-level MODS files combine metadata from the parent book with the page's specific page number. Specifically, MIK assumes that the parent (i.e., book) MODS contains a <titleInfo><title> element, e.g.:

"Title","<titleInfo><title>%value%</title></titleInfo>",

A sample page-level MODS.xml file generated using this option is:

<?xml version="1.0"?>
<mods xmlns="http://www.loc.gov/mods/v3" xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
  <titleInfo>
    <title>Cave Regions of the Ozarks and Black Hills, page 1</title>
  </titleInfo>
</mods>

Generation of page-level MODS.xml files is enabled by default. To disable it, add the following entry to your .ini file:

[WRITER]
generate_page_modsxml = false
Clone this wiki locally