2
\$\begingroup\$

Write a program to output the part of speech of any word inputted to it. I doubt that anyone could get a perfect algorithm, so I will give the code a batch of words in order to ascertain what algorithm is the best.

Weighted Scoring:
+10pts for each word identified correctly: http://www.englishclub.com/grammar/parts-of-speech_1.htm (out of 100 randomly selected words)
-1pt for each byte
+5pts for each upvote on your answer

Rules:
no using external resources (unless they are counted in the size)

UPDATE: Due to the need for a standardized word list for testing purposes, I will be using the list provided in the response to this question. http://www-personal.umich.edu/~jlawler/wordlist It seems to be a fairly complete list, and will make this a challenge more than a guessing game.

\$\endgroup\$

closed as unclear what you're asking by Peter Taylor, SztupY, Howard, manatwork, gnibbler Mar 3 '14 at 9:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ "+style points (tie-breakers, mostly.)" How are these determined? "no golfscript or other languages designed for code golf." Why not? \$\endgroup\$ – Doorknob Feb 28 '14 at 2:36
  • 2
    \$\begingroup\$ "(out of 10 randomly selected words)": Randomly selected from what set? \$\endgroup\$ – DavidC Feb 28 '14 at 2:52
  • 2
    \$\begingroup\$ I believe this is near impossible: programmers.stackexchange.com/a/133789/115106 \$\endgroup\$ – Zero Fiber Feb 28 '14 at 3:32
  • 3
    \$\begingroup\$ @StackTracer It may be better to use 1000 randomly selected words, granting one point each, rather than 10 words each worth 100. \$\endgroup\$ – primo Feb 28 '14 at 6:04
  • 3
    \$\begingroup\$ This isn't a spec: it's an invitation to write a mind-reading program. \$\endgroup\$ – Peter Taylor Feb 28 '14 at 9:29
4
\$\begingroup\$

Mathematica

Mathematica has a native database of words (called up by the simple command WordData ) that includes, among other properties, the parts of speech. Without this database, it would be impossible for me to answer the question.

The word list from here was downloaded. Once stored, it is called up as follows:

words = Import["wordlist.txt", "Table"];
Length[words]

69905

Forty words are randomly chosen from the list:

list = Flatten@RandomSample[words, 40]

{"mealtime", "deride", "cricketground", "torpedinidae", "rosefish", "akron", "sloppy", "deaden", "assaultive", "mick", "unperceptiveness", "skeg", "pad", "mane", "carvel-built", "night-stop", "monarchy", "corking", "backlog", "scaphopoda", "bagman", "phrthe", "wholesome", "proprietress", "hortus", "unreliable", "farthermost", "fearfulness", "malposed", "stoke", "affiche", "lunatic", "holcus", "devoutness", "macaque", "zenithal", "poetry", "precipitate", "agoraphobic", "snapper"}


The following asks Mathematica to return the parts of speech for the list of 40 words. The parts of 31 words are identified. 9 words are not recognized.

(s = Select[Flatten@{{#}, WordData[#, "PartsOfSpeech"]} & /@ 
     list, ! MatchQ[#, {_, WordData[_, _]}] &]) // TableForm
Length[s]

words

\$\endgroup\$
  • 1
    \$\begingroup\$ Seems like cheating, using an internal dictionary.. \$\endgroup\$ – TheDoctor Feb 28 '14 at 23:22
  • \$\begingroup\$ I agree. But it is essentially impossible to determine the part of speech of a word by raw computing power. Some sort of database is required. \$\endgroup\$ – DavidC Feb 28 '14 at 23:48
  • 1
    \$\begingroup\$ "no using external resources (unless they are counted in the size)" What's your score? -1,000,000? \$\endgroup\$ – qwr Mar 1 '14 at 0:44
  • \$\begingroup\$ It was't an external resource. And the word list did not contain information about parts of speech. It was used because the OP did not provide words to use as test cases. \$\endgroup\$ – DavidC Mar 1 '14 at 1:38
  • \$\begingroup\$ This is currently the best solution. I do admit that I was hoping for something less cheaty than a database lookup, but there is no rule against it. I could see a way to do it based on word structure, but that gets rather fuzzy due to the nature of english. \$\endgroup\$ – Stack Tracer Mar 1 '14 at 4:31

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