diff --git a/res/main.less b/res/main.less index 66e885e..22380c3 100644 --- a/res/main.less +++ b/res/main.less @@ -315,6 +315,21 @@ .ske-line { display: block; margin-top: 0.2em; + + .checkable { + display: block; + } + + .grey1 { + margin-left: 0.3em; + background-color: @silver; + color: @black; + } + .grey2 { + margin-left: 0.3em; + background-color: @black; + color: @silver; + } } } diff --git a/src/message/ske_messages.py b/src/message/ske_messages.py index 8d3c361..6fb0774 100644 --- a/src/message/ske_messages.py +++ b/src/message/ske_messages.py @@ -6,6 +6,7 @@ from lib.snabbdom import h from model.example.example import Example from model.example.corpus_example import CorpusExample +from model.example.multiword_example import MultiwordExample from model.example.component_lexeme import ComponentLexeme @@ -32,10 +33,23 @@ class SkeExample: class SkeCollocation: def __init__(self, data): - self.text = data.cm - + self.word = data.word + self.frequency = data.count + self.structure_name = data.gramrel + + self.other = {"score": data.score, "cm": data.cm} + def view(self): - return h("span", {}, self.text) + return [ + h("span.grey1", {}, self.word), + h("span", {}, ","), + h("span.grey2", {}, self.frequency), + h("span", {}, ","), + h("span.grey1", {}, self.other["score"]), + h("span", {}, ","), + h("span.grey2", {}, self.other["cm"]), + h("span", {}, ","), + h("span.grey1", {}, self.structure_name)] def get_parser(ske_index_type): @@ -102,9 +116,6 @@ class SkeInsert(DataChgClickMessage): if len(data) == 0: return - if not isinstance(data[0], SkeExample): - return - sense_num = document.getElementById("ske-sense-select").selectedIndex sense = model.entry.senses[sense_num] @@ -114,24 +125,56 @@ class SkeInsert(DataChgClickMessage): for ex, element in zip(data, elements): if not element.checked: continue - - new_example = Example() - new_example.inner = CorpusExample() - - lex_left = ComponentLexeme() - lex_left.text = ex["left"] - lex_left.role = "other" - - lex_mid = ComponentLexeme() - lex_mid.text = ex["mid"] - lex_mid.role = "headword" - - lex_right = ComponentLexeme() - lex_right.text = ex["right"] - lex_right.role = "other" - - new_example.components.extend([lex_left, lex_mid, lex_right]) - - # now add it to senses - sense.examples.append(new_example) + elif isinstance(ex, SkeExample): + sense.examples.append(self._as_corpus_example(ex)) + + elif isinstance(ex, SkeCollocation): + sense.examples.append(self._as_multiword_example(ex)) + + else: + console.log("You really should not be here, my lady") + continue + + def _as_corpus_example(self, example): + new_example = Example() + new_example.inner = CorpusExample() + + lex_left = ComponentLexeme() + lex_left.text = example["left"] + lex_left.role = None + + lex_mid = ComponentLexeme() + lex_mid.text = example["mid"] + lex_mid.role = "headword" + + lex_right = ComponentLexeme() + lex_right.text = example["right"] + lex_right.role = None + + new_example.components.extend([lex_left, lex_mid, lex_right]) + return new_example + + def _as_multiword_example(self, example): + new_collocation = Example() + new_collocation.inner = MultiwordExample() + + new_collocation.inner.other_attributes["structureName"] = example.structure_name + new_collocation.inner.other_attributes["logDice"] = example.other["score"] + new_collocation.inner.other_attributes["frequency"] = example.frequency + new_collocation.inner.type = "collocation" + + lex_left = ComponentLexeme() + lex_left.text = "" + lex_left.role = None + + lex_mid = ComponentLexeme() + lex_mid.text = example.word + lex_mid.role = "headword" + + lex_right = ComponentLexeme() + lex_right.text = "" + lex_right.role = None + + new_collocation.components.extend([lex_left, lex_mid, lex_right]) + return new_collocation