[TASK] Add memberships with appropriate business_role labels.
Also add acronyms for organizations.
This commit is contained in:
parent
2192686872
commit
b37360c97d
106
triplify.py
106
triplify.py
|
@ -25,13 +25,14 @@ class HsHMembership(Base):
|
|||
__tablename__ = 'membership'
|
||||
id = Column(Integer, primary_key=True)
|
||||
person = Column(Integer, ForeignKey('person.id'))
|
||||
organizational_unit = Column(Integer)
|
||||
organizational_unit = Column(Integer, ForeignKey('organizational_unit.id'))
|
||||
start_date = Column(DateTime)
|
||||
end_date = Column(DateTime)
|
||||
active = Column(String)
|
||||
business_role = Column(Integer, ForeignKey('business_role.id'))
|
||||
mPerson = relationship("HsHPerson")
|
||||
mBusinessRole = relationship("HsHBusinessRole")
|
||||
mOrg = relationship("HsHOrganizationalUnit")
|
||||
|
||||
class HsHBusinessRole(Base):
|
||||
__tablename__ = 'business_role'
|
||||
|
@ -74,8 +75,9 @@ vcard = Namespace('http://www.w3.org/2006/vcard/ns#')
|
|||
obo = Namespace('http://purl.obolibrary.org/obo/')
|
||||
hsh = Namespace('http://vivo.bib.hs-hannover.de/ontology/hshOntologie#')
|
||||
|
||||
localPerson = Namespace('http://vivo.bib.hs-hannover.de/individual/person')
|
||||
localOrg = Namespace('http://vivo.bib.hs-hannover.de/individual/org')
|
||||
localPerson = Namespace('http://vivo.bib.hs-hannover.de/individual/p')
|
||||
localOrg = Namespace('http://vivo.bib.hs-hannover.de/individual/o')
|
||||
localMembership = Namespace('http://vivo.bib.hs-hannover.de/individual/m')
|
||||
|
||||
def get_graph():
|
||||
"""Small little helper to create graph with namespaces ;-)"""
|
||||
|
@ -88,6 +90,7 @@ def get_graph():
|
|||
g.bind('obo', obo)
|
||||
g.bind('localperson', localPerson)
|
||||
g.bind('localorg', localOrg)
|
||||
g.bind('localMembership', localMembership)
|
||||
g.bind('hsh', hsh)
|
||||
return g
|
||||
|
||||
|
@ -128,6 +131,42 @@ class Organization(hshThing):
|
|||
rdf_type = foaf.Organization
|
||||
label = rdfSingle(RDFS.label)
|
||||
parentOe = rdfSingle(obo.BFO_0000050)
|
||||
acronym = rdfSingle(vivo.abbreviation)
|
||||
|
||||
class OboMembership(Thing):
|
||||
rdf_type = obo.BFO_0000020
|
||||
|
||||
class Membership(OboMembership):
|
||||
rdf_type = vivo.Position
|
||||
label = rdfSingle(RDFS.label)
|
||||
person = rdfSingle(vivo.relates)
|
||||
organization = rdfSingle(vivo.relates)
|
||||
dateTimeInterval = rdfSingle(vivo.dateTimeInterval)
|
||||
|
||||
class FacultyPosition(Membership):
|
||||
rdf_type = vivo.FacultyPosition
|
||||
|
||||
class NonFacultyPosition(Membership):
|
||||
rdf_type = vivo.NonFacultyPosition
|
||||
|
||||
class NonAcademicPosition(Membership):
|
||||
rdf_type = vivo.NonAcademicPosition
|
||||
|
||||
class OboDateTimeInterval(Thing):
|
||||
rdf_type = obo.BFO_0000038
|
||||
|
||||
class DateTimeInterval(OboDateTimeInterval):
|
||||
rdf_type = vivo.DateTimeInterval
|
||||
start = rdfSingle(vivo.start)
|
||||
end = rdfSingle(vivo.end)
|
||||
|
||||
class OboDateTimeValue(Thing):
|
||||
rdf_type = obo.BFO_0000148
|
||||
|
||||
class DateTimeValue(OboDateTimeValue):
|
||||
rdf_type = vivo.DateTimeValue
|
||||
dateTime = rdfSingle(vivo.dateTime)
|
||||
dateTimePrecision = rdfSingle(vivo.dateTimePrecision)
|
||||
|
||||
class IdSequence:
|
||||
"""Small Helper for easy sequences"""
|
||||
|
@ -148,7 +187,7 @@ def addPersonToGraph(sqlP, additionalIdSeq):
|
|||
else:
|
||||
combined_title += ' ' + sqlP.title_suffix
|
||||
|
||||
person_uri = URIRef("%s/%s" % (localPerson, sqlP.id))
|
||||
person_uri = URIRef("%s%s" % (localPerson, sqlP.id))
|
||||
hshThing(person_uri)
|
||||
rdfP = Person(person_uri) #WTF?!
|
||||
rdfP.firstname = sqlP.firstname;
|
||||
|
@ -156,11 +195,11 @@ def addPersonToGraph(sqlP, additionalIdSeq):
|
|||
rdfP.label = "%s, %s" % (sqlP.name, sqlP.firstname)
|
||||
# If there is a title to add, do it.
|
||||
if(combined_title != ''):
|
||||
title_uri = URIRef("%s/%s" % (localPerson, additionalIdSeq.getNext()))
|
||||
title_uri = URIRef("%s%s" % (localPerson, additionalIdSeq.getNext()))
|
||||
rdfTitle = Title(title_uri)
|
||||
rdfTitle.title = combined_title
|
||||
|
||||
contact_info_uri = URIRef("%s/%s" % (localPerson, additionalIdSeq.getNext()))
|
||||
contact_info_uri = URIRef("%s%s" % (localPerson, additionalIdSeq.getNext()))
|
||||
rdfCi = ContactInfo(contact_info_uri)
|
||||
rdfCi.hasTitle = rdfTitle
|
||||
rdfCi.contactInformationFor = rdfP
|
||||
|
@ -168,6 +207,45 @@ def addPersonToGraph(sqlP, additionalIdSeq):
|
|||
rdfP.hasContactInfo = rdfCi
|
||||
return person_uri
|
||||
|
||||
def processMembership(membership, additionalIdSeq):
|
||||
#create membership
|
||||
membershipUri = URIRef("%s%s" % (localMembership, membership.id))
|
||||
personUri = URIRef("%s%s" % (localPerson, membership.mPerson.id))
|
||||
organizationUri = URIRef("%s%s" % (localOrg, membership.mOrg.id))
|
||||
|
||||
dtiUri = URIRef("%s%s" % (localMembership, additionalIdSeq.getNext()))
|
||||
dtsUri = URIRef("%s%s" % (localMembership, additionalIdSeq.getNext()))
|
||||
dteUri = URIRef("%s%s" % (localMembership, additionalIdSeq.getNext()))
|
||||
|
||||
rdfM = OboMembership(membershipUri)
|
||||
rdfM = Membership(membershipUri)
|
||||
rdfM.label = membership.mBusinessRole.name
|
||||
rdfM.person = personUri
|
||||
rdfM.organization = organizationUri
|
||||
rdfM.dateTimeInterval = dtiUri
|
||||
|
||||
if membership.mBusinessRole.name == "ProfessorIn":
|
||||
rdfM = FacultyPosition(membershipUri)
|
||||
elif membership.mBusinessRole.name == "WiMi":
|
||||
rdfM = NonFacultyPosition(membershipUri)
|
||||
else:
|
||||
rdfM = NonAcademicPosition(membershipUri)
|
||||
|
||||
rdfDts = OboDateTimeValue(dtsUri)
|
||||
rdfDts = DateTimeValue(dtsUri)
|
||||
rdfDts.dateTime = membership.start_date
|
||||
rdfDts.dateTimePrecision = vivo.yearPrecision
|
||||
|
||||
rdfDte = OboDateTimeValue(dteUri)
|
||||
rdfDte = DateTimeValue(dteUri)
|
||||
rdfDte.dateTime = membership.end_date
|
||||
rdfDte.dateTimePrecision = vivo.yearPrecision
|
||||
|
||||
rdfDti = OboDateTimeInterval(dtiUri)
|
||||
rdfDti = DateTimeInterval(dtiUri)
|
||||
rdfDti.start = dtsUri
|
||||
rdfDti.end = dteUri
|
||||
|
||||
def processPersons(session, additionalIdSeq):
|
||||
"""Fetch persons, create triples for them."""
|
||||
persons = session.query(HsHPerson)
|
||||
|
@ -186,34 +264,36 @@ def processPersons(session, additionalIdSeq):
|
|||
if membership.active != 'Y':
|
||||
continue #SKIP INACTIVE MEMBERSHIPS!
|
||||
|
||||
processMembership(membership, additionalIdSeq)
|
||||
|
||||
#This is an active membership with an id and a business_role.
|
||||
if membership.mBusinessRole.name == 'ProfessorIn':
|
||||
isNonAcademic = False
|
||||
organization_uri = URIRef("%s/%s" % (localOrg, membership.organizational_unit))
|
||||
organization_uri = URIRef("%s%s" % (localOrg, membership.organizational_unit))
|
||||
rdfP = FacultyMember(personUri)
|
||||
rdfP.associatedOe = organization_uri
|
||||
|
||||
if membership.mBusinessRole.name == 'WiMi':
|
||||
elif membership.mBusinessRole.name == 'WiMi':
|
||||
isNonAcademic = False
|
||||
organization_uri = URIRef("%s/%s" % (localOrg, membership.organizational_unit))
|
||||
organization_uri = URIRef("%s%s" % (localOrg, membership.organizational_unit))
|
||||
rdfP = NonFacultyAcademic(personUri)
|
||||
rdfP.associatedOe = organization_uri
|
||||
|
||||
#assign non-academic person type if neccessary
|
||||
if isNonAcademic:
|
||||
NonAcademic(personUri)
|
||||
pass
|
||||
|
||||
def processOrganizations(session, additionalIdSeq):
|
||||
"""Generate triples for organizational units."""
|
||||
organizations = session.query(HsHOrganizationalUnit)
|
||||
for count, sqlO in enumerate(organizations):
|
||||
organization_uri = URIRef("%s/%s" % (localOrg, sqlO.id))
|
||||
organization_uri = URIRef("%s%s" % (localOrg, sqlO.id))
|
||||
rdfO = hshThing(organization_uri)
|
||||
rdfO = Organization(organization_uri)
|
||||
rdfO.label = sqlO.name
|
||||
if sqlO.acronym != None:
|
||||
rdfO.acronym = sqlO.acronym
|
||||
if sqlO.oParent != None:
|
||||
parent_organization_uri = URIRef("%s/%s" % (localOrg, sqlO.oParent.id))
|
||||
parent_organization_uri = URIRef("%s%s" % (localOrg, sqlO.oParent.id))
|
||||
rdfO.parentOe = parent_organization_uri
|
||||
|
||||
def createTriples():
|
||||
|
|
Loading…
Reference in New Issue