Skip to content

Commit

Permalink
zml2lido: lido:culture and einheimische Bezeichnung hinzugefügt; some…
Browse files Browse the repository at this point in the history
… work on paths in python
  • Loading branch information
mokko committed May 25, 2024
1 parent d6c467f commit a66bead
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 17 deletions.
3 changes: 2 additions & 1 deletion test/test_lidoTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def test_saxon() -> None:
# print(xsl["zml2lido"])
lt.saxon(src=lt.src, xsl=xsl["zml2lido"], output="test.lido.xml")


def test_saxon_umlaut() -> None:
lt = LidoTool(src="ä.xml")
assert str(lt.src == "ä.xml")
lido_fn = lt.zml2lido()
print(f"{lido_fn=}")
print(f"{lido_fn=}")
4 changes: 2 additions & 2 deletions zml2lido/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def saxon():
"-x", "--xsl", help="(xslt) transformation filename", required=True
)
args = parser.parse_args()
m = LidoTool(src=args.source)
m = LidoTool(src=args.source)
m.saxon(xsl=args.xsl, output=args.output)


Expand All @@ -112,7 +112,7 @@ def validate():
# query570068-chunk283.lido.xml
# query570068-chunk284.lido.xml
m = LidoTool(src=args.input)
m.validate() # raises if does not validate
m.validate() # raises if does not validate


def vocmap():
Expand Down
34 changes: 33 additions & 1 deletion zml2lido/data/xsl/zml2lido/event-Herstellung.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
'Stecher', 'Stecherin', 'Stecher*in',
'Verfasser', 'Verfasserin', 'Verfasser*in',
'Zeichner', 'Zeichnerin', 'Zeichner*in'"/>


<!-- TODO: -->
<xsl:variable name="herstellendeKollektive" select="
'Ethnie',
'Kultur',
Expand Down Expand Up @@ -123,6 +124,8 @@

<!-- Ethnien und andere Kollektive aus GeoBezug-->
<xsl:apply-templates mode="eventActor" select="$herstellendeKollektiveN"/>
<!-- lido:culture-->
<xsl:apply-templates select="z:repeatableGroup[@name = 'ObjCulturalContextGrp']"/>

<!-- eventDate
SPEC allows repeated displayDates only for language variants;
Expand Down Expand Up @@ -201,6 +204,35 @@
</xsl:if>
</xsl:template>


<xsl:template match="z:repeatableGroup[@name = 'ObjCulturalContextGrp']">
<xsl:message>yyyyyyyyyyyyyyyyyy yyyyyyyyyyyyyyyyyyyy yyyyyyyyyyyyyyyyyy</xsl:message>
<xsl:for-each select="z:repeatableGroupItem">
<lido:culture>
<lido:conceptID lido:type="local" lido:source="ObjCulturalContextGrp">
<xsl:value-of select="z:vocabularyReference[
@name = 'NameVoc'
]/z:vocabularyReferenceItem/@id"/>
</lido:conceptID>
<lido:term>
<xsl:if test="z:vocabularyReference[
@name = 'NameVoc'
]/z:vocabularyReferenceItem/z:formattedValue/@language ne ''">
<xsl:attribute name="xml:lang">
<xsl:value-of select="z:vocabularyReference[
@name = 'NameVoc'
]/z:vocabularyReferenceItem/z:formattedValue/@language"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="z:vocabularyReference[
@name = 'NameVoc'
]/z:vocabularyReferenceItem/z:formattedValue"/>
</lido:term>
</lido:culture>
</xsl:for-each>
</xsl:template>



<!--
m3: Kultur auf Actor gemappt entsprechend Vorschlag FvH;
Expand Down
2 changes: 1 addition & 1 deletion zml2lido/data/xsl/zml2lido/eventWrap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<!-- http://xtree-public.digicult-verbund.de/vocnet/?uriVocItem=http://terminology.lido-schema.org/&startNode=lido00409&lang=en&d=n -->
<lido:actor>
<xsl:attribute name="lido:type" select="$kue/z:vocabularyReference[@name = 'PerTypeVoc']/z:vocabularyReferenceItem/z:formattedValue"/>
<lido:actorID lido:type="local" lido:source="RIA/SMB">
<lido:actorID lido:type="local" lido:source="ObjPerAssociationRef">
<xsl:value-of select="$kueId"/>
</lido:actorID>
<xsl:if test="$gnd">
Expand Down
28 changes: 28 additions & 0 deletions zml2lido/data/xsl/zml2lido/titleWrap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<xsl:template name="titleWrap">
<lido:titleWrap>
<!-- Wenn ein Titel, dann nutze ihn, sonst Sachbegriff-->
<xsl:choose>
<xsl:when test="z:repeatableGroup[@name='ObjObjectTitleGrp']/z:repeatableGroupItem">
<xsl:apply-templates select="z:repeatableGroup[@name='ObjObjectTitleGrp']/z:repeatableGroupItem"/>
Expand All @@ -29,9 +30,36 @@
</lido:titleSet>
</xsl:otherwise>
</xsl:choose>
<!-- Wenn es einheimische Bezeichnung im Sachbegriff gibt, dann schreibe sie in title\@type="titleLanguageOrigin" -->
<xsl:apply-templates select="z:repeatableGroup[
@name = 'ObjTechnicalTermGrp'
]/z:repeatableGroupItem[
z:vocabularyReference/z:vocabularyReferenceItem/@id = '4402610'
]"/>
</lido:titleWrap>
</xsl:template>

