I need to just adapt this code in order to work for phrases but I don't know where to start (I wrote this code for the words)
Using this code in order to get a pig latin code that works for phrases as well
1 回表示 (過去 30 日間)
古いコメントを表示
function out = word2piglatin
word = input ( 'Enter a word:' , 's' );
% Check if the first letter of the word is vowel or not
if ismember(word(1), 'aeiouAEIOU' )
out = [word 'way' ]; %Append 'way' to the word
else
out= [word(2:end) word(1) 'ay' ]; %Place the starting letter at the end and append the 'ay'
end
end
3 件のコメント
Walter Roberson
2020 年 3 月 20 日
"How do you define a phrase?", she asked through e-mail.
Walter Roberson
2020 年 3 月 20 日
編集済み: Walter Roberson
2020 年 3 月 21 日
The given code does not produce correct Pig Latin.
- what has to be moved is consonant clusters, not single consonants. For example switch has the sw move, not just the s
- initial y is treated as a consonant even if it is acting as a vowel in English
- internal y is treated as a vowel, ending a consonant cluster, even if it is acting as a consonant in English
- compound words must be separated into their parts, such as bedroom being treated as bed room. This is probably the most difficult part, as suffixes can modify a word to not be able to stand alone. For example, "He's a bedroomista" cannot be split into "bed" and "roomista" because "roomista" is not considered a standalone word.
- I don't know how to handle contractions at the moment. I suspect that it is "remove the apostrophe and process what is left"
回答 (1 件)
Sriram Tadavarty
2020 年 3 月 20 日
編集済み: Sriram Tadavarty
2020 年 3 月 20 日
Hi Charlotte,
You can perform this by entering the phase in the input and then splitting in to words, process and combining. Here is the code:
function out = word2piglatin
phrase = input('Enter a phrase: ','s');
words = strsplit(phrase);
temp = words;
for i = 1:numel(words)
if ismember(words{i}(1), 'aeiouAEIOU' )
temp{i} = [words{i} 'way' ]; %Append 'way' to the word
else
temp{i}= [words{i}(2:end) words{i}(1) 'ay' ]; %Place the starting letter at the end and append the 'ay'
end
end
out = strjoin(temp, ' ');
end
Try this in command window:
>> word2piglatin
Enter a phrase: Hello Everybody
ans =
'elloHay Everybodyway'
Hope this helps.
Regards,
Sriram
1 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Data Preparation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!