Skip to content

Commit

Permalink
add nbest configuration to ibus. fixed several bugs in ime-core
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeandmore committed Aug 14, 2011
1 parent f563d9d commit 5b16645
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/ime-core/imi_context.cpp
Expand Up @@ -759,12 +759,14 @@ CIMIContext::getCandidates(unsigned frIdx, CCandidates& result)
cp.m_candi.m_end = frIdx;
if (fr.m_bwType != CLatticeFrame::NO_BESTWORD) {
for (size_t i = 0; i < m_nBest; i++) {
if (fr.m_bestWords[i].m_start != m_candiStarts)
continue;
if (fr.m_bestWords.find(i) == fr.m_bestWords.end())
continue;

CCandidate candi = fr.m_bestWords[i];
if (candi.m_start != m_candiStarts)
continue;
if (candi.m_pLexiconState == NULL)
continue;

TLexiconState & lxst = *(candi.m_pLexiconState);
int len = lxst.m_syls.size() - lxst.m_num_of_inner_fuzzies;
if (len == 0) len = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/ime-core/imi_context.h
Expand Up @@ -256,13 +256,15 @@ class CIMIContext

bool searchFrom(unsigned from = 1);

size_t getMaxBest() const { return m_maxBest; }
void setMaxBest(size_t maxBest) {
m_maxBest = maxBest;
for (int i = 0; i < MAX_LATTICE_LENGTH; i++) {
m_lattice[i].m_latticeStates.setMaxBest(m_maxBest);
}
}

size_t getMaxTailCandidateNum() const { return m_maxTailCandidateNum; }
void setMaxTailCandidateNum(size_t maxTailCandidateNum) {
m_maxTailCandidateNum = maxTailCandidateNum;
}
Expand Down
1 change: 1 addition & 0 deletions src/ime-core/imi_view_classic.cpp
Expand Up @@ -131,6 +131,7 @@ CIMIClassicView::updateWindows(unsigned mask)
for (size_t j = 0; j < tail.size(); j++) {
tail_text += tail[j].m_cwstr;
}
m_tails.push_back(std::make_pair(tail_text, tail));
}
}

Expand Down
10 changes: 9 additions & 1 deletion wrapper/ibus/setup/main.py
Expand Up @@ -452,6 +452,11 @@ def __init__(self):
option_klass=PunctMapping)

class MainWindow():
SPECIAL_OBJECTS = [
'pymodel', 'memory_adjustment', 'candidate_adjustment',
'max_best_adjustment', 'max_tail_candidate_adjustment',
]

