Esempio n. 1
0
 def attenuateSuccessorsOnType(self):
     for key, phoneme in self.phonemeObjects.items():
         # Each successor must have its probability review
         for successorKey, successor in phoneme.successors.items():
             # Modifier is initially neutral
             modifier = 1
             # Compare phoneme types
             if phoneme.phonemeType == successor.phonemeType:
                 # Phonemes are same type; probability should be drastically reduced
                 modifier = utils.sampleTruncatedNormalDist(0, 1, 0.05, 0.1)
             phoneme.successorProbabilities[successorKey] *= modifier
Esempio n. 2
0
 def generateWords(self, generatedWords, totalWords):
     debugMode = False
     print("Generating (" + str(totalWords) + ") words...")
     for nextWordIndex in range(totalWords):
         if debugMode: print("Generating word " + str(nextWordIndex))
         wordLength = int(utils.sampleTruncatedNormalDist(3, 10, 4.5, 2))
         # Indicate if word length will be calculted in characters or phonemes
         measureLengthInPhonemes = False
         # Call generator function
         finishedWord, symbolString = self.generateWord(wordLength, measureLengthInPhonemes)
         # Add generated word to list
         generatedWords.append(finishedWord)
Esempio n. 3
0
def generateAndPrintParagraph(totalLines, lineWidth, language):
    paragraph = ""
    capitalizeNext = True
    # Indicate if word length will be calculted in characters or phonemes
    measureWordLengthInPhonemes = False
    # Sentence length counters aid decision of punctuation placement
    currentSentenceLength = 0
    minimumSentenceLength = 20
    # Iterate over required lines
    for lineNumber in range(totalLines):
        currentLine = ""
        while len(currentLine) < lineWidth:
            # Generate sanother word for this line
            wordLength = int(utils.sampleTruncatedNormalDist(0, 7, 3, 2)) + 1
            # Generate word
            word, symbolString = language.generateWord(wordLength, measureWordLengthInPhonemes)
            # Words at beginning of sentences will be capitalized, based on flag
            if capitalizeNext:
                capitalizeNext = False
                word = str.capitalize(word)
            # Chance of sentence ending increases the more the sentence exceeds the minimum length
            currentSentenceLength += len(word)
            if currentSentenceLength > minimumSentenceLength:
                # Sentence overflow is number of characters in sentence past minimum sentence length
                sentenceOverflow = currentSentenceLength - minimumSentenceLength
                # Sentence termination probability increases with sentenceOverflow
                terminationProb = 0.02
                if random.random() < (terminationProb * sentenceOverflow):
                    # If sentence ends here, add a full stop
                    word += "."
                    currentSentenceLength = 0
                    capitalizeNext = True
            # Add a space before the next word
            word += " "
            currentLine += word
        # Add a newline symbol
        currentLine += "\n"
        # Add line to paragraph
        paragraph += currentLine
    # Print the paragraph
    print("\nGenerated paragraph:")
    print(paragraph)
Esempio n. 4
0
 def getNoiseAlteredBaseProb(self):
     # Normal distribution sample (mean, sd)
     noise = utils.sampleTruncatedNormalDist(0, 2, 1, 0.25)
     return self.baseProbability * noise