UPDATED: One Weird Query: Resolving LC Subject Strings to URIs Using Python

This is one where I’m pulling the whole post because some recent experiments indicate that the method I shared no longer works. But – good news! There’s actually a much simpler way to do it!

Ed Summers made the idloc tool which lets you work easily with authorized LC headings and their respective URIs. idloc can be installed using pip and will work in both the terminal and as a Python library.

You can use idloc to search for a specific string in any given concept scheme or across all the concept schemes. I’ve found it very handy both for getting URIs for known authors or getting the authorized titles of a set of URIs. For example, instead of all kinds of wacky logic I’ve used in the past to process name authorities, this is a snippet of one of my scripts with logic I use to grab the authorized name:

authorityRecord = idloc.get(lcURI)
  if "mads:authoritativeLabel" in authorityRecord:
      if isinstance(authorityRecord["mads:authoritativeLabel"], str):
          author_data["authorized"] = authorityRecord["mads:authoritativeLabel"]
      elif isinstance(authorityRecord["mads:authoritativeLabel"], list):
          author_data["authorized"] = authorityRecord["mads:authoritativeLabel"][0]

(There are cases where it’s a list, in which case I’m grabbing the first. In the cases I had, this was always the Latin alphabet label because LC is Latin alphabet-first.)

If you want to read the original post, there’s a few copies in the Wayback Machine.