class SilverEye: def __init__(self, server_ip, server_port, database): self.client = MongoClient(server_ip, server_port, connect=True) self.database = database self.twitter_controller = TwitterController(self) self.analysis_controller = AnalysisController(self.client, database) self.dao_collection_tags = DAOTags(self.client, self.database) def start(self): keywords = self.dao_collection_tags.get_array_of_the_name_of_classified_tags() self.twitter_controller.start(keywords) def stop(self): self.twitter_controller.stop() def analyze_tweet(self, tweet): self.analysis_controller.analyze_tweet(tweet) def analyse_temporal_time(self, init_time=0): self.analysis_controller.analyse_temporal_lines(init_time) def analyze_global_results(self): self.analysis_controller.overall_analysis()
def __init__(self, server_ip, server_port, database): self.client = MongoClient(server_ip, server_port, connect=True) self.database = database self.twitter_controller = TwitterController(self) self.analysis_controller = AnalysisController(self.client, database) self.dao_collection_tags = DAOTags(self.client, self.database)
def __init__(self, client, database): self.dao_tags = DAOTags(client, database)
u"#Solucions!" , u"@Marti_Barbera" , u"@Ramon_Espadaler"] upyd = [u"@UPYD" , u"#VotaUPYD" , u"#MásEspaña" , u"@Herzogoff" , u"@sryuriaguilar"] if __name__ == "__main__": client = MongoClient('0.0.0.0', 27017, connect=True) database = "SilverEye" daoTags = DAOTags(client, database) daoTags.add_collection("ciudadanos") for tag in ciudadanos: daoTags.add_tag(tag, []) daoTags.add_tag_to_collection("ciudadanos", tag) daoTags.add_collection("democracia_llibertat") for tag in democracia_llibertat: daoTags.add_tag(tag, []) daoTags.add_tag_to_collection("democracia_llibertat", tag) daoTags.add_collection("ehbildu") for tag in ehbildu: daoTags.add_tag(tag, []) daoTags.add_tag_to_collection("ehbildu", tag)
class CollectionClassifierController: def __init__(self, client, database): self.dao_tags = DAOTags(client, database) def get_tags_of_tweet(self, text): try: text = text.replace(".", " ") text = text.replace(":", " ") text = text.replace(",", " ") tags_in_text = [] split_text = text.split(' ') tags = self.dao_tags.get_all_tags() for tag in tags: if tag["_id"] in text: tags_in_text.append(tag["_id"]) if split_text[0] == "RT": del split_text[0] del split_text[1] for word in split_text: if len(word) > 1 and word[0] == "@": if word not in tags_in_text: tags_in_text.append(word) if len(word) > 1 and word[0] == "#": if word not in tags_in_text: tags_in_text.append(word) return tags_in_text except Exception as exception: # Oh well, reconnect and keep trucking raise Exception("get_tags_of_tweets->CollectionClassifierController" + exception.message) def get_collection_by_tags(self, input_tags): collection_in_tag = {} unclassified_tags = list(input_tags) identified_tags = [] try: for tag in input_tags: if self.dao_tags.tag_exist(tag): collection = self.dao_tags.get_the_collection_name_of_tag(tag) if collection is not None: collection = collection['_id'] if collection_in_tag.has_key(collection): collection_in_tag[collection] += collection_in_tag[collection] + 1 else: collection_in_tag[collection] = 1 try: unclassified_tags.remove(tag) identified_tags.append(tag) except ValueError: continue self.add_or_update_unclassified_tags(unclassified_tags, input_tags) self.update_classified_tags(identified_tags, input_tags) return collection_in_tag except Exception as exception: # Oh well, reconnect and keep trucking raise Exception("get_collection_by_tags->CollectionClassifierController" + exception.message) def update_classified_tags(self, classified_tags, related_tags): for classified_tag in classified_tags: self.dao_tags.update_related_tags_and_plus_repeat(classified_tag, related_tags) def add_or_update_unclassified_tags(self, unclassified_tags, related_tags): for unclassified_tag in unclassified_tags: if self.dao_tags.tag_exist(unclassified_tag): self.dao_tags.update_related_tags_and_plus_repeat(unclassified_tag, related_tags) else: self.dao_tags.add_tag(unclassified_tag, related_tags) def add_suggestions_collections(self): unclassified_tags = self.dao_tags.get_unclassified_tags() collections = {} for tag in unclassified_tags: for related_tag, repeat in tag["related"].iteritems(): related_tag_complete = self.dao_tags.get_tag_by_id(related_tag) if related_tag_complete["classified"]: collection = self.dao_tags.get_the_collection_name_of_tag(related_tag) collection = collection["_id"] if collection in collections.keys(): collections[collection][related_tag] = repeat else: collections[collection] = {} collections[collection][related_tag] = repeat collections[collection][related_tag] = repeat self.dao_tags.add_suggested_collection_to_tag(tag["_id"], collections) collections = {}