Bug 24544 - Add a script for inserting persistent identifiers to MARC records
Summary: Add a script for inserting persistent identifiers to MARC records
Status: CLOSED WONTFIX
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Marcel de Rooy
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-30 12:05 UTC by Marcel de Rooy
Modified: 2021-12-13 21:10 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 24544: Database revision for two new preferences (4.24 KB, patch)
2020-07-02 06:45 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 24544: Introduce Koha::PID::Controller with unit test (27.58 KB, patch)
2020-07-02 06:45 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 24544: Add script to insert persistent identifiers (6.72 KB, patch)
2020-07-02 06:45 UTC, Marcel de Rooy
Details | Diff | Splinter Review
DO NOT PUSH: Example plugins (12.22 KB, patch)
2020-07-02 06:45 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 24544: Add new cronjob to cron files (1.76 KB, patch)
2020-07-02 07:08 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Marcel de Rooy 2020-01-30 12:05:24 UTC

    
Comment 1 Marcel de Rooy 2020-01-30 13:43:47 UTC Comment hidden (obsolete)
Comment 2 Marcel de Rooy 2020-01-30 13:44:02 UTC Comment hidden (obsolete)
Comment 3 Marcel de Rooy 2020-03-11 15:37:49 UTC
Adding a see also to 21708. It helps to insert the 003/024/035 fields for PIDs at the right position in the MARC record.
Comment 4 Marcel de Rooy 2020-03-30 09:00:11 UTC
Interesting read:
https://journal.code4lib.org/articles/14978
Comment 5 Marcel de Rooy 2020-07-02 06:45:37 UTC
Created attachment 106460 [details] [review]
Bug 24544: Database revision for two new preferences

We add PID_Domain and PID_Field here.

Test plan:
Run install or upgrade.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 6 Marcel de Rooy 2020-07-02 06:45:41 UTC
Created attachment 106461 [details] [review]
Bug 24544: Introduce Koha::PID::Controller with unit test

This new module will facilitate inserting/updating PIDs in authority,
biblio and item records.

Test plan:
Run t/db_dependent/Koha/PID/Controller.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 7 Marcel de Rooy 2020-07-02 06:45:45 UTC
Created attachment 106462 [details] [review]
Bug 24544: Add script to insert persistent identifiers

Test plan: See patch with example plugins.
This script can only be tested fully when you enable a plugin to
generate new identifiers. The next patch provides samples to do
that.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 8 Marcel de Rooy 2020-07-02 06:45:50 UTC
Created attachment 106463 [details] [review]
DO NOT PUSH: Example plugins

This patch contains a few example plugins for testing and
illustrating the use of the various plugin hooks.

Prerequisites:
[1] Fill PID_Domain with http://[your_domain]
    Note: This domain is used for pid recognition.
[2] Fill PID_Field with say 'auth:024,biblio:024,item'.
    In other words: enable PIDs for all categories and use 024.
[3] Where we refer to (un)install plugin X below, we mean:
    perl -MKoha::Plugin::Test::PID::X -e"Koha::Plugin::Test::PID::X->install;"
    perl -MKoha::Plugin::Test::PID::X -e"Koha::Plugin::Test::PID::X->uninstall;"
    Replace X by the plugin name.

Test plan:
[1] Koha::Plugin::Test::PID::External with opac/svc/pid_test
    This part shows the use of pid_create_hook.
[a] Install the External plugin.
[b] Execute shell command:
    export PID_SERVICE=http://[your_server:opac_port]/cgi-bin/koha/svc/pid_test
[c] Edit your first authority record, add a 024 with $a. Make sure that
    it fully includes your PID_Domain.
[d] Run insert_persistent_id.pl -a -c -v -records 2
    Should report back: records 2, updates 1.
[e] Verify that your first authority was not modified again and that
    your second authority record contains a new 024.

[2] Koha::Plugin::Test::PID::Orgcode
    This part shows all three hooks, one hook from External and
    two other hooks from Orgcode. For instance note the move from
    $a to $z in the insert hook here.
[a] Keep the External plugin, also install the Orgcode plugin.
[b] Replace PID_Field by biblio:035$a
[c] Fill MARCOrgCode with some string.
[d] Edit first biblio record. Add a 035 with $a containing orgcode
    but with another domain than PID_Domain.
    Edit the second biblio record. Add a 035 with PID_Domain in $a
    but without a prefixing orgcode.
