# MODS-derived bucket mapping for the David Rumsey collection.

import re

from ADL_mapper import *
input()

import MODS_mapping

# Note that, in coordinate strings, the N/S/E/W suffixes are not
# directions, but are fixed labels indicating which coordinate is
# which.

def coordinateString (v):
  m = re.match("([\d.-]+)W, *([\d.-]+)E, *([\d.-]+)N, *([\d.-]+)S$", v[0])
  if m:
    return (m.group(3), m.group(4), m.group(2), m.group(1))
  else:
    return None

appendConverter("adl:geographic-locations", coordinateString)

# Issue date is the closest thing to temporal coverage for this
# collection (and perhaps the closest concept to temporal coverage for
# maps anyway).

map("adl:dates",
    "/M:mods/M:originInfo/M:dateIssued",
    MODS_mapping.field("originInfo/dateIssued"))

# Every item is a TIFF map.

mapConstant("adl:types", ("ADL Object Type Thesaurus", "maps"))
mapConstant("adl:formats", ("ADL Object Formats", "TIFF"))

expectation("adl:titles", "1")
expectation("adl:geographic-locations", "1")
expectation("adl:dates", "1")

output()
