source: TI01-discovery/trunk/ingestAutomation/OAIBatch/People.py @ 3785

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/trunk/ingestAutomation/OAIBatch/People.py@3785
Revision 3785, 4.6 KB checked in by selatham, 11 years ago (diff)

gather required utilities. improve elementree imports in keywordAdder. put host etc in arguments for oai_ingest.

Line 
1from Utilities import wrapGetText
2from ETxmlView import nsdumb
3from htmlUtilities import *
4
5class Name:
6        ''' Handles the name type in MOLES '''
7        def __init__(self,element):
8                if element is None:
9                        self.name=''
10                        return
11                if wrapGetText(element,'nameOrder')=='L2R':
12                        o=('title','initials','familyName')
13                else:
14                        o=('title','familyName','personalName')
15                self.name=''
16                for i in o: self.name+=' '+ wrapGetText(element,i)
17        def __str__(self):
18                return self.name
19       
20       
21class contact:
22        ''' Handles the basic content for a person or organisation '''
23        def __init__(self):
24            ''' Instantiates a basic contact and html to represent it. Here, for
25            presentation purposes we assume that a contact consists of
26               personName (for a person can be a name or a role holder description or both)
27               personEmail addresss (for a person)
28               personPhone (number for a person)
29               searchlink (to search something on things by this contact)
30               orgName (organisation name)
31               orgURL
32                 ... for presentation we figure further org contacts can be found by following the link which ought to exist) '''
33            self.data={'personName':Name(None),'personEmail':'','personPhone':'','orgURL':'','orgName':'','searchlink':''}
34        def toHTML(self,prefix=''):
35            print self.data
36            if self.elem is None: return ''
37            html=prefix #para start?
38            if self.data['personName'].name!='':
39                if self.data['personEmail']!='':
40                    html+=hyperlink(self.data['personName'].name,self.data['personEmail'])
41                else:
42                    html+=self.data['personName'].name
43            br=''
44            if html!='': br='<br/>' #only need a linebreak if there is already content ... or '<p>
45            if self.data['orgName']!='':
46                html+=br+hyperlink(self.data['orgName'],self.data['orgURL'])
47            if self.data['personPhone']!='': html+='<br/>Phone: %s'%self.data['personPhone']
48            if self.data['searchlink']!='': html+='<br/>'+self.data['searchlink']
49            html+='' # para end?
50            return html
51       
52       
53class dgContact(contact):
54        '''A simple summary of contact information for an organisation or a person '''
55        #want to contract organisations and people into one simple type here ...
56        #This is moles 1.2.3 ... hopefully we can improve this ...
57        def __init__(self,element,ctype='organisation'):
58                ''' Instantiate a MOLES contact element '''
59                self.elem=element
60                contact.__init__(self)
61                if self.elem is None: return
62                self.data['personName']=Name(self.elem.find('dgRoleHolder/dgPerson/name'))
63                if ctype=='organisation':
64                        base='dgRoleHolder/organisation/'
65                else:
66                        base='dgRoleHolder/dgPerson/'
67                self.data['orgName']=wrapGetText(self.elem,base+'name')
68                self.data['personEmail']=wrapGetText(self.elem,base+'contactDetails/eMail')
69                self.data['personPhone']=wrapGetText(self.elem,'contactDetails/telephone')
70                self.data['orgURL']=wrapGetText(self.elem,'contactDetails/URI')
71       
72class DIFcontact(contact):
73    def __init__(self,elem,ctype='centre',helper=None):
74        if helper is None: helper=nsdumb()
75        self.elem=elem
76        contact.__init__(self)
77        if self.elem is None: return
78        if ctype=='centre':
79            self.data['orgName']=helper.getText(self.elem,'Data_Center_Name/Short_Name')
80            self.data['orgURL']=helper.getText(self.elem,'Data_Center_URL')
81        else:
82            self.data['personName'].name='Placeholder'
83           
84           
85class DIFAuthors:
86    ''' Attempt to get dataset authorship information from a DIF '''
87    def __init__(self,elem,helper=None):
88        if helper is None: helper=nsdumb()
89        # first try for an investigator in the personnel section
90        authors=['Investigator','Dataset_Creator','Dataset_Author']
91        people=helper.findall(elem,'Personnel')
92        a,e='',''
93        people=helper.findall(elem,'Personnel')
94        for p in people:
95            role=helper.getText(p,'Role')
96            if role=='Investigator':
97                a+='%s, %s;'%(helper.getText(p,'Last_Name'),helper.getText(p,'First_Name'))
98                e=helper.getText(p,'Email')
99        if a!='':a=a[0:-1]
100        if a=='':
101            # carry on looking in the citation element instead
102            a=helper.getText(elem,'Data_Set_Citation/Dataset_Creator')
103        self.authors,self.email=a,e
104    def __str__(self):
105        return self.authors
106   
107           
108           
Note: See TracBrowser for help on using the repository browser.