Function Repository Resource:

HiraganaQ

Source Notebook

Test if a string is composed of hiragana characters

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["HiraganaQ"][string]

yields True if all the characters in string are hiragana characters, and yields False otherwise.

Details and Options

Hiragana (平仮名, ひらがな) is a Japanese syllabary, one component of the Japanese writing system, along with katakana, kanji and in some cases, rōmaji (Latin script).
ResourceFunction["HiraganaQ"][string] by default gives False if string contains any space or punctuation characters.
ResourceFunction["HiraganaQ"] has the following options:
IgnorePunctuationFalsewhether to ignore PunctuationCharacter in the string
"IgnoreWhitespace"Falsewhether to ignore WhitespaceCharacter in the string
ResourceFunction["HiraganaQ"] automatically threads over lists.

Examples

Basic Examples (2) 

Test whether a character is hiragana:

In[1]:=
ResourceFunction["HiraganaQ"]["あ"]
Out[1]=
In[2]:=
ResourceFunction["HiraganaQ"]["a"]
Out[2]=
In[3]:=
ResourceFunction["HiraganaQ"]["ア"]
Out[3]=

Test if a string contains only hiragana characters:

In[4]:=
ResourceFunction["HiraganaQ"]["ひらがな"]
Out[4]=
In[5]:=
ResourceFunction["HiraganaQ"]["平仮名"]
Out[5]=
In[6]:=
ResourceFunction["HiraganaQ"]["hiragana"]
Out[6]=
In[7]:=
ResourceFunction["HiraganaQ"]["ヒラガナ"]
Out[7]=

Scope (3) 

HiraganaQ yields False when given spaces:

In[8]:=
ResourceFunction["HiraganaQ"]["これ は ひらがなきゅ ではありません"]
Out[8]=
In[9]:=
ResourceFunction["HiraganaQ"]["これはひらがなきゅです"]
Out[9]=

HiraganaQ also yields False when given punctuation characters:

In[10]:=
ResourceFunction["HiraganaQ"]["これはひらがなきゅではありません。"]
Out[10]=

HiraganaQ threads over lists:

In[11]:=
ResourceFunction["HiraganaQ"][{"あ", "ア", "やった", "二"}]
Out[11]=

Options (4) 

IgnorePunctuation (2) 

By default, the presence of characters that match PunctuationCharacter will cause HiraganaQ to yield False:

In[12]:=
ResourceFunction["HiraganaQ"]["やった!"]
Out[12]=

Ignore punctuation:

In[13]:=
ResourceFunction["HiraganaQ"]["やった!", IgnorePunctuation -> True]
Out[13]=

IgnoreWhitespace (2) 

By default, the presence of characters that match WhitespaceCharacter will cause HiraganaQ to yield False:

In[14]:=
ResourceFunction["HiraganaQ"]["ねこ いぬ とり"]
Out[14]=

Ignore whitespace characters:

In[15]:=
ResourceFunction["HiraganaQ"]["ねこ いぬ とり", "IgnoreWhitespace" -> True]
Out[15]=

Properties and Relations (4) 

The empty string will yield True:

In[16]:=
ResourceFunction["HiraganaQ"][""]
Out[16]=

Get the full list of hiragana characters:

In[17]:=
Select[FromCharacterCode /@ Range[0, 65535], ResourceFunction[
 "HiraganaQ"]]
Out[17]=

Verify the output of Alphabet["Hiragana"]:

In[18]:=
ResourceFunction["HiraganaQ"][Alphabet["Hiragana"]]
Out[18]=

Test if a character name corresponds to a hiragana character:

In[19]:=
hiraganaNameQ = ResourceFunction["HiraganaQ"]@*ResourceFunction["FromCharacterName"]
Out[19]=
In[20]:=
hiraganaNameQ["HiraganaLetterA"]
Out[20]=
In[21]:=
hiraganaNameQ["KatakanaLetterA"]
Out[21]=

Possible Issues (1) 

The set of characters matched by HiraganaQ is larger than Alphabet["Hiragana"], since it includes additional characters (e.g. diacritics):

In[22]:=
Select[FromCharacterCode /@ Range[0, 65535], ResourceFunction[
 "HiraganaQ"]]
Out[22]=
In[23]:=
Complement[%, Alphabet["Hiragana"]]
Out[23]=
In[24]:=
 CharacterName /@ %
Out[24]=

Neat Examples (2) 

Test if a string will fully Transliterate into hiragana:

In[25]:=
ResourceFunction["HiraganaQ"][Transliterate[#, "Hiragana"], "IgnoreWhitespace" -> True] & /@ {
  "watashi no neko ha watashi ni nihongo wo oshiete imasu",
  "HiraganaQ[\"hiragana\"]",
  "hello world",
  "1234"
  }
Out[25]=

Apply SpeechSynthesize to a piece of text, but use a Japanese voice for hiragana characters:

In[26]:=
text = "This text contains some hiragana: これはひらがなきゅです. It is spoken by a different voice. びいるどせいはわたしのおきにいりのりいそおすふぁんきしゃんです!"
Out[26]=
In[27]:=
voice = First[VoiceStyleData[#Language == "Japanese" &]]
Out[27]=
In[28]:=
Replace[StringSplit[text, h : (Longest[__?(
ResourceFunction["HiraganaQ"])] ~~ PunctuationCharacter) :> SpeechSynthesize[h, voice]], s_String :> SpeechSynthesize[s], {1}]
Out[28]=
In[29]:=
AudioPlay[AudioJoin[%]]
Out[29]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 04 March 2019

Related Resources

License Information