Skip to content

Commit

Permalink
bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pzhaonet committed Oct 15, 2018
1 parent 5e11f1c commit fab7581
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27,539 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pinyin
Version: 1.1.4
Date: 2018-10-10
Date: 2018-10-14
Title: Convert Chinese Characters into Pinyin
Author: Peng Zhao
Authors@R: c(
Expand Down
10 changes: 5 additions & 5 deletions R/py.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ pydic <- function(method = c('quanpin', 'tone', 'toneless'),
dic <- match.arg(dic)
mypath <- paste0(.libPaths(), '/pinyin/lib/', dic, '.txt')
lib <- readLines(mypath[file.exists(mypath)][1], encoding = 'UTF-8')
lib <- lib[-grep('^#', lib)] # remove headers
lib <- lib[nchar(lib) != 0] # remove blank lines
if(dic == 'pinyin') {
lib <- lib[-grep('^#', lib)] # remove headers
lib <- lib[-which(nchar(lib) == 0)] # remove blank lines
zh <- substr(lib, 1, 1) # chinese char
bracketloc <- regexpr('\\(', lib)
if (multi) {
Expand All @@ -69,7 +69,7 @@ pydic <- function(method = c('quanpin', 'tone', 'toneless'),
if(dic == 'pinyin2'){
zh <- substr(lib, 1, 1)
if(multi){
qp <- substr(lib, 2, nchar(lib))
qp <- substr(lib, 3, nchar(lib))
mylib <- switch( # extract all pinyins
method,
quanpin = qp,
Expand All @@ -78,15 +78,15 @@ pydic <- function(method = c('quanpin', 'tone', 'toneless'),
)
mylib <- ifelse(grepl(' ', qp), paste0('[', mylib, ']'), mylib)
} else {
qp <- sapply(substr(lib, 2, nchar(lib)), strsplit2)
qp <- sapply(substr(lib, 3, nchar(lib)), strsplit2)
mylib <- switch(method,
quanpin = qp,
tone = qp,
toneless = gsub("[1-4]","", qp))
mylib <- sapply(mylib, strsplit2)
}
}
if (only_first_letter) mylib <- substr(mylib, 1, 1)
if (only_first_letter) mylib <- gsub('[^a-z]*([a-z]).*', '\\1', mylib)
mylib <- list2env(setNames(as.list(mylib),zh))
return(mylib)
}
Expand Down
Loading

0 comments on commit fab7581

Please sign in to comment.