Build and match patterns for semantic role labelling
Project description
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(doc, 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.
Built with
- SpaCy - DependencyMatcher
- SpaCy pattern builder
- networkx - Used by SpaCy pattern builder
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size role_pattern_nlp-0.0.2-py3-none-any.whl (9.0 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size role-pattern-nlp-0.0.2.tar.gz (5.7 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for role_pattern_nlp-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6ee0e8cb2a1e386c5224d44f94243312bd58b697c7a9c6bba42906af06adf0c |
|
MD5 | ac4d7053158e2b5769752ab76650bc44 |
|
BLAKE2-256 | c992e9eb5902e4a8c6e2a34cdb8e73e9bdc1b8c71734e56c06c908a3a433fa14 |