def make_section_rdf(taught_data):
    """
    Given teaching data, make a section and a teaching role.  Link
    the section to its teaching role, to its course and term.  Link the
    role to the instructor.
    """
    from vivofoundation import get_vivo_uri
    import tempita
    from datetime import datetime
    section_rdf_template = tempita.Template("""
    <rdf:Description rdf:about="{{section_uri}}">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
        <rdf:type rdf:resource="http://vivo.ufl.edu/ontology/vivo-ufl/CourseSection"/>
        <rdf:type rdf:resource="http://vivo.ufl.edu/ontology/vivo-ufl/UFEntity"/>
        <rdfs:label>{{section_name}}</rdfs:label>
        <ufVivo:sectionNum>{{section_number}}</ufVivo:sectionNum>
        <vivo:dateTimeInterval rdf:resource="{{term_uri}}"/>
        <ufVivo:sectionForCourse rdf:resource="{{course_uri}}"/>
        <ufVivo:harvestedBy>Python Courses version 0.5</ufVivo:harvestedBy>
        <ufVivo:dateHarvested>{{harvest_datetime}}</ufVivo:dateHarvested>
    </rdf:Description>
    <rdf:Description rdf:about="{{term_uri}}">
        <ufVivo:dateTimeIntervalFor rdf:resource="{{section_uri}}"/>
    </rdf:Description>
    {{if course_new}}
        <rdf:Description rdf:about="{{course_role_uri}}">
            <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
            <rdf:type rdf:resource="http://vivoweb.org/ontology/core#TeacherRole"/>
            <rdfs:label>{{course_name}}</rdfs:label>
            <ufVivo:courseRoleOf rdf:resource="{{person_uri}}"/>
            <vivo:roleRealizedIn rdf:resource="{{course_uri}}"/>        
        </rdf:Description>
    {{endif}}
    <rdf:Description rdf:about="{{teacher_role_uri}}">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
        <rdf:type rdf:resource="http://vivoweb.org/ontology/core#TeacherRole"/>
        <vivo:teacherRoleOf rdf:resource="{{person_uri}}"/>
        <vivo:roleRealizedIn rdf:resource="{{section_uri}}"/>
    </rdf:Description>""")

    section_uri = get_vivo_uri()
    rdf = section_rdf_template.substitute(
        section_uri=section_uri,
        section_name=taught_data['section_name'],
        section_number=taught_data['section_number'],
        term_uri=taught_data['term_uri'],
        course_uri=taught_data['course_uri'],
        course_name=taught_data['course_name'],
        course_new=taught_data['course_new'],
        teacher_role_uri=get_vivo_uri(),
        course_role_uri=get_vivo_uri(),
        person_uri=taught_data['person_uri'],
        harvest_datetime=datetime.now().isoformat())
    return [rdf, section_uri]
Esempio n. 2
0
def make_section_rdf(taught_data):
    """
    Given teaching data, make a section and a teaching role.  Link
    the section to its teaching role, to its course and term.  Link the
    role to the instructor.
    """
    from vivofoundation import get_vivo_uri
    import tempita
    from datetime import datetime
    section_rdf_template = tempita.Template("""
    <rdf:Description rdf:about="{{section_uri}}">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
        <rdf:type rdf:resource="http://vivo.ufl.edu/ontology/vivo-ufl/CourseSection"/>
        <rdf:type rdf:resource="http://vivo.ufl.edu/ontology/vivo-ufl/UFEntity"/>
        <rdfs:label>{{section_name}}</rdfs:label>
        <ufVivo:sectionNum>{{section_number}}</ufVivo:sectionNum>
        <vivo:dateTimeInterval rdf:resource="{{term_uri}}"/>
        <ufVivo:sectionForCourse rdf:resource="{{course_uri}}"/>
        <ufVivo:harvestedBy>Python Courses version 0.5</ufVivo:harvestedBy>
        <ufVivo:dateHarvested>{{harvest_datetime}}</ufVivo:dateHarvested>
    </rdf:Description>
    <rdf:Description rdf:about="{{term_uri}}">
        <ufVivo:dateTimeIntervalFor rdf:resource="{{section_uri}}"/>
    </rdf:Description>
    {{if course_new}}
        <rdf:Description rdf:about="{{course_role_uri}}">
            <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
            <rdf:type rdf:resource="http://vivoweb.org/ontology/core#TeacherRole"/>
            <rdfs:label>{{course_name}}</rdfs:label>
            <ufVivo:courseRoleOf rdf:resource="{{person_uri}}"/>
            <vivo:roleRealizedIn rdf:resource="{{course_uri}}"/>        
        </rdf:Description>
    {{endif}}
    <rdf:Description rdf:about="{{teacher_role_uri}}">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
        <rdf:type rdf:resource="http://vivoweb.org/ontology/core#TeacherRole"/>
        <vivo:teacherRoleOf rdf:resource="{{person_uri}}"/>
        <vivo:roleRealizedIn rdf:resource="{{section_uri}}"/>
    </rdf:Description>""")

    section_uri = get_vivo_uri()
    rdf = section_rdf_template.substitute(section_uri=section_uri,
                                          section_name=taught_data['section_name'],
                                          section_number=taught_data['section_number'],
                                          term_uri=taught_data['term_uri'],
                                          course_uri=taught_data['course_uri'],
                                          course_name=taught_data['course_name'],
                                          course_new=taught_data['course_new'],
                                          teacher_role_uri=get_vivo_uri(),
                                          course_role_uri=get_vivo_uri(),
                                          person_uri=taught_data['person_uri'],
                                          harvest_datetime=datetime.now().isoformat())
    return [rdf, section_uri]
