{"id":19338282,"url":"https://github.com/gbv/pica-data","last_synced_at":"2025-04-23T01:31:23.782Z","repository":{"id":20852319,"uuid":"24138945","full_name":"gbv/PICA-Data","owner":"gbv","description":"Perl module to handle PICA+ data","archived":false,"fork":false,"pushed_at":"2023-10-27T05:27:57.000Z","size":717,"stargazers_count":6,"open_issues_count":6,"forks_count":5,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-02T06:22:07.190Z","etag":null,"topics":["code4lib","gbv","pica"],"latest_commit_sha":null,"homepage":"https://metacpan.org/release/PICA-Data","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gbv.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-09-17T09:47:06.000Z","updated_at":"2024-10-23T15:02:03.000Z","dependencies_parsed_at":"2023-02-16T17:46:04.242Z","dependency_job_id":"9bcc7c07-331f-421a-8384-9bf677d87ea8","html_url":"https://github.com/gbv/PICA-Data","commit_stats":null,"previous_names":[],"tags_count":80,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbv%2FPICA-Data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbv%2FPICA-Data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbv%2FPICA-Data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbv%2FPICA-Data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gbv","download_url":"https://codeload.github.com/gbv/PICA-Data/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250352279,"owners_count":21416462,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code4lib","gbv","pica"],"created_at":"2024-11-10T03:16:54.636Z","updated_at":"2025-04-23T01:31:23.144Z","avatar_url":"https://github.com/gbv.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nPICA::Data - PICA record processing\n\n[![Linux build status](https://github.com/gbv/PICA-Data/actions/workflows/linux.yml/badge.svg)](https://github.com/gbv/PICA-Data/actions/workflows/linux.yml)\n[![Linux build status](https://github.com/gbv/PICA-Data/actions/workflows/linux.yml/badge.svg)](https://github.com/gbv/PICA-Data/actions/workflows/linux.yml)\n[![Windows build status](https://ci.appveyor.com/api/projects/status/5qjak74x7mjy7ne6?svg=true)](https://ci.appveyor.com/project/nichtich/pica-data)\n[![Coverage Status](https://coveralls.io/repos/gbv/PICA-Data/badge.svg)](https://coveralls.io/r/gbv/PICA-Data)\n[![Kwalitee Score](http://cpants.cpanauthors.org/dist/PICA-Data.png)](http://cpants.cpanauthors.org/dist/PICA-Data)\n\n# SYNOPSIS\n\n      use PICA::Data ':all';\n      $parser = pica_parser( xml =\u003e 'picadata.xml' );\n      $writer = pica_writer( plain =\u003e \\*STDOUT );\n     \n      use PICA::Parser::XML;\n      use PICA::Writer::Plain;\n      $parser = PICA::Parser::XML-\u003enew( @options );\n      $writer = PICA::Writer::Plain-\u003enew( @options );\n\n      use PICA::Schema;\n      $schema = PICA::Schema-\u003enew();\n\n      # parse records\n      while ( my $record = $parser-\u003enext ) {\n          \n          # function accessors\n          my $ppn      = pica_value($record, '003@0');\n          my $ppn      = pica_match($record, '045Ue', split =\u003e 1, nested_array =\u003e 1);\n          my $holdings = pica_holdings($record);\n          my $items    = pica_items($record);\n          ...\n\n          # object accessors\n          my $ppn      = $record-\u003eid;\n          my $ppn      = $record-\u003evalue('003@0');\n          my $ppn      = $record-\u003esubfields('003@')-\u003e{0};\n          my $ddc      = $record-\u003ematch('045Ue', split =\u003e 1, nested_array =\u003e 1);\n          my $holdings = $record-\u003eholdings;\n          my $items    = $record-\u003eitems;\n          ...\n\n          # write record\n          $writer-\u003ewrite($record);\n          \n          # write methods\n          $record-\u003ewrite($writer);\n          $record-\u003ewrite( xml =\u003e @options );\n          $record-\u003ewrite; # default \"plain\" writer\n\n          # stringify record\n          my $plain = $record-\u003estring;\n          my $xml = $record-\u003estring('xml');\n\n          # validate record\n          my $errors = $schema-\u003echeck($record);\n      }\n    \n      # parse single record from string\n      my $record = pica_parser('plain', \\\"...\")-\u003enext;\n\n      # guess parser from input string\n      my $parser = pica_guess($string)-\u003enew(\\$string);\n\n# DESCRIPTION\n\nPICA::Data provides methods, classes, functions, and [a command line\napplication](https://metacpan.org/pod/picadata) to process [PICA+ records](http://format.gbv.de/pica).\n\nPICA+ is the internal data format of the Local Library System (LBS) and the\nCentral Library System (CBS) of OCLC, formerly PICA. Similar library formats\nare the MAchine Readable Cataloging format (MARC) and the Maschinelles\nAustauschformat fuer Bibliotheken (MAB). In addition to PICA+ in CBS there is\nthe cataloging format Pica3 which can losslessly be convert to PICA+ and vice\nversa.\n\nRecords in PICA::Data are encoded either as array of arrays, the inner arrays\nrepresenting PICA fields, or as an object with two keys, `_id` and `record`,\nthe latter holding the record as array of arrays, and the former holding the\nrecord identifier, stored in field `003@`, subfield `0`. For instance a\nminimal record with just one field (having tag `003@` and no occurrence):\n\n    {\n      _id    =\u003e '12345X',\n      record =\u003e [\n        [ '003@', undef, '0' =\u003e '12345X' ]\n      ]\n    }\n\nor in short form:\n\n    [ [ '003@', undef, '0' =\u003e '12345X' ] ]\n\nPICA path expressions (see [PICA::Path](https://metacpan.org/pod/PICA%3A%3APath)) can be used to facilitate processing\nPICA+ records and [PICA::Schema](https://metacpan.org/pod/PICA%3A%3ASchema) can be used to validate PICA+ records with\n[Avram Schemas](https://format.gbv.de/schema/avram/specification).\n\n# FUNCTIONS\n\nThe following functions can be exported on request (use export tag `:all` to\nget all of them):\n\n## pica\\_data( \\[ $data \\] )\n\nReturn a new PICA::Data object from any guessable serialization form (or die).\n\n## pica\\_field( $tag, \\[$occ,\\] \\[ @subfields \\] )\n\nReturn a new PICA+ field as blessed [PICA::Data::Field](https://metacpan.org/pod/PICA%3A%3AData%3A%3AField) array reference (or\ndie).\n\n## pica\\_parser( $type \\[, @options\\] )\n\nCreate a PICA parsers object (see [PICA::Parser::Base](https://metacpan.org/pod/PICA%3A%3AParser%3A%3ABase)). Case of the type is\nignored and additional parameters are passed to the parser's constructor:\n\n- [PICA::Parser::Binary](https://metacpan.org/pod/PICA%3A%3AParser%3A%3ABinary) for type `binary` (binary PICA+)\n- [PICA::Parser::Plain](https://metacpan.org/pod/PICA%3A%3AParser%3A%3APlain) for type `plain` or `picaplain` (human-readable PICA+)\n- [PICA::Parser::Plus](https://metacpan.org/pod/PICA%3A%3AParser%3A%3APlus) for type `plus` or `picaplus` (normalized PICA+)\n- [PICA::Parser::Import](https://metacpan.org/pod/PICA%3A%3AParser%3A%3AImport) for type `import` (PICA Import format)\n- [PICA::Parser::JSON](https://metacpan.org/pod/PICA%3A%3AParser%3A%3AJSON) for type `json` (PICA JSON)\n- [PICA::Parser::XML](https://metacpan.org/pod/PICA%3A%3AParser%3A%3AXML) for type `xml` or `picaxml` (PICA-XML)\n- [PICA::Parser::PPXML](https://metacpan.org/pod/PICA%3A%3AParser%3A%3APPXML) for type `ppxml` (PicaPlus-XML)\n- [PICA::Parser::PIXML](https://metacpan.org/pod/PICA%3A%3AParser%3A%3APIXML) for type `pixml` (PICA FOLIO Import XML)\n- [PICA::Parser::Patch](https://metacpan.org/pod/PICA%3A%3AParser%3A%3APatch) for type `patch` (PICA Patch format)\n\n## pica\\_guess( $data )\n\nGuess PICA serialization format from input data. Returns name of the\ncorresponding parser class or `undef`.\n\n## pica\\_xml\\_struct( $xml, %options )\n\nConvert PICA-XML, expressed in [XML::Struct](https://metacpan.org/pod/XML%3A%3AStruct) structure into a PICA::Data object.\n\n## pica\\_writer( $type \\[, @options\\] )\n\nCreate a PICA writer object (see [PICA::Writer::Base](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3ABase)) in the same way as\n`pica_parser` with one of\n\n- [PICA::Writer::Binary](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3ABinary) for type `binary` (binary PICA)\n- [PICA::Writer::Generic](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3AGeneric) for type `generic` (PICA with self defined data separators)\n- [PICA::Writer::Plain](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3APlain) for type `plain` or `picaplain` (human-readable PICA+)\n- [PICA::Writer::Import](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3AImport) for type `import` (PICA Import format)\n- [PICA::Writer::Plus](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3APlus) for type `plus` or `picaplus` (normalized PICA+)\n- [PICA::Writer::JSON](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3AJSON) for type `json` (PICA JSON)\n- [PICA::Writer::XML](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3AXML) for type `xml` or `picaxml` (PICA-XML)\n- [PICA::Writer::PPXML](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3APPXML) for type `ppxml` (PicaPlus-XML)\n- [PICA::Writer::PIXML](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3APIXML) for type `pixml` (PICA FOLIO Import XML)\n- [PICA::Writer::Patch](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3APatch) for type `patch` (PICA Patch format)\n\n## pica\\_string( $record \\[, $type \\[, @options\\] \\] )\n\nStringify a record with given writer (`plain` as default) and options.\n\n## pica\\_path( $path )\n\nEquivalent to [PICA::Path](https://metacpan.org/pod/PICA%3A%3APath)-\u003enew($path).\n\n## pica\\_match( $record, $path, %options )\n\nEquivalent to [PICA::Path](https://metacpan.org/pod/PICA%3A%3APath)-\u003ematch\\_record($path, %options).\n\nExtract the subfield values from a PICA record based on a PICA path\nexpression and options (see [PICA::Path](https://metacpan.org/pod/PICA%3A%3APath)). Also available as accessor \n`match($path, %options)`.\n\n## pica\\_value( $record, $path )\n\nExtract the first subfield values from a PICA record based on a PICA path\nexpression. Also available as accessor `value($path)`.\n\n## pica\\_values( $record, $path )\n\nExtract a list of subfield values from a PICA record based on a PICA path\nexpression. The following are virtually equivalent:\n\n    pica_values($record, $path);\n    $path-\u003erecord_subfields($record);\n    $record-\u003evalues($path);\n\n## pica\\_fields( $record\\[, $path...\\] )\n\nReturns a PICA record (or empty array reference) limited to fields optionally\nspecified by PICA path expressions. The following are virtually equivalent:\n\n    pica_fields($record, $path);\n    $path-\u003erecord_fields($record);\n    $record-\u003efields($path);\n\n## pica\\_subfields( $record\\[, $path...\\] )\n\nReturns a [Hash::MultiValue](https://metacpan.org/pod/Hash%3A%3AMultiValue) of all subfields of fields optionally specified\nby PICA path expressions. Also available as accessor `subfields`.\n\n## pica\\_title( $record )\n\nReturns the record limited to level 0 fields (\"title record\") in sorted order.\n\n## pica\\_holdings( $record )\n\nReturns a list (as array reference) of local holding records, sorted by ILN.\nLevel2 fields are included in sorted order. The ILN (if given) is available as\n`_id`. Also available as accessor `holdings`.\n\n## pica\\_items( $record )\n\nReturns a list (as array reference) of item records. The EPN (if given) is\navailable as `_id` Also available as accessor `items`.\n\n## pica\\_split( $record \\[, $level \\])\n\nReturns the record splitted into individual records for each level. Optionally\nlimits result to given level, including identifiers (PPN/ILN) of higher levels.\n\n## pica\\_sort( $record )\n\nReturns a copy of the record with sorted fields (first level 1 fields, then\nlevel 2 fields not belonging to a level 1, then level 1, each followed by level\n2 sorted by EPN). Also available as accessor `sort`. \n\n## pica\\_sort\\_subfields( $field, $schedule )\n\nSorts and filters subfields of a PICA field (given as array reference) with an\n[subfield schedule](https://format.gbv.de/schema/avram/specification#subfield-schedule).\nThe schedule can also be given as string of subfield codes, parsed with\n[parse\\_subfield\\_schedule](https://metacpan.org/pod/PICA%3A%3ASchema#parse_subfield_schedule): repeatable\nsubfields must be marked with `*` or `+`, otherwise or only the first\nsubfield of this code is preserved. Undefined and missing subfields are ignored\nas well as subfield without information about its order. Returns the modified\nfield, unless it is empty.\n\n## pica\\_annotation( $field \\[, $annotation \\] )\n\nGet or set a PICA field annotation. Use `undef` to remove annotation.\n\n## pica\\_diff( $before, $after )\n\nReturn the difference between two records as annotated record. Also available\nas method `diff`. See [PICA::Patch](https://metacpan.org/pod/PICA%3A%3APatch) for details.\n\n## pica\\_patch( $record, $diff )\n\nReturn a new record by application of a difference given as annotated PICA.\nAlso available as method `patch`. See [PICA::Patch](https://metacpan.org/pod/PICA%3A%3APatch) for details.\n\n## pica\\_append( $record, $tag, \\[$occurrence,\\] @subfields )\n\nAppend a new field to the end of the record.\n\n## pica\\_update( $record, ... )\n\nChange an existing field. This method can be used like method `append` or with\ntwo arguments (path and value) to replace, add or remove a subfield value.\n\n## pica\\_remove( $record, $path \\[, $path..\\] )\n\nRemove all fields matching given PICA Path expressions. Subfields and positions\nin the path are ignored.\n\n## pica\\_split( $level )\n\nReduce and split record to given level except for identifiers PPN/ILN. Returns\na list of records.\n\n# ACCESSORS\n\nAll accessors of `PICA::Data` are also available as [\"FUNCTIONS\"](#functions), prefixed\nwith `pica_` (see [\"SYNOPSIS\"](#synopsis)).\n\n## match( $path, %options )\n\nExtract the subfield values from a PICA record based on a [PICA::Path](https://metacpan.org/pod/PICA%3A%3APath)\nexpression and options (see method `match` of PICA::Path).\n\n## values( $path )\n\nExtract a list of subfield values from a PICA record based on a [PICA::Path](https://metacpan.org/pod/PICA%3A%3APath)\nexpression.\n\n## value( $path )\n\nSame as `values` but only returns the first value.\n\n## fields( \\[$path...\\] )\n\nReturns a PICA record limited to fields specified in a [PICA::Path](https://metacpan.org/pod/PICA%3A%3APath)\nexpression.  Always returns an array reference.\n\n## subfields( \\[$path...\\] )\n\nReturns a [Hash::MultiValue](https://metacpan.org/pod/Hash%3A%3AMultiValue) of all subfields of fields optionally specified\nby PICA path expressions.\n\n## holdings\n\nReturns a list (as array reference) of local holding records (level 1 and 2),\nwhere the id of each record contains the ILN (subfield `101@a`).\n\n## items\n\nReturns a list (as array reference) of item records (level 1),\nwhere the id of each record contains the EPN (subfield `203@/**0`).\n\n## id\n\nReturns the record id, if given.\n\n## empty\n\nTell whether the record is empty (no fields).\n\n## split($level)\n\nReduce and split the record into title record (level=0), holding records\n(level=1) or copy/item records (level=2). PPN and ILN are included for level 1\nand 2 respectively.\n\n# METHODS\n\n## write( \\[ $type \\[, @options\\] \\] | $writer )\n\nWrite PICA record with given [PICA::Writer::...](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3ABase) or\n[PICA::Writer::Plain](https://metacpan.org/pod/PICA%3A%3AWriter%3A%3APlain) by default. This are equivalent:\n\n    pica_writer( xml =\u003e $file )-\u003ewrite( $record );\n    $record-\u003ewrite( xml =\u003e $file );\n\n## string( \\[ $type \\] )\n\nSerialize PICA record in a given format (`plain` by default). This method can\nalso be used as function `pica_string`.\n\n## append( $tag, \\[$occurrence,\\] @subfields )\n\nAdd a field to the end of the record. An occurrence can be specified as part of\nthe tag or as second argument. Subfields with empty value are ignored, so the\nfollowing are equivalent:\n\n    $record-\u003eappend('037A/01', a =\u003e 'hello', b =\u003e 'world', x =\u003e undef, y =\u003e '');\n    $record-\u003eappend('037A', 1, a =\u003e 'hello', b =\u003e 'world');\n\nTo simplify migration from [PICA::Record](https://metacpan.org/pod/PICA%3A%3ARecord) the field may also be given as\ninstance of [PICA::Field](https://metacpan.org/pod/PICA%3A%3AField) but this feature may be removed in a future version.\n\n## remove( $path \\[, $path..\\] )\n\nRemove all fields matching given PICA Path expressions. Subfields and positions\nare ignored so far.\n\n## update( ... )\n\nCan be used like method `append` but replaces an existing field. Alternatively\nchanges selected subfields if called with two arguments:\n\n    $record-\u003eupdate('012X$a', 1); # set or add subfield $a to 1, keep other subfields\n\nSetting a subfield value to the empty string or `undef` removes the subfield.\n\n## diff( $record )\n\nCalculate the difference of the record to another record.\n\n## patch( $diff )\n\nCalculate a new record by application of an annotated PICA record. Annotations\n`+` and `-` denote fields to be added or removed. Fields with blank\nannotations are check to exist in the original record.\n\nThe records should not contain multiple records of level 1 and/or level 2.\n\n# CONTRIBUTORS\n\nJohann Rolschewski, `\u003cjorol@cpan.org\u003e`\n\nJakob Voß `\u003cvoss@gbv.de\u003e`\n\nCarsten Klee `\u003cklee@cpan.org\u003e`\n\n# COPYRIGHT AND LICENSE\n\nCopyright 2014- Johann Rolschewski and Jakob Voss\n\nThis library is free software; you can redistribute it and/or modify it under\nthe same terms as Perl itself.\n\n# SEE ALSO\n\n- [picadata](https://metacpan.org/pod/picadata) command line script to parse, serialize, count, and validate\nPICA+ data.\n- Use [Catmandu::PICA](https://metacpan.org/pod/Catmandu%3A%3APICA) for more elaborated processing of PICA records with the\n[Catmandu](https://metacpan.org/pod/Catmandu) toolkit.\n- [PICA::Record](https://metacpan.org/pod/PICA%3A%3ARecord) implemented an alternative framework for processing PICA+\nrecords (**deprecated!**).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbv%2Fpica-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgbv%2Fpica-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbv%2Fpica-data/lists"}