Adding nospace flag and modified flag to multiword example

pull/1/head
Ozbolt Menegatti 4 years ago
parent 6a2507a9c2
commit 73ef517c8a

@ -178,7 +178,7 @@
.example {
clear: left;
margin-left: 1em;
.example-dot, .example-rest {
float: left;
max-width: 90%;
@ -289,6 +289,10 @@
.example-component-none {
color: @gray;
}
.example-component-no-space {
color: @silver;
}
}

@ -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.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, 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.ske_messages import ShowSkeModal, SearchInSkeModal, SkeInsert

@ -67,6 +67,16 @@ class ExampleRoleChange(NoReset):
component_new_role = None
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):
def update_model(self, model):

@ -5,6 +5,7 @@ class ComponentLexeme(Data):
self.other_attributes = {}
self.text = ""
self.role = ""
self.no_space = False
def import_xml(self, xml):
if xml.nodeName == "#text":
@ -13,6 +14,9 @@ class ComponentLexeme(Data):
else:
self.text = xml.textContent
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"]:
if xml.hasAttribute(oth_attr):
@ -21,7 +25,7 @@ class ComponentLexeme(Data):
def isValid(self):
return len(self.text) > 0
def export(self, doc):
def export(self, doc, is_multiword, last_component):
if self.role is None:
return doc.createTextNode(self.text)
@ -29,12 +33,17 @@ class ComponentLexeme(Data):
result.setAttribute("role", self.role)
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():
result.setAttribute(key, value)
return result
def view_style(self):
# no-space is handled in multiword-example directly
result = ".comp-text"
if self.role is not None:
result += ".comp-role"

@ -9,8 +9,11 @@ class CorpusExample:
if example_xml.hasAttribute(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")
if modified:
result.setAttribute("modified", "true")
for key, value in self.other_attributes.items():
result.setAttribute(key, value)
return result

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

@ -26,7 +26,7 @@ class MultiwordExample:
ExampleClusters.register_index(cluster)
return cluster
def export(self, doc):
def export(self, doc, _modified):
result = doc.createElement("multiwordExample")
for key, value in self.other_attributes.items():
@ -49,5 +49,11 @@ class MultiwordExample:
return None
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()

@ -47,19 +47,32 @@ def edit_example(example, sense):
return message.msg(message.ExampleRoleChange, example_original, idx, role)
divs = []
buttons_right = lambda idx: [
h("span.example-component-button.example-component-headword",
{"on": {"click": role_msg(idx, "headword")}}, "H"),
h("span.example-component-button.example-component-collocate",
{"on": {"click": role_msg(idx, "collocate")}}, "C"),
h("span.example-component-button.example-component-other",
{"on": {"click": role_msg(idx, "other")}}, "O"),
h("span.example-component-button.example-component-none",
{"on": {"click": role_msg(idx, "none")}}, "N"),
h("span.example-component-button",
{"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"),
h("span.example-component-button",
{"on": {"click": message.msg(message.ExampleComponentRemove, example_original, idx)}}, "-")]
def list_of_right_buttons(idx, component):
result = [
h("span.example-component-button.example-component-headword",
{"on": {"click": role_msg(idx, "headword")}}, "H"),
h("span.example-component-button.example-component-collocate",
{"on": {"click": role_msg(idx, "collocate")}}, "C"),
h("span.example-component-button.example-component-other",
{"on": {"click": role_msg(idx, "other")}}, "O"),
h("span.example-component-button.example-component-none",
{"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",
{"on": {"click": message.msg(message.ExampleComponentAdd, example_original, idx)}}, "+"),
h("span.example-component-button",
{"on": {"click": message.msg(message.ExampleComponentRemove, example_original, idx)}}, "-")])
return result
for idx, component in enumerate(example.components):
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", {}, [
h("div.one-fifth", {}, left),
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))

Loading…
Cancel
Save