def add_position(person_uri, position):
    """
    Given a person_uri and a position dictionary containing the attributes
    of a position, generate the RDF necessary to create the position,
    associate it with the person and assign its attributes.
    """
    from vivofoundation import assert_resource_property
    from vivofoundation import assert_data_property
    from vivofoundation import add_dti
    from vivofoundation import get_vivo_uri

    ardf = ""
    position_uri = get_vivo_uri()
    dti = {
        'start': position.get('start_date', None),
        'end': position.get('end_date', None)
    }
    [add, dti_uri] = add_dti(dti)
    ardf = ardf + add
    ardf = ardf + assert_resource_property(position_uri, 'rdf:type',
                                           position['position_type'])
    ardf = ardf + assert_resource_property(position_uri, 'rdfs:label',
                                           position['position_label'])
    ardf = ardf + assert_resource_property(position_uri,
                                           'vivo:dateTimeInterval', dti_uri)
    ardf = ardf + assert_resource_property(position_uri, 'vivo:relates',
                                           person_uri)
    ardf = ardf + assert_resource_property(position_uri, 'vivo:relates',
                                           position['position_orguri'])

    return [ardf, position_uri]
Esempio n. 4
0
def add_position(person_uri, position):
    """
    Given a person_uri and a position dictionary containing the attributes
    of a position, generate the RDF necessary to create the position,
    associate it with the person and assign its attributes.
    """
    from vivofoundation import assert_resource_property
    from vivofoundation import assert_data_property
    from vivofoundation import add_dti
    from vivofoundation import get_vivo_uri
    
    ardf = ""
    position_uri = get_vivo_uri()
    dti = {'start' : position.get('start_date',None),
           'end': position.get('end_date',None)}
    [add, dti_uri] = add_dti(dti)
    ardf = ardf + add
    ardf = ardf + assert_resource_property(position_uri,
            'rdf:type', position['position_type'])
    ardf = ardf + assert_resource_property(position_uri,
            'rdfs:label', position['position_label'])
    ardf = ardf + assert_resource_property(position_uri,
            'vivo:dateTimeInterval', dti_uri)
    ardf = ardf + assert_resource_property(position_uri,
            'vivo:relates', person_uri)
    ardf = ardf + assert_resource_property(position_uri,
            'vivo:relates', position['position_orguri'])
    
    return [ardf, position_uri]
Esempio n. 5
0
def make_course_rdf(taught_data):
    """
    Given taught_data, generate the RDF for a course,
    a teacher role and links between course, teacher role and instructor
    """
    import tempita
    from vivofoundation import get_vivo_uri
    from datetime import datetime

    course_rdf_template = tempita.Template("""
    <rdf:Description rdf:about="{{course_uri}}">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
        <rdf:type rdf:resource="http://vivo.ufl.edu/ontology/vivo-ufl/Course"/>
        <rdf:type rdf:resource="http://vivo.ufl.edu/ontology/vivo-ufl/UFEntity"/>
        <rdfs:label>{{course_name}}</rdfs:label>
        <ufVivo:courseNum>{{course_number}}</ufVivo:courseNum>
        <ufVivo:harvestedBy>Python Courses version 0.5</ufVivo:harvestedBy>
        <ufVivo:dateHarvested>{{harvest_datetime}}</ufVivo:dateHarvested>
    </rdf:Description>""")
    course_uri = get_vivo_uri()
    rdf = course_rdf_template.substitute(course_uri=course_uri,
                                         course_name=taught_data['course_name'],
                                         course_number=taught_data['course_number'],
                                         harvest_datetime=datetime.now().isoformat(),
                                         person_uri=taught_data['person_uri'])
    return [rdf, course_uri]
