def createOutputObjects(self): # for each relevant relation for relation in self.text_wrapper.relations: # relevancy of output if relation.containsMainInformation() and relation.containsSpecificInformation(): # for each stock in relation for stock_str in self.getStocks(relation): # try to match this stock_str on some already used stock_key = stock_str same_named = self.getSameNamedEntity(stock_str, self.output_objects.keys()) if same_named != None: stock_key = same_named # temp holder object current = {} in_hashmap = False if stock_key in self.output_objects.keys(): in_hashmap = True current = self.output_objects[stock_key] # # add name or abbreviation title # if Utils.isStockAbbreviation(stock_str): # if not 'stock abbreviation' in current.keys(): # current['stock abbreviation'] = stock_str # elif not 'stock name' in current.keys(): # current['stock name'] = stock_str # # # add price change # price_change = Utils.extractPriceChange(stock_str) # if price_change != None: # current['price change'] = price_change entity_parts = Utils.getEntityParts(stock_str) if 'name' in entity_parts.keys() and not 'stock name' in current.keys(): current['stock name'] = entity_parts['name'] if 'abbreviation' in entity_parts.keys() and not 'stock abbreviation' in current.keys(): current['stock abbreviation'] = entity_parts['abbreviation'] if 'price change' in entity_parts.keys() and not 'price change' in current.keys(): current['price change'] = entity_parts['price change'] # resolve agencies agencies = self.getAgencies(relation) # if there is no agency mentioned, just add to main object if len(agencies) == 0: # recommendation attributes for recommendation in relation.getRolesWithBase('state'): if recommendation.second_level_role == '<state_past:1>' and not 'past recommendation' in current.keys(): current['past recommendation'] = Utils.getRecommendationString(recommendation.phrase) elif recommendation.second_level_role == '<state_current:1>' and not 'current recommendation' in current.keys(): current['current recommendation'] = Utils.getRecommendationString(recommendation.phrase) # agency mentioned else: # create agencies attribute array if not 'agencies' in current.keys(): current['agencies'] = {} # for each agency for agency_key in agencies: # add agency attr. if not agency_key in current['agencies'].keys(): current['agencies'][agency_key] = {} current['agencies'][agency_key]['agency name'] = agency_key # agency recommendations for recommendation in relation.getRolesWithBase('state'): if recommendation.second_level_role == '<state_past:1>': #and not 'past recommendation' in current['agencies'][agency_key].keys(): current['agencies'][agency_key]['past recommendation'] = Utils.getRecommendationString(recommendation.phrase) elif recommendation.second_level_role == '<state_current:1>': #and not 'current recommendation' in current['agencies'][agency_key].keys(): current['agencies'][agency_key]['current recommendation'] = Utils.getRecommendationString(recommendation.phrase) # agency prices for price in relation.getRolesWithBase('price'): if price.second_level_role == '<price_past:1>' and not 'past price' in current['agencies'][agency_key].keys(): current['agencies'][agency_key]['past price'] = Utils.getNumberEntityString(price.phrase) elif price.second_level_role == '<price_current:1>' and not 'current price' in current['agencies'][agency_key].keys(): current['agencies'][agency_key]['current price'] = Utils.getNumberEntityString(price.phrase) elif price.second_level_role == '<price_change:1>' and not 'price change' in current['agencies'][agency_key].keys(): current['agencies'][agency_key]['price change'] = Utils.getNumberEntityString(price.phrase) # prices in general for price in relation.getRolesWithBase('price'): if price.second_level_role == '<price_past:1>' and not 'past price' in current.keys() and len(agencies) == 0: current['past price'] = Utils.getNumberEntityString(price.phrase) elif price.second_level_role == '<price_current:1>' and not 'current price' in current.keys() and len(agencies) == 0: current['current price'] = Utils.getNumberEntityString(price.phrase) elif price.second_level_role == '<price_change:1>' and not 'price change' in current.keys() and len(agencies) == 0: current['price change'] = Utils.getNumberEntityString(price.phrase) # add created new object to hashmap, if contains recommendation value if not in_hashmap: #and self.addedRecommendation(current): self.output_objects[stock_key] = current # filter output objects self.filterOutputObjects()