Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test with latest examples -> lots of fixes
  • Loading branch information
EsGeh authored and EsGeh committed Dec 19, 2019
1 parent fa4f45e commit a419107
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 77 deletions.
14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -95,7 +95,7 @@ In order to apply the workflow to any other publication copy it into the `runtim

1. eoatex -> pdf

$ process_eoa_latex.py -f input/example/eoatex/EOASample.tex
$ process_eoa_latex.py -f input/example/124_eoatex/EOASample.tex

(adjust filename if necessary)

Expand All @@ -113,23 +113,23 @@ In order to apply the workflow to any other publication copy it into the `input/

1. eoaTEI -> eoaTEI with bibliography

$ tei_add_bibl.py input/example/tei
$ tei_add_bibl.py -o output/125/with_bibl input/example/125_tei_part

1. eoaTEI -> eoaTEX

$ tei2eoatex.py -f input/example/tei/exampleTEI.xml
$ tei2eoatex.py -f input/example/125_tei_part/tei_part.xml -o output/125/eoatex

1. eoaTEX -> pdf

$ eoatex2pdf.py -f output/from_tei/eoatex/main.tex -o output/from_tei/pdf
$ eoatex2pdf.py -f output/125/eoatex/main.tex -o output/125/pdf

(adjust filename if necessary)

1. eoaTEI -> imxml (to intermediate xml)

