使用python将段落中的每一行的句子分开

2024-09-28 21:34:26 发布

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

我有以下段落:

输入:---

“然而,通常缺乏足够可靠的地方、区域和国家土地利用和土地覆盖数据以及提供准确的景观变化估计所需的时间和地理细节。美国地质调查局(U.S.GeologicalSurvey)的EROS数据中心和美国环境保护署(U.S.EnvironmentalProtectionAgency)的景观生态学分部正在合作进行一项为期四年的研究项目,以记录近30年来美国土地覆被变化的类型、分布、速率、驱动因素和后果。该项目使用生态区域框架作为地理分层工具。”

想在新行中分隔每个句子。我正在将“.”替换为“\n”(换行符)。它可以正常工作的句子,但当“美国地质…”这样的事情来了我的脚本,使两个单独的句子,我不想。请提出任何可能的建议

预期输出:——(3句按顺序编号)

1)然而,通常缺乏足够可靠的地方、区域和国家土地利用和土地覆盖数据以及时间和地理细节,以提供准确的景观变化估计。你知道吗

2)美国地质调查局的EROS数据中心和美国环境保护署的景观生态学分会正在合作进行一项为期四年的研究项目,以记录近30年来美国土地覆盖变化的类型、分布、速率、驱动因素和后果。你知道吗

3)该项目使用生态区域框架作为地理分层。你知道吗

当前获得:(7句话)

1)然而,通常缺乏足够可靠的地方、区域和国家土地利用和土地覆盖数据以及时间和地理细节,以提供准确的景观变化估计。你知道吗

2)美国

3)S

4)美国地质调查局EROS数据中心和景观生态学分会

5)S

6)环境保护署正在合作进行一项为期四年的研究项目,以记录近30年来美国土地覆盖变化的类型、分布、比率、驱动因素和后果。你知道吗

7)该项目使用生态区域框架作为地理分层。你知道吗


Tags: 数据项目区域地方时间国家地理细节
1条回答
网友
1楼 · 发布于 2024-09-28 21:34:26

使用nltk无疑是一种很好的方法。这些句子可以列举如下:

import nltk

text = "However, there is generally a lack of local, regional, and national land use and land cover data of sufficient reliability and temporal and geographic detail for providing accurate estimates of landscape change. The U.S. Geological Survey's EROS Data Center and the Landscape Ecology Branch of the U.S. Environmental Protection Agency are collaborating on a four-year research project to document the types, distributions, rates, drivers, and consequences of land cover change for the conterminous United States over the past 30 years. The project is using an ecoregion framework as a geographic stratifier."                
tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')

for index, sentence in enumerate(tokenizer.tokenize(text), start=1):
    print "{}) {}\n".format(index, sentence)

这将显示以下输出:

1) However, there is generally a lack of local, regional, and national land use and land cover data of sufficient reliability and temporal and geographic detail for providing accurate estimates of landscape change.

2) The U.S. Geological Survey's EROS Data Center and the Landscape Ecology Branch of the U.S. Environmental Protection Agency are collaborating on a four-year research project to document the types, distributions, rates, drivers, and consequences of land cover change for the conterminous United States over the past 30 years.

3) The project is using an ecoregion framework as a geographic stratifier.

相关问题 更多 >