-- Definition module for natural languages in the user interface. module Language ( Noun(..), Verb(..), Adjective(..), Adverb(..), Numeric(..), Negation(..), NounPhrase(..), VerbPhrase(..), Sentence(..), you, it, that, noun, noun_count, verb, negated, adjective, adverb, isPronoun, getCount, getNoun, getVerb, getAdverbs, getNegation ) where import Materials import BodyParts data Noun = PN_you | PN_it | PN_that | N_sword | N_helmet | N_vial | N_orc | N_cave_monster | N_door | N_doorway | N_direction | N_BODY BodyPart data Verb = V_hit | V_kill | V_is | V_open | V_close data Adjective = AJ_dirty | AJ_locked | AJ_broken | AJ_closed | AJ_empty | AJ_strange | AJ_smelly | AJ_huge | AJ_large | AJ_small | AJ_tiny | AJ_hairy | AJ_bald | AJ_fast | AJ_slow | AJ_red | AJ_green | AJ_brown | AJ_MATERIAL Material data Adverb = AV_quickly | AV_silently | AV_already data Numeric = None | Definite | Indefinite | Count Int deriving Eq data Negation = Is | IsNot deriving Eq data NounPhrase = NounPhrase Noun Numeric [Adjective] data VerbPhrase = VerbPhrase Verb [Adverb] Negation data Sentence -- subject, verb, object = BasicSentence NounPhrase VerbPhrase NounPhrase -- subject "is" [adjectives] | DescriptiveSentence NounPhrase [Adverb] [Adjective] -- verb object in which direction? | DirQuestion VerbPhrase NounPhrase -- Construct a basic noun noun :: Noun -> NounPhrase noun n = NounPhrase n Definite [] -- Simple pronouns you :: NounPhrase you = NounPhrase PN_you Definite [] it :: NounPhrase it = NounPhrase PN_it Definite [] that :: NounPhrase that = NounPhrase PN_that Definite [] -- Change the count of a noun phrase noun_count :: Numeric -> NounPhrase -> NounPhrase noun_count count (NounPhrase n _ as) = NounPhrase n count as -- Construct a basic verb verb :: Verb -> VerbPhrase verb v = VerbPhrase v [] Is -- Negate a verb (hit -> doesn't hit, is -> isn't) -- This isn't supposed to do hit -> miss, just add a "not". negated :: VerbPhrase -> VerbPhrase negated (VerbPhrase v as Is) = VerbPhrase v as IsNot negated (VerbPhrase v as IsNot) = VerbPhrase v as Is -- Add an adjective to a noun phrase adjective :: Adjective -> NounPhrase -> NounPhrase adjective adj (NounPhrase w c as) = NounPhrase w c (adj : as) -- Add an adverb to a verb phrase adverb :: Adverb -> VerbPhrase -> VerbPhrase adverb adv (VerbPhrase w as n) = VerbPhrase w (adv : as) n isPronoun :: Noun -> Bool isPronoun PN_you = True isPronoun PN_it = True isPronoun PN_that = True isPronoun _ = False -- Extractor functions getCount :: NounPhrase -> Numeric getCount (NounPhrase _ c _) = c getNoun :: NounPhrase -> Noun getNoun (NounPhrase n _ _) = n getVerb :: VerbPhrase -> Verb getVerb (VerbPhrase v _ _) = v getAdverbs :: VerbPhrase -> [Adverb] getAdverbs (VerbPhrase _ as _) = as getNegation :: VerbPhrase -> Negation getNegation (VerbPhrase _ _ n) = n