Created
June 16, 2023 15:04
-
-
Save lsiddiqsunny/7c367ed15a2a5d39ef52c7c045bca05a to your computer and use it in GitHub Desktop.
Detect partial sentence and interrogation using space library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spacy | |
nlp = spacy.load("en_core_web_sm") | |
python_comment = """ | |
This function calculates the sum of two numbers. | |
What are the parameters of this function? | |
How does this function handle errors? | |
""" | |
doc = nlp(python_comment) | |
question_sentences = [ | |
sentence.text.strip() | |
for sentence in doc.sents | |
if sentence.text.strip().endswith('?') | |
] | |
for question_sentence in question_sentences: | |
print(question_sentence) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spacy | |
nlp = spacy.load("en_core_web_sm") | |
text = """ | |
This is a complete sentence. Partial sentence without a verb. Another complete sentence. | |
""" | |
doc = nlp(text) | |
partial_sentences = [] | |
for sentence in doc.sents: | |
if len(sentence) > 1 and not any(token.dep_ == 'ROOT' for token in sentence): | |
partial_sentences.append(sentence.text.strip()) | |
for partial_sentence in partial_sentences: | |
print(partial_sentence) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment