Using multiple custom dictionaries from one client
In practice, a single domain dictionary is rarely enough. You often want to apply a company-wide term dictionary, a team-specific technical dictionary,
and a temporary dictionary for the current campaign at the same time.
Bareun lets you pass a custom_dict_names array in a morphological analysis request to apply several custom dictionaries at once.
This document explains patterns for using several custom dictionaries together and the priority rules when the same word appears in more than one dictionary.
Applying multiple dictionaries with the custom_dict_names array
The custom_dict_names field of a morphological analysis request (AnalyzeSyntaxRequest) accepts multiple domains as an array. All of the specified dictionaries
are applied together.
| Setting | Dictionaries applied |
|---|---|
custom_dict_names = [] (not specified) | Default result, with no custom dictionary |
custom_dict_names = ["finance"] | Just finance |
custom_dict_names = ["common", "finance", "campaign"] | All three dictionaries |
The dictionary specified first takes priority
If the same headword is in more than one dictionary, the dictionary that appears first in custom_dict_names takes priority.
The array order is the priority order. So put the more specific or more trusted dictionary at the front.
Usage patterns
graph TD REQ[Analysis request] --> ARR["custom_dict_names<br>[common, finance, campaign]"]; ARR --> P1[Priority 1: common]; ARR --> P2[Priority 2: finance]; ARR --> P3[Priority 3: campaign]; P1 --> OUT[Merged and applied]; P2 --> OUT; P3 --> OUT;
- Common + domain combination: Always put the company-wide dictionary (
common) first, and append the domain dictionary that fits the calling service after it. - Priority for a temporary dictionary: If you want a particular spelling to win only during a campaign period, put that dictionary at the very front of the array so it takes priority over the others.
- A/B comparison: You can analyze the same sentence with different dictionary combinations and compare the results.
Example
from bareunpy import Tagger
my_tagger = Tagger('YOUR-API-KEY', 'localhost', port=5656)
text = '이번 분기 여신심사 결과를 정리했다.'
# Specify multiple dictionaries in priority order (the one listed first wins)
res = my_tagger.tags([text], custom_dict_names=['common', 'finance', 'campaign'])
print(res.pos())
[('이번', 'NNG'), ('분기', 'NNG'), ('여신심사', 'NNG'), ('결과', 'NNG'),
('를', 'JKO'), ('정리하', 'VV'), ('았', 'EP'), ('다', 'EF'), ('.', 'SF')]
Because 여신심사 is registered in the finance dictionary, it is recognized as a single noun.
If common also had the same word with a different part of speech (POS), common, which comes earlier in the array, would win.
Use priority as a design tool
Make good use of the fact that array order is priority. Ordering from "specific → general" favors domain-specific interpretations, and ordering from "common → domain" favors the company standard.
Check for conflicts between dictionaries in advance
When you use several dictionaries together, results are hard to predict if the same word is scattered across them with different POS.
It is a good idea to check the dictionaries you will combine in advance with CheckConflict.
Frequently asked questions
Q. Can I apply several dictionaries at the same time?
Yes. Pass the domain names as an array in custom_dict_names of the morphological analysis request.
All of the specified custom dictionaries are applied together.
Q. If the same word is in several dictionaries, which one applies?
In the custom_dict_names array, the dictionary that appears first takes priority. Put the dictionary you want to prioritize at the front.
Q. What happens if I don't specify any dictionary?
You get the default analysis result with no custom dictionary. To apply a registered domain, you must specify it
with custom_dict_names (or set_domain).