<!-- einheimische Bezeichnung aus mpx:Sachbegriff in lido:title-->
<xsl:template match="z:repeatableGroup[
@name = 'ObjTechnicalTermGrp'
]/z:repeatableGroupItem[
z:vocabularyReference/z:vocabularyReferenceItem/@id = '4402610'
]">
<xsl:if test="z:dataField[@name = 'TechnicalTermTxt'] ne ''">
<xsl:comment>titleLanguageOrigin ist vom CCC-Portal definierter Wert</xsl:comment>
<lido:titleSet>
<xsl:attribute name="lido:type">
<xsl:text>titleLanguageOrigin</xsl:text>
</xsl:attribute>
<lido:appellationValue>
<!-- Sprache wird in RIA nicht qualifiziert -->
<xsl:value-of select="z:dataField[@name = 'TechnicalTermTxt']"/>
</lido:appellationValue>
</lido:titleSet>
</xsl:if>
</xsl:template>


<xsl:template match="/z:application/z:modules/z:module[@name = 'Object']/
z:moduleItem/z:repeatableGroup[@name='ObjObjectTitleGrp']/z:repeatableGroupItem">
<lido:titleSet>
Expand Down
31 changes: 19 additions & 12 deletions zml2lido/lidoTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ def validateSingle(self, *, src: Path):
self.schema.assert_(doc) # raises error when not valid
return src

def zml2lido(self, *, src:str|Path|None=None, xslt="zml2lido") -> Path:
def zml2lido(self, *, src: str | Path | None = None, xslt="zml2lido") -> Path:
if src is None:
src = self.src
#print(f"ZML2LIDO {xslt}")
# print(f"ZML2LIDO {xslt}")
if self.chunks:
print(" with chunks")
for chunkFn in self.loopChunks(src=self.src):
Expand Down Expand Up @@ -311,10 +311,14 @@ def firstChunkName(self, *, src: str | Path):
# print(f"***firstChunkName {firstFn}")
return firstFn

def saxon(self, *, output: str | Path, xsl: str | Path, src: str | Path | None = None) -> None:
def saxon(
self, *, output: str | Path, xsl: str | Path, src: str | Path | None = None
) -> None:
"""
New: src is optional.
New: src is optional (for the LidoTool's method).
saxon could also be a function outside of this class.
lc = LidoTool(src="ere.xml")
lc.saxon(xsl="test.xsl", output="out.xml")
lc.saxon(src="other.xml", xsl="test.xsl", output="out.xml")
Expand All @@ -329,14 +333,14 @@ def saxon(self, *, output: str | Path, xsl: str | Path, src: str | Path | None =
raise SyntaxError("ERROR: xsl file does not exist!")

# https://stackoverflow.com/questions/78468764
xml_file_name=Path(src).absolute().as_uri()
xml_file_name = Path(src).absolute().as_uri()

orig = Path.cwd()
with PySaxonProcessor(license=False) as proc:
xsltproc = proc.new_xslt30_processor()
executable = xsltproc.compile_stylesheet(stylesheet_file=str(xsl))
xml = proc.parse_xml(xml_file_name=xml_file_name)
os.chdir(self.script_dir)
os.chdir(self.script_dir) # so that saxon finds vocmap.xml
result_tree = executable.apply_templates_returning_file(
xdm_node=xml, output_file=str(output)
)
Expand Down Expand Up @@ -394,18 +398,21 @@ def _prepareOutdir(self) -> Path:
if re.match(r"\d\d\d\d\d\d", self.src.parent.name):
outdir = sdataP / self.src.parents[1].name / self.src.parent.name
elif self.src.parent.name == "sdata":
print("_outdir:Case2")
outdir = sdataP
#raise SyntaxError(
# """ERROR: Don't use an src file inside of sdata.
# raise SyntaxError(
# """ERROR: Don't use an src file inside of sdata.
# Use a subdirectory instead!"""
#)
# )
else:
outdir = sdataP / self.src.parent.name
# should write in sdata/ccc for example, which may be pwd
print(f"_outdir:Case3 {self.src.parent.resolve().name}")
outdir = sdataP / self.src.parent.resolve().name

if not outdir.exists():
print(f"Making new dir {outdir}")
outdir.mkdir(parents=True, exist_ok=False)
#print(f" outdir {outdir}")
# print(f" outdir {outdir}")
return outdir

def _sanitize(self, *, src: str | Path) -> Path:
Expand Down

0 comments on commit a66bead

Please sign in to comment.