Count number of sentences in a string
Tag : chash , By : sgmichelsen
Date : March 29 2020, 07:55 AM
wish helps you If you already have Word installed, you can use Word interop to get the sentence count, as well as other statistics. This also has the benefit of potentially working with other languages besides English. object oMissing = System.Reflection.Missing.Value;
var oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false;
var oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.Content.Text = inputTextBox.Text;
//get just sentence count
sentenceCountLabel.Text = oDoc.Sentences.Count.ToString();
//get all statistics
foreach (Microsoft.Office.Interop.Word.ReadabilityStatistic stat in oDoc.ReadabilityStatistics)
{
Console.WriteLine("{0}: {1}", stat.Name, stat.Value);
}
object oFalse = false;
oDoc.Close(ref oFalse, ref oMissing, ref oMissing);
Words: 283
Characters: 1271
Paragraphs: 3
Sentences: 6
Sentences per Paragraph: 2
Words per Sentence: 47.1
Characters per Word: 4.3
Passive Sentences: 0
Flesch Reading Ease: 55.2
Flesch-Kincaid Grade Level: 12.5
|
How to count the number of sentences in a text in R?
Date : March 29 2020, 07:55 AM
To fix this issue Thank you @gui11aume for your answer. A very good package I just found that can help do the work is {openNLP}. This is the code to do that: install.packages("openNLP") ## Installs the required natural language processing (NLP) package
install.packages("openNLPmodels.en") ## Installs the model files for the English language
library(openNLP) ## Loads the package for use in the task
library(openNLPmodels.en) ## Loads the model files for the English language
text = "Dr. Brown and Mrs. Theresa will be away from a very long time!!! I can't wait to see them again." ## This sentence has unusual punctuation as suggested by @gui11aume
x = sentDetect(text, language = "en") ## sentDetect() is the function to use. It detects and seperates sentences in a text. The first argument is the string vector (or text) and the second argument is the language.
x ## Displays the different sentences in the string vector (or text).
[1] "Dr. Brown and Mrs. Theresa will be away from a very long time!!! "
[2] "I can't wait to see them again."
length(x) ## Displays the number of sentences in the string vector (or text).
[1] 2
|
count number of sentences in a string, while accounting for decimals in javascript
Date : March 29 2020, 07:55 AM
This might help you pherris is right: periods after a sentence should be followed by a space. You can modify the regex to account for it: word.split(/[.!?]+\s/).filter(Boolean).length;
|
How to count number of sentences in a string?
Tag : cpp , By : AJacques
Date : March 29 2020, 07:55 AM
|
How do I make my program count the number of sentences starting with a capital letter in a string?
Date : March 29 2020, 07:55 AM
|