PitchHut
Log in / Sign up
sent-pattern
7 views
Master English sentence patterns effortlessly.
Pitch

The sent-pattern package simplifies English sentence structure for beginners by categorizing sentences into five fundamental patterns. Built on established grammatical theories, it helps users identify key components like subjects and verbs, making learning efficient and clear. Whether used in classrooms or for self-study, this tool enhances understanding and mastery of English syntax.

Description

The sent-pattern package is specifically designed to categorize English sentences into one of five fundamental sentence patterns, as outlined in C. T. Onions's Advanced English Syntax. This tool not only classifies sentences but also identifies key components such as the subject, verb, and object, making it an ideal learning resource for beginner English students, particularly in Japan.

Key Features

  • Categorization: Effectively categorizes sentences into five basic patterns, enhancing your understanding of sentence structure.
  • Component Identification: Automatically identifies subjects, verbs, objects, and other critical elements within a sentence.
  • Learning Tool: Tailored for novice English learners, providing essential grammar insights and syntax patterns.

Quick Start

To help you get started, the package includes an example of how to use it with FastAPI in a Docker environment. Refer to the fastapi docker Example Code for implementation details.

Usage Example

Here’s a basic example of how to utilize the sent-pattern package in Python:

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)  # gives (Token)

Analyzing Without the Pipeline

For cases where you wish to analyze a sentence without utilizing the components, you can follow these methods sequentially:

  1. create_dep_list
  2. create_elements
  3. create_sent_pattern

Here's how to do it:

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
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)

Extracting Prepositional Phrases

To extract prepositional phrases from a sentence, you can use the following technique:

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]

The sent-pattern package is a free and open-source software distributed under the MIT license, designed to enhance your English grammar education.