示例#1
0
    def convert(self, namespace):
        '''Converts the XML file into a RDFLib graph.
        
        Parameters
        @namespace: A RDFLib Namespace.
        
        Returns
        @graph: The RDFLib Graph of the activity.
        @id: The ID of the activity.
        @last_updated: The DateTime of the last update.'''
        
        if (self.id == None) or (self.id == ""):
            return None, None, None

        defaults = self.get_codelist_defaults()
        defaults['namespace'] = namespace
        
        converter = IatiElements.CodelistElements(defaults)
        
        for entry in self.xml:
            
            # Get code, language and category code from entry
            code = AttributeHelper.attribute_text(entry, 'code')
            language = AttributeHelper.attribute_text(entry, 'language')
            category_code = AttributeHelper.attribute_text(entry, 'category')
            
            for attribute in entry:
                
                try:
                    funcname = attribute.tag.replace("-","_")
                
                    update = getattr(converter, funcname)
                    update(attribute, code, language, category_code)
                    
                except AttributeError as e:
                    print "Error in " + funcname + ", " + self.id + ": " + str(e)
        
        
        # Add 'is codelist type' statement 
        resulting_graph = converter.get_result()

        resulting_graph.add((namespace['codelist/' + self.id],
                             RDF.type,
                             namespace['codelist']))
        
        # Add label for codelist
        resulting_graph.add((namespace['codelist/' + self.id],
                             RDFS.label,
                             Literal(self.id, lang=defaults['language'])))    
        
                
        return resulting_graph, self.id, self.last_updated
示例#2
0
 def get_id(self):
     '''Returns the ID of the activity.
     
     Returns
     @activity_id: The ID of the activity.'''
     
     id = AttributeHelper.attribute_text(self.xml, 'iati-identifier')
     
     if not id == None:
         return str(id[0].split()[0])
     
     return id
示例#3
0
    def get_id(self):
        '''Returns the ID of the organisation.
        
        Returns
        @activity_id: The ID of the organisation.'''
        
        id = AttributeHelper.attribute_text(self.xml, 'iati-identifier')
        
        if not id == None:
            return str("-".join(id[0].split()))
        
        elif id == None:
            id = AttributeHelper.attribute_text(self.xml, 'identifier')
            
            if not id == None:
                return str("-".join(id[0].split()))
        
#            if id == None:
#                try:
#                    id = self.xml.find('reporting-org').attrib['ref']
#                except:
#                    id = None
        
        return id