def _convert_row_to_claim(self, row): claim = Claim() claim_id = unicode(row['claim_id']) title = unicode(row['title'], errors='replace') claim.title = title description = unicode(row['description'], errors='replace') claim.description = description url = unicode(row['url']) claim.url = url verdict_date = row['publication_date'] claim.verdict_date = date(verdict_date) post_guid = compute_post_guid(self._social_network_url, claim_id, verdict_date) claim.claim_id = post_guid claim.domain = self._domain keywords = unicode(row['keywords']) claim.keywords = keywords verdict = unicode(row['post_type']) claim.verdict = verdict return claim
def _add_claim(self, claim_id, content, date_str, post_type=None): claim = Claim() claim.claim_id = claim_id claim.verdict = post_type claim.title = claim_id claim.description = content claim.verdict_date = convert_str_to_unicode_datetime(date_str) claim.url = "claim url" self._db.addPost(claim)
def get_claim_from_article(self, article, source): claim = Claim() claim.title = article['title'] claim.description = article['description'] claim.url = article['url'] try: publish_date = str_to_date(article['publishedAt'].split('+')[0], '%Y-%m-%dT%H:%M:%SZ') except: publish_date = str_to_date(article['publishedAt'].split('+')[0], '%Y-%m-%dT%H:%M:%S') claim.verdict_date = publish_date claim.domain = article['source'].get('id', str(source)) claim.verdict = True claim.claim_id = compute_post_guid(self._social_network_url, claim.url, date_to_str(claim.verdict_date)) claim.category = str(source) return claim
def _add_claim(self, claim_id, content, date_str=u"2017-06-14 05:00:00", keywords=u"", post_type=None): claim = Claim() claim.claim_id = claim_id claim.verdict = post_type claim.title = claim_id claim.description = content claim.verdict_date = convert_str_to_unicode_datetime(date_str) claim.keywords = keywords claim.url = u"claim url" self._db.addPost(claim) self._claim_dictionary[claim.claim_id] = claim
def import_to_db(self, file_path): with open(file_path, 'rb') as f: data = csv.reader(f) res = [] for row in data: try: c = Claim() c.title = str(row[3]) c.claim_id = str(uuid.uuid4().__str__()) c.description = str(row[0]) c.category = str(row[4]) c.verdict = str(row[1]) c.domain= "Claim" c.verdict_date = datetime.datetime.strptime(row[6],'%d %B %Y') c.url = str(row[2]) except Exception as e: continue res.append(c) print(','.join(row)) self._db.add_claims(res)
def _convert_row_to_claim(self, row): claim = Claim() claim_id = unicode(row['campaign_id']) title = unicode(row['title'], errors='replace') claim.title = title try: verdict_date = datetime.datetime.strftime( datetime.datetime.strptime(row['date'], '%d-%m-%y'), '%Y-%m-%d %H:%M:%S') except: verdict_date = getConfig().eval(self.__class__.__name__, 'default_date') claim.verdict_date = date(verdict_date) post_guid = compute_post_guid(self._social_network_url, claim_id, verdict_date) claim.claim_id = post_guid claim.domain = self._domain keywords = unicode(row['category']) claim.keywords = keywords verdict = unicode(row['campaign_class']) claim.verdict = verdict #claim.claim_topic = unicode(row['category']) return claim
def _convert_row_to_claim(self, claim_row): claim = Claim() claim.claim_id = compute_author_guid_by_author_name( str(claim_row['social_id'])) claim.domain = str(claim_row['site']) claim.verdict = str(claim_row['ruling_val']) claim.verdict_date = datetime.datetime.fromtimestamp( claim_row['ruling_time']) self._claims.append(claim) attribute_name = self.__class__.__name__ + "_claim_type" author_feature = BaseFeatureGenerator.create_author_feature( attribute_name, claim.claim_id, claim.verdict, self._window_start, self._window_end) self._author_features.append(author_feature) attribute_name = self.__class__.__name__ + "_claim_id" author_feature = BaseFeatureGenerator.create_author_feature( attribute_name, claim.claim_id, claim.claim_id, self._window_start, self._window_end) self._author_features.append(author_feature)
def create_claim_from_record(self, series): claim = Claim() claim.title = str(series['title']) claim.description = str(series['description']) claim.url = str(series['url']) claim.verdict_date = str_to_date(series['verdict_date']) claim.verdict = str(series['verdict']) claim.category = str(series['main_category']) claim.keywords = str(series['keywords']) claim.domain = str(series['domain']) post_guid = compute_post_guid(self._social_network_url, claim.url, date_to_str(claim.verdict_date)) claim.claim_id = post_guid return claim
def _create_claim(self, original_liar_dataset_id, speaker, targeted_label, statement, subject): claim = Claim() osn_id = str(original_liar_dataset_id) claim.claim_id = compute_post_guid(self._social_network_url, osn_id, '2007-01-01 00:00:00') claim.domain = 'LiarLiar' claim.description = statement claim.title = statement claim.url = '' claim.category = 'Politic' claim.sub_category = subject claim.verdict = targeted_label claim.verdict_date = str_to_date('2007-01-01 00:00:00') claim.keywords = '' return claim
def _add_claim(self, claim_id): claim = Claim() claim.claim_id = claim_id self._db.addPosts([claim])
def _parse_articles_lst_to_articles(self, all_articles_lst_of_dics): print("###### 'Entering _parse_articles_lst_to_articles'") parsed_articles_lst = [] claims_lst = [] posts_lst = [] articles_lst = [] article_items_lst = [] # Parsing articles list of dictionaries data, received using the API. for news_articles_dic in all_articles_lst_of_dics: print("###### 'PARSING: {}'".format(str(news_articles_dic))) parsed_articles_lst += self._parse_news_article(news_articles_dic) # For each news article dictionary commit: for parsed_news_article in parsed_articles_lst: print("###### 'Iterating parsed_articles_lst single item: {}'". format(str(parsed_news_article))) # Building: claim & News_Article & News_Article_Item objects. claim = Claim() post = Post() article = News_Article() article_item = News_Article_Item() # Initializing Claim object with data: identifier = compute_post_guid(parsed_news_article['url'], parsed_news_article['author'], parsed_news_article['publishedAt']) claim.claim_id = post.post_id = post.guid = post.post_osn_guid = article.post_id = article_item.post_id = unicode( identifier) author_guid = compute_author_guid_by_author_name( parsed_news_article['author']) post.author_guid = article.author_guid = article_item.author_guid = unicode( author_guid) post.author = article.author = unicode( parsed_news_article['author']) post.title = claim.title = article.title = unicode( parsed_news_article['title']) post.content = article_item.content = unicode( parsed_news_article['content']) post.description = claim.description = article.description = unicode( parsed_news_article['description']) post.date = post.created_at = claim.verdict_date = article.published_date = datetime.datetime.strptime( parsed_news_article['publishedAt'], '%Y-%m-%d %H:%M:%S') article_item.source_newsapi_internal_id = unicode( parsed_news_article['source_id']) article_item.source_newsapi_internal_name = unicode( parsed_news_article['source_name']) post.url = claim.url = article.url = unicode( parsed_news_article['url']) article_item.img_url = unicode(parsed_news_article['urlToImage']) post.post_type = claim.verdict = unicode( "TRUE" ) # todo: Add constant. We assume all news articles are true. post.domain = claim.domain = unicode( "NewsSite") # todo: Add constant. # Update objects lists: posts_lst.append(post) claims_lst.append(claim) articles_lst.append(article) article_items_lst.append(article_item) print("###### 'EXITING _parse_articles_lst_to_articles'") return posts_lst, claims_lst, articles_lst, article_items_lst
def _convert_row_to_claim(self, row): claim = Claim() # claim_id = unicode(row['claim_id']) title = unicode(row['title'], errors='replace') claim.title = title description = unicode(row['description'], errors='replace') claim.description = description url = unicode(row['url']) claim.url = url verdict_date = row['verdict_date'] claim.verdict_date = date(verdict_date) post_guid = compute_post_guid(self._social_network_url, url, verdict_date) claim.claim_id = post_guid claim.domain = self._domain keywords = unicode(row['keywords']) claim.keywords = keywords verdict = unicode(row['verdict']) claim.verdict = verdict claim.category = unicode(row['main_category']) claim.sub_category = unicode(row['secondary_category']) return claim