[e] Run insert_persistent_id.pl -a -c -v -updates 2
    Should report back: records 2, updates 2
[f] Check that the first two biblio records contain a 035 with your
    orgcode in $a before PID_Domain and a new identifier.
    The first biblio should contain a 035 with $a and $z where $z
    contains the edit from step [d].
    The second biblio record should also contain the 035 from step [d].
[g] Replace PID_Field by: item
[h] Run insert_persistent_id.pl -a -c -v -updates 4
    Should insert pid's in 4 item records.

[3] Koha::Plugin::Test::PID::Cleanup
    This part shows a 'creative' use of get and insert in order to
    actually remove identifiers from a record, just illustrating the
    power of plugins.
[a] Uninstall plugins External and Orgcode.
[b] Install the Cleanup plugin.
[c] Run insert_persistent_id.pl -a -c -v -updates 3
    Verify that first three items were cleaned up. Fourth untouched.
[d] Uninstall Cleanup.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 9 Marcel de Rooy 2020-07-02 06:48:58 UTC
A potential follow-up will add a call for inserting PIDs when storing a new item, biblio or authority. Did not want to add them here yet.
Comment 10 Marcel de Rooy 2020-07-02 07:08:30 UTC
Created attachment 106464 [details] [review]
Bug 24544: Add new cronjob to cron files

Added the additional parameter -hours 2 to prevent a first time
run at night to do a full update (perhaps unexpected).
I would recommend to run a full update after configuring the
preferences.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 11 David Cook 2020-07-06 03:05:27 UTC
While I see the advantage of using PIDs (I use them in DSpace and other GLAM systems), after browsing these patches, I don't see the advantages of adding these patches.

What are you trying to achieve here?

Personally, I think that it would be better to add a plugin to the authority/biblio/item records and allow you to mint PIDs while cataloguing. That's how most systems I've used have worked.

That said, sometimes you want to batch mint PIDs, but I think that would be up to the entity doing the batch work. I don't see why we'd need anything special for that in Koha.

