def __init__(self, token, quantityType): """ initialize template given a token containing a quantity """ BaseTemplate.__init__(self, quantityType) self.token = token self.time = None self.start = self.token.index self.end = self.token.index self.value = token.getValue()
def __init__(self, mention, mentionType, useAnnotations=False): """ initialize template given a mention """ BaseTemplate.__init__(self, mentionType) self.mention = mention self.start = mention.start self.end = mention.end self.id = '' self.annotatedId = '' self.parent = None self.children = [] self.matched = False self.exactMatch = False self.matchedTemplate = None self.outcomeMeasurements = [] if self.mention.matchedMention != None or useAnnotations: if useAnnotations: annotatedMention = self.mention else: annotatedMention = self.mention.matchedMention # this mention has already been matched to an annotated mention # use the id from that mention for token in annotatedMention.tokens: # find first token with an id id = token.getAnnotationAttribute(self.type, 'id') if len(id) > 0: self.annotatedId = id break self.name = self.mention.text.strip() self.umlsCodes = set([]) self.snomedCodes = set([]) for token in mention.tokens: for uc in token.umlsConcepts: self.umlsCodes.add(uc.id) if len(uc.snomed) > 0: self.snomedCodes.add(uc.snomed)