def __init__(self, row): self.identifier, self.attributes = None, {} for key, value in parseTokens(row): if key == u"Identifier": self.identifier = value else: self.attributes[_specificsMap[key]] = value
def generateGraph(self): context = aq_inner(self.context) if not context.webServiceURL: raise MissingParameterError(context, 'webServiceURL') if not context.operationName: raise MissingParameterError(context, 'operationName') if not context.identifyingKey: raise MissingParameterError(context, 'identifyingKey') if not context.uriPrefix: raise MissingParameterError(context, 'uriPrefix') if not context.typeURI: raise MissingParameterError(context, 'typeURI') verificationNum = context.verificationNum if context.verificationNum else DEFAULT_VERIFICATION_NUM predicates = {} for objID, item in context.contentItems(): predicates[item.title] = IAsserter(item) client = get_suds_client(context.webServiceURL, context) function = getattr(client.service, context.operationName) horribleString = function(verificationNum) graph = rdflib.Graph() for row in splitDMCCRows(horribleString): subjectURI, statements, statementsMade = None, [], False for key, value in parseTokens(row): if key == context.identifyingKey and not subjectURI: subjectURI = URIRef(context.uriPrefix + value) elif key in predicates and len(value) > 0: statements.extend(predicates[key].characterize(value)) statementsMade = True # DMCC is giving out empty rows: they have an Identifier number, but no values in any of the columns. # While we may wish to generate RDF for those (essentially just saying "Disease #31 exists", for example) # It means we need to update EDRN Portal code to handle them, which we can't do right now. # So just drop these. TODO: Add them back, but update the EDRN Portal. if statementsMade: graph.add((subjectURI, rdflib.RDF.type, URIRef(context.typeURI))) for predicate, obj in statements: graph.add((subjectURI, predicate, obj)) return graph
def __init__(self, row): self.identifier = None for key, value in parseTokens(row): if key == u"Identifier": self.identifier = value elif key == u"Protocol_1_Identifier": self.fromID = value elif key == u"Protocol_2_Identifier": self.toID = value elif key == u"Protocol_relationship_type": self.relationshipType = value
def generateGraph(self): graph = rdflib.Graph() context = aq_inner(self.context) verificationNum = context.verificationNum if context.verificationNum else DEFAULT_VERIFICATION_NUM client = get_suds_client(context.webServiceURL, context) committees = getattr(client.service, context.committeeOperation) members = getattr(client.service, context.membershipOperation) # Get the committees horribleCommittees = committees(verificationNum) for row in splitDMCCRows(horribleCommittees): subjectURI = None statements = {} for key, value in parseTokens(row): if key == u'Identifier' and not subjectURI: subjectURI = URIRef(context.uriPrefix + value) graph.add((subjectURI, rdflib.RDF.type, URIRef(context.typeURI))) elif key in _committeePredicates and len(value) > 0: predicateURI = URIRef(getattr(context, _committeePredicates[key])) statements[predicateURI] = Literal(value) for predicateURI, obj in statements.iteritems(): graph.add((subjectURI, predicateURI, obj)) # Get the members of the committees horribleMembers = members(verificationNum) for row in splitDMCCRows(horribleMembers): subjectURI = predicateURI = obj = None for key, value in parseTokens(row): if not value: continue if key == u'committee_identifier': subjectURI = URIRef(context.uriPrefix + value) elif key == u'Registered_Person_Identifer': obj = URIRef(context.personPrefix + value) elif key == u'roleName': if value not in _roleNamePredicates: continue predicateURI = URIRef(getattr(context, _roleNamePredicates[value])) if subjectURI and predicateURI and obj: graph.add((subjectURI, predicateURI, obj)) # C'est tout. return graph
def getSlottedItems(self, operation, kind): function = getattr(self.client.service, operation) horribleString = function(self.verificationNum) objects = {} obj = None for row in splitDMCCRows(horribleString): lastSlot = None for key, value in parseTokens(row): if key == u"Identifier": if obj is None or obj.identifier != value: obj = kind(value) objects[value] = obj elif key == u"slot": lastSlot = value elif key == u"value": if lastSlot is None: raise ValueError('Value with no preceding slot in row "%r"' % row) obj.slots[lastSlot] = value lastSlot = None return objects
def main(): file = open("verbs.txt", "r", encoding='utf-8') Dict = {} for line in file: tokens = utils.extractTokens(line) t, e, v = utils.parseTokens(tokens) if e != '': print(line) print(tokens) print(t) print(e) print(v) else: Dict = utils.includeInDict(v, Dict) file.close() for Verb in Dict.keys(): Paradigm = Dict[Verb]['Paradigm'] if Paradigm != '': for Mood in utils.moodId: if Mood in Dict[Paradigm]: Dict[Verb][Mood] = utils.conjugate(Verb, Mood, Paradigm, Dict) utils.printDict(Dict)