def make_course_rdf(taught_data):
    """
    Given taught_data, generate the RDF for a course,
    a teacher role and links between course, teacher role and instructor
    """
    import tempita
    from vivofoundation import get_vivo_uri
    from datetime import datetime

    course_rdf_template = tempita.Template("""
    <rdf:Description rdf:about="{{course_uri}}">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
        <rdf:type rdf:resource="http://vivo.ufl.edu/ontology/vivo-ufl/Course"/>
        <rdf:type rdf:resource="http://vivo.ufl.edu/ontology/vivo-ufl/UFEntity"/>
        <rdfs:label>{{course_name}}</rdfs:label>
        <ufVivo:courseNum>{{course_number}}</ufVivo:courseNum>
        <ufVivo:harvestedBy>Python Courses version 0.5</ufVivo:harvestedBy>
        <ufVivo:dateHarvested>{{harvest_datetime}}</ufVivo:dateHarvested>
    </rdf:Description>""")
    course_uri = get_vivo_uri()
    rdf = course_rdf_template.substitute(
        course_uri=course_uri,
        course_name=taught_data['course_name'],
        course_number=taught_data['course_number'],
        harvest_datetime=datetime.now().isoformat(),
        person_uri=taught_data['person_uri'])
    return [rdf, course_uri]
Esempio n. 7
0
"""
    test_get_vivo_uri.py -- return a valid, unused, vivo URI

    Version 0.1 MC 2013-12-28
    --  Initial version.
    Version 0.2 MC 2014-07-21
    --  Formatting improvements. Tested with 1.6

"""

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

from vivofoundation import get_vivo_uri
from datetime import datetime

print datetime.now(), "Start"

for i in range(0, 9):
    print get_vivo_uri()

print datetime.now(), "Finished"
def add_person(person):
    """
    Add a person to VIVO.  The person structure may have any number of
    elements.  These elements may represent direct assertions (label,
    ufid, homeDept), vcard assertions (contact info, name parts),
    and/or position assertions (title, tye, dept, start, end dates)
    """
    from vivofoundation import assert_data_property
    from vivofoundation import assert_resource_property
    from vivofoundation import untag_predicate
    from vivofoundation import get_vivo_uri

    ardf = ""
    person_uri = get_vivo_uri()

    # Add direct assertions

    person_type = person['person_type']
    ardf = ardf + assert_resource_property(person_uri, 'rdf:type', person_type)
    ardf = ardf + assert_resource_property(person_uri, 'rdf:type',
                                           untag_predicate('ufv:UFEntity'))
    ardf = ardf + assert_resource_property(
        person_uri, 'rdf:type', untag_predicate('ufv:UFCurrentEntity'))

    direct_data_preds = {
        'ufid': 'ufv:ufid',
        'privacy_flag': 'ufv:privacyFlag',
        'display_name': 'rdfs:label',
        'gatorlink': 'ufv:gatorlink'
    }
    direct_resource_preds = {'homedept_uri': 'ufv:homeDept'}
    for key in direct_data_preds:
        if key in person:
            pred = direct_data_preds[key]
            val = person[key]
            ardf = ardf + assert_data_property(person_uri, pred, val)
    for key in direct_resource_preds:
        if key in person:
            pred = direct_resource_preds[key]
            val = person[key]
            ardf = ardf + assert_resource_property(person_uri, pred, val)

    # Add Vcard Assertions

    vcard = {}
    for key in [
            'last_name',
            'first_name',
            'middle_name',
            'primary_email',
            'name_prefix',
            'name_suffix',
            'fax',
            'phone',
            'preferred_title',
    ]:
        if key in person.keys():
            vcard[key] = person[key]
    [add, vcard_uri] = add_vcard(person_uri, vcard)
    ardf = ardf + add

    # Add Position Assertions

    position = {}
    for key in [
            'start_date', 'position_label', 'end_date', 'position_orguri',
            'position_type'
    ]:
        if key in person.keys():
            position[key] = person[key]

    [add, position_uri] = add_position(person_uri, position)
    ardf = ardf + add

    return [ardf, person_uri]
