Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix scripts to work with 126 (anthology) example publ.
  • Loading branch information
EsGeh authored and EsGeh committed Dec 20, 2019
1 parent a419107 commit 380d7af
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -132,4 +132,4 @@ In order to apply the workflow to any other publication copy it into the `input/

1. eoaTEI -> html

$ tei2html.py output/125/with_bibl -o output/125/html
$ tei2html.py -o output/125/html output/125/with_bibl
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 = 5237e12c6205cff45d46c7d5f62d5222040be7a1
hash = 62eb49dd05ebe3697e47acac31a1cff2f60c6f7a
# init not needed, since only example publication is needed

[webdesign_platform]
Expand Down
28 changes: 25 additions & 3 deletions src/stylesheets/insert_bibliography.xsl
Expand Up @@ -15,8 +15,17 @@
version="1.0"
/>

<param name="tei_bib_file" as="xs:string"/>
<variable name="tei_bib" select="doc($tei_bib_file)"/>
<!--
; seperated list of tei files containing
bibliographies to insert
-->
<param name="tei_bib_files" as="xs:string"/>
<variable name="tei_bib_files_parsed" as="xs:string*" select="tokenize($tei_bib_files, ';')"/>
<!--
<variable name="tei_bibs" as="document-node()*"
select="for f in $tei_bib_files return doc($f)"
/>
-->

<template match="@* | node()">
<copy>
Expand All @@ -43,7 +52,20 @@
<template name="print_bibliography">
<param name="args" as="xs:string*"/>
<variable name="keyword" select="if (count($args) > 0) then $args[1] else ''"/>
<variable name="bibl_chapter_content" select="$tei_bib//tei:div[@type = 'bibliographies']/tei:listBibl[@type = 'references'][@n = $keyword]"/>
<variable name="chapter_id" as="xs:string" select="ancestor::tei:div[@type = 'chapter']/@xml:id"/>
<message>print bibliography in chapter <value-of select="$chapter_id"/></message>
<variable name="tei_bib_candidate_files" as="document-node()*">
<for-each select="$tei_bib_files_parsed">
<variable name="filename"
select="if (not(contains(., '/'))) then . else tokenize(., '/')[last()]"
/>
<if test="starts-with($filename, concat('bibliography_chap_', $chapter_id)) or starts-with($filename, 'bibliography_all.') and doc-available(.)">
<message>inserting from file <value-of select="."/></message>
<sequence select="doc(.)"/>
</if>
</for-each>
</variable>
<variable name="bibl_chapter_content" select="$tei_bib_candidate_files//tei:div[@type = 'bibliographies']/tei:listBibl[@type = 'references'][@n = $keyword]"/>
<choose>
<when test="$bibl_chapter_content">
<sequence select="$bibl_chapter_content"/>
Expand Down
4 changes: 2 additions & 2 deletions src/stylesheets/tex4ht_2_tei.xsl
Expand Up @@ -28,7 +28,7 @@
<teiHeader>
<fileDesc>
<titleStmt>
<title>Title</title>
<title>Bibliography for </title>
</titleStmt>
<publicationStmt>
<p>Publication Information</p>
Expand Down Expand Up @@ -116,7 +116,7 @@

<template name="render_citations">
<message>rendering citations</message>
<for-each select="//html:h3[. = '1 Citations']/following-sibling::html:div//html:table/html:tr">
<for-each select="//html:h3[. = '1 Citations']/following-sibling::html:div//html:table/html:tr[normalize-space(.) != '']">
<variable name="citekey" as="xs:string" select="html:td[1]"/>
<variable name="authoryear" as="xs:string" select="html:td[2]"/>
<variable name="year" as="xs:string" select="html:td[3]"/>
Expand Down
61 changes: 41 additions & 20 deletions src/tei_add_bibl.py
Expand Up @@ -76,16 +76,16 @@ def publication_info(xml_tree):

}

def create_bibl_and_insert(
tei_tree,
def create_bibl(
tei_node,
publ_info,
temp_dir,
tei_bib_file,
tei_file,
tei_with_bibl_file
# tei_with_bibl_file
):
translations = {"de" : "german", "en" : "english", "it" : "italian", "fr" : "french"}
tei_info = bib2html.get_bibl_info( tei_tree )
tei_info = bib2html.get_bibl_info( tei_node )
logging.debug( f"info from tei file: {tei_info}" )
bib2html.bib2tei(
bib_file = publ_info['bib_file'],
Expand All @@ -97,12 +97,6 @@ def create_bibl_and_insert(
output_file = tei_bib_file,
log_dir = temp_dir / "log"
)
run_xslt(
tei_file,
BASE_DIR / "stylesheets/insert_bibliography.xsl",
params = [ f"tei_bib_file={tei_bib_file.absolute()}" ],
output_file = tei_with_bibl_file
)

if __name__ == '__main__':

Expand Down Expand Up @@ -200,26 +194,53 @@ def create_bibl_and_insert(
output_dir,
# ignore = ignore_patterns( tei_file_input ) if not(tei_file_input . is_absolute()) else None
)
tei_with_bibl_file = \
(output_dir / (tei_file.with_suffix("").name + "_with_bibl")) . with_suffix( ".xml" )
if publ_info["publ_type"] == "monograph":
create_bibl_and_insert(
# create bibliography in tei format:
tei_bib_file = \
(output_dir/ "bibliography/bibliography_all") . with_suffix(".tei")
create_bibl(
tei_tree,
publ_info = publ_info,
temp_dir = output_dir / "temp/all",
tei_bib_file = (output_dir/ "bibliography/bibliography_all") . with_suffix(".tei"),
tei_bib_file = tei_bib_file,
tei_file = tei_file,
tei_with_bibl_file = (output_dir / (tei_file.with_suffix("").name + "_with_bibl")) . with_suffix( ".xml" )
# tei_with_bibl_file = tei_with_bibl_file
)
# insert bibliography:
run_xslt(
tei_file,
BASE_DIR / "stylesheets/insert_bibliography.xsl",
params = [ f"tei_bib_files={tei_bib_file.absolute()}" ],
output_file = tei_with_bibl_file
)
elif publ_info["publ_type"] == "anthology":
for chap_node in tei_tree.xpath("//tei:body//tei:div[@type = 'chapter']"):

chapter_id = chap_node.xpath("@xml:id", namespaces=NS_MAP)
create_bibl_and_insert(
tei_tree,
all_chapter_bibl_filepaths = []
# for every chapter:
for chap_node in tei_tree.xpath("//tei:body//tei:div[@type = 'chapter']", namespaces = NS_MAP):

chapter_id = chap_node.xpath("@xml:id", namespaces=NS_MAP)[0]
logging.info( f"creating bibliography for chapter: {chapter_id}" )
# create bibliography in tei format:
tei_bib_file = (output_dir/ f"bibliography/bibliography_chap_{chapter_id}") . with_suffix(".tei")
create_bibl(
chap_node,
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 = tei_bib_file,
tei_file = tei_file,
tei_with_bibl_file = (output_dir / (tei_file.with_suffix("").name + "_with_bibl")) . with_suffix( ".xml" ),
)
all_chapter_bibl_filepaths += [tei_bib_file]
# insert bibliography:
all_teibibs_arg = ";".join(
[str(f.absolute()) for f in all_chapter_bibl_filepaths]
)
run_xslt(
tei_file,
BASE_DIR / "stylesheets/insert_bibliography.xsl",
params = [ f"tei_bib_files={all_teibibs_arg}" ],
output_file = tei_with_bibl_file
)
else:
raise( Exception("unknown publication type!"))
2 changes: 1 addition & 1 deletion src/utils/bib2html.py
Expand Up @@ -424,5 +424,5 @@ def teibib_to_eoa1(
language = translations[language],
temp_dir = args.temp_dir
)
print( etree.tostring( references_in_html ) )
# print( etree.tostring( references_in_html ) )
# finis

0 comments on commit 380d7af

Please sign in to comment.