/** This class contains methods for words and parts of speech. The wordlist files are part of the Moby wordlist project, available at: http://icon.shef.ac.uk/Moby/ You will need to adjust the MobyPath variable to match your system. */ class Words { /** A root URL where the Moby wordlists reside */ class var MobyPath = "file:/home/eliasen/prog/mobydict/" /** A set of nouns. */ class var nouns = new set /** A set of plurals. */ class var plurals = new set /** A set of noun phrases. */ class var nounPhrases = new set /** A set of verbs. */ class var verbs = new set /** A set of adjectives. */ class var adjectives = new set /** A set of adverbs. */ class var adverbs = new set /** A set of conjunctions. */ class var conjunctions = new set /** A set of prepositions. */ class var prepositions = new set /** A set of interjections. */ class var interjections = new set /** A set of pronouns. */ class var pronouns = new set /** A set of definite and indefinite articles. */ class var articles = new set /** A set of definite articles. */ class var definiteArticles = new set /** A set of indefinite articles. (There appear to be none in the wordlist) */ class var indefiniteArticles = new set /** A set of nominatives. (There appear to be none in the wordlist) */ class var nominatives = new set /** A set of all words. This triggers initialization of all wordlists. */ class var words = Words.initAll[] /** This triggers initialization of wordlists and returns a set of all words. */ class initAll[] := { // This will contain a set of all words. all = new set pos = url[MobyPath, "mpos/partsofspeechUTF-8.txt"] for line = lines[pos, "UTF-8"] // Encodings are sorta random { if [word, parts] = line =~ %r/(.+)\|(.+)/ { all.put[word] // Noun? Including plural or noun phrase if parts =~ %r/[Nph]/ nouns.put[word] // Plural? if parts =~ %r/[p]/ plurals.put[word] // Noun phrases? if parts =~ %r/[h]/ nounPhrases.put[word] // Any type of verb? (verb, transitive, intransitive) if parts =~ %r/[Vti]/ verbs.put[word] // Adjective? if parts =~ %r/[A]/ adjectives.put[word] // Adverb? if parts =~ %r/[v]/ adverbs.put[word] // Conjunction? if parts =~ %r/[C]/ conjunctions.put[word] // Preposition? if parts =~ %r/[P]/ prepositions.put[word] // Interjection? if parts =~ %r/[!]/ interjections.put[word] // Pronoun? if parts =~ %r/[r]/ pronouns.put[word] // Definite articles? if parts =~ %r/[D]/ { definiteArticles.put[word] articles.put[word] } // Indefinite articles? (there appear to be none) if parts =~ %r/[I]/ { indefiniteArticles.put[word] articles.put[word] } // Nominative? (there appear to be none) if parts =~ %r/[o]/ nominatives.put[word] } } return all } /** Returns true if the word is in the wordlist. */ class isKnown[str] := words.contains[str] /** Returns true if the string contains a noun. */ class isNoun[str] := { return nouns.contains[str] or (right[str, 1] == "s" and nouns.contains[left[str, -1]]) } /** Returns true if the string contains a verb. */ class isVerb[str] := verbs.contains[str] /** Returns true if the string contains a adjective. */ class isAdjective[str] := adjectives.contains[str] /** Returns true if the string contains a adverb. */ class isAdverb[str] := adverbs.contains[str] /** Returns true if the string contains a conjunction. */ class isConjunction[str] := conjunctions.contains[str] /** Returns true if the string contains a preposition. */ class isPreposition[str] := prepositions.contains[str] /** Returns true if the string contains a interjection. */ class isInterjection[str] := interjections.contains[str] /** Returns true if the string contains a pronoun. */ class isPronoun[str] := pronouns.contains[str] /** Returns true if the string contains a article. */ class isArticle[str] := articles.contains[str] }