相关疑难解决方法(0)

是否值得使用Python的re.compile?

在Python中使用正则表达式编译有什么好处吗?

h = re.compile('hello')
h.match('hello world')
Run Code Online (Sandbox Code Playgroud)

VS

re.match('hello', 'hello world')
Run Code Online (Sandbox Code Playgroud)

python regex

422
推荐指数
13
解决办法
24万
查看次数

从Python中的非结构化文本中提取一个人的年龄

我有一个包含简短履历的行政文件数据集。我试图通过使用python和某些模式匹配来提取人们的年龄。句子的一些示例是:

  • “现年67岁的邦德先生是英国的工程师”
  • “ 34岁的阿曼达·拜恩斯是一位女演员”
  • “彼得·帕克(45岁)将成为我们的下一位管理员”
  • “迪伦先生今年46岁。”
  • “史蒂夫·琼斯,年龄:32岁”

这些是我在数据集中确定的一些模式。我想补充一点,还有其他模式,但是我还没有遇到它们,并且不确定如何实现。我编写了以下代码,效果很好,但是效率很低,因此在整个数据集上运行将花费太多时间。

#Create a search list of expressions that might come right before an age instance
age_search_list = [" " + last_name.lower().strip() + ", age ",
" " + clean_sec_last_name.lower().strip() + " age ",
last_name.lower().strip() + " age ",
full_name.lower().strip() + ", age ",
full_name.lower().strip() + ", ",
" " + last_name.lower() + ", ",
" " + last_name.lower().strip()  + " \(",
" " + last_name.lower().strip()  + " is "]

#for each element in …
Run Code Online (Sandbox Code Playgroud)

python nlp pattern-matching text-mining

5
推荐指数
2
解决办法
180
查看次数

标签 统计

python ×2

nlp ×1

pattern-matching ×1

regex ×1

text-mining ×1