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

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第三方库


热门话题
Java的Arraylist上的操作运行时是什么?   java按下按钮并显示通知   java如何修复“javax.net.ssl.SSLHandshakeException:20190416之后颁发并由不受信任的旧Symantec根CA锚定的TLS服务器证书”   用于新语言插件SonarQube的java解析器   java ANTLR4:参考书示例静态类定义   java如何计算用户点击按钮的次数以及如何保存按钮。安卓工作室   JSP if()语句中的java HTML不起作用   java仿真器崩溃“无效int”   雪花与Java应用程序的集成   从一家银行一行一行地拿到。带有自定义行尾的java txt文档   java从该方法的参数中获取值并显示   我的Eclipse插件尚未找到JAXBAPI的java实现   类如何从顶部文件夹加载java字节码(如果存在“.”)在子文件夹中?   ibm集成总线ibm MessageBroker Java API:Java。lang.NoClassDefFoundError:com。国际商用机器公司mq。MQException