view and save of ske examples/collocations

This commit is contained in:
Ozbolt Menegatti 2020-04-05 16:46:24 +02:00
parent 8bb506700d
commit 6912222a53
2 changed files with 84 additions and 26 deletions

View File

@ -315,6 +315,21 @@
.ske-line { .ske-line {
display: block; display: block;
margin-top: 0.2em; 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;
}
} }
} }

View File

@ -6,6 +6,7 @@ from lib.snabbdom import h
from model.example.example import Example from model.example.example import Example
from model.example.corpus_example import CorpusExample from model.example.corpus_example import CorpusExample
from model.example.multiword_example import MultiwordExample
from model.example.component_lexeme import ComponentLexeme from model.example.component_lexeme import ComponentLexeme
@ -32,10 +33,23 @@ class SkeExample:
class SkeCollocation: class SkeCollocation:
def __init__(self, data): 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): 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): def get_parser(ske_index_type):
@ -102,9 +116,6 @@ class SkeInsert(DataChgClickMessage):
if len(data) == 0: if len(data) == 0:
return return
if not isinstance(data[0], SkeExample):
return
sense_num = document.getElementById("ske-sense-select").selectedIndex sense_num = document.getElementById("ske-sense-select").selectedIndex
sense = model.entry.senses[sense_num] sense = model.entry.senses[sense_num]
@ -115,23 +126,55 @@ class SkeInsert(DataChgClickMessage):
if not element.checked: if not element.checked:
continue continue
new_example = Example() elif isinstance(ex, SkeExample):
new_example.inner = CorpusExample() sense.examples.append(self._as_corpus_example(ex))
lex_left = ComponentLexeme() elif isinstance(ex, SkeCollocation):
lex_left.text = ex["left"] sense.examples.append(self._as_multiword_example(ex))
lex_left.role = "other"
lex_mid = ComponentLexeme() else:
lex_mid.text = ex["mid"] console.log("You really should not be here, my lady")
lex_mid.role = "headword" continue
lex_right = ComponentLexeme() def _as_corpus_example(self, example):
lex_right.text = ex["right"] new_example = Example()
lex_right.role = "other" new_example.inner = CorpusExample()
new_example.components.extend([lex_left, lex_mid, lex_right]) lex_left = ComponentLexeme()
lex_left.text = example["left"]
lex_left.role = None
# now add it to senses lex_mid = ComponentLexeme()
sense.examples.append(new_example) 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