This posting describes VIAF Finder. In short, given the values from MARC fields 1xx$a, VIAF Finder will try to find and record a VIAF identifier.  This identifier, in turn, can be used to facilitate linked data services against authority and bibliographic data.
Here is the way to quickly get started:
- download and uncompress the distribution to your Unix-ish (Linux or Macintosh) computer 
- put a file of MARC records named authority.mrc in the ./etc directory, and the file name is VERY important
- from the root of the distribution, run ./bin/build.sh
VIAF Finder will then commence to:
- create a “database” from the MARC records, and save the result in ./etc/authority.db
- use the VIAF API (specifically the AutoSuggest interface) to identify VAIF numbers for each record in your database, and if numbers are identified, then the database will be updated accordingly 
- repeat Step #2 but through the use of the SRU interface
- repeat Step #3 but limiting searches to authority records from the Vatican
- repeat Step #3 but limiting searches to the authority named ICCU
Once done the reader is expected to programmatically loop through ./etc/authority.db to update the 024 fields of their MARC authority data.
Here is a listing of the VIAF Finder distribution:
- 00-readme.txt – this file
- bin/build.sh – “One script to rule them all”
- bin/initialize.pl – reads MARC records and creates a simple “database”
- bin/make-dist.sh – used to create a distribution of this system
- bin/search-simple.pl – rudimentary use of the SRU interface to query VIAF
- bin/search-suggest.pl – rudimentary use of the AutoSuggest interface to query VIAF
- bin/subfield0to240.pl – sort of demonstrates how to update MARC records with 024 fields
- bin/truncate.pl – extracts the first n number of MARC records from a set of MARC records, and useful for creating smaller, sample-sized datasets
- etc – the place where the reader is expected to save their MARC files, and where the database will (eventually) reside
- lib/subroutines.pl – a tiny set of… subroutines used to read and write against the database
If the reader hasn’t figured it out already, in order to use VIAF Finder, the Unix-ish computer needs to have Perl and various Perl modules — most notably, MARC::Batch — installed.
If the reader puts a file named authority.mrc in the ./etc directory, and then runs ./bin/build.sh, then the system ought to run as expected. A set of 100,000 records over a wireless network connection will finish processing in a matter of many hours, if not the better part of a day. Speed will be increased over a wired network, obviously.
But in reality, most people will not want to run the system out of the box. Instead, each of the individual tools will need to be run individually. Here’s how:
- save a file of MARC (authority) records anywhere on your file system
- not recommended, but optionally edit the value of DB in bin/initialize.pl
- run ./bin/initialize.pl feeding it the name of your MARC file, as per Step #1
- if you edited the value of DB (Step #2), then edit the value of DB in bin/search-suggest.pl, and then run ./bin/search-suggest.pl
- if you want to possibly find more VIAF identifiers, then repeat Step #4 but with ./bin/search-simple.pl and with the “simple” command-line option
- optionally repeat Step #5, but this time use the “named” command-line option, and the possible named values are documented as a part of the VAIF API (i.e., “bav” denotes the Vatican
- optionally repeat Step #6, but with other “named” values
- optionally repeat Step #7 until you get tired
- once you get this far, the reader may want to edit bin/build.sh, specifically configuring the value of MARC, and running the whole thing again — “one script to rule them all”
A word of caution is now in order. VIAF Finder reads & writes to its local database. To do so it slurps up the whole thing into RAM, updates things as processing continues, and periodically dumps the whole thing just in case things go awry. Consequently, if you want to terminate the program prematurely, try to do so a few steps after the value of “count” has reached the maximum (500 by default). A few times I have prematurely quit the application at the wrong time and blew my whole database away. This is the cost of having a “simple” database implementation.
Alas, search-simple.pl contains a memory leak. Search-simple.pl makes use of the SRU interface to VIAF, and my SRU queries return XML results. Search-simple.pl then uses the venerable XML::XPath Perl module to read the results. Well, after a few hundred queries the totality of my computer’s RAM is taken up, and the script fails. One work-around would be to request the SRU interface to return a different data structure. Another solution is to figure out how to destroy the XML::XPath object. Incidentally, because of this memory leak, the integer fed to simple-search.pl was implemented allowing the reader to restart the process at a different point dataset. Hacky.
The use of the database is key to the implementation of this system, and the database is really a simple tab-delimited table with the following columns:
- id (MARC 001)
- tag (MARC field name)
- _1xx (MARC 1xx)
- a (MARC 1xx$a)
- b (MARC 1xx$b and usually empty)
- c (MARC 1xx$c and usually empty)
- d (MARC 1xx$d and usually empty)
- l (MARC 1xx$l and usually empty)
- n (MARC 1xx$n and usually empty)
- p (MARC 1xx$p and usually empty)
- t (MARC 1xx$t and usually empty)
- x (MARC 1xx$x and usually empty)
- suggestions (a possible sublist of names, Levenshtein scores, and VIAF identifiers)
- viafid (selected VIAF identifier)
- name (authorized name from the VIAF record)
Most of the fields will be empty, especially fields b through x. The intention is/was to use these fields to enhance or limit SRU queries. Field #13 (suggestions) is for future, possible use. Field #14 is key, literally. Field #15 is a possible replacement for MARC 1xx$a. Field #15 can also be used as a sort of sanity check against the search results. “Did VIAF Finder really identify the correct record?”
Consider pouring the database into your favorite text editor, spreadsheet, database, or statistical analysis application for further investigation. For example, write a report against the database allowing the reader to see the details of the local authority record as well as the authority data in VIAF. Alternatively, open the database in OpenRefine in order to count & tabulate variations of data it contains.  Your eyes will widened, I assure you.
First, this system was written during my “artist’s education adventure” which included a three-month stint in Rome. More specifically, this system was written for the good folks at Pontificia Università della Santa Croce. “Thank you, Stefano Bargioni, for the opportunity, and we did some very good collaborative work.”
Second, I first wrote search-simple.pl (SRU interface) and I was able to find VIAF identifiers for about 20% of my given authority records. I then enhanced search-simple.pl to include limitations to specific authority sets. I then wrote search-suggest.pl (AutoSuggest interface), and not only was the result many times faster, but the result was just as good, if not better, than the previous result. This felt like two steps forward and one step back. Consequently, the reader may not ever need nor want to run search-simple.pl.
Third, while the AutoSuggest interface was much faster, I was not able to determine how suggestions were made. This makes the AutoSuggest interface seem a bit like a “black box”. One of my next steps, during the copious spare time I still have here in Rome, is to investigate how to make my scripts smarter. Specifically, I hope to exploit the use of the Levenshtein distance algorithm. 
Finally, I would not have been able to do this work without the “shoulders of giants”. Specifically, Stefano and I took long & hard looks at the code of people who have done similar things. For example, the source code of Jeff Chiu’s OpenRefine Reconciliation service demonstrates how to use the Levenshtein distance algorithm.  And we found Jakob Voß’s viaflookup.pl useful for pointing out AutoSuggest as well as elegant ways of submitting URL’s to remote HTTP servers.  “Thanks, guys!”
Fun with MARC-based authority data!
 VIAF – http://viaf.org
 VIAF Finder distribution – http://infomotions.com/sandbox/pusc/etc/viaf-finder.tar.gz
 OpenRefine – http://openrefine.org
 Levenshtein distance – https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance
 Chiu’s reconciliation service – https://github.com/codeforkjeff/refine_viaf
 Voß’s viaflookup.pl – https://gist.github.com/nichtich/832052/3274497bfc4ae6612d0c49671ae636960aaa40d2