def update_vcard(vivo_vcard, source_vcard):
    """
    Given a vivo vcard and a source vccard, generate the add and sub rdf
    necesary to update vivo the the values ion the source
    """

    from vivofoundation import update_entity
    from vivofoundation import update_data_property
    from vivofoundation import get_vivo_uri
    from vivofoundation import assert_data_property
    from vivofoundation import assert_resource_property
    from vivofoundation import untag_predicate

    ardf = ""
    srdf = ""

    # Update the name entity

    name_keys = {
        'given_name': {
            'predicate': 'vcard:givenName',
            'action': 'literal'
        },
        'family_name': {
            'predicate': 'vcard:familyName',
            'action': 'literal'
        },
        'additional_name': {
            'predicate': 'vcard:additionalName',
            'action': 'literal'
        },
        'honorific_prefix': {
            'predicate': 'vcard:honorificPrefix',
            'action': 'literal'
        },
        'honorific_suffix': {
            'predicate': 'vcard:honorificSuffix',
            'action': 'literal'
        }
    }

    # Update name entity

    if 'name' in source_vcard and 'name' not in vivo_vcard:
        name_uri = get_vivo_uri()
        ardf = ardf + assert_resource_property(name_uri, 'rdf:type',
                                               untag_predicate('vcard:Name'))
        ardf = ardf + assert_resource_property(vcard['vcard_uri'],
                                               'vcard:hasName', name_uri)
        vivo_vcard['name_uri'] = name_uri
        vivo_vcard['name'] = {}
    if 'name' in source_vcard:
        vivo_vcard['name']['uri'] = vivo_vcard['name_uri']
        [add, sub] = update_entity(vivo_vcard['name'], source_vcard['name'],
                                   name_keys)
        ardf = ardf + add
        srdf = srdf + sub

    #   Update title

    if 'title' in source_vcard and 'title' not in vivo_vcard:
        title_uri = get_vivo_uri()
        ardf = ardf + assert_resource_property(title_uri, 'rdf:type',
                                               untag_predicate('vcard:Title'))
        ardf = ardf + assert_resource_property(vivo_vcard['vcard_uri'],
                                               'vcard:hasTitle', title_uri)
        vivo_vcard['title_uri'] = title_uri
        vivo_vcard['title'] = None
    if 'title' in source_vcard:
        [add, sub] = update_data_property(vivo_vcard['title_uri'],
                                          'vcard:title', vivo_vcard['title'],
                                          source_vcard['title'])
        ardf = ardf + add
        srdf = srdf + sub

    #   Update phone.  For now, assert a phone.  We can't seem to tell which
    #   phone is to be "updated".  If VIVO has telephones a and b, and the
    #   source says the phone number is c, what is the appropriate operation?
    #   We will just pick a phone and update it to c.  If ther person has zero
    #   or one phones, everything is fine.  These are the most likely cases.
    #   And in the above two phone case, we have a 50-50 chance of doing the
    #   right thing.  So perhaps 1% of people will be effected adversely by
    #   the code that follows.

    if 'phone' in source_vcard and source_vcard['phone'] is not None:
        if 'telephones' not in vivo_vcard or vivo_vcard['telephones'] == []:
            telephone_uri = get_vivo_uri()
            ardf = ardf + assert_resource_property(
                vivo_vcard['vcard_uri'], 'vcard:hasTelephone', telephone_uri)
            ardf = ardf + assert_resource_property(
                telephone_uri, 'rdf:type', untag_predicate('vcard:telephone'))
            telephone_value = None
        else:
            for telephone in vivo_vcard['telephones']:
                if telephone['telephone_type'] == 'Telephone':
                    telephone_uri = telephone['telephone_uri']
                    telephone_value = telephone['telephone_number']
                    continue
        [add,
         sub] = update_data_property(telephone_uri, 'vcard:telephone',
                                     telephone_value, source_vcard['phone'])
        ardf = ardf + add
        srdf = srdf + sub

    #   Analogous processing with analogous comments for a fax number

    if 'fax' in source_vcard and source_vcard['fax'] is not None:
        if 'telephones' not in vivo_vcard or vivo_vcard['telephones'] == []:
            telephone_uri = get_vivo_uri()
            ardf = ardf + assert_resource_property(
                vivo_vcard['vcard_uri'], 'vcard:hasTelephone', telephone_uri)
            ardf = ardf + assert_resource_property(
                telephone_uri, 'rdf:type', untag_predicate('vcard:Fax'))
            telephone_value = None
        else:
            for telephone in vivo_vcard['telephones']:
                if telephone['telephone_type'] == 'Fax':
                    telephone_uri = telephone['telephone_uri']
                    telephone_value = telephone['telephone_number']
                    continue
        [add, sub] = update_data_property(telephone_uri, 'vcard:telephone',
                                          telephone_value, source_vcard['fax'])
        ardf = ardf + add
        srdf = srdf + sub

    #   Analogous processing with analogous comments for an email address

    if 'primary_email' in source_vcard and \
       source_vcard['primary_email'] is not None:
        if 'email_addresses' not in vivo_vcard or \
           vivo_vcard['email_addresses'] == []:
            email_uri = get_vivo_uri()
            ardf = ardf + assert_resource_property(vivo_vcard['vcard_uri'],
                                                   'vcard:hasEmail', email_uri)
            ardf = ardf + assert_resource_property(
                email_uri, 'rdf:type', untag_predicate('vcard:Email'))
            email_value = None
        else:
            email_uri = email_addresses[0]['email_uri']
            email_value = email_address[0]['email_address']
        [add,
         sub] = update_data_property(email_uri, 'vcard:email', email_value,
                                     source_vcard['primary_email'])
        ardf = ardf + add
        srdf = srdf + sub

    return [ardf, srdf]