def __init__ (self):
self.__bus = ibus.Bus()
self.__config = self.__bus.get_config()
Expand All @@ -466,7 +471,8 @@ def __init_ui(self, name):
self.__init_gettext()
xml_file = path.join(path.dirname(__file__), XML_FILE)
self.__xml = gtk.Builder()
self.__xml.add_objects_from_file(xml_file, [name, 'pymodel', 'memory_adjustment', 'candidate_adjustment'])
self.__xml.add_objects_from_file(xml_file, self.SPECIAL_OBJECTS)
self.__xml.add_objects_from_file(xml_file, [name])
self.__xml.connect_signals(self)
self.__init_options()
self.window = self.__xml.get_object(name)
Expand All @@ -486,6 +492,8 @@ def __init_options(self):
self.__options = [
TrivalOption("General/MemoryPower", 3, self.__xml),
TrivalOption("General/PageSize", 10, self.__xml),
TrivalOption("General/MaxBest", 1, self.__xml),
TrivalOption("General/MaxTailCandidate", 0, self.__xml),

RadioOption("General/InitialStatus/Mode", 'Chinese', ['Chinese', 'English'], self.__xml),
RadioOption("General/InitialStatus/Punct", 'Full', ['Full', 'Half'], self.__xml),
Expand Down
72 changes: 71 additions & 1 deletion wrapper/ibus/setup/setup.xml
Expand Up @@ -1615,6 +1615,7 @@
<property name="title" translatable="yes">SunPinyin Setup</property>
<property name="resizable">False</property>
<property name="window_position">center</property>
<signal name="destroy" handler="on_main_cancel_clicked" swapped="no"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
Expand Down Expand Up @@ -2540,7 +2541,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">10</property>
<property name="n_rows">2</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="homogeneous">True</property>
<child>
Expand Down Expand Up @@ -2599,6 +2600,64 @@
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkLabel" id="max_best">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Number of Best Sentence</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="max_tail_candidate">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Number of Best Tail Candidate</property>
</object>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<object class="GtkHScale" id="General/MaxBest">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">max_best_adjustment</property>
<property name="round_digits">0</property>
<property name="digits">0</property>
<property name="value_pos">right</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkHScale" id="General/MaxTailCandidate">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">max_tail_candidate_adjustment</property>
<property name="round_digits">0</property>
<property name="digits">0</property>
<property name="value_pos">right</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
</packing>
</child>
</object>
</child>
</object>
Expand Down Expand Up @@ -2778,6 +2837,17 @@
</object>
</child>
</object>
<object class="GtkAdjustment" id="max_best_adjustment">
<property name="upper">10</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="max_tail_candidate_adjustment">
<property name="upper">10</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="memory_adjustment">
<property name="upper">11</property>
<property name="value">3</property>
Expand Down
2 changes: 2 additions & 0 deletions wrapper/ibus/src/sunpinyin_config_keys.h
Expand Up @@ -39,6 +39,8 @@
#define CONFIG_GENERAL_PAGE_SIZE "General/PageSize"
#define CONFIG_GENERAL_MEMORY_POWER "General/MemoryPower"
#define CONFIG_GENERAL_CHARSET_LEVEL "General/Charset"
#define CONFIG_GENERAL_MAX_BEST "General/MaxBest"
#define CONFIG_GENERAL_MAX_TAIL_CANDIDATE "General/MaxTailCandidate"
#define CONFIG_GENERAL_INITIAL_MODE "General/InitialStatus/Mode"
#define CONFIG_GENERAL_INITIAL_PUNCT "General/InitialStatus/Punct"
#define CONFIG_GENERAL_INITIAL_LETTER "General/InitialStatus/Letter"
Expand Down
29 changes: 28 additions & 1 deletion wrapper/ibus/src/sunpinyin_engine.cpp
Expand Up @@ -244,6 +244,10 @@ SunPinyinEngine::onConfigChanged(const COptionEvent& event)
update_cand_window_size();
} else if (event.name == CONFIG_GENERAL_CHARSET_LEVEL) {
update_charset_level();
} else if (event.name == CONFIG_GENERAL_MAX_BEST) {
update_max_best();
} else if (event.name == CONFIG_GENERAL_MAX_TAIL_CANDIDATE) {
update_max_tail_candidate();
} else if (event.name == CONFIG_KEYBOARD_MODE_SWITCH) {
update_mode_key();
} else if (event.name == CONFIG_KEYBOARD_PUNCT_SWITCH) {
Expand All @@ -270,6 +274,8 @@ SunPinyinEngine::update_config()
{
update_history_power();
update_cand_window_size();
update_max_best();
update_max_tail_candidate();
update_charset_level();
update_page_key_minus();
update_page_key_comma();
Expand Down Expand Up @@ -350,7 +356,7 @@ SunPinyinEngine::update_preedit_string(const IPreeditString& preedit)

ibus_engine_update_preedit_text(m_engine,
ibus_text_new_from_ucs4(embed_cstr),
preedit.caret() - embed_pos, TRUE);
preedit.caret(), TRUE);

} else {
ibus_engine_hide_auxiliary_text(m_engine);
Expand Down Expand Up @@ -487,6 +493,27 @@ SunPinyinEngine::update_smart_punc()
m_pv->setSmartPunct(m_config.get(CONFIG_KEYBOARD_SMARK_PUNCT, true));
}

void
SunPinyinEngine::update_max_best()
{
if (m_pv->getIC() == NULL) {
return;
}
int oldval = (int) m_pv->getIC()->getMaxBest();
m_pv->getIC()->setMaxBest(m_config.get(CONFIG_GENERAL_MAX_BEST, oldval));
}

void
SunPinyinEngine::update_max_tail_candidate()
{
if (m_pv->getIC() == NULL) {
return;
}
int oldval = (int) m_pv->getIC()->getMaxTailCandidateNum();
m_pv->getIC()->setMaxTailCandidateNum(
m_config.get(CONFIG_GENERAL_MAX_TAIL_CANDIDATE, oldval));
}

string_pairs parse_pairs(const std::vector<std::string>& strings)
{
string_pairs pairs;
Expand Down
2 changes: 2 additions & 0 deletions wrapper/ibus/src/sunpinyin_engine.h
Expand Up @@ -101,6 +101,8 @@ class SunPinyinEngine : public IConfigurable
void update_candi_delete_key();
void update_cancel_with_backspace();
void update_smart_punc();
void update_max_best();
void update_max_tail_candidate();

void update_charset_level();
void update_user_data_dir();
Expand Down

0 comments on commit 5b16645

Please sign in to comment.