Adding nospace flag and modified flag to multiword example

This commit is contained in:
Ozbolt Menegatti 2020-06-11 18:47:09 +02:00
parent 6a2507a9c2
commit 73ef517c8a
8 changed files with 70 additions and 27 deletions

View File

@ -289,6 +289,10 @@
.example-component-none { .example-component-none {
color: @gray; color: @gray;
} }
.example-component-no-space {
color: @silver;
}
} }

View File

@ -4,7 +4,7 @@ from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, Show
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd 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.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin
from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentSpace, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters
from message.delete_messages import DeleteComment, DeleteVariants, DeleteRelatedEntries, DeleteEntryLabels from message.delete_messages import DeleteComment, DeleteVariants, DeleteRelatedEntries, DeleteEntryLabels
from message.ske_messages import ShowSkeModal, SearchInSkeModal, SkeInsert from message.ske_messages import ShowSkeModal, SearchInSkeModal, SkeInsert

View File

@ -68,6 +68,16 @@ class ExampleRoleChange(NoReset):
example.copy().components[component_num].role = component_new_role example.copy().components[component_num].role = component_new_role
class ExampleComponentSpace(NoReset):
def update_model(self, model):
example = self.get_arg(0, Example)
component_num = self.get_arg(1, int)
component = example.copy().components[component_num]
component.no_space = not component.no_space
class ExampleComponentAdd(NoReset): class ExampleComponentAdd(NoReset):
def update_model(self, model): def update_model(self, model):
example = self.get_arg(0, Example) example = self.get_arg(0, Example)

View File

@ -5,6 +5,7 @@ class ComponentLexeme(Data):
self.other_attributes = {} self.other_attributes = {}
self.text = "" self.text = ""
self.role = "" self.role = ""
self.no_space = False
def import_xml(self, xml): def import_xml(self, xml):
if xml.nodeName == "#text": if xml.nodeName == "#text":
@ -14,6 +15,9 @@ class ComponentLexeme(Data):
self.text = xml.textContent self.text = xml.textContent
self.role = xml.getAttribute("role") self.role = xml.getAttribute("role")
if xml.hasAttribute("space"):
self.no_space = xml.getAttribute("space") == "false"
for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]: for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]:
if xml.hasAttribute(oth_attr): if xml.hasAttribute(oth_attr):
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr) self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
@ -21,7 +25,7 @@ class ComponentLexeme(Data):
def isValid(self): def isValid(self):
return len(self.text) > 0 return len(self.text) > 0
def export(self, doc): def export(self, doc, is_multiword, last_component):
if self.role is None: if self.role is None:
return doc.createTextNode(self.text) return doc.createTextNode(self.text)
@ -29,12 +33,17 @@ class ComponentLexeme(Data):
result.setAttribute("role", self.role) result.setAttribute("role", self.role)
result.textContent = self.text result.textContent = self.text
# no space is only allowed in in multiword examples that are not last component
if self.no_space is True and is_multiword and not last_component:
result.setAttribute("space", "false")
for key, value in self.other_attributes.items(): for key, value in self.other_attributes.items():
result.setAttribute(key, value) result.setAttribute(key, value)
return result return result
def view_style(self): def view_style(self):
# no-space is handled in multiword-example directly
result = ".comp-text" result = ".comp-text"
if self.role is not None: if self.role is not None:
result += ".comp-role" result += ".comp-role"

View File

@ -9,8 +9,11 @@ class CorpusExample:
if example_xml.hasAttribute(oth_attr): if example_xml.hasAttribute(oth_attr):
self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr) self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr)
def export(self, doc): def export(self, doc, modified):
result = doc.createElement("corpusExample") result = doc.createElement("corpusExample")
if modified:
result.setAttribute("modified", "true")
for key, value in self.other_attributes.items(): for key, value in self.other_attributes.items():
result.setAttribute(key, value) result.setAttribute(key, value)
return result return result

View File

