一套连接到强化批评实验室的工具

Augmented-Criticism-Lab-Toolkit的Python项目详细描述


增强的批评实验室工具包和连接器

这套工具是为与增强批评实验室的API接口而设计的, https://acriticismlab.org。工具包可以与pip一起安装:

pip install Augmented-Criticism-Lab-Toolkit

使用接头

连接器用于通过api从数据库中提取数据。下面是一些示例:

fromconnectors.poemimportPoem# To get a list of all poems:all_poems=Poem().all()# To get a specific poem by database id:single_poem=Poem().by_id(1)fromconnectors.bookimportBook# To get a list of all books:all_books=Book().all()# To get a specific book by database id:single_book=Book().by_id(1)

包含的连接符是book、poem和section。每个连接器的工作原理相同。

使用工具

基于api的工具:

fromtools.apiimportTools# Lemmatize text:lemmas=Tools().lemmatize("text to lemmatize")# Part of speech tags:tags=Tools().pos_tag("text to tag")# Frequency distribution:freqdist=Tools().frequency_distribution("text to get distribution for")# Topic model:model=Tools().topic_model("text to model")

注意:主题模型运行大约需要一分钟。

基于python的工具:

押韵方案分析器:

fromtools.rhymeimportRhymefromtools.rhymeimportclassify_sonnet# Initialize a Rhyme object with the text you want to analyze.# The text must be separated into lines, you can define a delimiter# the default is '\\n'. This returns a list of rhyme pairs:# ['A','B','B','A','C','D','D','C','E','F','E','F','G,'G']rhyme=Rhyme("text\n broken\n into lines",delimiter='\n').find_rhyme_scheme()# To classify the rhyme scheme (only works for sonnets) run:# Returns a tuple such that (each number represents a probability# the sonnet of the type listed):#(Petrarchan 1, Petrarchan 2, Petrarchan 3, Shakespearean,  Spenserian)sonnet_type=classify_sonnet(rhyme)

音节计数器:

fromtools.syllableimportSyllableCounter# Initialize a counter:syllable_counter=SyllableCounter()# Run a line of poetry through the counter:syllable_count_for_line=syllable_counter.count_syllables_by_line("line of text")

也可以直接从acl数据库对诗歌运行音节计数器:

fromtools.syllableimportSyllableCounterfromconnectors.poemimportPoem# Initialize a counter:syllable_counter=SyllableCounter()# Get a poem:poem=Poem().by_id(1)# Get counts for the poem:counts=syllable_counter.count_syllables_poem(poem)

扩展离群值:(即没有给出正确音节计数的单词)

创建一个csv文件,格式为:

WORD, NUMBER_OF_SYLLABES

# Example
apple, 2
orange, 2

然后加载csv文件:

fromtools.syllableimportSyllableCounter# Initialize a SyllableCounter.syllable_counter=SyllableCounter()# Load the custom outliers file into the counter.syllable_counter.load_custom_outliers('PATH_TO_FILE')

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

推荐PyPI第三方库


热门话题
Android中Axis2 web服务的java解析响应   java读取Dockerfile命令时遇到问题:是否可以将cd刻录到jar文件中?那么tarcf是做什么的呢?   java如何防止gcmTaskService periodicTask在上一个任务尚未完成时再次运行?   jquery希望使用Java生成自动登录程序   在Hibernate中检索用BigInteger映射的属性时出现java问题   与错误用户连接时发生java错误   java Hibernate+c3p0池+ehcache失败启动   JAVAlang.ClassNotFoundException:org。mysql。JDBC无法解决,添加了mysql连接器   java如何在其键包含JSTL中的点时访问映射值?   packageprivate类中的Java方法可访问性?   java如何将文件转换为StorageObject(谷歌API)   java apache commons httpclient 4.23表单登录问题不同请求中使用的不同会话cookie   所有组件的java一个侦听器instance或每个组件的一个实例   重新启动应用程序后,不会保存ListView中的java更新   java如何修复libgdx中的屏幕无渲染   java在使用mongotemplate时遇到ClassNotFound异常