Skip to content

Instantly share code, notes, and snippets.

@fordmadox
fordmadox / aspace_agent_overview_for_mrs_and_miss.sql
Created May 18, 2020 19:00
Hacky SQL query to get a report re: Mrs./Miss name forms from ArchivesSpace
SET SESSION GROUP_CONCAT_max_len=20000;
# the length is too small by default to search for all variations in the name forms... should consider another tactic for this, though.
SET @base_public_uri = 'https://archives.yale.edu/';
# specify database name, if needed.
/* Requested fields:
Agent Name Display name Authorized name URI Record type (resource or accession) Repository Source Identifier/call number
*/
@fordmadox
fordmadox / aspace-resource-extent-example.sql
Last active February 26, 2019 15:27
Sample ASpace SQL query to get Resource information and their extent statements
SELECT
r.id AS 'resource database id',
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(r.identifier, ',', '.'),'"',''),']',''),'[',''),'.null','') AS 'collection call number',
r.title,
r.publish,
r.repo_id,
r.ead_id,
r.finding_aid_author,
GROUP_CONCAT(DISTINCT extent.number, ' ', ev.value
SEPARATOR '; ') AS 'Extent',
AppConfig[:record_inheritance] = {
:archival_object => {
:composite_identifiers => {
:include_level => true,
:identifier_delimiter => " ",
},
:inherited_fields => [
{
:property => "title",
:inherit_directly => true
<!-- i've been using this to sort top/circulating containers in EAD, but i need a way to do this in the ASpace staff/public interface, as well...
the gist is that boxes like 1, 2, 2a, 2b, 3, 4, should be able to be sorted in order, regardless of where they occur in a finding aid... and it should also use what ASpace calls container2 and container3 values for sorting if multiple components are displayed
... so component Y would sort before component X if component Y was box 12a, folder 22 and component X was box 12a, folder 29
-->
<xsl:function name="mdc:container-to-number" as="xs:decimal">
<xsl:param name="current-container" as="node()*"/>
<xsl:variable name="primary-container-number" select="replace($current-container, '\D', '')"/>
<xsl:variable name="primary-container-modify">
<xsl:choose>
<xsl:when test="matches($current-container, '\D')">
xquery version "3.0";
declare namespace ead="urn:isbn:1-931666-22-9";
declare namespace xlink = "http://www.w3.org/1999/xlink";
<results>
{
for $ead in ead:ead
let $doc := base-uri($ead)
return
xquery version "3.0";
declare namespace mdc = "http://mdc";
declare function mdc:add-check-digit-to-partial-barcode ($partial-barcode as xs:string) as xs:string {
(: the next two variables compute the Codabar barcode sum for 14-digit library barcodes according to the Luhn algorithm:)
let $barcode-sum :=
(: add up the even sequence :)
sum(string-to-codepoints($partial-barcode)[position() mod 2 eq 0] ! xs:integer(codepoints-to-string(.)))
+
(: add up the odd sequence :)
declare namespace tei="http://www.tei-c.org/ns/1.0";
<results>
{
for $actor-list in //tei:stage/@who,
$actor in $actor-list/tokenize(., ' ')
group by $actor
order by $actor
return
<actor> {
(:
combine...
1 to 3
"TEST"
"ING"
=
1, 2, 3 testing
declare namespace tei = "http://www.tei-c.org/ns/1.0";
(: give a scene list and for each actor, give a list of the scenes that they appear in :)
(: should do an intersect, union, except with the speaking role result set :)
<results>
{
for $stage-direction in //tei:div2[@type="scene"]//tei:stage[@who]
let $actor-list := $stage-direction/@who
let $scenes := concat($stage-direction[. = tokenize(., '#| #')]/ancestor::tei:div1/tei:head/normalize-space(.), ', ', $stage-direction[. = tokenize(., '#| #')]/ancestor::tei:div2/tei:head/normalize-space(.))
declare namespace tei = "http://www.tei-c.org/ns/1.0";
(: for each actor, give a list of the scenes that they appear in :)
for $actor in //tei:div2[@type="scene"]//tei:sp/tei:speaker/tei:w
let $scene := concat($actor/ancestor::tei:div1/tei:head/normalize-space(.), ', ', $actor/ancestor::tei:div2/tei:head/normalize-space(.))
group by $actor