Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial commit
- Loading branch information
Klaus Thoden
committed
Feb 11, 2016
1 parent
57540c0
commit 015837e
Showing
120 changed files
with
30,576 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,315 @@ | ||
import re | ||
class Bibitem: | ||
|
||
# TODO: Interne Funktion, um° durch Leerzeichen zu ersetzen | ||
# TODO: Eine Lösung finden, für Autoren die nur aus einem Namen bestehen, ie keinen Vornamen haben | ||
|
||
def __init__(self,xmlEntry): | ||
self.xmlEntry = xmlEntry | ||
|
||
def sanitize(self,strString): | ||
strString = re.sub("°", " ", strString) | ||
return strString | ||
|
||
def gettext(self,xmlElement): | ||
xmlText = xmlElement.text or "" | ||
for xmlChild in xmlElement: | ||
xmlText += self.gettext(xmlChild) | ||
if xmlChild.tail: | ||
xmlText += xmlChild.tail | ||
return xmlText | ||
|
||
def citekey(self): | ||
xmlEntry = self.xmlEntry | ||
xmlLabel = xmlEntry.find(".//label") | ||
if xmlLabel is not None: | ||
return xmlLabel.text | ||
else: | ||
return None | ||
|
||
def entrytype(self): | ||
strType = self.xmlEntry.find(".//type").text | ||
return strType | ||
|
||
def title(self): | ||
xmlTitle = self.xmlEntry.find(".//title") | ||
if xmlTitle is not None: | ||
strTitle = xmlTitle.text | ||
return strTitle | ||
else: | ||
return "" | ||
|
||
def addendum(self): | ||
xmlAddendum = self.xmlEntry.find(".//addendum") | ||
if xmlAddendum is not None: | ||
return xmlAddendum.text | ||
else: | ||
return "" | ||
|
||
def volume(self): | ||
xmlVolume = self.xmlEntry.find(".//volume") | ||
if xmlVolume is not None: | ||
strResult = " Vol. " + xmlVolume.text + ". " | ||
return strResult | ||
else: | ||
return "" | ||
|
||
def volumenumeric(self): | ||
xmlVolume = self.xmlEntry.find(".//volume") | ||
if xmlVolume is not None: | ||
strResult = " " + xmlVolume.text + ". " | ||
return strResult | ||
else: | ||
return "" | ||
|
||
|
||
def series(self): | ||
xmlSeries = self.xmlEntry.find(".//series") | ||
if xmlSeries is not None: | ||
if xmlSeries.text is not None: | ||
strResult = " " + xmlSeries.text + ". " | ||
return strResult | ||
else: | ||
return "" | ||
else: | ||
return "" | ||
|
||
def journaltitle(self): | ||
xmlJournaltitle = self.xmlEntry.find(".//journaltitle") | ||
if xmlJournaltitle is not None: | ||
strResult = " <i>" + str(xmlJournaltitle.text) + "</i> " | ||
return strResult | ||
else: | ||
return "" | ||
|
||
def booktitle(self): | ||
xmlBooktitle = self.xmlEntry.find(".//booktitle") | ||
if xmlBooktitle is not None: | ||
strResult = " In: <i>" + xmlBooktitle.text + "</i> " | ||
return strResult | ||
else: | ||
return "" | ||
|
||
def volumenumberpages(self): | ||
xmlVolume = self.xmlEntry.find(".//volume") | ||
xmlPages = self.xmlEntry.find(".//pages") | ||
xmlNumber = self.xmlEntry.find("number") | ||
strResult = "" | ||
if xmlVolume is not None and xmlNumber is not None and xmlPages is not None and xmlPages.text is not None: | ||
strResult = xmlVolume.text + "(" + xmlNumber.text + "): " + xmlPages.text | ||
if xmlVolume is not None and xmlNumber is None and xmlPages is not None: | ||
strResult = xmlVolume.text + ": " + xmlPages.text | ||
return strResult | ||
|
||
def location(self): | ||
xmlLocation = self.xmlEntry.find(".//location") | ||
if xmlLocation is not None: | ||
xmlPublisher = self.xmlEntry.find(".//publisher") | ||
if xmlPublisher is not None: | ||
strResult = " " + xmlLocation.text + ": " + self.gettext(xmlPublisher) | ||
else: | ||
strResult = " " + xmlLocation.text | ||
return strResult | ||
else: | ||
return "" | ||
|
||
def howpublished(self): | ||
xmlHowpublished = self.xmlEntry.find(".//howpublished") | ||
if xmlHowpublished is not None: | ||
strResult = xmlHowpublished.text | ||
return strResult | ||
else: | ||
return "" | ||
|
||
|
||
def pages(self): | ||
xmlPages = self.xmlEntry.find(".//pages") | ||
if xmlPages is not None: | ||
strResult = " " + xmlPages.text | ||
return strResult | ||
else: | ||
return "" | ||
|
||
def thesistype(self): | ||
xmlTypes = self.xmlEntry.findall(".//type") | ||
strThesisType = " " + xmlTypes[1].text + ". " | ||
return strThesisType | ||
|
||
def institution(self): | ||
xmlInstitution = self.xmlEntry.find(".//institution") | ||
if xmlInstitution is not None: | ||
strInstitution = xmlInstitution.text | ||
return strInstitution | ||
else: | ||
return "" | ||
|
||
def labelyear(self): | ||
xmlEntry = self.xmlEntry | ||
xmlEdition = xmlEntry.find(".//labelyear") | ||
if xmlEdition is not None: | ||
return xmlEdition.text | ||
else: | ||
# If no year is given, return empty string | ||
return "" | ||
|
||
def year(self): | ||
xmlEntry = self.xmlEntry | ||
xmlYear = xmlEntry.find(".//year") | ||
if xmlYear is not None: | ||
return xmlYear.text | ||
else: | ||
return "" | ||
|
||
def labelyearsuffix(self): | ||
xmlEntry = self.xmlEntry | ||
xmlExtrayear = xmlEntry.find(".//extrayear") | ||
if xmlExtrayear is not None: | ||
intExtrayear = int(xmlExtrayear.text) | ||
listCharacters = ["","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] | ||
strLabelYearSuffix = listCharacters[intExtrayear] | ||
return strLabelYearSuffix | ||
else: | ||
return "" | ||
|
||
def fullauthorlastfirst(self): | ||
xmlEntry = self.xmlEntry | ||
# If no Name is given, return either the Shorthand or the Title (Shorthand prefererred) | ||
if xmlEntry.find(".//labelname/number") == None: | ||
if xmlEntry.find(".//shorthand") is not None: | ||
strComplete = xmlEntry.find(".//shorthand").text | ||
return strComplete | ||
else: | ||
strComplete = self.title() | ||
return strComplete | ||
intNumberOfAuthors = int(xmlEntry.find(".//labelname/number").text) | ||
if intNumberOfAuthors == 1: | ||
xmlAuthorRows = xmlEntry.findall(".//labelname/mrow/mrow") | ||
strLastName = xmlAuthorRows[0].text | ||
if len(xmlAuthorRows) > 3: | ||
strFirstName = xmlAuthorRows[2].text | ||
strCompleteName = strLastName + ", " + strFirstName | ||
return self.sanitize(strCompleteName) | ||
else: | ||
return self.sanitize(strLastName) | ||
if intNumberOfAuthors > 1: | ||
xmlAuthorRows = xmlEntry.findall(".//labelname/mrow/mrow/mrow") | ||
# First Author here would be Lastname, Firstname | ||
strLastName = xmlAuthorRows[0].text | ||
strFirstName = xmlAuthorRows[2].text | ||
strCompleteName = strLastName + ", " + strFirstName | ||
# Remaining Authors are to be Firstname Lastname | ||
for i in range(0, (intNumberOfAuthors - 1)): | ||
a = i + 4 | ||
strLastName = "" | ||
strFirstName = "" | ||
if len(xmlAuthorRows) > a: | ||
strLastName = xmlAuthorRows[a].text | ||
a = i + 6 | ||
if len(xmlAuthorRows) > a: | ||
strFirstName = xmlAuthorRows[a].text | ||
strCompleteName = strCompleteName + ", " + strFirstName + " " + strLastName | ||
return self.sanitize(strCompleteName) | ||
|
||
def fullauthorfirstlast(self): | ||
xmlEntry = self.xmlEntry | ||
# If no Name is given, return either the Shorthand or the Title (Shorthand prefererred) | ||
if xmlEntry.find(".//labelname/number") == None: | ||
if xmlEntry.find(".//shorthand") is not None: | ||
strComplete = xmlEntry.find(".//shorthand").text | ||
return strComplete | ||
else: | ||
strComplete = self.title() | ||
return strComplete | ||
intNumberOfAuthors = int(xmlEntry.find(".//labelname/number").text) | ||
if intNumberOfAuthors == 1: | ||
xmlAuthorRows = xmlEntry.findall(".//labelname/mrow/mrow") | ||
strLastName = xmlAuthorRows[0].text | ||
if len(xmlAuthorRows) > 3: | ||
strFirstName = xmlAuthorRows[2].text | ||
strCompleteName = strFirstName + " " + strLastName | ||
return self.sanitize(strCompleteName) | ||
else: | ||
return self.sanitize(strLastName) | ||
if intNumberOfAuthors > 1: | ||
xmlAuthorRows = xmlEntry.findall(".//labelname/mrow/mrow/mrow") | ||
# First Author here would be Lastname, Firstname | ||
strLastName = xmlAuthorRows[0].text | ||
strFirstName = xmlAuthorRows[2].text | ||
strCompleteName = strFirstName + " " + strLastName | ||
# Remaining Authors are to be Firstname Lastname | ||
for i in range(0, (intNumberOfAuthors - 1)): | ||
a = i + 4 | ||
strLastName = "" | ||
strFirstName = "" | ||
if len(xmlAuthorRows) > a: | ||
strLastName = xmlAuthorRows[a].text | ||
a = i + 6 | ||
if len(xmlAuthorRows) > a: | ||
strFirstName = xmlAuthorRows[a].text | ||
strCompleteName = strCompleteName + ", " + strFirstName + " " + strLastName | ||
return self.sanitize(strCompleteName) | ||
|
||
def shortauthor(self): | ||
xmlEntry = self.xmlEntry | ||
# If no Name is given, return either the Shorthand or the Title (Shorthand prefererred) | ||
if xmlEntry.find(".//labelname/number") == None: | ||
if xmlEntry.find(".//shorthand") is not None: | ||
strComplete = xmlEntry.find(".//shorthand").text | ||
return strComplete | ||
else: | ||
#strComplete = xmlEntry.find(".//title").text | ||
strComplete = self.title() | ||
return strComplete | ||
intNumberOfAuthors = int(xmlEntry.find(".//labelname/number").text) | ||
if intNumberOfAuthors == 1: | ||
xmlAuthorRows = xmlEntry.findall(".//labelname/mrow/mrow") | ||
strLastName = xmlAuthorRows[0].text | ||
return self.sanitize(strLastName) | ||
if intNumberOfAuthors == 2: | ||
xmlAuthorRows = xmlEntry.findall(".//labelname/mrow/mrow/mrow") | ||
strLastName1 = xmlAuthorRows[0].text | ||
if len(xmlAuthorRows) > 5: | ||
strLastName2 = xmlAuthorRows[4].text | ||
else: | ||
strLastName2 = "" | ||
strCompleteName = strLastName1 + " and " + strLastName2 | ||
return self.sanitize(strCompleteName) | ||
if intNumberOfAuthors > 2: | ||
xmlAuthorRows = xmlEntry.findall(".//labelname/mrow/mrow/mrow") | ||
strLastName1 = xmlAuthorRows[0].text | ||
strCompleteName = strLastName1 + " et.al." | ||
return self.sanitize(strCompleteName) | ||
|
||
def editor(self): | ||
xmlEntry = self.xmlEntry | ||
# If no Name is given, return either the Shorthand or the Title (Shorthand prefererred) | ||
if xmlEntry.find(".//editor/number") is None: | ||
return "" | ||
intNumberOfEditors = int(xmlEntry.find(".//editor/number").text) | ||
if intNumberOfEditors == 1: | ||
xmlEditorRows = xmlEntry.findall(".//editor/mrow/mrow") | ||
strLastName = xmlEditorRows[0].text | ||
if len(xmlEditorRows) > 3: | ||
strFirstName = xmlEditorRows[2].text | ||
strCompleteName = "Ed. by " + strFirstName + " " + strLastName + "." | ||
return self.sanitize(strCompleteName) | ||
else: | ||
return self.sanitize(strLastName) | ||
if intNumberOfEditors > 1: | ||
xmlEditorRows = xmlEntry.findall(".//editor/mrow/mrow/mrow") | ||
strLastName = xmlEditorRows[0].text | ||
strFirstName = xmlEditorRows[2].text | ||
strCompleteName = "Ed. by " + strFirstName + " " + strLastName | ||
for i in range(0, (intNumberOfEditors - 1)): | ||
a = i + 4 | ||
strLastName = "" | ||
strFirstName = "" | ||
if len(xmlEditorRows) > a: | ||
strLastName = xmlEditorRows[a].text | ||
a = i + 6 | ||
if len(xmlEditorRows) > a: | ||
strFirstName = xmlEditorRows[a].text | ||
strCompleteName = strCompleteName + ", " + strFirstName + " " + strLastName | ||
strCompleteName = strCompleteName + "." | ||
return self.sanitize(strCompleteName) | ||
|
Oops, something went wrong.