Add cluster num option
This commit is contained in:
parent
a03deb3737
commit
be90c9dc89
|
@ -1,7 +1,7 @@
|
|||
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress
|
||||
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
||||
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowRelatedEntriesEdit
|
||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit
|
||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd
|
||||
from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
|
||||
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin
|
||||
from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples
|
||||
|
|
|
@ -106,3 +106,18 @@ class ExampleClusterEdit(NoReset):
|
|||
cluster = self.get_arg(1, int)
|
||||
example.set_cluster(cluster)
|
||||
|
||||
|
||||
class ExampleClusterAdd(NoReset):
|
||||
def update_model(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
|
||||
max_example_cluster_num = 0
|
||||
for sense in model.entry.senses:
|
||||
for ex in sense.examples:
|
||||
cnum = ex.get_cluster()
|
||||
if cnum is not None:
|
||||
max_example_cluster_num = max(max_example_cluster_num, cnum)
|
||||
|
||||
console.log(max_example_cluster_num, example.text())
|
||||
example.set_cluster(max_example_cluster_num + 1)
|
||||
|
||||
|
|
|
@ -27,22 +27,19 @@ class Sense(Editable):
|
|||
sense_xml.querySelectorAll("exampleContainerList exampleContainer")]
|
||||
|
||||
# set limit for example cluster
|
||||
cluster_min =max(cluster_mappings.values()) + 2
|
||||
|
||||
self._original_examples = set([cluster_min - 1])
|
||||
self._original_examples = set(self.example_clusters())
|
||||
cluster_min = max(cluster_mappings.values()) + 1
|
||||
|
||||
def merge_labels(self):
|
||||
return ", ".join(val for _, val in self.labels)
|
||||
|
||||
def example_clusters(self):
|
||||
result = self._original_examples
|
||||
result = set()
|
||||
for ex in self.examples:
|
||||
cluster = ex.get_cluster()
|
||||
if cluster is not None:
|
||||
result.add(cluster)
|
||||
|
||||
return sorted(result)
|
||||
|
||||
return sorted(result, key=lambda x: x)
|
||||
|
||||
@staticmethod
|
||||
def reset_cluster_count():
|
||||
|
|
|
@ -5,27 +5,30 @@ import message
|
|||
from math import log10
|
||||
|
||||
|
||||
def num2str(x):
|
||||
return str(int(log10(x)) + 1)
|
||||
|
||||
|
||||
def show_toggle_cluster_buttons(sense, example):
|
||||
cls = example.get_cluster()
|
||||
if cls is None:
|
||||
return []
|
||||
|
||||
base_tag = "input.cluster-list-button"
|
||||
result = []
|
||||
for opt in sense.example_clusters():
|
||||
tag = "input.cluster-list-button"
|
||||
tag = base_tag
|
||||
if opt == cls:
|
||||
tag += ".cluster-button-checked"
|
||||
|
||||
attrs = {"value": str(opt + 1), "type": "button"}
|
||||
style = {"width": num2str(opt + 1) + "em"}
|
||||
style = {"width": str(int(log10(opt + 1)) + 1) + "em"}
|
||||
|
||||
result.append(h(tag,
|
||||
{"attrs": attrs, "style": style,
|
||||
"on": {"click": message.msg(message.ExampleClusterEdit(example, opt))}}, []))
|
||||
|
||||
result.append(h(base_tag,
|
||||
{"attrs": {"value": "+", "type": "button"},
|
||||
"style": {"width": "1em"},
|
||||
"on": {"click": message.msg(message.ExampleClusterAdd(example))}},
|
||||
[]))
|
||||
return result
|
||||
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ class View:
|
|||
|
||||
example_content = []
|
||||
if cluster is not None:
|
||||
example_content.append(h("span.example-cluster", {}, num2str(cluster)))
|
||||
example_content.append(h("span.example-cluster", {}, str(cluster + 1)))
|
||||
|
||||
example_text_inner_tag = "span.example-text-{}".format(example.get_view_type())
|
||||
example_content.append(h(example_text_inner_tag, {}, example.text()))
|
||||
|
|
Loading…
Reference in New Issue
Block a user