Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fill header with more dummy data
  • Loading branch information
Klaus Thoden committed Nov 21, 2018
1 parent 53580f8 commit 82b9718
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions fix_tei.py
Expand Up @@ -59,19 +59,6 @@
BOILERPLATES = configparser.ConfigParser() BOILERPLATES = configparser.ConfigParser()
BOILERPLATES.read(TEI_BOILERPLATE) BOILERPLATES.read(TEI_BOILERPLATE)


def get_place_in_xml_tree(element, tree):
"""Find out the position of an element in a tree.
Return the index. Example: how to insert an element after a specific
element
"""

xml_children = tree.getchildren()
position = xml_children.index(element)

return position
# def get_place_in_xml_tree ends here

def parse_bibtex(bibfile): def parse_bibtex(bibfile):
"""Parse the bibtex file, return a dict""" """Parse the bibtex file, return a dict"""


Expand Down Expand Up @@ -383,6 +370,23 @@ def fix_tei_header(xml_tree, bibfile_string, bibtype):
else: else:
pass pass


author_element = title_statement.find("t:author", namespaces=NS_MAP)
author_element.tag = "editor"
author_element.set("n", "1")
author_element.set("ref", "#nn")
author_element.set("role", "volumeeditor")
author_element.set("key", "eoa_00")
author_element.text = "N.N."

example_resp = etree.Element("respStmt")
example_resp.attrib["{http://www.w3.org/XML/1998/namespace}id"] = "nn"
respresp = etree.SubElement(example_resp, "resp")
respresp.text = "chapter author"
respname = etree.SubElement(example_resp, "persName")
surname = etree.SubElement(respname, "surname").text = "N"
forename = etree.SubElement(respname, "forename").text = "N"
libeoaconvert.insert_after(example_resp, author_element)

edition = xml_tree.xpath("//t:editionStmt/t:edition", namespaces=NS_MAP)[0] edition = xml_tree.xpath("//t:editionStmt/t:edition", namespaces=NS_MAP)[0]
edition_date = edition.find("t:date", namespaces=NS_MAP) edition_date = edition.find("t:date", namespaces=NS_MAP)
edition_date.clear() edition_date.clear()
Expand All @@ -395,6 +399,11 @@ def fix_tei_header(xml_tree, bibfile_string, bibtype):
unknown_paragraph.clear() unknown_paragraph.clear()
unknown_paragraph.tag = "tagtobestripped" unknown_paragraph.tag = "tagtobestripped"


extent_element = etree.Element("extent")
pages = etree.SubElement(extent_element, "measure", commodity="pages", quantity="0")
price = etree.SubElement(extent_element, "measure", type="price", unit="EUR", quantity="0")
libeoaconvert.insert_after(extent_element, publication_statement, before=True)

publisher_element = etree.SubElement(publication_statement, "publisher") publisher_element = etree.SubElement(publication_statement, "publisher")
overall_org = etree.SubElement(publisher_element, "orgName", n="EOA", ref=BOILERPLATES.get("Header","eoa_url")) overall_org = etree.SubElement(publisher_element, "orgName", n="EOA", ref=BOILERPLATES.get("Header","eoa_url"))
overall_org.text = BOILERPLATES.get("Header","eoa_name") overall_org.text = BOILERPLATES.get("Header","eoa_name")
Expand All @@ -408,14 +417,14 @@ def fix_tei_header(xml_tree, bibfile_string, bibtype):


# series statement # series statement
series_stmt = etree.Element("seriesStmt") series_stmt = etree.Element("seriesStmt")
title_element = etree.SubElement(series_stmt, "title").text = "Series title" title_element = etree.SubElement(series_stmt, "title").text = "Series_title"
resp_stmt = etree.SubElement(series_stmt, "respStmt") resp_stmt = etree.SubElement(series_stmt, "respStmt")
resp_title = etree.SubElement(resp_stmt, "resp").text = "Series Editors" resp_title = etree.SubElement(resp_stmt, "resp").text = "Series Editors"
resp_names = etree.SubElement(resp_stmt, "name", type="serieseditors") resp_names = etree.SubElement(resp_stmt, "name", type="serieseditors")
resp_names.text = BOILERPLATES.get("Header","mprl_series_editors") resp_names.text = BOILERPLATES.get("Header","mprl_series_editors")
series_number = etree.SubElement(series_stmt, "idno", type="number").text = "number" series_number = etree.SubElement(series_stmt, "idno", type="number").text = "number"
publication_stmt_parent = publication_statement.getparent() publication_stmt_parent = publication_statement.getparent()
series_stmt_insertion_point = get_place_in_xml_tree(publication_statement, publication_stmt_parent) + 1 series_stmt_insertion_point = libeoaconvert.get_place_in_xml_tree(publication_statement, publication_stmt_parent) + 1
publication_stmt_parent.insert(series_stmt_insertion_point, series_stmt) publication_stmt_parent.insert(series_stmt_insertion_point, series_stmt)


source_desc = xml_tree.xpath("//t:sourceDesc", namespaces=NS_MAP)[0] source_desc = xml_tree.xpath("//t:sourceDesc", namespaces=NS_MAP)[0]
Expand All @@ -436,7 +445,7 @@ def fix_tei_header(xml_tree, bibfile_string, bibtype):
list_keywords = etree.SubElement(keywords, "list") list_keywords = etree.SubElement(keywords, "list")
keyword_item = etree.SubElement(list_keywords, "item").text = BOILERPLATES.get("Header","eoa_name") keyword_item = etree.SubElement(list_keywords, "item").text = BOILERPLATES.get("Header","eoa_name")
langusage = etree.SubElement(profile_desc, "langUsage") langusage = etree.SubElement(profile_desc, "langUsage")
language = etree.SubElement(langusage, "language", ident="principal language") language = etree.SubElement(langusage, "language", ident="principal_language")
xml_tree.insert(1, profile_desc) xml_tree.insert(1, profile_desc)


encoding_desc = xml_tree.xpath("//t:encodingDesc", namespaces=NS_MAP)[0] encoding_desc = xml_tree.xpath("//t:encodingDesc", namespaces=NS_MAP)[0]
Expand Down

0 comments on commit 82b9718

Please sign in to comment.