prepositions1 = 
  TextCases[WordList[], "Preposition"] /. {} -> Nothing // Flatten // 
prepositions1a = 
  TextCases[#, "Preposition"] & /@ WordList[] /. {} -> Nothing // 
    Flatten // Union;

The two syntaxes above check if a word is a preposition (or so I think).

Then I checked every word in the dictionary using WordData for PartOfSpeech:

prepositions2 = 
  If[MemberQ[WordData[ToLowerCase[#], "PartsOfSpeech"], 
      "Preposition"], #, Nothing] & /@ WordList[];

Finally I generated enough prepositions using RandomWord such that the result didn't change after applying Union. This seems like a recognizable list.

prepositions3 = RandomWord["Preposition", 1000] // Union

{"a", "abaft", "aboard", "about", "above", "across", "after",
"against", "along", "alongside", "amid", "amidst", "among",
"amongst", "anent", "around", "as", "aslant", "astraddle", "astride", \ "at", "athwart", "atop", "bar", "barring", "bating", "before",
"behind", "below", "beneath", "beside", "besides", "between",
"betwixt", "beyond", "but", "by", "circa", "concerning",
"considering", "contra", "despite", "down", "during", "ere", "ex",
"except", "excepting", "failing", "fer", "for", "fore", "forth",
"from", "in", "inside", "into", "lacking", "less", "like", "mid",
"midst", "minus", "near", "neath", "next", "nigh", "notwithstanding", \ "o'er", "of", "off", "on", "onto", "opposite", "out", "outshout",
"outside", "outwith", "over", "pace", "past", "pending", "per",
"plus", "pro", "qua", "re", "reference", "regarding", "respecting",
"round", "roundabout", "sans", "save", "saving", "since", "sine",
"than", "through", "throughout", "thru", "thwart", "till", "to",
"touching", "toward", "towards", "under", "underneath", "unless",
"unlike", "until", "unto", "up", "upon", "versus", "via", "vice",
"wanting", "while", "with", "withal", "within", "without"}

Length /@ {prepositions1, prepositions1a, prepositions2, 

{394, 394, 124, 124}

Try: Select[StringContainsQ["ist"]][prepositions1] to see what has made its way into the prepositions1 list.


How can I use TextCases to identify prepositions (or another part of speech) properly? Since I didn't get any warnings, I want to ask if TextCases is intended to be used like this.

Thanks for your help in advance.


1 Answer 1


Not really an answer, but rather a comment.

I believe TextCases is meant to operate on whole sentences instead of individual words, and probably relies on neural networks.

Consider finding "Preposition"s on The Origin Of Species:

TextCases[ExampleData[{"Text", "OriginOfSpecies"}], "Preposition"] // 
     ToLowerCase // Tally // ReverseSortBy@Last // Take[#, 20] & // TableForm

$$ \begin{array}{cc} \text{of} & 7269 \\ \text{in} & 3904 \\ \text{to} & 3560 \\ \text{that} & 1772 \\ \text{as} & 1436 \\ \text{by} & 1322 \\ \text{on} & 1239 \\ \text{from} & 1118 \\ \text{for} & 1109 \\ \text{with} & 973 \\ \text{at} & 680 \\ \text{if} & 415 \\ \text{than} & 371 \\ \text{between} & 329 \\ \text{under} & 221 \\ \text{during} & 214 \\ \text{into} & 199 \\ \text{though} & 183 \\ \text{within} & 104 \\ \text{whether} & 102 \\ \end{array} $$

Also, PerformanceGoal -> "Quality" may affect results. At least it drastically affects performance...

  • $\begingroup$ Everyone gets performance issues. Even Mathematica. $\endgroup$
    – bmf
    Feb 4 at 14:41
  • 1
    $\begingroup$ Thanks @kirma for your effort and the answer. I will wait for half a day to see if there is more activity on this. I thought prepositions in a language were fixed but since I am not a linguist, I can't say for sure. Why would someone need AI for this! $\endgroup$
    – Syed
    Feb 4 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.