Skip to main content

一、文本事理类型分析

中文复合事件抽取,可以用来识别文本的模式,包括条件事件、顺承事件、反转事件。

我仅仅是对代码做了简单的修改,增加了函数说明注释和stats函数,可以用于统计文本中各种模式的分布(数量)情况。代码原作者为刘焕勇 https://github.com/liuhuanyong


事件图谱(事理图谱)的类型

项目地址https://github.com/liuhuanyong/ComplexEventExtraction 项目介绍很详细,感兴趣的一定要去原项目看一下。

事件 含义 形式化 事件应用 图谱场景 举例
条件事件 某事件条件下另一事件发生 如果A那么B 事件预警 时机判定 <限制放宽,立即增产>
反转事件 某事件与另一事件形成对立 虽然A但是B 预防不测 反面教材 <起步晚,发展快>
顺承事件 某事件紧接着另一事件发生 A接着B 事件演化 未来意图识别 <去旅游,买火车票>

分析出文本中的条件、顺承、反转,理论上就可以构建知识网络(本库做不到这可视化)。 1、反转事件图谱 2、条件事件图谱



二、安装方法

2.1 方法一

最简单的安装,现在由于国内外网络不稳定,可能需要尝试几次

pip3 install eventextraction

2.2 加镜像站点

有的童鞋已经把pip默认安装镜像站点改为国内,如果国内镜像还未收录我的这个包,那么可能会安装失败。只能从国外

https://pypi.org/simple

站点搜索eventextraction资源并安装

pip3 install eventextraction -i https://pypi.org/simple

2.3 国内镜像安装

如果国内镜像站点已经收录,那么使用这个会更快

pip3 install eventextraction -i https://pypi.tuna.tsinghua.edu.cn/simple/



三、使用

3.1 主函数

from eventextraction import EventsExtraction

extractor = EventsExtraction()
content = '虽然你做了坏事,但我觉得你是好人。一旦时机成熟,就坚决推行'
datas = extractor.extract_main(content)
print(datas)

运行结果

[{'sent': '虽然你做了坏事,但我觉得你是好人', 'type': 'but', 'tuples': {'pre_wd': '虽然', 'pre_part': '你做了坏事,', 'post_wd': '但', 'post_part ': '我觉得你是好人'}},
{'sent': '一旦时机成熟,就坚决推行', 'type': 'condition', 'tuples': {'pre_wd': '一旦', 'pre_part': '时机成熟,', 'post_wd': '就', 'post_part ': '坚决推行'}}]


3.2 统计

from eventextraction import EventsExtraction

extractor = EventsExtraction()
content = '虽然你做了坏事,但我觉得你是好人。一旦时机成熟,就坚决推行'
datas = extractor.extract_main(content)
print(extractor.stats(datas))

运行结果

{'but': 1, 'condition': 1, 'seq': 0, 'more': 0, 'other': 0}



如果

如果您是经管人文社科专业背景,编程小白,面临海量文本数据采集和处理分析艰巨任务,可以参看《python网络爬虫与文本数据分析》视频课。作为文科生,一样也是从两眼一抹黑开始,这门课程是用五年时间凝缩出来的。自认为讲的很通俗易懂o( ̄︶ ̄)o,

  • python入门
  • 网络爬虫
  • 数据读取
  • 文本分析入门
  • 机器学习与文本分析
  • 文本分析在经管研究中的应用

感兴趣的童鞋不妨 戳一下《python网络爬虫与文本数据分析》进来看看~

更多


Metadata

Release files for eventextraction 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eventextraction 1.1
File Size Uploaded
eventextraction-1.1.macosx-10.9-x86_64.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eventextraction 1.1
File Interpreter ABI Platform
eventextraction-1.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.2 kB

Release files / eventextraction-1.1.macosx-10.9-x86_64.tar.gz

Download URL eventextraction-1.1.macosx-10.9-x86_64.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f9f2240355ba6f84fe6f456ceb7b337db22a3fc3e7af902cfebab3cae20ff4c9
BLAKE2b-256 checksum
How to use checksums
22dd01f0d6c78d531d158388194fe04251110f2fb2a6d3b5e2c561e2e79c4b93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5

Release files / eventextraction-1.1-py3-none-any.whl

Download URL eventextraction-1.1-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3436d9ace465bcc65c85abed89bc5dc23e376f7379e736a603b10098b1625ce
BLAKE2b-256 checksum
How to use checksums
fe67dcc0042ba100bafa1866cec4266623508be31ea30ad207e48c0b48998679
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page