如何计算R中文本中的句子数?

如何计算R中文本中的句子数?,第1张

概述我使用readChar()函数将文本读入R中.我的目的是检验这样一个假设,即文本的句子出现的字母“a”与字母“b”的出现次数一样多.我最近发现了{stringr}包,这对我的文本做了很多有用的事情,比如计算整个文本中的字符数和每个字母的出现次数.现在,我需要知道整篇文章中的句子数量. R有任何功能,可以帮我做到吗?非常感谢你! 谢谢@ gui11aume的回答.我刚刚发现的一个非常好的包可以帮助完 我使用readChar()函数将文本读入R中.我的目的是检验这样一个假设,即文本的句子出现的字母“a”与字母“b”的出现次数一样多.我最近发现了{stringr}包,这对我的文本做了很多有用的事情,比如计算整个文本中的字符数和每个字母的出现次数.现在,我需要知道整篇文章中的句子数量. R有任何功能,可以帮我做到吗?非常感谢你!解决方法 谢谢@ gui11aume的回答.我刚刚发现的一个非常好的包可以帮助完成工作{openNLP}.这是执行此 *** 作的代码:
install.packages("openNLP") ## Installs the required natural language processing (NLP) packageinstall.packages("openNLPmodels.en") ## Installs the model files for the English languagelibrary(openNLP) ## Loads the package for use in the tasklibrary(openNLPmodels.en) ## Loads the model files for the English languagetext = "Dr. brown and Mrs. Theresa will be away from a very long time!!! I can't wait to see them again." ## This sentence has unusual punctuation as suggested by @gui11aumex = sentDetect(text,language = "en") ## sentDetect() is the function to use. It detects and seperates sentences in a text. The first argument is the string vector (or text) and the second argument is the language.x ## displays the different sentences in the string vector (or text).[1] "Dr. brown and Mrs. Theresa will be away from a very long time!!! "[2] "I can't wait to see them again."length(x) ## displays the number of sentences in the string vector (or text).[1] 2

{openNLP}包非常适合R中的自然语言处理,你可以找到它的简短介绍here,或者你可以查看软件包的文档here.

包中还支持三种语言.您只需安装并加载相应的模型文件即可.

> {openNLPmodels.es}为西班牙语> {openNLPmodels.ge}为德语> {openNLPmodels.th}泰语

总结

以上是内存溢出为你收集整理的如何计算R中文本中的句子数?全部内容,希望文章能够帮你解决如何计算R中文本中的句子数?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1136757.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存