Skip to content

Commit

Permalink
Merge branch 'master' of github.com:proycon/foliatools
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Apr 28, 2021
2 parents c532991 + 998dc47 commit dc1cb5f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion foliatools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""FoLiA-tools contains various Python-based command line tools for working with FoLiA XML (Format for Linguistic Annotation)"""

VERSION = "2.5.0"
VERSION = "2.5.1"
2 changes: 2 additions & 0 deletions foliatools/tei2folia.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def convert(filename, transformer, parser=None, **kwargs):
if data.find(b"xmlns=\"http://www.tei-c.org/ns/1.0\"") == -1:
data = data.replace(b"<TEI ",b"<TEI xmlns=\"http://www.tei-c.org/ns/1.0\" ")
data = data.replace(b"<TEI.2 ",b"<TEI.2 xmlns=\"http://www.tei-c.org/ns/1.0\" ")
data = data.replace(b"<teiTrim ",b"<teiTrim xmlns=\"http://www.tei-c.org/ns/1.0\" ")
data = data.replace(b"<teiTrim>",b"<teiTrim xmlns=\"http://www.tei-c.org/ns/1.0\">")
parsedsource = lxml.etree.fromstring(data, parser)
del data
else:
Expand Down
27 changes: 23 additions & 4 deletions foliatools/tei2folia.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ Heavily adapted by Maarten van Gompel (Radboud University)

<!-- *************************************************** DOCUMENT & METADATA ************************************************** -->

<xsl:template match="TEI|TEI.2">
<xsl:template match="TEI|TEI.2|teiTrim">
<xsl:message terminate="yes">ERROR: TEI document lacks proper XML namespace declarations! Run tei2folia --forcenamespace to try to recover automatically or add xmlns="http://www.tei-c.org/ns/1.0" manually.</xsl:message>
</xsl:template>

<xsl:template match="tei:TEI|tei:TEI.2">
<xsl:template match="tei:TEI|tei:TEI.2|tei:teiTrim">
<FoLiA xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://ilk.uvt.nl/folia" version="2.3.0" generator="tei2folia.xsl">
<xsl:attribute name="xml:id"><xsl:value-of select="$docid"/></xsl:attribute>
<metadata type="native">
Expand Down Expand Up @@ -108,7 +108,17 @@ Heavily adapted by Maarten van Gompel (Radboud University)
</metadata>
<text>
<xsl:attribute name="xml:id"><xsl:value-of select="$docid"/>.text</xsl:attribute>
<xsl:apply-templates select="//tei:text/*" mode="structure"/>
<xsl:choose>
<xsl:when test="./tei:body">
<!-- We see this behaviour in some files, no tei:text but directly a body, not sure if it's valid TEI but we can deal with it -->
<div class="body">
<xsl:apply-templates select="//tei:body/*" mode="structure"/>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="/text/tei:text/*" mode="structure"/>
</xsl:otherwise>
</xsl:choose>
</text>
</FoLiA>
</xsl:template>
Expand Down Expand Up @@ -439,7 +449,16 @@ Heavily adapted by Maarten van Gompel (Radboud University)
</cell>
</xsl:template>

<xsl:template match="tei:p|tei:speaker|tei:trailer|tei:closer|tei:opener|tei:lxx|tei:byline|tei:salute" mode="structure">
<xsl:template match="tei:p|tei:speaker|tei:trailer|tei:closer|tei:opener|tei:lxx|tei:byline|tei:salute|tei:para|tei:remark" mode="structure">
<xsl:call-template name="p"/>
</xsl:template>

<!-- These are not real TEI elements but they occur in some dialects and we squash them to paragraphs -->
<xsl:template match="tei:para|tei:remark|tei:folio" mode="structure">
<xsl:if test="$quiet = 'false'">
<xsl:message terminate="no">NOTICE: Found an unofficial TEI element that doesn't exist in the P5 specification <xsl:value-of select="name(.)"/> (in <xsl:value-of select="name(parent::node())" />), we're converting these to a FoLiA paragraph</xsl:message>
</xsl:if>
<comment>[tei2folia WARNING] Unofficial TEI element: <xsl:value-of select="name(.)"/> (in <xsl:value-of select="name(parent::node())" />) was converted to a paragraph</comment>
<xsl:call-template name="p"/>
</xsl:template>

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def read(fname):

setup(
name = "FoLiA-tools",
version = "2.5.0", #also change in __init__.py
version = "2.5.1", #also change in __init__.py
author = "Maarten van Gompel",
author_email = "proycon@anaproy.nl",
description = ("FoLiA-tools contains various Python-based command line tools for working with FoLiA XML (Format for Linguistic Annotation)"),
Expand Down

0 comments on commit dc1cb5f

Please sign in to comment.