Esempio n. 10
0
def add_vcard(person_uri, vcard):
    """
    Given a person_uri and a vcard dictionary of items on the vcard,
    generate ther RDF necessary to create the vcard, associate it with
    the person, and associate attributes to the vcard.

    The person_uri will be associated to the vcard and the vcard may have
    any number of single entry entities to references.  The single_entry
    table controls the processing of these entities.

    The name entity is a special case. All values are attrbuted to the name
    entity.

    The single_entry table contains some additional keys for future use
    Both the name table and the single entry table are easily extensible to
    handle additional name attributes and additional single entry entities
    respectively.
    """

    from vivofoundation import assert_resource_property
    from vivofoundation import assert_data_property
    from vivofoundation import get_vivo_uri
    from vivofoundation import untag_predicate

    single_entry = {
        'primary_email': {
            'resource': 'vcard:hasEmail',
            'type': 'vcard:Email',
            'pred': 'vcard:email'
        },
        'email': {
            'resource': 'vcard:hasEmail',
            'type': 'vcard:Email',
            'pred': 'vcard:email'
        },
        'fax': {
            'resource': 'vcard:hasTelephone',
            'type': 'vcard:Fax',
            'pred': 'vcard:telephone'
        },
        'telephone': {
            'resource': 'vcard:hasTelephone',
            'type': 'vcard:Telephone',
            'pred': 'vcard:telephone'
        },
        'preferred_title': {
            'resource': 'vcard:hasTitle',
            'type': 'vcard:Title',
            'pred': 'vcard:title'
        },
        'title': {
            'resource': 'vcard:hasTitle',
            'type': 'vcard:Title',
            'pred': 'vcard:title'
        }
    }
    name_table = {
        'first_name': 'vcard:givenName',
        'last_name': 'vcard:familyName',
        'middle_name': 'vcard:additionalName',
        'name_prefix': 'vcard:honoraryPrefix',
        'name_suffix': 'vcard:honorarySuffix'
    }
    ardf = ""
    vcard_uri = get_vivo_uri()
    ardf = ardf + assert_resource_property(vcard_uri, 'rdf:type',
                                           untag_predicate('vcard:Individual'))
    ardf = ardf + assert_resource_property(person_uri, 'obo:ARG2000028',
                                           vcard_uri)  # hasContactInfo
    ardf = ardf + assert_resource_property(vcard_uri, 'obo:ARG2000029',
                                           person_uri)  # contactInfoOf

    # Create the name entity and attach to vcard. For each key in the
    # name_table, assert its value to the name entity

    name_uri = get_vivo_uri()
    ardf = ardf + assert_resource_property(name_uri, 'rdf:type',
                                           untag_predicate('vcard:Name'))
    ardf = ardf + assert_resource_property(vcard_uri, 'vcard:hasName',
                                           name_uri)
    for key in vcard.keys():
        if key in name_table:
            pred = name_table[key]
            val = vcard[key]
            ardf = ardf + assert_data_property(name_uri, pred, val)

    # Process single entry vcard bits of info:
    #   Go through the keys in the vcard.  If it's a single entry key, then
    #   create it.  Assign the data vaue and link the vcard to the single
    #   entry entity

    for key in vcard.keys():
        if key in single_entry:
            val = vcard[key]
            entry = single_entry[key]
            entry_uri = get_vivo_uri()
            ardf = ardf + assert_resource_property(
                entry_uri, 'rdf:type', untag_predicate(entry['type']))
            ardf = ardf + assert_data_property(entry_uri, entry['pred'], val)
            ardf = ardf + assert_resource_property(
                vcard_uri, entry['resource'], entry_uri)
    return [ardf, vcard_uri]
