Пример #1
0
def get_name(name_uri):
    """
    Given the uri of a vcard name entity, get all the data values
    associated with the entity
    """
    from vivofoundation import get_triples
    name = {'name_uri': name_uri}
    triples = get_triples(name_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://www.w3.org/2006/vcard/ns#givenName":
            name['given_name'] = o
        if p == "http://www.w3.org/2006/vcard/ns#familyName":
            name['family_name'] = o
        if p == "http://www.w3.org/2006/vcard/ns#additionalName":
            name['additional_name'] = o
        if p == "http://www.w3.org/2006/vcard/ns#honorificPrefix":
            name['honorific_prefix'] = o
        if p == "http://www.w3.org/2006/vcard/ns#honorificSuffix":
            name['honorific_suffix'] = o
        i = i + 1
    return name
Пример #2
0
def get_name(name_uri):
    """
    Given the uri of a vcard name entity, get all the data values
    associated with the entity
    """
    from vivofoundation import get_triples
    name = {'name_uri':name_uri}
    triples = get_triples(name_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://www.w3.org/2006/vcard/ns#givenName":
            name['given_name'] = o
        if p == "http://www.w3.org/2006/vcard/ns#familyName":
            name['family_name'] = o
        if p == "http://www.w3.org/2006/vcard/ns#additionalName":
            name['additional_name'] = o
        if p == "http://www.w3.org/2006/vcard/ns#honorificPrefix":
            name['honorific_prefix'] = o
        if p == "http://www.w3.org/2006/vcard/ns#honorificSuffix":
            name['honorific_suffix'] = o
        i = i + 1
    return name
Пример #3
0
def get_telephone(telephone_uri):
    """
    Given the uri of a telephone number, return the uri, number and type
    """
    from vivofoundation import get_triples
    telephone = {'telephone_uri': telephone_uri}
    type = ""
    triples = get_triples(telephone_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://www.w3.org/2006/vcard/ns#telephone":
            telephone['telephone_number'] = o
        if p == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type":
            if o.startswith('http://www.w3.org/2006/vcard'):
                ptype = o[32:]
                if type == "" or type == "Telephone" and ptype == "Fax" \
                    or ptype == "Telephone":
                    type = ptype
        i = i + 1
    telephone['telephone_type'] = type
    return telephone
Пример #4
0
def get_telephone(telephone_uri):
    """
    Given the uri of a telephone number, return the uri, number and type
    """
    from vivofoundation import get_triples
    telephone = {'telephone_uri':telephone_uri}
    type = ""
    triples = get_triples(telephone_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://www.w3.org/2006/vcard/ns#telephone":
            telephone['telephone_number'] = o
        if p == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type":
            if o.startswith('http://www.w3.org/2006/vcard'):
                ptype = o[32:]
                if type == "" or type == "Telephone" and ptype == "Fax" \
                    or ptype == "Telephone":
                    type = ptype
        i = i + 1
    telephone['telephone_type'] = type
    return telephone
Пример #5
0
def get_vcard(vcard_uri):
    """
    Given the uri of a vcard, get all the data values and uris associated with
    the vcard
    """
    from vivofoundation import get_triples
    from vivofoundation import get_vivo_value
    vcard = {'vcard_uri': vcard_uri}
    vcard['telephone_uris'] = []
    vcard['email_uris'] = []
    triples = get_triples(vcard_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://www.w3.org/2006/vcard/ns#hasTitle":
            vcard['title_uri'] = o
        if p == "http://purl.obolibrary.org/obo/ARG_2000029":
            vcard['person_uri'] = o
        if p == "http://www.w3.org/2006/vcard/ns#hasTelephone":
            vcard['telephone_uris'].append(o)
        if p == "http://www.w3.org/2006/vcard/ns#hasName":
            vcard['name_uri'] = o
        if p == "http://www.w3.org/2006/vcard/ns#hasEmail":
            vcard['email_uris'].append(o)
        i = i + 1

    # And now deref each of the uris to get the data values.

    if 'name_uri' in vcard:
        vcard['name'] = get_name(vcard['name_uri'])

    if vcard.get('title_uri', None) is not None:
        vcard['title'] = get_vivo_value(vcard['title_uri'], 'vcard:title')

    vcard['telephones'] = []
    for telephone_uri in vcard['telephone_uris']:
        vcard['telephones'].append(get_telephone(telephone_uri))
    del vcard['telephone_uris']

    vcard['email_addresses'] = []
    for email_uri in vcard['email_uris']:
        vcard['email_addresses'].append({
            'email_uri':
            email_uri,
            'email_address':
            get_vivo_value(email_uri, "vcard:email")
        })
    del vcard['email_uris']
    return vcard
Пример #6
0
def get_vcard(vcard_uri):
    """
    Given the uri of a vcard, get all the data values and uris associated with
    the vcard
    """
    from vivofoundation import get_triples
    from vivofoundation import get_vivo_value
    vcard = {'vcard_uri':vcard_uri}
    vcard['telephone_uris'] = []
    vcard['email_uris'] = []
    triples = get_triples(vcard_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://www.w3.org/2006/vcard/ns#hasTitle":
            vcard['title_uri'] = o
        if p == "http://purl.obolibrary.org/obo/ARG_2000029":
            vcard['person_uri'] = o
        if p == "http://www.w3.org/2006/vcard/ns#hasTelephone":
            vcard['telephone_uris'].append(o)
        if p == "http://www.w3.org/2006/vcard/ns#hasName":
            vcard['name_uri'] = o
        if p == "http://www.w3.org/2006/vcard/ns#hasEmail":
            vcard['email_uris'].append(o)
        i = i + 1

    # And now deref each of the uris to get the data values.

    if 'name_uri' in vcard:
        vcard['name'] = get_name(vcard['name_uri'])

    if vcard.get('title_uri', None) is not None:
        vcard['title'] = get_vivo_value(vcard['title_uri'],'vcard:title')

    vcard['telephones'] = []
    for telephone_uri in vcard['telephone_uris']:
        vcard['telephones'].append(get_telephone(telephone_uri))
    del vcard['telephone_uris']

    vcard['email_addresses'] = []
    for email_uri in vcard['email_uris']:
        vcard['email_addresses'].append({
            'email_uri':email_uri,
            'email_address':get_vivo_value(email_uri,
                                              "vcard:email")
            })
    del vcard['email_uris']
    return vcard
Пример #7
0
def get_degree(degree_uri):
    """
    Given a URI, return an object that contains the degree (educational
    training) it represents

    """
    from vivofoundation import get_triples
    from vivofoundation import get_vivo_value
    from vivofoundation import get_organization
    from vivofoundation import get_datetime_interval

    degree = {'degree_uri': degree_uri}
    triples = get_triples(degree_uri)
    try:
        count = len(triples["results"]["bindings"])
    except KeyError:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://vivoweb.org/ontology/core#majorField":
            degree['major_field'] = o

        # dereference the academic degree

        if p == "http://vivoweb.org/ontology/core#degreeEarned":
            degree['earned_uri'] = o
            degree['degree_name'] = get_vivo_value(o, 'core:abbreviation')

        # dereference the Institution

        if p == "http://vivoweb.org/ontology/core#trainingAtOrganization":
            degree['training_institution_uri'] = o
            institution = get_organization(o)
            if 'label' in institution:  # home department might be incomplete
                degree['institution_name'] = institution['label']

        # dereference the datetime interval

        if p == "http://vivoweb.org/ontology/core#dateTimeInterval":
            datetime_interval = get_datetime_interval(o)
            degree['datetime_interval'] = datetime_interval
            if 'start_date' in datetime_interval:
                degree['start_date'] = datetime_interval['start_date']
            if 'end_date' in datetime_interval:
                degree['end_date'] = datetime_interval['end_date']
        i += 1
    return degree
Пример #8
0
def get_degree(degree_uri):
    """
    Given a URI, return an object that contains the degree (educational
    training) it represents

    """
    from vivofoundation import get_triples
    from vivofoundation import get_vivo_value
    from vivofoundation import get_organization
    from vivofoundation import get_datetime_interval

    degree = {'degree_uri': degree_uri}
    triples = get_triples(degree_uri)
    try:
        count = len(triples["results"]["bindings"])
    except KeyError:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://vivoweb.org/ontology/core#majorField":
            degree['major_field'] = o

        # dereference the academic degree

        if p == "http://vivoweb.org/ontology/core#degreeEarned":
            degree['earned_uri'] = o
            degree['degree_name'] = get_vivo_value(o, 'core:abbreviation')

        # dereference the Institution

        if p == "http://vivoweb.org/ontology/core#trainingAtOrganization":
            degree['training_institution_uri'] = o
            institution = get_organization(o)
            if 'label' in institution:  # home department might be incomplete
                degree['institution_name'] = institution['label']

        # dereference the datetime interval

        if p == "http://vivoweb.org/ontology/core#dateTimeInterval":
            datetime_interval = get_datetime_interval(o)
            degree['datetime_interval'] = datetime_interval
            if 'start_date' in datetime_interval:
                degree['start_date'] = datetime_interval['start_date']
            if 'end_date' in datetime_interval:
                degree['end_date'] = datetime_interval['end_date']
        i += 1
    return degree
Пример #9
0
def get_person(person_uri, get_contact=True):
    """
    Given the URI of a person in VIVO, get the poerson's attributes and
    return a flat, keyed structure appropriate for update and other
    applications.

    To Do:
    Add get_grants, get_papers, etc as we had previously
    """
    from vivofoundation import get_triples
    person = {'person_uri': person_uri}
    triples = get_triples(person_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == \
           "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType":
            person['person_type'] = o
        if p == "http://purl.obolibrary.org/obo/ARG_2000028":
            person['vcard_uri'] = o
        if p == "http://www.w3.org/2000/01/rdf-schema#label":
            person['display_name'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/ufid":
            person['ufid'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/homeDept":
            person['homedept_uri'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/privacyFlag":
            person['privacy_flag'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/gatorlink":
            person['gatorlink'] = o
        if p == "http://vivoweb.org/ontology/core#eRACommonsId":
            person['eracommonsid'] = o
        i = i + 1

    # deref the vcard

    if get_contact == True:
        person['vcard'] = get_vcard(person['vcard_uri'])

    return person
Пример #10
0
def get_person(person_uri, get_contact=True):
    """
    Given the URI of a person in VIVO, get the poerson's attributes and
    return a flat, keyed structure appropriate for update and other
    applications.

    To Do:
    Add get_grants, get_papers, etc as we had previously
    """
    from vivofoundation import get_triples
    person = {'person_uri': person_uri}
    triples = get_triples(person_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == \
           "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType":
            person['person_type'] = o
        if p == "http://purl.obolibrary.org/obo/ARG_2000028":
            person['vcard_uri'] = o
        if p == "http://www.w3.org/2000/01/rdf-schema#label":
            person['display_name'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/ufid":
            person['ufid'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/homeDept":
            person['homedept_uri'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/privacyFlag":
            person['privacy_flag'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/gatorlink":
            person['gatorlink'] = o
        if p == "http://vivoweb.org/ontology/core#eRACommonsId":
            person['eracommonsid'] = o
        i = i + 1

    # deref the vcard

    if get_contact == True:
        person['vcard'] = get_vcard(person['vcard_uri'])
        
    return person
Пример #11
0
#!/usr/bin/env/python
"""
    show_triples.py -- from the command line show the triples of any uri
    Version 0.1 MC 2014-07-22
     -- works as expected

"""

__author__ = "Michael Conlon"
__copyright__ = "Copyright 2014, University of Florida"
__license__ = "BSD 3-Clause license"
__version__ = "0.1"

import sys
from datetime import datetime
from vivofoundation import get_triples
from vivofoundation import VIVO_URI_PREFIX
import json

#   Start here

print sys.argv[1]
uri = VIVO_URI_PREFIX + sys.argv[1]
print uri
print json.dumps(get_triples(uri), indent=4)

print datetime.now(), "End"
Пример #12
0
def get_grant(grant_uri, get_investigators=False):
    """
    Given a URI, return an object that contains the grant it represents
    """
    from vivofoundation import get_triples
    from vivofoundation import get_organization
    from vivofoundation import get_datetime_interval
    from vivofoundation import get_role

    grant = {'grant_uri':grant_uri}
    grant['contributing_role_uris'] = []
    grant['pi_uris'] = []
    grant['coi_uris'] = []
    grant['inv_uris'] = []
    grant['role_uris'] = {}
    grant['investigators'] = []
    triples = get_triples(grant_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']
        if p == "http://www.w3.org/2000/01/rdf-schema#label":
            grant['title'] = o
        if p == "http://vivoweb.org/ontology/core#totalAwardAmount":
            grant['total_award_amount'] = o
        if p == "http://vivoweb.org/ontology/core#grantDirectCosts":
            grant['grant_direct_costs'] = o
        if p == "http://purl.org/ontology/bibo/abstract":
            grant['abstract'] = o
        if p == "http://vivoweb.org/ontology/core#sponsorAwardId":
            grant['sponsor_award_id'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/dsrNumber":
            grant['dsr_number'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/psContractNumber":
            grant['pcn'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/dateHarvested":
            grant['date_harvested'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/harvestedBy":
            grant['harvested_by'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/localAwardId":
            grant['local_award_id'] = o
        if p == "http://vivoweb.org/ontology/core#contributingRole":
            grant['contributing_role_uris'].append(o['value'])
        
        # deref administered by

        if p == "http://vivoweb.org/ontology/core#administeredBy":
            grant['administered_by_uri'] = o['value']
            administered_by = get_organization(o['value'])
            if 'label' in administered_by:
                grant['administered_by'] = administered_by['label']

        # deref awarded by

        if p == "http://vivoweb.org/ontology/core#grantAwardedBy":
            grant['sponsor_uri'] = o['value']
            awarded_by = get_organization(o['value'])
            if 'label' in awarded_by:
                grant['awarded_by'] = awarded_by['label']

        # deref the datetime interval

        if p == "http://vivoweb.org/ontology/core#dateTimeInterval":
            grant['dti_uri'] = o['value']
            datetime_interval = get_datetime_interval(o['value'])
            grant['datetime_interval'] = datetime_interval
            if 'start_date' in datetime_interval:
                grant['start_date'] = datetime_interval['start_date']
            if 'end_date' in datetime_interval:
                grant['end_date'] = datetime_interval['end_date']

        i = i + 1

    # deref the roles

    for role_uri in grant['contributing_role_uris']:
        role = get_role(role_uri)
        if 'principal_investigator_role_of' in role:
            pi_uri = role['principal_investigator_role_of']
            if pi_uri not in grant['pi_uris']:
                grant['pi_uris'].append(pi_uri)
                grant['role_uris'][pi_uri] = role_uri
        if 'co_principal_investigator_role_of' in role:
            coi_uri = role['co_principal_investigator_role_of']
            if coi_uri not in grant['coi_uris']:
                grant['coi_uris'].append(coi_uri)
                grant['role_uris'][coi_uri] = role_uri
        if 'investigator_role_of' in role:
            inv_uri = role['investigator_role_of']
            if inv_uri not in grant['inv_uris']:
                grant['inv_uris'].append(inv_uri)
                grant['role_uris'][inv_uri] = role_uri

    # deref the investigators

    if get_investigators == True:
        for role_uri in grant['contributing_role_uris']:
            role = get_role(role_uri)
            if 'co_principal_investigator_role_of' in role:
                person = \
                    get_person(role['co_principal_investigator_role_of'])
                person['role'] = 'co_principal_investigator'
                grant['investigators'].append(person)
            if 'principal_investigator_role_of' in role:
                person = \
                    get_person(role['principal_investigator_role_of'])
                person['role'] = 'principal_investigator'
                grant['investigators'].append(person)
            if 'investigator_role_of' in role:
                person = \
                    get_person(role['investigator_role_of'])
                person['role'] = 'investigator'
                grant['investigators'].append(person)
    return grant
Пример #13
0
def get_position(position_uri):
    """
    Given a URI, return an object that contains the position it represents
    """
    from vivofoundation import get_triples
    from vivofoundation import get_types
    from vivofoundation import get_datetime_interval
    from vivofoundation import untag_predicate

    position = {'position_uri': position_uri}  # include position_uri
    triples = get_triples(position_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://vivoweb.org/ontology/core#relates":

            #   deref relates.  Get the types of the referent.  If its an org,
            #   assign the uri of the relates (o) to the org_uri of the
            #   position.  Otherwise, assume its the person_uri

            types = get_types(o)
            if untag_predicate('foaf:Organization') in types:
                position['position_orguri'] = o
            else:
                position['person_uri'] = o

        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/hrJobTitle":
            position['hr_title'] = o
        if p == "http://www.w3.org/2000/01/rdf-schema#label":
            position['position_label'] = o
        if o == "http://vivoweb.org/ontology/core#FacultyPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/core#Non-FacultyAcademicPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/ClinicalFacultyPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/PostDocPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/core#LibrarianPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/core#Non-AcademicPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/StudentAssistant":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/GraduateAssistant":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/Housestaff":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/TemporaryFaculty":
            position['position_type'] = o
        if o == \
            "http://vivoweb.org/ontology/core#FacultyAdministrativePosition":
            position['position_type'] = o
        if p == "http://vivoweb.org/ontology/core#dateTimeInterval":
            position['dti_uri'] = o
            datetime_interval = get_datetime_interval(o)
            position['datetime_interval'] = datetime_interval
            if 'start_date' in datetime_interval:
                position['start_date'] = datetime_interval['start_date']
            if 'end_date' in datetime_interval:
                position['end_date'] = datetime_interval['end_date']
        i = i + 1

    return position
Пример #14
0
def get_position(position_uri):
    """
    Given a URI, return an object that contains the position it represents
    """
    from vivofoundation import get_triples
    from vivofoundation import get_types
    from vivofoundation import get_datetime_interval
    from vivofoundation import untag_predicate
    
    position = {'position_uri':position_uri} # include position_uri
    triples = get_triples(position_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']['value']
        if p == "http://vivoweb.org/ontology/core#relates":

            #   deref relates.  Get the types of the referent.  If its an org,
            #   assign the uri of the relates (o) to the org_uri of the
            #   position.  Otherwise, assume its the person_uri

            types = get_types(o)
            if untag_predicate('foaf:Organization') in types:
                position['position_orguri'] = o
            else:
                position['person_uri'] = o

        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/hrJobTitle":
            position['hr_title'] = o
        if p == "http://www.w3.org/2000/01/rdf-schema#label":
            position['position_label'] = o
        if o == "http://vivoweb.org/ontology/core#FacultyPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/core#Non-FacultyAcademicPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/ClinicalFacultyPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/PostDocPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/core#LibrarianPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/core#Non-AcademicPosition":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/StudentAssistant":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/GraduateAssistant":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/Housestaff":
            position['position_type'] = o
        if o == "http://vivoweb.org/ontology/vivo-ufl/TemporaryFaculty":
            position['position_type'] = o
        if o == \
            "http://vivoweb.org/ontology/core#FacultyAdministrativePosition":
            position['position_type'] = o
        if p == "http://vivoweb.org/ontology/core#dateTimeInterval":
            position['dti_uri'] = o
            datetime_interval = get_datetime_interval(o)
            position['datetime_interval'] = datetime_interval
            if 'start_date' in datetime_interval:
                position['start_date'] = datetime_interval['start_date']
            if 'end_date' in datetime_interval:
                position['end_date'] = datetime_interval['end_date']  
        i = i + 1

    return position
Пример #15
0
"""

__author__ = "Michael Conlon"
__copyright__ = "Copyright 2014, University of Florida"
__license__ = "BSD-3"

from vivofoundation import show_triples
from vivofoundation import get_triples
from datetime import datetime

#  Test cases for access and display functions

print datetime.now, "Start"

print "\nDateTime"
print show_triples(get_triples("http://vivo.ufl.edu/individual/n7860108656"))


print "\nDateTimeInterval"
print show_triples(get_triples("http://vivo.ufl.edu/individual/n182882417"))

print "\nOrganization"
print show_triples(get_triples("http://vivo.ufl.edu/individual/n8763427"))


print "\nAuthorship"
print show_triples(get_triples("http://vivo.ufl.edu/individual/n148010391"))

print "\nRole"
print show_triples(get_triples("http://vivo.ufl.edu/individual/n1864549239"))
Пример #16
0
def get_grant(grant_uri, get_investigators=False):
    """
    Given a URI, return an object that contains the grant it represents
    """
    from vivofoundation import get_triples
    from vivofoundation import get_organization
    from vivofoundation import get_datetime_interval
    from vivofoundation import get_role

    grant = {'grant_uri': grant_uri}
    grant['contributing_role_uris'] = []
    grant['pi_uris'] = []
    grant['coi_uris'] = []
    grant['inv_uris'] = []
    grant['role_uris'] = {}
    grant['investigators'] = []
    triples = get_triples(grant_uri)
    try:
        count = len(triples["results"]["bindings"])
    except:
        count = 0
    i = 0
    while i < count:
        b = triples["results"]["bindings"][i]
        p = b['p']['value']
        o = b['o']
        if p == "http://www.w3.org/2000/01/rdf-schema#label":
            grant['title'] = o
        if p == "http://vivoweb.org/ontology/core#totalAwardAmount":
            grant['total_award_amount'] = o
        if p == "http://vivoweb.org/ontology/core#grantDirectCosts":
            grant['grant_direct_costs'] = o
        if p == "http://purl.org/ontology/bibo/abstract":
            grant['abstract'] = o
        if p == "http://vivoweb.org/ontology/core#sponsorAwardId":
            grant['sponsor_award_id'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/dsrNumber":
            grant['dsr_number'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/psContractNumber":
            grant['pcn'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/dateHarvested":
            grant['date_harvested'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/harvestedBy":
            grant['harvested_by'] = o
        if p == "http://vivo.ufl.edu/ontology/vivo-ufl/localAwardId":
            grant['local_award_id'] = o
        if p == "http://vivoweb.org/ontology/core#contributingRole":
            grant['contributing_role_uris'].append(o['value'])

        # deref administered by

        if p == "http://vivoweb.org/ontology/core#administeredBy":
            grant['administered_by_uri'] = o['value']
            administered_by = get_organization(o['value'])
            if 'label' in administered_by:
                grant['administered_by'] = administered_by['label']

        # deref awarded by

        if p == "http://vivoweb.org/ontology/core#grantAwardedBy":
            grant['sponsor_uri'] = o['value']
            awarded_by = get_organization(o['value'])
            if 'label' in awarded_by:
                grant['awarded_by'] = awarded_by['label']

        # deref the datetime interval

        if p == "http://vivoweb.org/ontology/core#dateTimeInterval":
            grant['dti_uri'] = o['value']
            datetime_interval = get_datetime_interval(o['value'])
            grant['datetime_interval'] = datetime_interval
            if 'start_date' in datetime_interval:
                grant['start_date'] = datetime_interval['start_date']
            if 'end_date' in datetime_interval:
                grant['end_date'] = datetime_interval['end_date']

        i = i + 1

    # deref the roles

    for role_uri in grant['contributing_role_uris']:
        role = get_role(role_uri)
        if 'principal_investigator_role_of' in role:
            pi_uri = role['principal_investigator_role_of']
            if pi_uri not in grant['pi_uris']:
                grant['pi_uris'].append(pi_uri)
                grant['role_uris'][pi_uri] = role_uri
        if 'co_principal_investigator_role_of' in role:
            coi_uri = role['co_principal_investigator_role_of']
            if coi_uri not in grant['coi_uris']:
                grant['coi_uris'].append(coi_uri)
                grant['role_uris'][coi_uri] = role_uri
        if 'investigator_role_of' in role:
            inv_uri = role['investigator_role_of']
            if inv_uri not in grant['inv_uris']:
                grant['inv_uris'].append(inv_uri)
                grant['role_uris'][inv_uri] = role_uri

    # deref the investigators

    if get_investigators == True:
        for role_uri in grant['contributing_role_uris']:
            role = get_role(role_uri)
            if 'co_principal_investigator_role_of' in role:
                person = \
                    get_person(role['co_principal_investigator_role_of'])
                person['role'] = 'co_principal_investigator'
                grant['investigators'].append(person)
            if 'principal_investigator_role_of' in role:
                person = \
                    get_person(role['principal_investigator_role_of'])
                person['role'] = 'principal_investigator'
                grant['investigators'].append(person)
            if 'investigator_role_of' in role:
                person = \
                    get_person(role['investigator_role_of'])
                person['role'] = 'investigator'
                grant['investigators'].append(person)
    return grant