def describeComponentOverview(self, doFullSentence, masterPronoun):
         description = ""
         # May only describe components if they exist
         if not len(self.components.keys()) == 0:
                 if doFullSentence:
                         # Begin with pronoun
                         description = utils.getPronoun(self.gender, 'subject') + " "
                 else:
                         # Full sentence not required
                         description += random.choice(", and ", ", which ")
                 # Describe possession
                 description += random.choice(["is made up of", "is composed of", "has"]) + " "
                 # Track components listed so last 
                 keyCount = 0
                 for key, value in self.components.items():
                         keyCount += 1
                         description += utils.intToWord(len(value)) + " " + utils.pluralise(str(type(value[0]).__name__), len(value))
                         if len(self.components.keys()) > 1 and keyCount+1 == len(self.components.keys()):
                                 # insert a connector before last component
                                 description += " and "
                         elif not keyCount == len(self.components.keys()):
                                 # comma separate components
                                 description += ", "
                         description += ". "
                 if doFullSentence:
                         description = string.capitalize(description)
         return description
예제 #2
0
global whitespace

iPrint("\nLet's Describe Something!\n", True)

print("Creating a cube...")
box = geometry.Cube()
box.setNoun("box")
box.addColours(["red", "orange"])
box.describe()
#wsWrapper(box.printComponentTree)

print("Creating a rabbit...")
rabbit = creatures.Creature()
rabbit.setNoun("rabbit")
rabbit.addColours(["brown"])
rabbit.describe()

print("Creating a humanoid...")
percy = creatures.Humanoid()
percy.setNoun("human")
percy.setName("percy")
percy.addColours(["pink"])
percy.describe()

# Sentence building tests
noun = "turkey"
tNum = 1
for tNum in range(0,12):
        print("There "+utils.isOrAre(tNum)+" "+utils.intToWord(tNum)+" "+utils.pluralise(noun, tNum)+" on my lawn.")