gbv / Catmandu-PICA

Catmandu modules for working with PICA+ data
https://metacpan.org/release/Catmandu-PICA
Other
4 stars 4 forks source link

pica_map error #72

Closed schwabmi closed 3 years ago

schwabmi commented 3 years ago

Hi

i try to use pica_map, but I get the following error when I execute the following command:

catmandu convert JSON --fix 'pica_map(021A, dc_title)' < test.json

Oops! Tried to execute the fix 'pica_map' but can't find Catmandu::Fix::pica_map on your system.
Error: No such fix package: pica_map
Package name: Catmandu::Fix::pica_map
Fix name: pica_map
Source:
    pica_map(021A, dc_title)

When I look into the install moduls via catmandu info, it says: Catmandu::Fix::pica_map | 1.03 | copy pica values of one field to a new field

Catmandu version: catmandu (Catmandu::CLI) version 1.2015 (/usr/bin/catmandu)

I also use e.g. pica_add() which works.

Cheers Michel

jorol commented 3 years ago

Hi,

pica_map can just be used with PICA data formats (see https://pro4bib.github.io/pica/#/formate), not arbitrary JSON data structures.

Examples:

# fetch some PICA data via SRU & map title
$ catmandu convert -v SRU --base http://sru.k10plus.de/gvk \
--recordSchema picaxml --parser picaxml --query 'code4lib' \
--fix 'pica_map(021Aa,dc_title);remove_field(record)' \
to JSON --pretty 1
# or with file input
$ catmandu convert PICA to JSON --pretty 1 \
--fix 'pica_map(021Aa,dc_title);remove_field(record)' \
< pica.dat

Best

Johann

schwabmi commented 3 years ago

Hi, thanks for the answer. Unfortunately, the example:

$ catmandu convert -v SRU --base http://sru.k10plus.de/gvk \
--recordSchema picaxml --parser picaxml --query 'code4lib' \
--fix 'pica_map(021Aa,dc_title);remove_field(record)' \
to JSON --pretty 1

results in the same error as before:

Oops! Tried to execute the fix 'pica_map' but can't find Catmandu::Fix::pica_map on your system.
Error: No such fix package: pica_map
Package name: Catmandu::Fix::pica_map
Fix name: pica_map
Source:
    pica_map(021Aa,dc_title);remove_field(record)

Cheers Michel

jorol commented 3 years ago

Ah, sorry. You have to add the modules to your Perl installation:

$ cpanm Catmandu::PICA Catmandu::SRU
schwabmi commented 3 years ago

I already got them installed:

Catmandu::PICA is up to date. (1.03)
Catmandu::SRU is up to date. (0.429)
jorol commented 3 years ago

Please check the output of

$ catmandu info

and check for the modules.

schwabmi commented 3 years ago

Catmandu::PICA | 1.03 | Catmandu modules for working with PICA+ data Catmandu::Fix::pica_map | 1.03 | copy pica values of one field to a new field Catmandu::SRU | 0.429 | Catmandu module for working with SRU data

They all appear in the list.

jorol commented 3 years ago

Windows or Unix?

schwabmi commented 3 years ago

Unix (Ubuntu 18.04.5 LTS)

jorol commented 3 years ago

Weird. Can you convert PICA data without a fix?

$ wget https://raw.githubusercontent.com/gbv/Catmandu-PICA/master/t/files/picaplus.dat
$ catmandu convert PICA --type plus to JSON < picaplus.dat
schwabmi commented 3 years ago

Yes that works!

jorol commented 3 years ago

Ok, but I still have no idea why the fixes don't work...

Could you please try to run catmandu with a local lib:

$ git clone https://github.com/gbv/Catmandu-PICA.git
$ cd Catmandu-PICA
$ catmandu -I lib/ convert PICA --type plus to JSON \
--fix 'pica_map(021Aa,title);remove_field(record);' < picaplus.dat

... or you can try to install a local perl version with perlbrew:

# install perlbrew
$ \curl -L https://install.perlbrew.pl | bash
# edit .bashrc
$ echo -e '\nsource ~/perl5/perlbrew/etc/bashrc\n' >> ~/.bashrc
$ source ~/.bashrc
# initialize
$ perlbrew init
# see what versions are available
$ perlbrew available
# install a Perl version
$ perlbrew install -j 2 -n perl-5.28.2
# see installed versions
$ perlbrew list
# switch to an installation and set it as default
$ perlbrew switch perl-5.28.2
# install cpanm
$ perlbrew install-cpanm
# install some Catmandu modules
$ cpanm Catmandu Catmandu::Breaker Catmandu::Exporter::Table \
Catmandu::Identifier Catmandu::Importer::getJSON Catmandu::MARC Catmandu::OAI \
Catmandu::PICA Catmandu::PNX Catmandu::RDF Catmandu::SRU Catmandu::Stat \
Catmandu::Template Catmandu::VIAF Catmandu::Validator::JSONSchema \
Catmandu::Wikidata Catmandu::XLS Catmandu::XSD Catmandu::Z3950
schwabmi commented 3 years ago

Thanks a lot! It did not work with the local lib, but with perlbrew!