用R中的变音符制表字符 [英] Tabulating characters with diacritics in R

查看:90
本文介绍了用R中的变音符制表字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将字符串中出现的电话(字符)列表化,但变音符号则单独作为字符列表化.理想情况下,我在国际语音字母"中有一个字词列表,其中包含大量变音符号,以及它们与基本字符的几种组合.我在这里只给出一个单词的MWE,但是单词列表和更多类型的组合也是如此.

I'm trying to tabulate phones (characters) occurrences in a string, but diacritics are tabulated as characters on their own. Ideally, I have a wordlist in International Phonetic Alphabet, with a fair amount of diacritics and several combinations of them with base characters. I give here a MWE with just one word, but the same goes with list of words and more types of combinations.

> word <- "n̥ana" # word constituted by 4 phones: [n̥],[a],[n],[a]
> table(strsplit(word, ""))
 ̥ a n 
1 2 2

但是想要的结果是:

a n n̥
2 1 1

我如何设法获得这种结果?

How can I manage to get this kind of result?

推荐答案

尝试

library(stringi)
table(stri_split_boundaries(word, type='character'))
#a n n̥ 
#2 1 1 

 table(strsplit(word, '(?<=\\P{Ll}|\\w)(?=\\w)', perl=TRUE))
 #a n  n̥ 
 #2 1 1 

这篇关于用R中的变音符制表字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