Exemplo n.º 1
0
def generate_features(input_data, mode, filename=None):
    new_data = []

    from umls import UMLS
    from generate_features import Generator
    cui_retriever = UMLS()
    feature_generator = Generator(cui_retriever)

    def save_one_line(doc_id, sentence_id, features, filename):
        line = ','.join([doc_id, sentence_id, features]) + "\n"

        # save data to files
        with open(filename, 'a') as f:
            f.writelines(line)

    for i, line in enumerate(input_data):
        import datetime
        print(i, datetime.datetime.now(), mode, line)

        sentence = line[-1]
        sentence_id = line[-2]
        doc_id = line[-3]
        features = feature_generator.produce_features_from_sentence(
            sentence, sentence_id, doc_id, mode)
        new_data.append(features)

        if filename is not None:
            # save the data
            save_one_line(doc_id, sentence_id, features, filename)

    return new_data
Exemplo n.º 2
0
	def report_row(self):
		""" Generates an HTML row for the report_row document.
		"""
		if self.criteria is None or len(self.criteria) < 1:
			return ''
		
		# collect criteria
		rows = []
		for crit in self.criteria:
			
			# this criterium has been codified
			if len(crit.snomed) > 0:
				c_html = '<td rowspan="%d">%s</td><td rowspan="%d">%s</td>' % (len(crit.snomed), crit.text, len(crit.snomed), 'in' if crit.is_inclusion else 'ex')
				for sno in crit.snomed:
					rows.append(c_html + '<td>%s</td><td>%s</td>' % (sno, UMLS.lookup_snomed(sno)))
					if len(c_html) > 0:
						c_html = ''
			
			# no codes for this criterium
			else:
				rows.append('<td>%s</td><td>%s</td><td></td>' % (crit.text, 'in' if crit.is_inclusion else 'ex'))
		
		if len(rows) < 1:
			return ''
		
		# compose HTML
		html = """<tr>
		<td rowspan="%d">
			<a href="http://clinicaltrials.gov/ct2/show/%s" target="_blank">%s</a>
		</td>
		<td rowspan="%d" onclick="toggle(this)">
			<div style="display:none;">%s</div>
		</td>
		%s</tr>""" % (len(rows), self.nct, self.nct, len(rows), self.eligibility_formatted, rows[0])
		
		rows.pop(0)
		for row in rows:
			html += "<tr>%s</tr>" % row
		
		return html
Exemplo n.º 3
0
	sys.exit(1)

if _BG:
	from settings_background import ENDPOINTS
else:
	from settings import ENDPOINTS


def forever_alone():
	with open('forever.txt') as handle:
		return handle.read()


# if run as a script, we kick in here
if __name__ == "__main__":
	UMLS.import_snomed_if_necessary()
	
	if _BG:
		print "->  Running as a background app"
	
	# load all rules
	rules = Rule.load_rules()
	if len(rules) < 1:
		print "There are no rules, no point in continuing"
		print forever_alone()
		sys.exit(1)
	print "->  Did load %d %s" % (len(rules), 'rule' if 1 == len(rules) else 'rules')
	
	# multiple endpoints? Ask which one to use
	ep = None
	if len(ENDPOINTS) > 1: