def processRelations(self): # create relations list self.fetchRelations() # resolve <actor> roles RoleResolver.resolveActorRoles(self.relations, self.sentences) # apply constraints and remove invalid roles self.applyConstraints() # debug # print '\n---------------------------------------------------' # self.printRelations() # print '---------------------------------------------------' # look over all relations for relation in self.relations: # check whether relation contains state/price information # what's the point? if relation.containsMainInformation(): # first find agency # agency_role = relation.getSecondLevelRole('<actor_agency:1>') agency_roles = relation.getSecondLevelRoles('<actor_agency:1>') for agency_role in self.orderRoles(agency_roles): self.findNamedEntityCoreferent(agency_role) # ...then resolve stock role stock_roles = relation.getSecondLevelRoles('<actor_stock:1>') for stock_role in self.orderRoles(stock_roles): self.findNamedEntityCoreferent(stock_role)
def getAgencies(self, relation): agencies = [] agencies_phrases = relation.getSecondLevelRoles('<actor_agency:1>') # collect all agency phrases from given relation for candidate in agencies_phrases: if candidate.coreferent != None and Utils.isNamedEntity(candidate.coreferent) and not candidate.coreferent in agencies_phrases: # get named entities from given phrase for entity_str in Utils.getNamedEntities(candidate.coreferent): # is it relevant agency string? Dfens against bugs and wrong parses if RoleResolver.isRelevantAgencyEntity(entity_str) and not entity_str.replace('_', ' ') in agencies: agencies.append(entity_str.replace('_', ' ')) return agencies