Skip to main content

构建和匹配语义角色标签的模式

项目描述

d# 角色模式

为角色标签构建和匹配语言模式。提供示例驱动的方法来生成和改进模式。

使用基于图的模式匹配,基于 SpaCy。

安装

用点子:

pip install role-pattern-nlp

示例用法

# First, parse a string to create a SpaCy Doc object
import en_core_web_sm
text = "Forging involves the shaping of metal using localized compressive forces."
nlp = en_core_web_sm.load()
doc = nlp(text)

from role_pattern_nlp import RolePatternBuilder

# Provide an example by mapping role labels to tokens
match_example = {
    'arg1': [doc[0]],  # [Forging]
    'pred': [doc[1]],  # [involves]
    'arg2': [doc[3]],  # [shaping]
}

''' Create a dictionary of all the features we want the RolePatternBuilder to have access to
when building and refining patterns '''
feature_dict = {'DEP': 'dep_', 'TAG': 'tag_'}

# Instantiate the pattern builder
role_pattern_builder = RolePatternBuilder(feature_dict)

#  Build a pattern. It will use all the features in the feature_dict by default
role_pattern = role_pattern_builder.build(match_example)  

# Match against any doc with the role_pattern
matches = role_pattern.match(doc)
print(matches)
'''
[{'arg1': [Forging], 'arg2': [shaping], 'pred': [involves]}]
'''

有关如何使用反例改进模式的演示,请参见示例/。

API

角色模式

RolePattern.spacy_dep_pattern

用于创建 SpaCy DependencyMatcher 对象的表单中的依赖模式。

RolePattern.token_labels

与模式匹配的标记对应的标签列表。

内置

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

role-pattern-nlp-0.2.0.tar.gz (12.1 kB 查看哈希)

已上传 source

内置分布

role_pattern_nlp-0.2.0-py3-none-any.whl (16.9 kB 查看哈希)

已上传 py3