Converts uppercase to lowercase letters for the first n characters of a character string.
culf(x, n = 1, first = TRUE, second = FALSE, lower = FALSE)
a character string.
an integer. Number of characters that we want to convert.
logical. If TRUE
, it converts the n first characters into lowercase.
logical. If TRUE
, it checks if the second letter of x
is uppercase, the whole word will be converted to lower.
logical. If TRUE
, it works similar to tolower
in base R.
A character string.
It is a function to convert some uppercase letters into lowercase for which words with uppercase second letter. If tolower
in base R is used, it will be sometimes created a problem for proper nouns. Because, as we know, a name or proper noun starts with capital letter and we do not want to convert them into lowercase. But sometimes there are some words which are not a name or proper noun and displayed in capital letters. These words are the target of this function.
If we have a text of several sentences and we want to convert the first n letters of every sentence to lowercase, separately. We have to split text to sentences, furthermore we should consider first=TRUE
and apply the function for each sentence (see the examples below).
If we have a list, it works fine.
# NOT RUN {
# x is a list
x=list('W-A for an English-Persian Parallel Corpus (Mizan).','ALIGNMENT is a link between words.')
culf(x, n=8) ## culf(x, n=8) is not a list
y='MT is the automatic translation. SMT is one of the methods of MT.'
culf(y) # only run for the first sentence
u1=unlist(strsplit(y, ". ", fixed = TRUE))
sapply(1:length(u1),function(x)culf(u1[x])) ## run for all sentences
h = 'It is a METHOD for this function.'
culf (h, second = TRUE) #only run for the first word
h1 = strsplit(h, ' ')[[1]]
culf(h1, second = TRUE) # run for all words
# }
Run the code above in your browser using DataLab