From: Lady <redacted>
Date: Sat, 22 Jun 2024 21:54:29 +0000 (-0400)
Subject: Provide the location of parsed files in metadata
X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/ffe87ed345ae20b68cabd12741ee9c1c708780ff?ds=sidebyside

Provide the location of parsed files in metadata

Rather than hardcoding parsed file lookup into `expandmetadata.xslt`
and `catalog2transform.xslt`, provide a file U·R·I for the parsed file
as a part of its metadata and use that instead. It _is_ reasonable for
transforms to want to access the original parsed documents of
dependencies. Note, however, that there is no guarantee that the parsed
document actually exists if it _isn’t_ a dependency for the file.
---

diff --git a/GNUmakefile b/GNUmakefile
index 6b2ac54..e28b795 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -437,10 +437,10 @@ override parsed = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(
 # (callable) Get the source files for the given parsed file.
 override unparsed = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourceparsedpair))))
 
-# Pair each build directory, parser, transform, or source file with its file u·r·i.
-override fileuripairs := $(join $(patsubst %,%|,$(BUILDDIR) $(PARSERS) $(TRANSFORMS) $(sourcefiles) $(sourceincludes)),$(call pathenc,$(foreach uriable,$(BUILDDIR) $(PARSERS) $(TRANSFORMS) $(sourcefiles) $(sourceincludes),file://$(abspath $(uriable)))))
+# Pair each build directory, parser, transform, or parsed file with its file u·r·i.
+override fileuripairs := $(join $(patsubst %,%|,$(BUILDDIR) $(PARSERS) $(TRANSFORMS) $(call parsed,$(sourcefiles) $(sourceincludes))),$(call pathenc,$(foreach uriable,$(BUILDDIR) $(PARSERS) $(TRANSFORMS) $(call parsed,$(sourcefiles) $(sourceincludes)),file://$(abspath $(uriable)))))
 
-# (callable) Get the file u·r·is for the given parsers, transforms, parsed files, or metadata compilations.
+# (callable) Get the file u·r·is for the given parsers, transforms, or parsed files.
 override fileuri = $(foreach file,$1,$(or $(patsubst $(file)|%,%,$(filter $(file)|%,$(fileuripairs))),$(error Unable to get file u·r·i for `$(file)´)))
 
 ifneq ($(wildcard $(BUILDDIR)/dependencies),)
@@ -620,7 +620,7 @@ $(BUILDDIR)/parser.xslt : $(BUILDDIR)/parser.catalog $(THISDIR)/lib/catalog2pars
 # If the types have been updated but `typeupdates´ is not active, this recipe is skipped because a restart is forthcoming.
 $(call metadata,$(sourcefiles) $(sourceincludes)) : % : $$(call datadata,$$@) $(THISDIR)/lib/expandmetadata.xslt $(typeupdates)
 	$(call inform,$(call unlesstypeswillupdate,$(PRINTF) '%s\n' $(call quote,Generating metadata for `$<´…) >&2))
-	$(silent)$(call unlesstypeswillupdate,$(call ensuredirectory,$(dir $@)); { if $(TEST) ! -f $(call quote,$(BUILDDIR)/.mtime); then $(PRINTF) '%b' '\n' >|$(call quote,$(BUILDDIR)/.mtime); fi; $(TOUCH) -r $(call quote,$<) $(call quote,$(BUILDDIR)/.mtime); $(DIFF) -u $(call quote,$(BUILDDIR)/.mtime) /dev/null | $(SED) '1!d;s/.*	\([^ ]*\) \([^ ]*\).*$$/\1T\2Z/'; $(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//'; } | $(xargsmultiquote) | $(XARGS) -E '' $(PRINTF) '<?xml version="1.0"?><书社vocab:$(if $(filter $<,$(sourceincludes)),IncludeFile,SourceFile) xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#" xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:" rdf:about="%s" 书社vocab:path="%s"><nie:interpretedAs>$(if $(filter $<,$(assetfiles)),<nfo:InformationElement nie:mimeType="%s"/>,<nfo:PlainTextDocument nie:mimeType="%s"/>)</nie:interpretedAs><nfo:fileLastModified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">%s</nfo:fileLastModified><nfo:hasHash nfo:hashAlgorithm="CRC32" nfo:hashValue="%s"/></书社vocab:$(if $(filter $<,$(sourceincludes)),IncludeFile,SourceFile)>' $(call quote,$(call attresc,$(call localuri,$<))) $(call quote,$(call attresc,$(if $(filter $<,$(sourceincludes)),$(call includepath,$<),$(call sourcepath,$<)))) $(call quote,$(call attresc,$(call typeoffile,$<))) >|$(call quote,$@))
+	$(silent)$(call unlesstypeswillupdate,$(call ensuredirectory,$(dir $@)); { if $(TEST) ! -f $(call quote,$(BUILDDIR)/.mtime); then $(PRINTF) '%b' '\n' >|$(call quote,$(BUILDDIR)/.mtime); fi; $(TOUCH) -r $(call quote,$<) $(call quote,$(BUILDDIR)/.mtime); $(DIFF) -u $(call quote,$(BUILDDIR)/.mtime) /dev/null | $(SED) '1!d;s/.*	\([^ ]*\) \([^ ]*\).*$$/\1T\2Z/'; $(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//'; } | $(xargsmultiquote) | $(XARGS) -E '' $(PRINTF) '<?xml version="1.0"?><书社vocab:$(if $(filter $<,$(sourceincludes)),IncludeFile,SourceFile) xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#" xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:" rdf:about="%s" 书社vocab:path="%s"><nie:interpretedAs>$(if $(filter $<,$(assetfiles)),<nfo:InformationElement nie:mimeType="%s"/>,<nfo:PlainTextDocument nie:mimeType="%s"/>)</nie:interpretedAs><书社vocab:hasParsedFile nfo:fileUrl="%s"/><nfo:fileLastModified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">%s</nfo:fileLastModified><nfo:hasHash nfo:hashAlgorithm="CRC32" nfo:hashValue="%s"/></书社vocab:$(if $(filter $<,$(sourceincludes)),IncludeFile,SourceFile)>' $(call quote,$(call attresc,$(call localuri,$<))) $(call quote,$(call attresc,$(if $(filter $<,$(sourceincludes)),$(call includepath,$<),$(call sourcepath,$<)))) $(call quote,$(call attresc,$(call typeoffile,$<))) $(call quote,$(call attresc,$(call fileuri,$(call parsed,$<)))) >|$(call quote,$@))
 
 # Parse the files.
 #
diff --git a/lib/catalog2transform.xslt b/lib/catalog2transform.xslt
index d575a72..de98f40 100644
--- a/lib/catalog2transform.xslt
+++ b/lib/catalog2transform.xslt
@@ -349,20 +349,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 				<xslt:variable name="included" select="$书社:about//*[@rdf:about=$identifier]"/>
 				<xslt:choose>
 					<xslt:when test="$included">
-						<xslt:variable name="uri">
-							<xslt:text>
-								<value-of select="$builddir"/>
-							</xslt:text>
-							<xslt:choose>
-								<xslt:when test="$included/self::书社vocab:SourceFile">
-									<xslt:text>/sources/</xslt:text>
-								</xslt:when>
-								<xslt:when test="$included/self::书社vocab:IncludeFile">
-									<xslt:text>/includes/</xslt:text>
-								</xslt:when>
-							</xslt:choose>
-							<xslt:value-of select="$included/@书社vocab:path"/>
-						</xslt:variable>
+						<xslt:variable name="uri" select="$included/书社vocab:hasParsedFile/@nfo:fileUrl"/>
 						<xslt:variable name="expanded">
 							<xslt:apply-templates select="document($uri)" mode="书社:expand">
 								<xslt:with-param name="identifier" select="$identifier"/>
diff --git a/lib/expandmetadata.xslt b/lib/expandmetadata.xslt
index 3d46c82..dd39355 100644
--- a/lib/expandmetadata.xslt
+++ b/lib/expandmetadata.xslt
@@ -55,17 +55,8 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 			<for-each select="exsl:node-set($queue)/书社:*">
 				<for-each select="$files[@rdf:about=string(current()) and nie:interpretedAs/nfo:PlainTextDocument]">
 					<variable name="parent" select="@rdf:about"/>
-					<variable name="subdir">
-						<choose>
-							<when test="starts-with($parent, 'about:shushe?include=')">
-								<text>/includes/</text>
-							</when>
-							<when test="starts-with($parent, 'about:shushe?source=')">
-								<text>/sources/</text>
-							</when>
-						</choose>
-					</variable>
-					<for-each select="document(concat($builddir, $subdir, @书社vocab:path), .)//书社:link[@xlink:show='embed']">
+					<variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
+					<for-each select="document($uri)//书社:link[@xlink:show='embed']">
 						<if test="exsl:node-set($old)/书社:dependency-root[string()=string(current()/@xlink:href)]">
 							<书社:recursive-dependency>
 								<value-of select="$parent"/>
@@ -106,7 +97,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 		</copy>
 	</template>
 	<template match="//书社vocab:SourceFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
-		<variable name="parsed" select="document(concat($builddir, '/sources/', @书社vocab:path), .)"/>
+		<variable name="parsed" select="document(书社vocab:hasParsedFile/@nfo:fileUrl)"/>
 		<variable name="destination-delim" select="concat('/', $parsed/*/@书社:destination, '/')"/>
 		<variable name="destination">
 			<choose>