从课文中提取不带句号的句子

2024-04-18 03:57:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我是NLP新手,需要帮助从不包含句号的文本中提取句子。你知道吗

例如:(下面的文本不包含句号)

global warming is the term used to describe a gradual increase in the average
temperature of the earths atmosphere and its oceans a change that is believed to 
be permanently changing the earths climate there is great debate among many 
people and sometimes in the news on whether global warming is real (some call it 
a hoax) but climate scientists looking at the data and facts agree the planet is 
warming while many view the effects of global warming to be more substantial and 
more rapidly occurring than others do the scientific consensus on climatic 
changes related to global warming is that the average temperature of the earth 
has risen between 04 and 08 °c over the past 100 years the increased volumes of 
carbon dioxide and other greenhouse gases released by the burning of fossil 
fuels land clearing agriculture and other human activities are believed to be 
the primary sources of the global warming that has occurred over the past 50 
years scientists from the intergovernmental panel on climate carrying out global 
warming research have recently predicted that average global temperatures could 
increase between 14 and 58 °c by the year 2100 changes resulting from global 
warming may include rising sea levels due to the melting of the polar ice caps 
as well as an increase in occurrence and severity of storms and other severe 
weather events

有没有NLP库,我可以用它来提取上述句子。你知道吗

预期产量:

global warming is the term used to describe a gradual increase in the average temperature of the earths atmosphere and its oceans a change that is believed to be permanently changing the earths climate
there is great debate among many people and sometimes in the news on whether global warming is real (some call it a hoax)
but climate scientists looking at the data and facts agree the planet is warming
while many view the effects of global warming to be more substantial and more rapidly occurring than others do the scientific consensus on climatic changes related to global warming is that the average temperature of the earth has risen between 4 and 8 °c over the past 100 years
the increased volumes of carbon dioxide and other greenhouse gases released by the burning of fossil fuels land clearing agriculture and other human activities are believed to be the primary sources of the global warming that has occurred over the past 50 years
scientists from the intergovernmental panel on climate carrying out global warming research have recently predicted that average global temperatures could increase between 4 and 8 °c by the year 2100
changes resulting from global warming may include rising sea levels due to the melting of the polar ice caps as well as an increase in occurrence and severity of storms and other severe weather events

谢谢你。你知道吗


Tags: andofthetointhatison
1条回答
网友
1楼 · 发布于 2024-04-18 03:57:55

实际上,理解一个句子的开头和结尾是一个相对昂贵的操作。在你的例子中,你可以列一个不作为句子开头的单词的列表,比如“Earth”和“Intergovernmental”,将你的文本拆分成单词,检测大写单词(这些单词将作为句子开头),并将子列表连接成字符串。我是这样做的:

a = """
Global warming is the term used to describe a gradual increase in the average 
temperature of the Earths atmosphere and its oceans a change that is believed
to be permanently changing the Earths climate There is great debate among many
people and sometimes in the news on whether global warming is real (some call 
it a hoax) But climate scientists looking at the data and facts agree the 
planet is warming While many view the effects of global warming to be more 
substantial and more rapidly occurring than others do the scientific consensus 
on climatic changes related to global warming is that the average temperature 
of the Earth has risen between 4 and 8 °C over the past 100 years The 
increased volumes of carbon dioxide and other greenhouse gases released by the 
burning of fossil fuels land clearing agriculture and other human activities 
are believed to be the primary sources of the global warming that has occurred
over the past 50 years Scientists from the Intergovernmental Panel on Climate 
carrying out global warming research have recently predicted that average 
global temperatures could increase between 4 and 8 °C by the year 2100 
Changes resulting from global warming may include rising sea levels due to the 
melting of the polar ice caps as well as an increase in occurrence and severity 
of storms and other severe weather events
"""

preProc = a.replace("\n", "")
preProc = preProc.split(" ")

capitalizedWords = ['Intergovernmental','Panel', 'Climate', 'Earths', 'Earth', '°C']
results = []
previousIndex = 0
for idx, word in enumerate(preProc):
  if word.istitle() and word not in capitalizedWords:
    results.append(list(preProc[previousIndex:idx]))
    previousIndex = idx
results = [" ".join(x) for x in results]

print(results)

相关问题 更多 >