Esempio n. 11
0
def add_person(person):
    """
    Add a person to VIVO.  The person structure may have any number of
    elements.  These elements may represent direct assertions (label,
    ufid, homeDept), vcard assertions (contact info, name parts),
    and/or position assertions (title, tye, dept, start, end dates)
    """
    from vivofoundation import assert_data_property
    from vivofoundation import assert_resource_property
    from vivofoundation import untag_predicate
    from vivofoundation import get_vivo_uri
    
    ardf = ""
    person_uri = get_vivo_uri()

    # Add direct assertions

    person_type = person['person_type']
    ardf = ardf + assert_resource_property(person_uri, 'rdf:type', person_type)
    ardf = ardf + assert_resource_property(person_uri, 'rdf:type',
                        untag_predicate('ufv:UFEntity'))
    ardf = ardf + assert_resource_property(person_uri, 'rdf:type',
                        untag_predicate('ufv:UFCurrentEntity'))

    direct_data_preds = {'ufid':'ufv:ufid',
                         'privacy_flag':'ufv:privacyFlag',
                         'display_name':'rdfs:label',
                         'gatorlink':'ufv:gatorlink'
                         }
    direct_resource_preds = {'homedept_uri':'ufv:homeDept'}
    for key in direct_data_preds:
        if key in person:
            pred = direct_data_preds[key]
            val = person[key]
            ardf = ardf + assert_data_property(person_uri, pred, val)
    for key in direct_resource_preds:
        if key in person:
            pred = direct_resource_preds[key]
            val = person[key]
            ardf = ardf + assert_resource_property(person_uri, pred, val)

    # Add Vcard Assertions

    vcard = {}
    for key in ['last_name', 'first_name', 'middle_name', 'primary_email',
                'name_prefix', 'name_suffix', 'fax', 'phone', 'preferred_title',
                ]:
        if key in person.keys():
            vcard[key] = person[key]
    [add, vcard_uri] = add_vcard(person_uri, vcard)
    ardf = ardf + add

    # Add Position Assertions

    position = {}
    for key in ['start_date', 'position_label', 'end_date', 'position_orguri',
                'position_type']:
        if key in person.keys():
            position[key] = person[key]

    [add, position_uri] = add_position(person_uri, position)
    ardf = ardf + add
    
    return [ardf, person_uri]
