Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python词典上的RAKE分句函数_Python_Regex_Csv_Nlp_Nltk - Fatal编程技术网

Python词典上的RAKE分句函数

Python词典上的RAKE分句函数,python,regex,csv,nlp,nltk,Python,Regex,Csv,Nlp,Nltk,如何将此函数仅应用于python字典中的值: def split_sentences(text): """ Utility function to return a list of sentences. @param text The text that must be split in to sentences. """ sentence_delimiters = re.compile(u'[\\[\\]\n.!?,;:\t\\-\\"\\(\\)\\\'\u2019\u2013]') se

如何将此函数仅应用于python字典中的值:

def split_sentences(text):
"""
Utility function to return a list of sentences.
@param text The text that must be split in to sentences.
"""
sentence_delimiters = re.compile(u'[\\[\\]\n.!?,;:\t\\-\\"\\(\\)\\\'\u2019\u2013]')

sentences = (sentence_delimiters.split(text))
return sentences
new_dict = {k : split_sentences(v) for k, v in mydict.items()}
我用于从CSV文件输入创建词典的代码:

with open('second_table.csv', mode='r') as infile:
    #Read in the csv file
    reader = csv.reader(infile)
    #Skip the headers
    next(reader, None)
    #Iterates through each row to get the key value pairs
    mydict = {rows[0]:rows[1] for rows in reader}
python字典如下所示:

{'INC000007581947': '$BREM - CATIAV5 - Catia does not start',
 'INC000007581991': '$SPAI - REACT - react',
 'INC000007582037': 'access request',
 'INC000007582095': '$HAMB - DVOBROWSER - ACCESS RIGHTS',
 'INC000007582136': 'SIGLUM issue by opening a REACT request'}

mydict.values提供字典中的所有值。然后可以迭代它们并使用函数

for value in mydict.values():
    split_sentences(value)

有不同的解决方案,这取决于您是想创建一个新的字典,还是仅仅更新已有的字典

要更新字典值,请执行以下操作:

mydict.update({k : split_sentences(v) for k, v in mydict.items()})
要创建新词典,请执行以下操作:

def split_sentences(text):
"""
Utility function to return a list of sentences.
@param text The text that must be split in to sentences.
"""
sentence_delimiters = re.compile(u'[\\[\\]\n.!?,;:\t\\-\\"\\(\\)\\\'\u2019\u2013]')

sentences = (sentence_delimiters.split(text))
return sentences
new_dict = {k : split_sentences(v) for k, v in mydict.items()}