Or are you trying to create a local Koha PID minting service? If that's the case, I think storing the data in MARC fields is not a wise direction. It would be better to have a Koha PID lookup table mapping the PID to the record, so that PID resolution could be handled that way.
Comment 12 David Cook 2020-07-06 03:08:01 UTC
And if we do want to store the PID at the record level, I think it would be best to put that into the relational database (we could export it into the MARC at indexing/exporting time).
Comment 13 Marcel de Rooy 2020-07-07 12:20:11 UTC
(In reply to David Cook from comment #11)
Thanks for your feedback.

> Personally, I think that it would be better to add a plugin to the
> authority/biblio/item records and allow you to mint PIDs while cataloguing.
> That's how most systems I've used have worked.

See also comment9. I chose here to not add stuff directly to core Koha routines. But work my way thru the data with a cron job. Surely this would be a next step. Problem with a cataloguing plugin is that you just know the record number only after saving  it. Although a PID generator might theoretically not need it, many implementations, including my own, do use it.

> That said, sometimes you want to batch mint PIDs, but I think that would be
> up to the entity doing the batch work. I don't see why we'd need anything
> special for that in Koha.

Not sure how much you saw from the patches, but this patch set provides an interface via plugins to an external PID service.

> Or are you trying to create a local Koha PID minting service? If that's the
> case, I think storing the data in MARC fields is not a wise direction. It
> would be better to have a Koha PID lookup table mapping the PID to the
> record, so that PID resolution could be handled that way.

See before. No Koha should not mint its own PIDs. Formally the PID generator may have its own PID lookup table. We do not really care here. (My local generator does not, since it is based on a Koha identifier. Its result can be found with a Standard-identifier index in Koha or even another future ILS. In that way actually turning my ES or Zebra index into a PID lookup table..)
But even with a full resolver having its own table, I would still argue to save a copy of the PID in the MARC record too for optimization, while respecting the lookup table as authoritative.
As a side note: Could you give me another example of vital data on biblio level that we do not store in MARC? Not meaning optimization or calculated aggregates etc.
Comment 14 Marcel de Rooy 2020-07-07 12:20:36 UTC
(In reply to David Cook from comment #12)
> And if we do want to store the PID at the record level, I think it would be
> best to put that into the relational database (we could export it into the
> MARC at indexing/exporting time).

See ^^
Comment 15 Marcel de Rooy 2020-07-07 12:36:16 UTC
Adding a local comment in our discussion basket ;)

What is the right moment for a biblio record to receive a persistent identifier btw? Thinking about local procedures around acquisition etc.

The choice in this patch set is still influenced by the partial/meta resolving (see former comments). A replace by Z3950/SRU might result in two PIDs in the authoritative table and one local copy (the newest) in Koha.
Comment 16 David Cook 2020-07-08 02:39:33 UTC
(In reply to Marcel de Rooy from comment #13)
> See also comment9. I chose here to not add stuff directly to core Koha
> routines. But work my way thru the data with a cron job. Surely this would
> be a next step. Problem with a cataloguing plugin is that you just know the
> record number only after saving  it. Although a PID generator might
> theoretically not need it, many implementations, including my own, do use it.
> 

I could see the utility of that cronjob for you, but maybe not for all Koha users?

That's a good point about the PID generator. 

> Not sure how much you saw from the patches, but this patch set provides an
> interface via plugins to an external PID service.
> 

I skimmed through that code, but found it a bit difficult to read.

> No Koha should not mint its own PIDs. 

Ok excellent.

> Formally the PID generator
> may have its own PID lookup table. We do not really care here. (My local
> generator does not, since it is based on a Koha identifier. Its result can
> be found with a Standard-identifier index in Koha or even another future
> ILS. In that way actually turning my ES or Zebra index into a PID lookup
> table..)

I'm not sure that I understand this part. 

So you use the Koha identifier to mint a PID with a local non-Koha generator, then you store that in the Koha record and index it. 

Your organisation resolver then forward to a local non-Koha resolver which then queries Zebra/ES to get the record that matches... I assume not a full URL but a partial path?

> But even with a full resolver having its own table, I would still argue to
> save a copy of the PID in the MARC record too for optimization, while
> respecting the lookup table as authoritative.
> As a side note: Could you give me another example of vital data on biblio
> level that we do not store in MARC? Not meaning optimization or calculated
> aggregates etc.

I don't know what you mean by "vital data" in this case, but some standouts are biblio.frameworkcode, biblio.datecreated (debateable), biblio_metadata.format, biblio_metadata.schema. 

To be honest, I think that I see where you're coming from. In the past, I wanted to store OAI-PMH identifiers in the 024 field for imported MARC bibliographic records and then look them up with a Zebra index search, but then I realized was problematic for me. While those MARC fields exist, the data in those fields aren't descriptive metadata about the record. They're metadata about the metadata record. In my case, I ended up putting the OAI-PMH identifier in the relational database, as it was much more robust than putting it in the MARC record and indexing it into Zebra (especially since there can be a lag for index updates).
Comment 17 David Cook 2020-07-08 03:00:42 UTC
(In reply to Marcel de Rooy from comment #15)
> What is the right moment for a biblio record to receive a persistent
> identifier btw? Thinking about local procedures around acquisition etc.
> 
> The choice in this patch set is still influenced by the partial/meta
> resolving (see former comments). A replace by Z3950/SRU might result in two
> PIDs in the authoritative table and one local copy (the newest) in Koha.

That's an interesting question. In my mind, a biblionumber represents a conceptual metadata entity. While the actual metadata can change, that entity is tied to the point in time that the biblionumber is created. While we use the MySQL/MariaDB autonumber for that at the moment, in theory we could use a UUID or some other generated number (like we do for the item barcode rather than the item number).

For me, the MARCXML isn't the bibliographic record, but rather a view of it. In the future, that bibliographic record might have a RDF/XML view as well. They're both describing the same bibliographic entity, and that entity is the thing that should have the PID. After all, HTML, MARCXML, RDF/XML, they're just different content types available via content negotiation, right?

The replacement by Z3950/SRU is interesting. If we had versioned records, it might make sense to have a PID per version I suppose...

It could be interesting to see how DSpace manages this.
Comment 18 Marcel de Rooy 2020-07-17 10:02:55 UTC
(In reply to David Cook from comment #17)
> That's an interesting question. In my mind, a biblionumber represents a
> conceptual metadata entity. While the actual metadata can change, that
> entity is tied to the point in time that the biblionumber is created. While
> we use the MySQL/MariaDB autonumber for that at the moment, in theory we
> could use a UUID or some other generated number (like we do for the item
> barcode rather than the item number).

Yes, I think that creation time works best.

> For me, the MARCXML isn't the bibliographic record, but rather a view of it.
> In the future, that bibliographic record might have a RDF/XML view as well.
> They're both describing the same bibliographic entity, and that entity is
> the thing that should have the PID. After all, HTML, MARCXML, RDF/XML,
> they're just different content types available via content negotiation,
> right?

Just as the biblionumber the persistent identifier belongs/points to a conceptual thing, not talking about where we store it. This thing can indeed be described in MARCXML, RDF etc. What would be wrong about showing the PID in such views just like we often include biblionumber? Finally, storing it in a MARC field (just as many save biblionumber in 001) or not (only exporting or displaying it) is an implementation thing/technical optimization?
Comment 19 Katrin Fischer 2020-07-18 14:56:23 UTC
>I don't know what you mean by "vital data" in this case, but some standouts are biblio.frameworkcode, biblio.datecreated (debateable), biblio_metadata.format, biblio_metadata.schema. 

I was trying to follow the discussion here a bit, if I understand correctly, the difference between the PID and the fields you list would be that the PID is supposed to be exported via Z39.50/SRU etc. - so if not included in the MARC file, it would make things much more complicated?
Comment 20 Marcel de Rooy 2020-07-20 06:54:25 UTC
(In reply to Katrin Fischer from comment #19)
> I was trying to follow the discussion here a bit, if I understand correctly,
> the difference between the PID and the fields you list would be that the PID
> is supposed to be exported via Z39.50/SRU etc. - so if not included in the
> MARC file, it would make things much more complicated?

Thx for asking.

For me frameworkcode or metadata format are quite different from the persistent identifier. The frameworkcode is bound to the MARC view/representation. Which may not stay the only view. The reason we made metadata format. That field is repeatable and belongs to the corresponding view.
The PID on the other hand is a unique identifier that does not belong to a particular view but imo c/should be shown in each view. MARC21 and UNIMARC also added fields for such identifiers (auth 024, unimarc 003, etc.)
Although we could save the field outside MARC and just copy it in at export time or display time, I dont mind adding it in MARC as a technical optimization. See comment18.
Strict formally, the PID has been generated outside Koha and can be dereferenced outside Koha.
Comment 21 Marcel de Rooy 2020-08-05 11:16:43 UTC
From David Cook on dev mailing list:

Sorry that I haven’t had a chance to reply on Bugzilla. I’ve been super busy.

For what it’s worth, I’m fine with it being stored in the MARC, so long as it’s also stored in the relational database. I thought it was an either/or question rather than a both/and question.

Curious to hear what people have to say!
Comment 22 Marcel de Rooy 2020-08-05 11:18:09 UTC
From myself on July 20 on the dev mailing list:
===
What do you think? If your authority, biblio or item has a PID, should we save it in MARC too? Noting that MARC is just a representation or view of your data. We already have a biblio_metadata table that allows for more. What if we already had multiple views? If you can, you are welcome to contribute to that discussion on the bug report.
===

Note that this did not trigger any response or discussion sofar.
Comment 23 Marcel de Rooy 2020-12-08 13:34:50 UTC
(In reply to Marcel de Rooy from comment #22)
> From myself on July 20 on the dev mailing list:
> ===
> What do you think? If your authority, biblio or item has a PID, should we
> save it in MARC too? Noting that MARC is just a representation or view of
> your data. We already have a biblio_metadata table that allows for more.
> What if we already had multiple views? If you can, you are welcome to
> contribute to that discussion on the bug report.
> ===
> 
> Note that this did not trigger any response or discussion sofar.

It was heartwarming to see the amount of interest and feedback on this development ;) I decided to move things to local plugins. And will close this report now.
Comment 24 David Cook 2020-12-08 22:01:01 UTC
(In reply to Marcel de Rooy from comment #23)
> It was heartwarming to see the amount of interest and feedback on this
> development ;) I decided to move things to local plugins. And will close
> this report now.

I empathize. I have had a few developments that have been dear to me but haven't received much interest/feedback from others, unfortunately. 

I hope that local plugins are able to provide an adequate solution for you.