def getXML(self, doc, elementName): """ return an xml node that contains label information """ node = doc.createElement(elementName) node.setAttribute('type',self.type) for attrib, value in self.attributes.items(): node.appendChild(xmlutil.createNodeWithTextChild(doc, attrib, value)) return node
def getXML(self, doc): """ return an xml element containing all token information """ node = doc.createElement('token') node.setAttribute('id', str(self.index)) node.setAttribute('text', self.text) if len(self.lemma) > 0 and self.lemma != self.text: node.setAttribute('lemma', self.lemma) if len(self.pos) > 0: node.setAttribute('pos', self.pos) # add governors for gov in self.governors: node.appendChild(gov.getXML(doc, 'gov')) # add dependents for dep in self.dependents: node.appendChild(dep.getXML(doc, 'dep')) # add semantic tags for tag in self.semanticTags: sNode = xmlutil.createNodeWithTextChild(doc, 'semantic', tag) node.appendChild(sNode) # add true (original) annotations for annotation in self.annotations: node.appendChild(annotation.getXML(doc, 'annotation')) # add detected labels for label in self.labels: node.appendChild(label.getXML(doc, 'label')) for uc in self.umlsConcepts: node.appendChild(uc.getXML(doc)) return node
def getXML(self, doc, elementName): """ return an xml node that contains label information """ node = doc.createElement(elementName) node.setAttribute('type', self.type) for attrib, value in self.attributes.items(): node.appendChild( xmlutil.createNodeWithTextChild(doc, attrib, value)) return node
def getXML(self, doc): node = doc.createElement("umls") node.setAttribute("id", self.id) if len(self.snomed) > 0: node.setAttribute("snomed", self.snomed) node.setAttribute("score", str(self.score)) if self.isNegated: node.setAttribute("negated", "true") else: node.setAttribute("negated", "false") for type in self.types: node.appendChild(xmlutil.createNodeWithTextChild(doc, "type", type)) if self.inSnomed: node.appendChild(xmlutil.createNodeWithTextChild(doc, "source", "SNOMEDCT")) if self.inRxnorm: node.appendChild(xmlutil.createNodeWithTextChild(doc, "source", "RXNORM")) return node
def getXML(self, doc): """ return an xml element containing information for a clinical report element""" node = doc.createElement('report') node.appendChild(xmlutil.createNodeWithTextChild(doc, 'id', self.id)) node.appendChild(xmlutil.createNodeWithTextChild(doc, 'gender', self.gender)) node.appendChild(xmlutil.createNodeWithTextChild(doc, 'minAge', self.minAge)) node.appendChild(xmlutil.createNodeWithTextChild(doc, 'maxAge', self.maxAge)) if len(self.locations) > 0: lcNode = doc.createElement('location_countries') node.appendChild(lcNode) for country in self.locations: lcNode.appendChild(xmlutil.createNodeWithTextChild(doc, 'country', country)) for condition in self.conditions: node.appendChild(condition.getXML(doc)) if len(self.eligibilityCriteria) > 0: ecNode = doc.createElement('eligibility') node.appendChild(ecNode) for ec in self.eligibilityCriteria: ecNode.appendChild(ec.getXML(doc)) if len(self.inclusionCriteria) > 0: icNode = doc.createElement('inclusion') node.appendChild(icNode) for ic in self.inclusionCriteria: icNode.appendChild(ic.getXML(doc)) if len(self.exclusionCriteria) > 0: ecNode = doc.createElement('exclusion') node.appendChild(ecNode) for ec in self.exclusionCriteria: ecNode.appendChild(ec.getXML(doc)) for intervention in self.interventions: node.appendChild(intervention.getXML(doc)) for outcome in self.outcomes: node.appendChild(outcome.getXML(doc)) return node
def getXML(self, doc): """ return xml node contain all information relevant to this age value""" node = xmlutil.createNodeWithTextChild(doc, 'AgeValue', str(self.value)) if self.type != None: node.setAttribute('type',self.type) if self.units != None: node.setAttribute('units', self.units) if self.bounds != None: node.setAttribute('bounds', str(self.bounds)) node.setAttribute('source', self.source) return node
def getXML(self, doc): """ return xml node contain all information relevant to this age value""" node = xmlutil.createNodeWithTextChild(doc, 'AgeValue', str(self.value)) if self.type != None: node.setAttribute('type', self.type) if self.units != None: node.setAttribute('units', self.units) if self.bounds != None: node.setAttribute('bounds', str(self.bounds)) node.setAttribute('source', self.source) return node
def getXML(self, doc): """ Create an XML element with publication information """ node = doc.createElement('PublicationInformation') if self._journalNode is not None: node.appendChild(self._journalNode) node.appendChild(xmlutil.createNodeWithTextChild(doc, 'Country', self._country)) if self._authorListNode is not None: node.appendChild(self._authorListNode) if self._publicationTypeListNode is not None: node.appendChild(self._publicationTypeListNode) xmlutil.normalizeXMLTree(node) return node
def getGroupXML(self, doc, omTemplate, idPrefix): """ return XML node containing outcome results for group. omTemplate = outcome measurement template containing outcome info for the group""" groupNode = self.createGroupNode(doc, omTemplate.getGroup(), idPrefix) bad = omTemplate.getOutcomes() if bad >= 0: badNode = xmlutil.createNodeWithTextChild(doc, 'Bad', str(bad)) groupNode.appendChild(badNode) size = omTemplate.getGroupSize() if size > 0: gsNode = xmlutil.createNodeWithTextChild(doc, 'GroupSize', str(size)) groupNode.appendChild(gsNode) er = omTemplate.eventRateString() if len(er) > 0: er = omTemplate.eventRateString() erNode = xmlutil.createNodeWithTextChild(doc, 'EventRate', er) groupNode.appendChild(erNode) scoreNode = xmlutil.createNodeWithTextChild(doc, 'Score', str(omTemplate.getConfidence())) groupNode.appendChild(scoreNode) return groupNode
def getXML(self, doc, idPrefix): """ return an xml node that contains information about the outcomes measured in the study. """ locationList = self.getLocations() if len(locationList) == 0: return None locationListNode = doc.createElement('Locations') lCount = 0 for location in locationList: locationNode = xmlutil.createNodeWithTextChild(doc, 'Location', location) locationNode.setAttribute('source', self.source) locationNode.setAttribute('id', idPrefix+'loc'+str(lCount)) lCount += 1 # setUMLSAttribute(nameNode, oTemplate) locationListNode.appendChild(locationNode) return locationListNode
def getXML(self, doc, idPrefix): """ return an xml node that contains information about the outcomes measured in the study. """ locationList = self.getLocations() if len(locationList) == 0: return None locationListNode = doc.createElement('Locations') lCount = 0 for location in locationList: locationNode = xmlutil.createNodeWithTextChild( doc, 'Location', location) locationNode.setAttribute('source', self.source) locationNode.setAttribute('id', idPrefix + 'loc' + str(lCount)) lCount += 1 # setUMLSAttribute(nameNode, oTemplate) locationListNode.appendChild(locationNode) return locationListNode
def getXML(self, doc): """ return an xml element containing sentence information """ node = doc.createElement('sentence') if len(self.section) > 0: node.setAttribute('section', self.section) if len(self.nlmCategory) > 0: node.setAttribute('nlmCategory', self.nlmCategory) # if self.templates.noTemplates() == False: # node.appendChild(self.templates.getXML(doc)) for token in self.tokens: node.appendChild(token.getXML(doc)) for umlsChunk in self.umlsChunks: node.appendChild(umlsChunk.getXML(doc)) if self.parseTree != None: s = self.parseTree.treebankString() # s = self.parseString node.appendChild(xmlutil.createNodeWithTextChild(doc, 'parse', s)) return node
def getOutcomeXML(self, doc, oTemplate, idPrefix): """ write given outcome template to XML file stream """ outcomeNode = doc.createElement('Outcome') if oTemplate.isPrimary(): oType = 'primary' else: oType = 'unknown' poNode = xmlutil.createNodeWithTextChild(doc, 'Type', oType) id = idPrefix+oTemplate.id+'oType' poNode.setAttribute('Id', id) oTemplate.primaryOutcomeEvaluation.id = id outcomeNode.appendChild(poNode) id = idPrefix+oTemplate.id outcomeNode.setAttribute('Id', id) oTemplate.evaluation.id = id nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', oTemplate.getCanonicalName()) # setUMLSAttribute(nameNode, oTemplate) outcomeNode.appendChild(nameNode) # write Cost values cvCount = 0 for cvTemplate in oTemplate.costValues: cvNode = doc.createElement('CostValue') outcomeNode.appendChild(cvNode) id = idPrefix + oTemplate.id + 'cv' + str(cvCount) cvNode.setAttribute('id', id) cvCount += 1 if cvTemplate.group.name is not None: cvNode.appendChild(self.createGroupNode(doc, cvTemplate.group, idPrefix)) valueNode = xmlutil.createNodeWithTextChild(doc, 'Value', cvTemplate.token.text) valueNode.setAttribute('units', cvTemplate.token.getUnits()) cvNode.appendChild(valueNode) # write ARR/NNT epCount = 0 for ssTemplate in oTemplate.summaryStats: epNode = doc.createElement('Endpoint') id = idPrefix+oTemplate.id+'ep'+str(epCount) ssTemplate.evaluation.id = id epNode.setAttribute('id', id) epCount += 1 outcomeNode.appendChild(epNode) epNode.appendChild(self.getGroupXML(doc, ssTemplate.lessEffective, idPrefix)) epNode.appendChild(self.getGroupXML(doc, ssTemplate.moreEffective, idPrefix)) if ssTemplate.time != None: tNode = xmlutil.createNodeWithTextChild(doc, 'time', ssTemplate.time.name) if len(ssTemplate.time.units) > 0: tNode.setAttribute('units', ssTemplate.time.units) if ssTemplate.time.value > 0: tNode.setAttribute('value', str(ssTemplate.time.value)) epNode.appendChild(tNode) ssNode = doc.createElement('SummaryStatistics') epNode.appendChild(ssNode) sNode = doc.createElement('Statistic') sNode.setAttribute('Worse', idPrefix+ssTemplate.lessEffective.getGroup().id) sNode.setAttribute('Better', idPrefix+ssTemplate.moreEffective.getGroup().id) ssNode.appendChild(sNode) arNode = doc.createElement('AbsoluteRisk') sNode.appendChild(arNode) arNode.setAttribute('Type', ssTemplate.riskType()) vNode = xmlutil.createNodeWithTextChild(doc, 'Value', ssTemplate.arrString()) arNode.appendChild(vNode) if ssTemplate.hasConfidenceIntervals(): iNode = doc.createElement('Interval') iNode.setAttribute('lower', ssTemplate.arrLowerBound()) iNode.setAttribute('upper', ssTemplate.arrUpperBound()) arNode.appendChild(iNode) if ssTemplate.infiniteNumberNeeded() == False: nnNode = doc.createElement('NumberNeeded') sNode.appendChild(nnNode) nnNode.setAttribute('Type', ssTemplate.numberNeededType()) vNode = xmlutil.createNodeWithTextChild(doc, 'Value', ssTemplate.nntString()) nnNode.appendChild(vNode) if ssTemplate.hasConfidenceIntervals(): iNode = doc.createElement('Interval') iNode.setAttribute('lower', ssTemplate.nntLowerBound()) iNode.setAttribute('upper', ssTemplate.nntUpperBound()) nnNode.appendChild(iNode) # for omTemplate in oTemplate.unusedNumbers: # epNode = doc.createElement('Endpoint') # epNode.setAttribute('id', idPrefix+oTemplate.id+'ep'+str(epCount)) # epCount += 1 # outcomeNode.appendChild(epNode) # if omTemplate.getGroup() != None: # if omTemplate.getTime() != None: # tNode = xmlutil.createNodeWithTextChild(doc, 'time', omTemplate.getTime().name) # if len(omTemplate.getTime().units) > 0: # tNode.setAttribute('units', omTemplate.getTime().units) # if omTemplate.getTime().value > 0: # tNode.setAttribute('value', str(omTemplate.getTime().value)) # # epNode.appendChild(tNode) # outcomeNode.appendChild(epNode) # epNode.appendChild(self.getGroupXML(doc, omTemplate, idPrefix)) return outcomeNode
def getXML(self, doc, idPrefix): node = xmlutil.createNodeWithTextChild(doc, 'Gender', self.value) node.setAttribute('source', self.source) node.setAttribute('id', idPrefix + 'gen0') return node
def writeXML(self, path, version): """ Write summary to XML file in the destination directory specified by path. """ idPrefix = self.abstract.id + 'v' + version # build XML summary doc = xml.dom.minidom.Document() articleNode = doc.createElement('Study') if self.randomized: articleNode.setAttribute('RandomizationPresent', 'true') else: articleNode.setAttribute('RandomizationPresent', 'false') articleNode.setAttribute('Version', version) gmTime = time.gmtime() cNode = doc.createElement('Created') articleNode.appendChild(cNode) cNode.appendChild(xmlutil.createNodeWithTextChild(doc, 'Month', str(gmTime.tm_mon))) cNode.appendChild(xmlutil.createNodeWithTextChild(doc, 'Day', str(gmTime.tm_mday))) cNode.appendChild(xmlutil.createNodeWithTextChild(doc, 'Year', str(gmTime.tm_year))) nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', self.abstract.id) articleNode.appendChild(nameNode) titleString = '' for s in self.abstract.titleSentences: titleString += s.toString() titleNode = xmlutil.createNodeWithTextChild(doc, 'Title', titleString) articleNode.appendChild(titleNode) link = 'http://www.ncbi.nlm.nih.gov/pubmed/' + self.abstract.id linkNode = xmlutil.createNodeWithTextChild(doc, 'AbstractLink', link) articleNode.appendChild(linkNode) if self.abstract.report is not None and self.abstract.report.id[0:3] == 'NCT': link = 'http://clinicaltrials.gov/ct2/show/study/' + self.abstract.report.id linkNode = xmlutil.createNodeWithTextChild(doc, 'TrialRegistryLink', link) articleNode.appendChild(linkNode) node = self.locationList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) if self.useTrialReports and self.abstract.report is not None \ and len(self.abstract.report.conditions) > 0: cListNode = doc.createElement('ConditionsOfInterest') articleNode.appendChild(cListNode) for condition in self.abstract.report.conditions: cNode = doc.createElement('Condition') cNode.appendChild(xmlutil.createNodeWithTextChild(doc, 'Name', condition.sentences[0].toString())) cNode.setAttribute('source', 'trial_registry') cListNode.appendChild(cNode) node = self.subjectList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) node = self.outcomeList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) if self.abstract.meshHeadingList is not None: articleNode.appendChild(self.abstract.meshHeadingList.getXML(doc)) htmlString = StringIO.StringIO() self.writeHTML(htmlString, showError=False) htmlNode = xmlutil.createNodeWithTextChild(doc, 'HTMLData', htmlString.getvalue()) articleNode.appendChild(htmlNode) htmlString.close() # write summary to XML file filename = path + self.abstract.id + '.summary.xml' out = open(filename, 'w') out.write('<?xml version="1.0" encoding="utf-8"?>\n') # out.write('<?xml-stylesheet href="abstract.xsl" type="text/xsl"?>\n') xmlutil.writexml(articleNode, out) out.close()
def writeXML(self, path, version): """ Write summary to XML file in the destination directory specified by path. """ idPrefix = self.abstract.id + 'v' + version # build XML summary doc = xml.dom.minidom.Document() articleNode = doc.createElement('Study') if self.randomized: articleNode.setAttribute('RandomizationPresent', 'true') else: articleNode.setAttribute('RandomizationPresent', 'false') articleNode.setAttribute('Version', version) gmTime = time.gmtime() cNode = doc.createElement('Created') articleNode.appendChild(cNode) cNode.appendChild( xmlutil.createNodeWithTextChild(doc, 'Month', str(gmTime.tm_mon))) cNode.appendChild( xmlutil.createNodeWithTextChild(doc, 'Day', str(gmTime.tm_mday))) cNode.appendChild( xmlutil.createNodeWithTextChild(doc, 'Year', str(gmTime.tm_year))) nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', self.abstract.id) articleNode.appendChild(nameNode) titleString = '' for s in self.abstract.titleSentences: titleString += s.toString() titleNode = xmlutil.createNodeWithTextChild(doc, 'Title', titleString) articleNode.appendChild(titleNode) link = 'http://www.ncbi.nlm.nih.gov/pubmed/' + self.abstract.id linkNode = xmlutil.createNodeWithTextChild(doc, 'AbstractLink', link) articleNode.appendChild(linkNode) if self.abstract.report is not None and self.abstract.report.id[ 0:3] == 'NCT': link = 'http://clinicaltrials.gov/ct2/show/study/' + self.abstract.report.id linkNode = xmlutil.createNodeWithTextChild(doc, 'TrialRegistryLink', link) articleNode.appendChild(linkNode) node = self.locationList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) if self.useTrialReports and self.abstract.report is not None \ and len(self.abstract.report.conditions) > 0: cListNode = doc.createElement('ConditionsOfInterest') articleNode.appendChild(cListNode) for condition in self.abstract.report.conditions: cNode = doc.createElement('Condition') cNode.appendChild( xmlutil.createNodeWithTextChild( doc, 'Name', condition.sentences[0].toString())) cNode.setAttribute('source', 'trial_registry') cListNode.appendChild(cNode) node = self.subjectList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) node = self.outcomeList.getXML(doc, idPrefix) if node is not None: articleNode.appendChild(node) if self.abstract.meshHeadingList is not None: articleNode.appendChild(self.abstract.meshHeadingList.getXML(doc)) htmlString = StringIO.StringIO() self.writeHTML(htmlString, showError=False) htmlNode = xmlutil.createNodeWithTextChild(doc, 'HTMLData', htmlString.getvalue()) articleNode.appendChild(htmlNode) htmlString.close() # write summary to XML file filename = path + self.abstract.id + '.summary.xml' out = open(filename, 'w') out.write('<?xml version="1.0" encoding="utf-8"?>\n') # out.write('<?xml-stylesheet href="abstract.xsl" type="text/xsl"?>\n') xmlutil.writexml(articleNode, out) out.close()
def getXML(self, doc, idPrefix): """ return an xml node that contains information about subjects in the study. """ # if len(self.groupTemplates) == 0 and len(self.populationTemplates) == 0 \ # and len(self.ageTemplates) == 0 and len(self.conditionTemplates) == 0: # return None subjectListNode = doc.createElement('Subjects') eligibilityNode = doc.createElement('Eligibility') subjectListNode.appendChild(eligibilityNode) # for pTemplate in self.populationTemplates: # popNode = doc.createElement('Population') # # setUMLSAttribute(popNode, pTemplate) # nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', pTemplate.name) # popNode.appendChild(nameNode) # eligibilityNode.appendChild(popNode) eligibilityNode.appendChild(self.gender.getXML(doc, idPrefix)) if len(self.ageInfo.ageValues) > 0: eligibilityNode.appendChild(self.ageInfo.getXML(doc, idPrefix)) for cTemplate in self.conditionTemplates: cNode = doc.createElement('Criteria') cNode.setAttribute('source', 'abstract') id = idPrefix+cTemplate.id cTemplate.evaluation.id = id cNode.setAttribute('Id', id) # setUMLSAttribute(cNode, cTemplate) nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', cTemplate.name) cNode.appendChild(nameNode) type = 'unknown' firstToken = cTemplate.mention.tokens[0] if firstToken.text == 'with' or firstToken.lemma == 'have': type = 'inclusion' elif firstToken.text == 'without': type = 'exclusion' cNode.setAttribute('type', type) eligibilityNode.appendChild(cNode) if self.useTrialReports and self.abstract.report != None: icCount = 0 ecCount = 0 for criteria in self.abstract.report.inclusionCriteria: cNode = doc.createElement('Criteria') cNode.setAttribute('source', 'trial_registry') cNode.setAttribute('Id', idPrefix+'ic'+str(icCount)) icCount += 1 text = criteria.sentences[0].toString() for i in range(1, len(criteria.sentences)): text = text + ' ' + criteria.sentences[i].toString() nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', text) cNode.appendChild(nameNode) cNode.setAttribute('type', 'inclusion') eligibilityNode.appendChild(cNode) for criteria in self.abstract.report.exclusionCriteria: cNode = doc.createElement('Criteria') cNode.setAttribute('source', 'trial_registry') cNode.setAttribute('Id', idPrefix+'ec'+str(ecCount)) ecCount += 1 text = criteria.sentences[0].toString() for i in range(1, len(criteria.sentences)): text = text + ' ' + criteria.sentences[i].toString() nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', text) cNode.appendChild(nameNode) cNode.setAttribute('type', 'exclusion') eligibilityNode.appendChild(cNode) for gTemplate in self.groupTemplates: groupNode = doc.createElement('Group') id = idPrefix+gTemplate.id gTemplate.evaluation.id = idPrefix+gTemplate.id groupNode.setAttribute('Id', id) groupNode.setAttribute('Role', gTemplate.role) gSize = gTemplate.getSize(maxSize=True) if gSize > 0: sNode = xmlutil.createNodeWithTextChild(doc, 'Size', str(gSize)) id = idPrefix+gTemplate.id+'size' gTemplate.groupSizeEvaluation.id = id sNode.setAttribute('Id', id) groupNode.appendChild(sNode) # setUMLSAttribute(groupNode, gTemplate) nameNode = xmlutil.createNodeWithTextChild(doc, 'Name', gTemplate.name) groupNode.appendChild(nameNode) subjectListNode.appendChild(groupNode) return subjectListNode
def getXML(self, doc, idPrefix): node = xmlutil.createNodeWithTextChild(doc, 'Gender', self.value) node.setAttribute('source', self.source) node.setAttribute('id', idPrefix+'gen0') return node