def _percentage_capitalized_word_in_answer(self, row):
"""Percentage of capitalized words in the sentence that are in the answer
- Args:
row(pandas.dataframe): input pandas dataframe
- Returns:
row(pandas.dataframe): result a pandas dataframe with new feature
"""
answer = row.Answer
sentence = row.Sentence
if answer is not None and sentence is not None:
tokens = sentence.split()
num_tokens = len(tokens)
cap_tokens = [i for i in tokens if i.isupper() == True]
cap_tokens_in_answer = [i for i in cap_tokens if i in answer]
row['PERCENT_CAPITALIZED_WORDS_IN_ANSWER'] = float(
len(cap_tokens_in_answer)) / num_tokens
return row
else:
row['PERCENT_CAPITALIZED_WORDS_IN_ANSWER'] = 0
return row
feature_construction.py 文件源码
python
阅读 29
收藏 0
点赞 0
评论 0
评论列表
文章目录