@ -32,7 +32,7 @@ class Example(Data):
self.inner.import_xml(inner_xml) self.inner.import_xml(inner_xml)
for comp_xml in inner_xml.childNodes: for idx, comp_xml in enumerate(inner_xml.childNodes):
comp = ComponentLexeme() comp = ComponentLexeme()
comp.import_xml(comp_xml) comp.import_xml(comp_xml)
if comp.isValid(): if comp.isValid():
@ -41,13 +41,11 @@ class Example(Data):
def export(self, doc): def export(self, doc):
result = doc.createElement("exampleContainer") result = doc.createElement("exampleContainer")
if self.edited: inner = self.inner.export(doc, self.edited)
result.setAttribute("modified", "true")
inner = self.inner.export(doc)
# TODO: bad quick fix # TODO: bad quick fix
for comp in self.components: for idx, comp in enumerate(self.components):
inner.appendChild(comp.export(doc)) inner.appendChild(comp.export(
doc, self.is_multiword(), idx == len(self.components) - 1))
result.appendChild(inner) result.appendChild(inner)
return result return result

View File

@ -26,7 +26,7 @@ class MultiwordExample:
ExampleClusters.register_index(cluster) ExampleClusters.register_index(cluster)
return cluster return cluster
def export(self, doc): def export(self, doc, _modified):
result = doc.createElement("multiwordExample") result = doc.createElement("multiwordExample")
for key, value in self.other_attributes.items(): for key, value in self.other_attributes.items():
@ -49,5 +49,11 @@ class MultiwordExample:
return None return None
def view(self, components): def view(self, components):
return " ".join([comp.text for comp in components]) result = ""
for comp in components:
result += comp.text
if not comp.no_space:
result += " "
return result.strip()

View File

@ -47,7 +47,8 @@ def edit_example(example, sense):
return message.msg(message.ExampleRoleChange, example_original, idx, role) return message.msg(message.ExampleRoleChange, example_original, idx, role)
divs = [] divs = []
buttons_right = lambda idx: [ def list_of_right_buttons(idx, component):
result = [
h("span.example-component-button.example-component-headword", h("span.example-component-button.example-component-headword",
{"on": {"click": role_msg(idx, "headword")}}, "H"), {"on": {"click": role_msg(idx, "headword")}}, "H"),
h("span.example-component-button.example-component-collocate", h("span.example-component-button.example-component-collocate",
@ -55,11 +56,23 @@ def edit_example(example, sense):
h("span.example-component-button.example-component-other", h("span.example-component-button.example-component-other",
{"on": {"click": role_msg(idx, "other")}}, "O"), {"on": {"click": role_msg(idx, "other")}}, "O"),
h("span.example-component-button.example-component-none", h("span.example-component-button.example-component-none",
{"on": {"click": role_msg(idx, "none")}}, "N"), {"on": {"click": role_msg(idx, "none")}}, "N")]
if example.is_multiword():
additional_class = ".example-component-no-space" if component.no_space else ""
result.append(h("span.example-component-button" + additional_class,
{"on":
{"click":
message.msg(message.ExampleComponentSpace, example_original, idx)}},
""))
result.extend([
h("span.example-component-button", h("span.example-component-button",
{"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"), {"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"),
h("span.example-component-button", h("span.example-component-button",
{"on": {"click": message.msg(message.ExampleComponentRemove, example_original, idx)}}, "-")] {"on": {"click": message.msg(message.ExampleComponentRemove, example_original, idx)}}, "-")])
return result
for idx, component in enumerate(example.components): for idx, component in enumerate(example.components):
role_txt = component.role if component.role is not None else "none" role_txt = component.role if component.role is not None else "none"
@ -75,7 +88,7 @@ def edit_example(example, sense):
divs.append(h("div.flex.five.example-component", {}, [ divs.append(h("div.flex.five.example-component", {}, [
h("div.one-fifth", {}, left), h("div.one-fifth", {}, left),
h("div.three-fifth", {}, middle), h("div.three-fifth", {}, middle),
h("div.one-fifth", {}, buttons_right(idx))])) h("div.one-fifth", {}, list_of_right_buttons(idx, component))]))
return modal_template(divs, "Edit Example", (message.EditExampleText, example_original)) return modal_template(divs, "Edit Example", (message.EditExampleText, example_original))