Пример #1
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]
Пример #2
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]
Пример #3
0
"""
    test_assert_resource_property.py -- Given a URI, a vivo resource property
    predicate and a resource URI, generate RDF for asserting that the URI has
    the resource property URI.  The tests demonsrate that that the function does
    not check for a valid predicate, nor a valid resource URI.

    Version 0.1 MC 2013-12-27
    --  Initial version
    Version 0.2 MC 2014-08-30
    --  PEP 8, support for vivofoundation
"""

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

from vivofoundation import assert_resource_property
from datetime import datetime

print datetime.now(), "Start"

print assert_resource_property("http://a.b", "http://c.d", "http://e.f")
print assert_resource_property("http://a.b", "vivo:authorInAuthorship",
                                  "http://c.d")
print assert_resource_property("http://a.b", "vivo:authorInAuthorlist",
                                  "42")

print datetime.now(), "Finish"

Пример #4
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]
Пример #5
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]
Пример #6
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]
Пример #7
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]
Пример #8
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]
Пример #9
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]
Пример #10
0
position_data = read_csv('position_data.csv')
current_ufids = set()
for row_number, row in position_data.items():
    current_ufids.add(row['UFID'])
print datetime.now(), "UF has ", len(current_ufids), "ufids on the pay list"

#   Compare each ufid in VIVO to the ufids in the set of current ufids.  If
#   current, mark as current.  If not current, subtract current

k = 0
current_uri = untag_predicate('ufVivo:UFCurrentEntity')
for ufid in vivo_ufids.keys():
    k += 1
    if k % 1000 == 0:
        print datetime.now(), k
    if ufid in current_ufids:
        ardf += assert_resource_property(vivo_ufids[ufid], 'rdf:type', current_uri)
    else:
        srdf += assert_resource_property(vivo_ufids[ufid], 'rdf:type', current_uri)

ardf += rdf_footer()
srdf += rdf_footer()

add_file = open("current_add.rdf", "w")
sub_file = open("current_sub.rdf", "w")
print >>add_file, ardf
print >>sub_file, srdf
add_file.close()
sub_file.close()
print datetime.now(), "End"