诗意处理,对于python

poes的Python项目详细描述


诗歌

诗意的处理,对于python

在斯坦福文学实验室的“跨历史诗歌项目”中开发的代码,作者是Ryan Heuser(@Quadrismegistus)、J.D.Porter、Jonathan Sensenbaugh、Justin Tackett、Mark Alge Hewitt和Maria Kraxenberger。2018年从its original form清洁和改性。

poesy是建立在Prosodic上的,这是一个用python编写的韵律语音分析器。

安装

一。安装Poesy

从PIP安装(首选):

pip install poesy

或安装最新源(高级):

git clone git@github.com:quadrismegistus/poesy.git
cd poesy
python setup.py develop

2.安装espeak(可选,但推荐)

eSpeak是一个用于windows和unix系统(包括mac os x)的开源文本到语音(tts)引擎。poesy建立在Prosodic的基础上,使用它来读出不熟悉的单词。否则,CMU发音词典中未包含单词的行将无法用于韵律分析。

Download eSpeak for your operating system。或者,如果您运行的是Mac OS X,请使用HomeBrew package manager

安装espeak
brew install espeak

用法

创作一首诗:poem = Poem()

frompoesyimportPoem# create a Poem object by stringpoem=Poem("""When in the chronicle of wasted timeI see descriptions of the fairest wights,And beauty making beautiful old rhymeIn praise of ladies dead and lovely knights,Then, in the blazon of sweet beauty's best,Of hand, of foot, of lip, of eye, of brow,I see their antique pen would have express'dEven such a beauty as you master now.So all their praises are but propheciesOf this our time, all you prefiguring;And, for they look'd but with divining eyes,They had not skill enough your worth to sing:For we, which now behold these present days,Had eyes to wonder, but lack tongues to praise.""")# or create a Poem object by pointing to a text filela_belle_dame=Poem(fn='poems/keats.la_belle_dame_sans_merci.txt')

注释摘要:poem.summary()

