Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge TEI2EOADjango
  • Loading branch information
Klaus Thoden committed Mar 8, 2018
2 parents 429b619 + e2b1b6c commit cc2f136
Show file tree
Hide file tree
Showing 15 changed files with 2,356 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .gitignore
@@ -1,6 +1,10 @@
output
examples

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so
Expand Down Expand Up @@ -42,13 +46,22 @@ htmlcov/
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
Expand All @@ -58,3 +71,25 @@ target/

# Macos turds
.DS_Store

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Max Planck Institute for the History of Science
Copyright (c) 2016-2018 Max Planck Institute for the History of Science

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -31,7 +31,7 @@ you the PDF version of the document.

Next, comment line 9 in `EOASample.tex` (the EOA preambel) and
uncomment line 10 (the XML preambel) and run the older version of
biber (biber v2.1).
biber (biber v2.1).

biber_2.1 EOASample

Expand All @@ -48,5 +48,15 @@ If everything went well, you can also try and run
These scripts don't take any arguments and will produce output in the
`CONVERT` directory.

# Convert TEI to EOADjango #

Suite of functions to get from TEI encoded XML into the workflow of Edition Open Access. The main output file is an XML file called `IntermediateXML.xml` which can subsequently processed with `tralics2django`, a tool found in the `EOASkripts` repository.

Code written in Python3.

External dependencies
---------------------
- lxml
- BeautifulSoup
- pandoc
- pandoc-citeproc
617 changes: 617 additions & 0 deletions data/exampleTEI.xml

Large diffs are not rendered by default.

Binary file added data/images/0002.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/002.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/1_rot.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/inline/A.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
274 changes: 274 additions & 0 deletions data/tei2django.xsl
@@ -0,0 +1,274 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
version="1.0"
exclude-result-prefixes="tei cc rdf"
>
<!--
things missing:
- EOAparthtml
- numbering and ordering
- footnotes have a sup above and are gathered below
-
-->

<xsl:output method="xml" indent="yes" encoding="UTF-8"/>

<xsl:template match="/">
<xsl:element name="EOAdocument">
<xsl:apply-templates select="//tei:div[@type='chapter']"/>
</xsl:element>
</xsl:template>

<!--
<div type="part" n="1" xml:id="part1">
<head>This is the first part</head>
-->

<xsl:template match="//tei:div[@type='part']/tei:head">
<xsl:element name="EOAparthtml">
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='chapter'][not(@rend='nonumber')]">
<xsl:element name="EOAchapter">
<xsl:attribute name="language">
<xsl:value-of select="//tei:langUsage/tei:language/@ident"/>
</xsl:attribute>
<xsl:attribute name="order">
<xsl:value-of select="position()"/>
</xsl:attribute>
<xsl:attribute name="number">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:apply-templates/>
<xsl:element name="EOAsection">
<xsl:element name="head">
<xsl:text>Footnotes</xsl:text>
</xsl:element>
</xsl:element>
<xsl:apply-templates select="//tei:note[@place='bottom']"/>
<xsl:element name="EOAfootnote">
<xsl:attribute name="anchor">
<xsl:value-of select="tei:note/@n"/>
</xsl:attribute>
<xsl:value-of select="tei:note[@place='bottom']/tei:p"/>
<!-- </xsl:template> -->
</xsl:element>

</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='chapter'][@rend='nonumber']">
<xsl:element name="EOAchapter">
<xsl:attribute name="language">
<xsl:value-of select="//tei:langUsage/tei:language/@ident"/>
</xsl:attribute>
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='section'][not(@rend='nonumber')]/tei:head">
<xsl:element name="EOAsection">
<xsl:attribute name="number">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='section'][@rend='nonumber']/tei:head">
<xsl:element name="EOAsection">
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='subsection'][not(@rend='nonumber')]/tei:head">
<xsl:element name="EOAsubsection">
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:attribute name="number">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='subsection'][@rend='nonumber']/tei:head">
<xsl:element name="EOAsubsection">
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='subsubsection']/tei:head">
<xsl:element name="EOAsubsubsection">
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='chapter']/tei:head">
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:p">
<xsl:element name="EOAparagraph">
<xsl:attribute name="order">
<xsl:value-of select="position()"/>
</xsl:attribute>
<!-- <xsl:value-of select="."/> -->
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:p[@rend='Quote']">
<xsl:element name="EOAparagraph">
<xsl:attribute name="order">
<xsl:value-of select="position()"/>
</xsl:attribute>
<xsl:attribute name="rend">
<xsl:text>quoted</xsl:text>
</xsl:attribute>
<!-- <xsl:value-of select="."/> -->
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<!--
<span rel="popover" class="citation" data-toggle="popover" html="true" data-placement="bottom" data-title="Descartes 1644, 37–44" data-content="Principia philosophiae.">Descartes 1644, 37–44</span>
-->

<xsl:template match="tei:bibl/tei:abbr[@type='authoryear']">
<xsl:element name="span">
<xsl:attribute name="rel">
<xsl:text>popover</xsl:text>
</xsl:attribute>
<xsl:attribute name="class">
<xsl:text>citation</xsl:text>
</xsl:attribute>
<xsl:attribute name="data-toggle">
<xsl:text>popover</xsl:text>
</xsl:attribute>
<xsl:attribute name="html">
<xsl:text>true</xsl:text>
</xsl:attribute>
<xsl:attribute name="citekey">
<xsl:value-of select="substring-after(../tei:ref/@target, '#')"/>
</xsl:attribute>
<xsl:attribute name="data-placement">
<xsl:text>bottom</xsl:text>
</xsl:attribute>
<xsl:attribute name="data-title">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:attribute name="data-content">
<xsl:value-of select="../tei:abbr[@type='title']"/>
<!-- <xsl:text>Here goes the title of the publication</xsl:text> -->
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:figure">
<xsl:element name="EOAfigure">
<xsl:attribute name="file">
<xsl:value-of select="tei:graphic/@url"/>
</xsl:attribute>
<!-- <xsl:apply-templates/> -->
<xsl:element name="caption">
<xsl:value-of select="tei:head/text()"/>
</xsl:element>
</xsl:element>
</xsl:template>
<!-- <EOAfigure file="images1.jpg" width="66px;" order="8" number="4.1"><caption>An image with a caption. It resembles a bird looking at you. Doesn't it? And do you think it looks angry?</caption></EOAfigure> -->

<xsl:template match="tei:note[@place='bottom']/tei:p">
<xsl:element name="sup">
<xsl:attribute name="class">
<xsl:text>footnote</xsl:text>
</xsl:attribute>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="concat('#fn', ../@n)"/>
</xsl:attribute>
<xsl:value-of select="../@n"/>
</xsl:element>
</xsl:element>
</xsl:template>
<!-- <sup class="footnote"><a href="#fn1">1</a></sup> -->

<!--
<xsl:template match="tei:note[@place='bottom']/tei:p">
<xsl:element name="EOAfootnote">
<xsl:attribute name="anchor">
<xsl:value-of select="../@n"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
-->

<xsl:template match="tei:hi[@rend='italic']">
<xsl:element name="em">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:hi[@rend='sup']">
<xsl:element name="sup">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:hi[@rend='sub']">
<xsl:element name="sub">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!--
<xsl:template match="tei:hi[@rend='math']">
<xsl:element name="em">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
-->
<xsl:template match="tei:hi[@rend='bold']">
<xsl:element name="b">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>


</xsl:stylesheet>

0 comments on commit cc2f136

Please sign in to comment.