Mathematica has the experimental (as of v12) function TextStructure
which provides some guidance with this question, but things get tricky.
s1 = "This is a sentence.";
s2 = "This a is sentence.";
s3 = "This a sentence.";
sentenceQ[s_String]:=StringContainsQ[
TextStructure[s,"ConstituentStrings"],"Sentence"];
sentenceQ
yields True for s1
and s2
and False for the last example. Not having a verb phrase is grounds for TextStructure
to not declare that the string is a sentence.
Clearly, s2
is grammatically incorrect. Less clear, is whether or not a grammatically incorrect phrase is still considered a sentence.
If we take one definition of a sentence as containing a subject and a predicate, then s2
is a sentence with a subject This a and a predicate is sentence. Granted, the subject and predicate are nonsensical. Should Mathematica know that? At this point, I think the question belongs at a different StackExchange website.
I decided to stop my search for grammatical truth once I learned that Mathematica and Yoda agree:

I do not believe that current built-in functions of Mathematica provide the tools necessary to address the OPs problem, which I interpret to be identifying grammar errors in a sentence. The reason can be summarized by comparing the output of TextStructure
on "The baseball team are established." and "The baseball team is established." Both yield the same parts of speech, notably, "is" and "are" are both labeled correctly as verbs. However, in order for grammar checking to pick up this error, the two verbs must be tagged differently. A thesis has been written on creating an open-source grammar checker which describes parts-of-speech tagging in more detail. Perhaps if this level of detail is incorporated into future versions of the linguistics functions in Mathematica, this problem will become more tractable.
TextStructure
might be helpful here. It doesn't not tell you what's wrong with the second example, but can be used to show that one has a verb and one does not. $\endgroup$True
for obviously correct sentences andFalse
for obvious gibberish is doable. What it would or could do in the middle (non-obvious cases) and whether it could be useful for any real application are different questions. $\endgroup$TextStructure
-- as shown by @bobthechemist -- givesFalse
for that sentence. So, a narrowing definition is needed. $\endgroup$