【发布时间】:2021-05-03 13:06:55
【问题描述】:
我最近拿起 python 来做一些文本提取。 我有一个如下所示的数据集:
@article{noauthor_collective_nodate,
title = {Collective teacher efficacy},
abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},
@article{noauthor_collective_nodate,
title = {Collective teacher efficacy},
abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},
}
@article{noauthor_initial_nodate,
title = {Initial teacher education programs},
abstract = {Overview Influence: Initial teacher education programs Domain: Teacher Sub-Domain: Teacher Education Potential to Accelerate Student Achievement: Likely to have small positive impact Influence Definition: Initial teacher education or {ITEs} (sometimes at the undergraduate level and sometimes at the post-graduate level) is the entry-level qualification for teaching in numerous countries, including the United States. More recently, there are school-based {ITEs}, non-accredited {ITEs}, and many online {ITE} programs. Evidence Number of meta-analyses: 5 Number of studies: 117 Number of students: 106,016 Number of effects: 509 Effect size: 0.10},
}
@article{noauthor_professional_nodate,
title = {Professional development programs},
abstract = {Overview Influence: Professional development programs Domain: Teacher Sub-Domain: Teacher Education Potential to Accelerate Student Achievement: Likely to have positive impact Influence Definition: Professional development relates to courses or interventions aimed to enhance the beliefs, actions, impact of knowledge of teachers and school leaders. Evidence Number of meta-analyses: 21 Number of studies: 1,151 Number of students: 2,321,242 Number of effects: 2,938 Effect size: 0.37},
keywords = {Program Development},
}
我想从这篇文章中提取标题和摘要的一部分。 我设法使用以下代码提取了我想要的输出:
s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
start = s.find("title = {") + len("title = {")
end = s.find("}, abstract")
start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
end2 = s.find("Evidence Number of meta-analyses:")
substring = s[start:end]
substring2 = s[start2:end2]
print(substring+' - '+substring2+";")
输出:
Collective teacher efficacy - The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. ;
问题是:
- 这样只取出第一个搜索结果
- 我希望能够在原始文本文件上运行它,而不是将其复制为“s”。
有人可以伸出援助之手吗?
【问题讨论】:
-
你有多个文件还是只有一个?