Python Markov链中的字符串/列表/数组问题

问题描述

我最近正在制作或实际上复制了此视频中的马尔可夫链。 运行此程序时,我遇到了各种各样的字符串错误和列表错误,但是这个家伙似乎有一个错误代码。那么我在这里做错了什么?

代码>>

select 
    t.*,max(retail) over(partition by grp) real_retail
from (
    select 
        t.*,sum(case when retail is null then 0 else 1 end) over(order by rn) grp
    from mytable t
) t

我遇到的错误是

import random as r
print ('Hello to my text generator')
print ('This will generate text from the data which you enter')
#author = input("What is the Author's name? >> ")
#title = input("What is the name of this story? >>")
data = "A short story is a piece of prose fiction that typically can be read in one sitting and focuses on a self-contained incident or series of linked incidents,with the intent of evoking a single effect or mood.The short story is a crafted form in its own right. Short stories make use of plot,resonance,and other dynamic components as in a novel,but typically to a lesser degree. While the short story is largely distinct from the novel or novella/short novel,authors generally draw from a common pool of literary techniques.Short story writers may define their works as part of the artistic and personal expression of the form. They may also attempt to resist categorization by genre and fixed formation.Short stories have deep roots and the power of short fiction has been recognized in modern society for hundreds of years.As William Boyd,the award-winning British author and short story writer has said:seem to answer something very deep in our nature as if,for the duration of its telling,something special has been created,some essence of our experience extrapolated,some temporary sense has been made of our common,turbulent journey towards the grave and oblivion.[1]In terms of length,word count is typically anywhere from for short stories,however some have words and are still classed as short stories. Stories of fewer than words are sometimes referred to as short short stories,or flash fiction  Hello"
order = int(input("What should the order be? >> "))
length = int(input('How long should this "story" be? >> '))
class MarkovAlgorithm:
    def __init__(self,order):
        self.order = order
        self.graph = {}
        self.text = None
        return
    def train(self,text):
        self.text = text
        self.text= self.text.split()
        for i in range(0,(len(self.text) - self.order + 1)):
            word = tuple(self.text[i: i+self.order])
            nextWord = self.text[self.order]
            if nextWord in self.graph:
                self.graph[word].append(nextWord)
            else:
                self.graph[word] = nextWord
    def generate(self,length):
        index = r.randint(0,len(self.text) - self.order)
        startingWords = self.text[index: index+self.order]
        for i in range(length):
            orginalState = tuple(startingWords[len(startingWords) - self.order:])
            newWord = r.choice(self.graph[orginalState])
            startingWords.append(newWord)
            var = i + 3
        return ''.join(startingWords[self.order:])

text = MarkovAlgorithm(order)
text.train(data)
result = text.generate(length)
#print ("Viola! Our bot created a story from ",title," by ",author)
print (result)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...