Sent Pattern
This package categorizes English sentences into one of five basic sentence patterns and identifies the subject, verb, object, and other components. The five basic sentence patterns are based on C. T. Onions's Advanced English Syntax and are frequently used when teaching English in Japan.
Influence of His Grammar on English Language Education in Japan
Universe Project
Quick Start
fastapi docker Example Code
How To Use
Installation
pip install sent-pattern
Usage
import spacy
nlp = spacy.load("en_core_web_lg")
nlp.add_pipe("span_noun")
nlp.add_pipe("sent_pattern")
text = "he gives me something"
doc = nlp(text)
pattern = doc._.sentpattern
print(pattern)
# FourthSentencePattern (class)
print(pattern.subject.root)
# he (Token)
print(pattern.verb.root)
# give (Token)
Cases without pipeline
If you want to know the sentence pattern without using components, we recommend using method of tags module.
The following three methods must be followed in order.
create_dep_list, create_elements, create_sent_pattern.
execute in order to generate the sentpattern class.
merit: can get sentpattern type
import spacy
from sent_pattern import tags
nlp = spacy.load("en_core_web_lg")
doc = nlp("he gives me something")
dep_list = tags.create_dep_list(doc)
elements = tags.create_elements(dep_list=dep_list)
p = tags.create_sent_pattern(elements=elements)
pattern = p.pattern_type
# FourthSentencePattern(class)
print(pattern.subject.root.text)
# he (string)
print(pattern.verb.root)
# gives(spacy.Token)
print(dep_list)
# {'ROOT': [gives], 'dative': [me], 'dobj': [something], 'nsubj': [he]}
print(pattern.abbreviation)
# SVO (str)
how to get prep phrase
nlp = spacy.load("en_core_web_lg")
text = "The Eureka client handles all aspects of service instance registration and deregistration"
doc = nlp(text)
dep_list = tags.create_dep_list(doc)
custom = ElementsFactory.make_custom_elements(dep_list, doc=doc, option="prep")
phrase = custom.option
print(phrase.prep_groups)
# [of service instance registration and deregistration]
License
Distributed under the terms of the MIT license, "sent-pattern" is free and open source software
Release files for sent-pattern 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sent-pattern-0.1.2.tar.gz | 13.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sent_pattern-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.4 kB
Release files / sent-pattern-0.1.2.tar.gz
| Download URL | sent-pattern-0.1.2.tar.gz |
|---|---|
| Size | 13.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1b561816b52c8abb1b38ee91b02f0d7c02012ffcc0214162fb9ed041d6cee65
|
|
BLAKE2b-256 checksum How to use checksums |
0c7924a08bb6ada0e7da1cfe2037df45a91ecc531cb8dc060242fb524bbbd49b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / sent_pattern-0.1.2-py3-none-any.whl
| Download URL | sent_pattern-0.1.2-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a442d2f4352810cafad8372627e9b9c0238713c0e77fbc9c58dfcf71b1cb7da0
|
|
BLAKE2b-256 checksum How to use checksums |
d140587a1eb3ba80cc4acf9d13b27a2450be6d0ab418b76f92dca8251beaaada
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|