$ gather_pickledata.py input/example/tei/exampleTEI.xml input/example/tei/example.bib
$ tei2imxml.py -f input/example/tei/exampleTEI.xml
$ gather_pickledata.py -o output/125/pickle input/example/125_tei_part/*.xml input/example/125_tei_part/texfiles/example.bib
$ tei2imxml.py -f output/125/with_bibl/tei_part.xml -d output/125/pickle/data.pickle -o output/125/imxml

1. eoaTEI -> html

$ tei2html.py
$ tei2html.py output/125/with_bibl -o output/125/html
2 changes: 1 addition & 1 deletion dependencies.conf
Expand Up @@ -13,7 +13,7 @@ hash = 2a01be46ee82fce5eba6074359b3d18db2222e0c
[eoa-publication-model]

uri = https://github.molgen.mpg.de/EditionOpenAccess/eoa-publication-model.git
hash = 5ff326580a6bc34756bce511a23146453fdb82b6
hash = 5237e12c6205cff45d46c7d5f62d5222040be7a1
# init not needed, since only example publication is needed

[webdesign_platform]
Expand Down
3 changes: 2 additions & 1 deletion src/stylesheets/tei2eoatex.xsl
Expand Up @@ -24,7 +24,7 @@
<xsl:include href="tei2eoatex/eoatex_textparts.xsl"/>

<xsl:variable name="langid" select="//tei:langUsage/tei:language/@ident"/>
<xsl:variable name="transl" select="document('data/aux/translations.xml')"/>
<xsl:variable name="transl" select="document('../../data/aux/translations.xml')"/>
<xsl:key name="en" match="translations/entry" use="@en"/>
<xsl:key name="de" match="translations/entry" use="@de"/>
<xsl:key name="fr" match="translations/entry" use="@fr"/>
Expand Down Expand Up @@ -141,6 +141,7 @@ contexts, a double replacement is performed.
</xsl:choose>

<xsl:text>\end{document}&#x000a;</xsl:text>
<xsl:sequence select="eoa:debug(1, 'DONE!', '')"/>
</xsl:template>
<!-- <xsl:template match="/"> ends here -->

Expand Down
61 changes: 21 additions & 40 deletions src/tei2eoatex.py
Expand Up @@ -44,11 +44,19 @@ def copy_cmd(src, dst):
copy_dir_overwrite( src, dst )
else:
shutil.copytree( src, dst )
for dir in ("images", "inline", "facsim", "preambel"):
copy_cmd(
input_dir / dir,
output_dir / dir
)

for f in input_dir.iterdir():
logging.debug( f"copy dir: {f}" )
if f.is_dir():
copy_cmd(
f,
output_dir / f.name
)
else:
shutil.copy(
f,
output_dir / f.name
)

if __name__ == '__main__':

Expand Down Expand Up @@ -80,7 +88,8 @@ def copy_cmd(src, dst):
"-o", "--output-dir",
default = DEFAULT_OUTPUT_DIR / "from_tei/eoatex",
metavar = "OUTPUT_DIR",
help="output directory"
help="output directory",
type = Path
)
parser.add_argument(
"-p", "--param",
Expand Down Expand Up @@ -131,6 +140,12 @@ def copy_cmd(src, dst):
parents=True
)

copy_files(
input_dir = input_file.parent,
output_dir = output_file.parent,
overwrite = args.overwrite,
)

run_xslt(
input_file = input_file,
xslt_file = EOA_SCRIPTS_DIR / "stylesheets/tei2eoatex.xsl",
Expand All @@ -140,37 +155,3 @@ def copy_cmd(src, dst):
'output_to' : ToFile( log_dir / SCRIPT_NAME / "saxon.log" )
},
)

from lxml import etree

ns = {"tei": "http://www.tei-c.org/ns/1.0"}

tree = etree.parse(
str(input_file)
)

bib_file = tree.xpath(
"//tei:sourceDesc/tei:ab[@type='bibdatabase']/tei:ref/@target",
namespaces = ns
)[0]
bib_file = input_file.parent / bib_file

logging.info( f"bib_file: {bib_file}" )

copy_files(
input_dir = input_file.parent,

output_dir = output_file.parent,
overwrite = args.overwrite,
)

if not bib_file.is_file():
raise( Exception( f"bibfile not found: '{bib_file}'!" ) )

src = bib_file
dst = output_file.parent / bib_file.name
logging.info( f"copying {src} -> {dst}")
shutil.copy(
bib_file,
output_file.parent / bib_file.name
)
18 changes: 12 additions & 6 deletions src/tei2imxml.py
Expand Up @@ -1362,12 +1362,18 @@ def main():
logging.info( "checking executables 'utils.bib2html' needs...:" )
bib2html.check_executables()

if not os.path.exists(OUTPUT_DIR):
os.mkdir( OUTPUT_DIR )
if not os.path.exists(TEMP_DIR):
os.mkdir( TEMP_DIR )
if not os.path.exists( DEBUG_DIR ):
os.mkdir( DEBUG_DIR )
OUTPUT_DIR.mkdir(
parents = True,
exist_ok = True
)
TEMP_DIR.mkdir(
parents = True,
exist_ok = True
)
DEBUG_DIR.mkdir(
parents = True,
exist_ok = True
)

try:
with open(args.pickleddata, 'rb') as f:
Expand Down
40 changes: 19 additions & 21 deletions src/tei_add_bibl.py
Expand Up @@ -58,7 +58,9 @@ def copy_file(
def publication_info(xml_tree):
"""Check TEI header for bibliography data, return relevant data as dictionary."""

bib_file = xml_tree.xpath("//tei:teiHeader/tei:fileDesc/tei:sourceDesc/tei:ab[@type='bibdatabase']/tei:ref/@target", namespaces=NS_MAP)[0]
bib_file = Path(
xml_tree.xpath("//tei:teiHeader/tei:fileDesc/tei:sourceDesc/tei:ab[@type='bibdatabase']/tei:ref/@target", namespaces=NS_MAP)[0]
)
publ_type = xml_tree.xpath("//tei:teiHeader/tei:fileDesc/tei:sourceDesc/tei:ab[@type='bibdatabase']/tei:ref/@type", namespaces=NS_MAP)[0]
if publ_type not in ["monograph", "anthology", "monograph-numeric", "anthology-numeric"]:
logging.error(f"The bibliography type {publ_type} is not allowed. Exiting")
Expand All @@ -76,6 +78,7 @@ def publication_info(xml_tree):

def create_bibl_and_insert(
tei_tree,
publ_info,
temp_dir,
tei_bib_file,
tei_file,
Expand All @@ -85,7 +88,7 @@ def create_bibl_and_insert(
tei_info = bib2html.get_bibl_info( tei_tree )
logging.debug( f"info from tei file: {tei_info}" )
bib2html.bib2tei(
bib_file = bib_file,
bib_file = publ_info['bib_file'],
citekeys = tei_info['citekeys'],
keywords = tei_info['keywords'],
language = translations[publ_info['language']],
Expand All @@ -97,7 +100,7 @@ def create_bibl_and_insert(
run_xslt(
tei_file,
BASE_DIR / "stylesheets/insert_bibliography.xsl",
params = [ f"tei_bib_file={tei_bib_file}" ],
params = [ f"tei_bib_file={tei_bib_file.absolute()}" ],
output_file = tei_with_bibl_file
)

Expand Down Expand Up @@ -135,16 +138,11 @@ def create_bibl_and_insert(
type = Path,
help = "xml file inside PUBLICATION_DIR, or absolute path. Patterns like '*.xml' are also acceptable"
)
parser.add_argument(
"-b", "--bib-file",
default = Path("*.bib"),
type = Path,
help = "bib file inside PUBLICATION_DIR, or absolute path. Patterns like '*.bib' are also acceptable"
)
parser.add_argument(
"-o", "--output-dir",
default = DEFAULT_OUTPUT_DIR / "from_tei/with_bibl",
help="output directory"
help="output directory",
type = Path,
)
parser.add_argument(
"-!", "--overwrite",
Expand Down Expand Up @@ -173,19 +171,18 @@ def create_bibl_and_insert(

publ_dir = args.PUBLICATION_DIR
tei_file_input = args.filename
bib_file = args.bib_file

tei_file = \
tei_file_input if tei_file_input . is_absolute() else list(publ_dir . glob (str(tei_file_input)))[0]

bib_file = \
bib_file if bib_file . is_absolute() else list(publ_dir . glob (str(bib_file)))[0]


logging.info( f"publ_dir: {publ_dir}, tei_file: {tei_file}, bib_file: {bib_file}" )

output_dir = args.output_dir

tei_tree = etree.parse(str(tei_file))
publ_info = publication_info( tei_tree )
publ_info['bib_file'] = tei_file.parent / publ_info['bib_file']
logging.info( f"publ_dir: {publ_dir}, tei_file: {tei_file}" )
logging.info( f"The bibfile is '{publ_info['bib_file']}' and this publication type is '{publ_info['publ_type']}'. Language: '{publ_info['language']}'")

if not tei_file.is_file():
raise( Exception(
f"not a valid input file: {tei_file}"
Expand All @@ -203,12 +200,10 @@ def create_bibl_and_insert(
output_dir,
# ignore = ignore_patterns( tei_file_input ) if not(tei_file_input . is_absolute()) else None
)
tei_tree = etree.parse(str(tei_file))
publ_info = publication_info( tei_tree )
logging.info( f"The bibfile is '{publ_info['bib_file']}' and this publication type is '{publ_info['publ_type']}'. Language: '{publ_info['language']}'")
if publ_info["publ_type"] == "monograph":
create_bibl_and_insert(
tei_tree,
publ_info = publ_info,
temp_dir = output_dir / "temp/all",
tei_bib_file = (output_dir/ "bibliography/bibliography_all") . with_suffix(".tei"),
tei_file = tei_file,
Expand All @@ -220,8 +215,11 @@ def create_bibl_and_insert(
chapter_id = chap_node.xpath("@xml:id", namespaces=NS_MAP)
create_bibl_and_insert(
tei_tree,
publ_info = publ_info,
temp_dir = output_dir / f"temp/chap_{chapter_id}",
tei_bib_file = (output_dir/ f"bibliography/bibliography_chap_{chapter_id}") . with_suffix(".tei")
tei_bib_file = (output_dir/ f"bibliography/bibliography_chap_{chapter_id}") . with_suffix(".tei"),
tei_file = tei_file,
tei_with_bibl_file = (output_dir / (tei_file.with_suffix("").name + "_with_bibl")) . with_suffix( ".xml" ),
)
else:
raise( Exception("unknown publication type!"))
2 changes: 1 addition & 1 deletion src/utils/bib2html.py
Expand Up @@ -382,7 +382,7 @@ def __imhtml_2_tei(
run_xslt(
imhtml_file,
BASE_DIR / "stylesheets/tex4ht_2_tei.xsl",
params = [ f"dashed_file={imhtml_dashed_file}" ],
params = [ f"dashed_file={imhtml_dashed_file.absolute()}" ],
output_file = output_file
)

Expand Down

0 comments on commit a419107

Please sign in to comment.