Esempio n. 12
0
def update_vcard(vivo_vcard, source_vcard):
    """
    Given a vivo vcard and a source vccard, generate the add and sub rdf
    necesary to update vivo the the values ion the source
    """
    
    from vivofoundation import update_entity
    from vivofoundation import update_data_property
    from vivofoundation import get_vivo_uri
    from vivofoundation import assert_data_property
    from vivofoundation import assert_resource_property
    from vivofoundation import untag_predicate

    ardf = ""
    srdf = ""

    # Update the name entity

    name_keys = {
        'given_name' : {'predicate':'vcard:givenName','action':'literal'},
        'family_name' : {'predicate':'vcard:familyName',
                       'action':'literal'},
        'additional_name' : {'predicate':'vcard:additionalName',
                         'action':'literal'},
        'honorific_prefix' : {'predicate':'vcard:honorificPrefix',
                         'action':'literal'},
        'honorific_suffix' : {'predicate':'vcard:honorificSuffix',
                         'action':'literal'}
    }

    # Update name entity
    
    if 'name' in source_vcard and 'name' not in vivo_vcard:
        name_uri = get_vivo_uri()
        ardf = ardf + assert_resource_property(name_uri, 'rdf:type',
                                           untag_predicate('vcard:Name'))
        ardf = ardf + assert_resource_property(vcard['vcard_uri'],
            'vcard:hasName', name_uri)
        vivo_vcard['name_uri'] = name_uri
        vivo_vcard['name'] = {}
    if 'name' in source_vcard:
        vivo_vcard['name']['uri'] = vivo_vcard['name_uri']
        [add, sub] = update_entity(vivo_vcard['name'],
                                   source_vcard['name'], name_keys)
        ardf = ardf + add
        srdf = srdf + sub

    #   Update title

    if 'title' in source_vcard and 'title' not in vivo_vcard:
        title_uri = get_vivo_uri()
        ardf = ardf + assert_resource_property(title_uri, 'rdf:type',
                                           untag_predicate('vcard:Title'))
        ardf = ardf + assert_resource_property(vivo_vcard['vcard_uri'],
            'vcard:hasTitle', title_uri)
        vivo_vcard['title_uri'] = title_uri
        vivo_vcard['title'] = None
    if 'title' in source_vcard:
        [add, sub] = update_data_property(vivo_vcard['title_uri'],
            'vcard:title', vivo_vcard['title'], source_vcard['title'])
        ardf = ardf + add
        srdf = srdf + sub

    #   Update phone.  For now, assert a phone.  We can't seem to tell which
    #   phone is to be "updated".  If VIVO has telephones a and b, and the
    #   source says the phone number is c, what is the appropriate operation?
    #   We will just pick a phone and update it to c.  If ther person has zero
    #   or one phones, everything is fine.  These are the most likely cases.
    #   And in the above two phone case, we have a 50-50 chance of doing the
    #   right thing.  So perhaps 1% of people will be effected adversely by
    #   the code that follows.

    if 'phone' in source_vcard and source_vcard['phone'] is not None:
        if 'telephones' not in vivo_vcard or vivo_vcard['telephones'] == []:
            telephone_uri = get_vivo_uri()
            ardf = ardf + assert_resource_property(vivo_vcard['vcard_uri'],
                'vcard:hasTelephone', telephone_uri)
            ardf = ardf + assert_resource_property(telephone_uri,
                'rdf:type', untag_predicate('vcard:telephone'))
            telephone_value = None
        else:
            for telephone in vivo_vcard['telephones']:
                if telephone['telephone_type'] == 'Telephone':
                    telephone_uri = telephone['telephone_uri']
                    telephone_value = telephone['telephone_number']
                    continue
        [add, sub] = update_data_property(telephone_uri,
            'vcard:telephone', telephone_value, source_vcard['phone'])
        ardf = ardf + add
        srdf = srdf + sub

    #   Analogous processing with analogous comments for a fax number

    if 'fax' in source_vcard and source_vcard['fax'] is not None:
        if 'telephones' not in vivo_vcard or vivo_vcard['telephones'] == []:
            telephone_uri = get_vivo_uri()
            ardf = ardf + assert_resource_property(vivo_vcard['vcard_uri'],
                'vcard:hasTelephone', telephone_uri)
            ardf = ardf + assert_resource_property(telephone_uri,
                'rdf:type', untag_predicate('vcard:Fax'))
            telephone_value = None
        else:
            for telephone in vivo_vcard['telephones']:
                if telephone['telephone_type'] == 'Fax':
                    telephone_uri = telephone['telephone_uri']
                    telephone_value = telephone['telephone_number']
                    continue
        [add, sub] = update_data_property(telephone_uri,
            'vcard:telephone', telephone_value, source_vcard['fax'])
        ardf = ardf + add
        srdf = srdf + sub

    #   Analogous processing with analogous comments for an email address

    if 'primary_email' in source_vcard and \
       source_vcard['primary_email'] is not None:
        if 'email_addresses' not in vivo_vcard or \
           vivo_vcard['email_addresses'] == []:
            email_uri = get_vivo_uri()
            ardf = ardf + assert_resource_property(vivo_vcard['vcard_uri'],
                'vcard:hasEmail', email_uri)
            ardf = ardf + assert_resource_property(email_uri,
                'rdf:type', untag_predicate('vcard:Email'))
            email_value = None
        else:
            email_uri = email_addresses[0]['email_uri']
            email_value = email_address[0]['email_address']
        [add, sub] = update_data_property(email_uri,
            'vcard:email', email_value, source_vcard['primary_email'])
        ardf = ardf + add
        srdf = srdf + sub
    
    return [ardf, srdf]
