예제 #1
0
 def fixit(current_object, prefix_dictionary):
     """
     Read the def data structure and replace all string URIs with URIRef entities
     :param current_object: the piece of the data structure to be fixed
     :return current_object: the piece repaired in place
     """
     from rdflib import URIRef
     if isinstance(current_object, dict):
         for k in current_object.keys():
             current_object[k] = fixit(current_object[k], prefix_dictionary)
     elif isinstance(current_object, list):
         for i in range(0, len(current_object)):
             current_object[i] = fixit(current_object[i], prefix_dictionary)
     elif isinstance(current_object, basestring):
         if current_object.startswith("http://"):
             current_object = URIRef(current_object)
         elif current_object.startswith("xsd:"):
             current_object = cast_to_rdflib(current_object)
         elif ':' in current_object:
             k = current_object.find(':')
             tag = str(current_object[0:k + 1])
             if tag in prefix_dictionary:
                 current_object = URIRef(
                     str(current_object).replace(tag,
                                                 prefix_dictionary[tag]))
     return current_object
예제 #2
0
파일: vivopump.py 프로젝트: ctsit/vivo-pump
 def fixit(current_object, prefix_dictionary):
     """
     Read the def data structure and replace all string URIs with URIRef entities
     :param current_object: the piece of the data structure to be fixed
     :return current_object: the piece repaired in place
     """
     from rdflib import URIRef
     if isinstance(current_object, dict):
         for k in current_object.keys():
             current_object[k] = fixit(current_object[k], prefix_dictionary)
     elif isinstance(current_object, list):
         for i in range(0, len(current_object)):
             current_object[i] = fixit(current_object[i], prefix_dictionary)
     elif isinstance(current_object, basestring):
         if current_object.startswith("http://"):
             current_object = URIRef(current_object)
         elif current_object.startswith("xsd:"):
             current_object = cast_to_rdflib(current_object)
         elif ':' in current_object:
             k = current_object.find(':')
             tag = str(current_object[0:k + 1])
             if tag in prefix_dictionary:
                 current_object = URIRef(str(current_object).replace(tag, prefix_dictionary[tag]))
     return current_object
예제 #3
0
    station_name = URIRef(stations.find('{elrad}name').text + ' station')

    # contact
    g.add((station_name, hasAddress, Literal(root.find('.//{elrad}address').text)))
    g.add((station_name, hasPhone, Literal(root.find('.//{elrad}phone').text)))

    #toilet
    if root.find('.//{elrad}publictoilet').attrib == {'Exists': 'Yes'}:
        g.add((station_name, hasPublicToilet, Literal('yes')))
        g.add((station_name, hasLocation, Literal(root.find('.//{elrad}location').text)))
        g.add((station_name, isPaymentRequired, Literal(root.find('.//{elrad}paymentrequired').text)))
    else:
        g.add((station_name, hasPublicToilet, Literal('no')))

    #facilities
    if station_name.find('.//{elrad}facilities'):
        g.add((station_name, hasFacilities, Literal(station_name + ' facilities')))
        g.add((URIRef(station_name + ' facilities'), hasLifts, Literal(root.find('.//{elrad}facility/[@name="Lifts"]').text)))
        g.add((URIRef(station_name + ' facilities'), hasGates, Literal(root.find('.//{elrad}facility/[@name="Gates"]').text)))
        g.add((URIRef(station_name + ' facilities'), hasVendingMachines, Literal(root.find('.//{elrad}facility/[@name="Vending Machines"]').text)))
        g.add((URIRef(station_name + ' facilities'), hasHelpPoints, Literal(root.find('.//{elrad}facility/[@name="Help Points"]').text)))
    else:
        g.add((station_name, hasFacilities, Literal('no')))

    #entrance
    if root.findall('.//{elrad}entrances'):
        entrances = root.findall('.//{elrad}entrances')
        g.add((station_name, hasEntrances,Literal(len(entrances))))
        for entrance in entrances:
            try:
                g.add((URIRef(station_name + ' entrance'),hasEntrance,Literal(entrance.find('{elrad}name').text)))