一个简短的表格总结了诗歌对这首诗的大部分注释。

  (#s,#l)  parse                                             rhyme      #feet    #syll    #parse
---------  ------------------------------------------------  -------  -------  -------  --------
     1.1   WHEN|in.the|CHRON|i|CLE*|of|WAST|ed|TIME          a              5       10         2
     1.2   i|SEE|de|SCRIP|tions|OF*|the|FAI|rest|WIGHTS      b              5       10         1
     1.3   and|BEAU|ty|MAK|ing|BEAU|ti|FUL*|old*|RHYME       a              5       10         3
     1.4   in|PRAISE|of|LAD|ies|DEAD|and|LOVE|ly|KNIGHTS     b              5       10         1
     1.5   THEN|in.the|BLA|zon|OF*|sweet*|BEAU|tys|BEST      c              5       10         8
     1.6   of|HAND|of|FOOT|of|LIP|of|EYE|of|BROW             d              5       10         1
     1.7   i|SEE|their.an*|TIQUE.PEN*|would|HAVE|ex|PRESSD   c              4       10         5
     1.8   EV|en|SUCH*|a|BEAU|ty|AS*|you|MAS|ter|NOW         d              6       11         1
     1.9   so|ALL|their|PRAIS|es|ARE*|but|PRO|phe|CIES*      e              5       10         3
     1.1   OF*|this.our|TIME|all|YOU*|pre|FIG|ur|ING*        f              5       10        15
     1.11  and.for|THEY.LOOKD*|but|WITH*|di|VIN|ing|EYES     e              4       10         3
     1.12  THEY|had.not|SKILL|en|OUGH|your|WORTH|to|SING     f              5       10         2
     1.13  for|WE|which|NOW|be|HOLD|these|PRE|sent|DAYS      e              5       10         1
     1.14  had|EYES|to|WON|der|BUT*|lack*|TONGUES|to|PRAISE  e              5       10         3


estimated schema
----------
meter: Iambic
feet: Pentameter
syllables: 10
rhyme: Sonnet, Shakespearean (abab cdcd efefgg)

注释统计:poem.statd

这本词典结合了下列词典。

1.估计线路方案(英尺):poem.schemed_beat

{'scheme': (5,),
 'scheme_diff': 2,
 'scheme_length': 1,
 'scheme_repr': 'Pentameter',
 'scheme_type': 'Invariable'}

2.估计行方案(音节):poem.schemed_syll

{'scheme': (10,),
 'scheme_diff': 1,
 'scheme_length': 1,
 'scheme_repr': 10,
 'scheme_type': 'Invariable'}

3.估计测量方案:poem.meterd

{'ambiguity': 3.5,
 'constraint_TOTAL': 0.14285714285714285,
 'constraint_footmin-f-resolution': 0.007142857142857143,
 'constraint_footmin-w-resolution': 0.0,
 'constraint_strength_w=>-p': 0.0,
 'constraint_stress_s=>-u': 0.10714285714285714,
 'constraint_stress_w=>-p': 0.02857142857142857,
 'length_avg_line': 10.071428571428571,
 'length_avg_parse': 10.071428571428571,
 'mpos_s': 0.5,
 'mpos_ss': 0.007142857142857143,
 'mpos_w': 0.4928571428571429,
 'perc_lines_ending_s': 1.0,
 'perc_lines_fourthpos_s': 0.8571428571428571,
 'perc_lines_fourthpos_w': 0.14285714285714285,
 'perc_lines_starting_s': 0.14285714285714285,
 'perc_lines_starting_w': 0.8571428571428571,
 'type_foot': 'binary',
 'type_head': 'final',
 'type_scheme': 'iambic'}

4.估计押韵方案:poem.rhymed

{'rhyme_scheme': ('Sonnet, Shakespearean', 'abab cdcd efefgg'),
 'rhyme_scheme_accuracy': 0.6363636363636364,
 'rhyme_scheme_form': 'abab cdcd efefgg',
 'rhyme_scheme_name': 'Sonnet, Shakespearean',
 'rhyme_schemes': [(('Sonnet, Shakespearean', 'abab cdcd efefgg'),
   0.6363636363636364),
  (('Sonnet A', 'abab cdcd eefeff'), 0.6153846153846154),
  (('Sonnet E', 'abab cbcd cdedee'), 0.4117647058823529),
  (('Quatrain And Triplet', 'ababccc'), 0.4),
  (('Sonnet C', 'ababacdc edefef'), 0.4)]}

在行上迭代:poem.lined

每首诗都有许多字典,每一个都有一个“行id”,一个(linenum, stanzanum)的元组。

# The dictionary storing the string representation for the line:forlineid,line_strinsorted(poem.lined.items()):printlineid,line_str# Use this dictionary to loop over prosodic's Line objects insteadforlineid,line_objinsorted(poem.prosodic.items()):printlineid,line_obj.bestParse()# Other dictionariespoem.linenums# lineid -> line number within poempoem.linenums_bystanza# lineid -> line number within stanzapoem.stanzanums# lineid -> stanza numberpoem.linelengths# lineid -> length of linepoem.linelengths_bybeat# lineid -> length of line (in feet)poem.numparses# lineid -> number of plausible parses for linepoem.rhymes# lineid -> rhyme scheme symbol

配置

诗歌依靠Prosodic进行韵律分析。prosodic将其配置数据存储在~/prosodic_data/;其中的README.txt有更多信息。

默认情况下,poesy将使用~/prosodic_data/meters/meter_default.py作为度量(度量约束和行为的集合)。打开该文件以读取更多详细信息。

要指定不同的米,请将米名称传递给诗歌对象:

frompoesyimportPoempoem=Poem(fn='poems/shakespeare_sonnets/sonnet-001.txt',meter='iambic_pentameter')

或者解析方法:

poem.parse(meter='iambic_pentameter')

这些将在~/prosodic_data/meters/iambic_pentameter.py中加载仪表。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
多线程重新构造使用线程池和BlockingQueue的I/O密集型Java web服务   java SWT CTabFolder检查CTAB是否存在   java如何防止具体类的实例化?   java如何将子域定向到正确的JBoss应用程序?   java Android外部文件出现不一致   java FileSystemNotFoundException:未安装提供程序“jndi”   显示jframe上的java隐藏单选按钮   java CXF客户端TCP连接在每个请求之间关闭   Hadoop查询、日期、循环、BASH或Java   java从长类型到十进制类型对象的转换类型错误   java为什么不在用户消息中提供用户提供的数据?有可能的威胁/攻击吗?   使用作用域存储MediaStore的应用程序中的java共享意图问题   java我可以通过将成员指针传递给方法并在方法中分配来初始化它吗?   java如何在一个包含正负值的数组中找到最大的负值?   java有比较二叉树路径的简单方法吗?   java Swagger(ui)不显示操作   java KairosDB缺失值的线性插值   用于此特定求和的java循环