Esempio n. 13
0
def add_vcard(person_uri, vcard):
    """
    Given a person_uri and a vcard dictionary of items on the vcard,
    generate ther RDF necessary to create the vcard, associate it with
    the person, and associate attributes to the vcard.

    The person_uri will be associated to the vcard and the vcard may have
    any number of single entry entities to references.  The single_entry
    table controls the processing of these entities.

    The name entity is a special case. All values are attrbuted to the name
    entity.

    The single_entry table contains some additional keys for future use
    Both the name table and the single entry table are easily extensible to
    handle additional name attributes and additional single entry entities
    respectively.
    """
    
    from vivofoundation import assert_resource_property
    from vivofoundation import assert_data_property
    from vivofoundation import get_vivo_uri
    from vivofoundation import untag_predicate
    
    single_entry = {
        'primary_email': {'resource':'vcard:hasEmail','type':'vcard:Email',
                          'pred':'vcard:email'},
        'email': {'resource':'vcard:hasEmail','type':'vcard:Email',
                  'pred':'vcard:email'},
        'fax': {'resource':'vcard:hasTelephone','type':'vcard:Fax',
                'pred':'vcard:telephone'},
        'telephone': {'resource':'vcard:hasTelephone','type':'vcard:Telephone',
                      'pred':'vcard:telephone'},
        'preferred_title': {'resource':'vcard:hasTitle','type':'vcard:Title',
                            'pred':'vcard:title'},
        'title': {'resource':'vcard:hasTitle','type':'vcard:Title',
                  'pred':'vcard:title'}
    }
    name_table = {
        'first_name' : 'vcard:givenName',
        'last_name' : 'vcard:familyName',
        'middle_name' : 'vcard:additionalName',
        'name_prefix' : 'vcard:honoraryPrefix',
        'name_suffix' : 'vcard:honorarySuffix'
        }
    ardf = ""
    vcard_uri = get_vivo_uri()
    ardf = ardf + assert_resource_property(vcard_uri, 'rdf:type',
                                           untag_predicate('vcard:Individual'))
    ardf = ardf + assert_resource_property(person_uri, 'obo:ARG2000028',
                                           vcard_uri) # hasContactInfo
    ardf = ardf + assert_resource_property(vcard_uri, 'obo:ARG2000029',
                                           person_uri) # contactInfoOf

    # Create the name entity and attach to vcard. For each key in the
    # name_table, assert its value to the name entity

    name_uri = get_vivo_uri()
    ardf = ardf + assert_resource_property(name_uri, 'rdf:type',
                                           untag_predicate('vcard:Name'))
    ardf = ardf + assert_resource_property(vcard_uri, 'vcard:hasName',
                                           name_uri)
    for key in vcard.keys():
        if key in name_table:
            pred = name_table[key]
            val = vcard[key]
            ardf = ardf + assert_data_property(name_uri,
                pred, val)            

    # Process single entry vcard bits of info:
    #   Go through the keys in the vcard.  If it's a single entry key, then
    #   create it.  Assign the data vaue and link the vcard to the single
    #   entry entity

    for key in vcard.keys():
        if key in single_entry:
            val = vcard[key]
            entry = single_entry[key]
            entry_uri = get_vivo_uri()
            ardf = ardf + assert_resource_property(entry_uri,
                'rdf:type', untag_predicate(entry['type']))
            ardf = ardf + assert_data_property(entry_uri,
                entry['pred'], val)
            ardf = ardf + assert_resource_property(vcard_uri,
                entry['resource'], entry_uri)
    return [ardf, vcard_uri]
"""
    test_get_vivo_uri.py -- return a valid, unused, vivo URI

    Version 0.1 MC 2013-12-28
    --  Initial version.
    Version 0.2 MC 2014-07-21
    --  Formatting improvements. Tested with 1.6

"""

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

from vivofoundation import get_vivo_uri 
from datetime import datetime

print datetime.now(), "Start"

for i in range(0, 9):
    print get_vivo_uri()

print datetime.now(), "Finished"