Skip to main content

d# Role Pattern

Build and match linguistic patterns for role labelling. Provides an example-driven approach to generate and refine patterns.

Uses graph-based pattern matching, built on SpaCy.

Installation

With pip:

pip install role-pattern-nlp

Example usage

# 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]}]
'''

See examples/ for demonstration as to how to refine a pattern using negative examples.

API

RolePattern

RolePattern.spacy_dep_pattern

The dependency pattern in the form used to create the SpaCy DependencyMatcher object.

RolePattern.token_labels

The list of labels that corresponds to the tokens matched by the pattern.

Built with

Metadata

Release files for role-pattern-nlp 0.2.0

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

Source distribution (sdist)

Source distribution for role-pattern-nlp 0.2.0
File Size Uploaded Provenance Actions
role-pattern-nlp-0.2.0.tar.gz 12.1 kB Without provenance Details for role-pattern-nlp-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for role-pattern-nlp 0.2.0
File Interpreter ABI Platform Actions
role_pattern_nlp-0.2.0-py3-none-any.whl Python 3 none any Details for role_pattern_nlp-0.2.0-py3-none-any.whl

Total release size: 29.0 kB

Release files / role-pattern-nlp-0.2.0.tar.gz

Download URL role-pattern-nlp-0.2.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d7f10ec3990e2d9cb2a0582e87cab284e0f711e792ed99308c95fdb0a6e5a4ac
BLAKE2b-256 checksum
How to use checksums
3623fada487e59d13627cd8a38b3aa52fd61f65cac86466601793caf85753207
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.8

Release files / role_pattern_nlp-0.2.0-py3-none-any.whl

Download URL role_pattern_nlp-0.2.0-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50f6e7183d7f5179b791a0053cbffd7a04c3d5c79ec484f3b90e87db85dec682
BLAKE2b-256 checksum
How to use checksums
af9d738c2e2f97d16d84477a15c119561958f25277e834d9fd4e953b764666bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.8

Security for role-pattern-nlp 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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