Searching within a Dictionary

There are several ways to search in a dictionary, depending on what part of the dictionary entries are used and what the user is searching for.

(All the examples are using the default dictionary.)

CEDICT.search_headwordsFunction
search_headwords(dict, keyword)

Search for the given keyword in the dictionary as a headword, in either traditional or simplified characters (will only return results where the headword is an exact match for keyword; this behavior may change in future releases).

Examples

julia> search_headwords(dict, "2019冠狀病毒病") .|> println;
2019冠狀病毒病 (2019冠状病毒病): [er4 ling2 yi1 jiu3 guan1 zhuang4 bing4 du2 bing4]
        COVID-19, the coronavirus disease identified in 2019
source
CEDICT.search_sensesFunction
search_senses(dict, keyword)

Search for the given keyword in the dictionary among the meanings/senses (the keyword must appear exactly in one or more of the definition senses; this behavior may change in future releases).

Examples

julia> search_senses(dict, "fishnet") .|> println; 漁網 (渔网): [yu2 wang3] fishing net fishnet 扳罾: [ban1 zeng1] to lift the fishnet 網襪 (网袜): [wang3 wa4] fishnet stockings

source
CEDICT.search_pinyinFunction
search_pinyin(dict, keyword)

Search the dictionary for terms that fuzzy match the pinyin search key provided. The language that is understood for the search key is described below.

Examples

julia> search_pinyin(dict, "yi2 han4") .|> println;
遺憾 (遗憾): [yi2 han4]
        regret
        to regret
        to be sorry that

julia> search_pinyin(dict, "bang shou") .|> println;
榜首: [bang3 shou3]
        top of the list
幫手 (帮手): [bang1 shou3]
        helper
        assistant
source

Advanced Pinyin Searching

The search_pinyin function also supports a certain flavor of fuzzy matching and searches with missing information. For example, tone numbers are not required. In addition,

  • "*" will match any additional characters,
  • "?" will match up to one additional character, and
  • "+" will match one or more additional characters.

If these characters are separated by spaces (not attached to any other word character), "character" means a Chinese character; if these characters are attached to other word characters, "character" means a pinyin character.

For example, using these metacharacters on their own (separated by spaces), we can search where we may not know all the characters in the phrase.

julia> search_pinyin(dict, "si ma dang huo ma yi") .|> println;
死馬當活馬醫 (死马当活马医): [si3 ma3 dang4 huo2 ma3 yi1]
        lit. to give medicine to a dead horse (idiom)
        fig. to keep trying everything in a desperate situation

julia> search_pinyin(dict, "si ma dang ? ma yi") .|> println;
死馬當活馬醫 (死马当活马医): [si3 ma3 dang4 huo2 ma3 yi1]
        lit. to give medicine to a dead horse (idiom)
        fig. to keep trying everything in a desperate situation

julia> search_pinyin(dict, "si + ma yi") .|> println;
死馬當活馬醫 (死马当活马医): [si3 ma3 dang4 huo2 ma3 yi1]
        lit. to give medicine to a dead horse (idiom)
        fig. to keep trying everything in a desperate situation

julia> search_pinyin(dict, "si ma dang * huo ma yi") .|> println;
死馬當活馬醫 (死马当活马医): [si3 ma3 dang4 huo2 ma3 yi1]
        lit. to give medicine to a dead horse (idiom)
        fig. to keep trying everything in a desperate situation

The above examples all return the same result.

We could also instead use the metacharacters attached to pinyin letters if we don't know the full sound of a word.

More Advanced Searching

The un-exported method search_filtered can be used if none of the above options are powerful/flexible enough. However, this requires working with the raw DictionaryEntry struct and is subject to breakage in future releases (not a part of the public API).

CEDICT.search_filteredFunction
search_filtered(func, dict)

Produce a set of entries for which func(entry) returns true. This is considered an internal function and not part of the public API for this package; use at your own risk!

source