/
publicationinfo.py
131 lines (102 loc) · 4.03 KB
/
publicationinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
"""
Maintain publication information for an abstract
"""
__author__ = 'Rodney L. Summerscales'
import xml
import xmlutil
class PublicationInfo:
""" Contains Journal and author information for an abstract
"""
_journalNode = None
_authorListNode = None
_country = ""
_publicationTypeListNode = None
def __init__(self, pubInfoNode):
""" Parse a PublicationInformation
"""
assert pubInfoNode is not None
assert isinstance(pubInfoNode, xml.dom.minidom.Element)
self._journalNode = None
self._authorListNode = None
self._country = ""
self._publicationTypeListNode = None
journalNodes = pubInfoNode.getElementsByTagName('Journal')
if len(journalNodes) > 0:
self._journalNode = journalNodes[0].cloneNode(deep=True)
countryNodes = pubInfoNode.getElementsByTagName('Country')
if len(countryNodes) > 0:
self._country = xmlutil.getText(countryNodes[0])
authorListNodes = pubInfoNode.getElementsByTagName('AuthorList')
if len(authorListNodes) > 0:
self._authorListNode = authorListNodes[0].cloneNode(deep=True)
publicationTypeListNodes = pubInfoNode.getElementsByTagName('PublicationTypeList')
if len(publicationTypeListNodes) > 0:
self._publicationTypeListNode = publicationTypeListNodes[0].cloneNode(deep=True)
def getCountry(self):
"""
Return the country of publication
"""
return self._country
def getJournal(self):
"""
Return name of journal
"""
if self._journalNode is None:
return ''
journalName = xmlutil.getTextFromNodeCalled('Title', self._journalNode)
return journalName
def getPublicationDate(self):
"""
Return a string with month and year of publication
"""
if self._journalNode is None:
return ''
year = xmlutil.getTextFromNodeCalled('Year', self._journalNode)
return year
def getAuthors(self):
"""
Return list of authors for the abstract
"""
if self._authorListNode is None:
return []
authorNodeList = self._authorListNode.getElementsByTagName('Author')
authorList = []
for authorNode in authorNodeList:
initials = xmlutil.getTextFromNodeCalled('Initials', authorNode)
lastName = xmlutil.getTextFromNodeCalled('LastName', authorNode)
if lastName is "" and initials is "":
# no author name, it could be a collective
collectiveName = xmlutil.getTextFromNodeCalled('CollectiveName', authorNode)
if collectiveName is not "":
authorList.append(collectiveName)
else:
authorList.append('%s %s' % (initials, lastName))
return authorList
def getPublicationTypes(self):
"""
Return list of strings describing the type of publication that the abstract is
"""
if self._publicationTypeListNode is None:
return []
pTypes = []
publicationTypeNodes = self._publicationTypeListNode.getElementsByTagName('PublicationType')
for node in publicationTypeNodes:
pType = xmlutil.getText(node)
if pType is not None and pType is not "":
pTypes.append(pType)
return pTypes
def getXML(self, doc):
"""
Create an XML element with publication information
"""
node = doc.createElement('PublicationInformation')
if self._journalNode is not None:
node.appendChild(self._journalNode)
node.appendChild(xmlutil.createNodeWithTextChild(doc, 'Country', self._country))
if self._authorListNode is not None:
node.appendChild(self._authorListNode)
if self._publicationTypeListNode is not None:
node.appendChild(self._publicationTypeListNode)
xmlutil.normalizeXMLTree(node)
return node