Exporting examples, viewing logdice, frequency, clusternum
also: cluster num for example on load handled
This commit is contained in:
		
							parent
							
								
									d843080e40
								
							
						
					
					
						commit
						7e3fa499f8
					
				@ -154,6 +154,7 @@
 | 
			
		||||
 | 
			
		||||
    .example {
 | 
			
		||||
      clear: left;
 | 
			
		||||
      margin-left: 1em;
 | 
			
		||||
 | 
			
		||||
      .example-dot, .example-rest {
 | 
			
		||||
        float: left;
 | 
			
		||||
@ -167,6 +168,24 @@
 | 
			
		||||
        ._hoverable();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      .example-cluster, .example-logdice, .example-frequency {
 | 
			
		||||
        vertical-align: super;
 | 
			
		||||
        font-size: 0.7em;
 | 
			
		||||
        margin-left: 0.1em;
 | 
			
		||||
        margin-right: 0.1em;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      .example-cluster {
 | 
			
		||||
        color: @blue;
 | 
			
		||||
      }
 | 
			
		||||
      .example-logdice { 
 | 
			
		||||
        color: @gray;
 | 
			
		||||
      }
 | 
			
		||||
      .example-frequency {
 | 
			
		||||
        color: @red;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      .example-rest {
 | 
			
		||||
        border: 1px transparent solid;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@ -112,11 +112,9 @@ def export_sense(doc, sense):
 | 
			
		||||
    sense_xml.appendChild(example_container_list)
 | 
			
		||||
    
 | 
			
		||||
    for example in sense.examples:
 | 
			
		||||
        example_container = doc.createElement("exampleContainer")
 | 
			
		||||
        example_container_list.appendChild(example_container)
 | 
			
		||||
        
 | 
			
		||||
        example_container.appendChild(example.original_xml)
 | 
			
		||||
        example_container = example.export(doc)
 | 
			
		||||
        export_translation_list(doc, example, example_container)
 | 
			
		||||
        example_container_list.appendChild(example_container)
 | 
			
		||||
        
 | 
			
		||||
    return sense_xml
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,15 +3,6 @@ from model.translation import from_container_list
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Example(Editable):
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def from_xml(example_xml):
 | 
			
		||||
        ce_xml = example_xml.querySelector("corpusExample")
 | 
			
		||||
        if ce_xml is not None:
 | 
			
		||||
            return CorpusExample(example_xml)
 | 
			
		||||
        else:
 | 
			
		||||
            return MultiwordExample(example_xml)
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def add_clusters(entry):
 | 
			
		||||
        nocluster_examples = []
 | 
			
		||||
@ -32,25 +23,38 @@ class Example(Editable):
 | 
			
		||||
                cnum += 1
 | 
			
		||||
            taken_clusters.append(cnum)
 | 
			
		||||
            
 | 
			
		||||
            example.cluster = cnum
 | 
			
		||||
            example.set_cluster(cnum)
 | 
			
		||||
            
 | 
			
		||||
        
 | 
			
		||||
    def __init__(self, example_xml):
 | 
			
		||||
        self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
 | 
			
		||||
        self.components = [ComponentLexeme(el) for el in example_xml.querySelectorAll("comp")]
 | 
			
		||||
        
 | 
			
		||||
        ce_xml = example_xml.querySelector("corpusExample")
 | 
			
		||||
        if ce_xml is not None:
 | 
			
		||||
            self.inner = CorpusExample(example_xml)
 | 
			
		||||
        else:
 | 
			
		||||
            self.inner = MultiwordExample(example_xml)
 | 
			
		||||
    
 | 
			
		||||
    def get_cluster(self):
 | 
			
		||||
        return None
 | 
			
		||||
        
 | 
			
		||||
    def get_valid_cluster(self):
 | 
			
		||||
        return None
 | 
			
		||||
    def export(self, doc):
 | 
			
		||||
        result = doc.createElement("exampleContainer")
 | 
			
		||||
        result.appendChild(self.inner.export(doc))
 | 
			
		||||
        return result
 | 
			
		||||
    
 | 
			
		||||
    def text(self):
 | 
			
		||||
        return " ".join([comp.text for comp in self.components])
 | 
			
		||||
        
 | 
			
		||||
    def get_cluster(self):
 | 
			
		||||
        return self.inner.get_cluster()
 | 
			
		||||
    
 | 
			
		||||
class CorpusExample(Example):
 | 
			
		||||
    def get_valid_cluster(self):
 | 
			
		||||
        return self.inner.get_valid_cluster()
 | 
			
		||||
    
 | 
			
		||||
    def set_cluster(self, cluster):
 | 
			
		||||
        self.inner.cluster = cluster
 | 
			
		||||
            
 | 
			
		||||
class CorpusExample:
 | 
			
		||||
    def __init__(self, example_xml):
 | 
			
		||||
        super().__init__(example_xml)
 | 
			
		||||
        xml = example_xml.querySelector("corpusExample")
 | 
			
		||||
@ -60,8 +64,21 @@ class CorpusExample(Example):
 | 
			
		||||
            if xml.hasAttribute(oth_attr):
 | 
			
		||||
                self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
 | 
			
		||||
            
 | 
			
		||||
    def export(self, doc):
 | 
			
		||||
        result = doc.createElement("corpusExample")
 | 
			
		||||
        for comp in self.components:
 | 
			
		||||
            result.appendChild(comp.export(doc))
 | 
			
		||||
        for key, value in self.other_attributes.items():
 | 
			
		||||
            result.setAttribute(key, value)
 | 
			
		||||
        return result
 | 
			
		||||
    
 | 
			
		||||
class MultiwordExample(Example):
 | 
			
		||||
    def get_cluster(self):
 | 
			
		||||
        return None
 | 
			
		||||
    
 | 
			
		||||
    def get_valid_cluster(self):
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
class MultiwordExample:
 | 
			
		||||
    def __init__(self, example_xml):
 | 
			
		||||
        super().__init__(example_xml)
 | 
			
		||||
        xml = example_xml.querySelector("multiwordExample")
 | 
			
		||||
@ -77,6 +94,20 @@ class MultiwordExample(Example):
 | 
			
		||||
            self.cluster_valid = True
 | 
			
		||||
            self.cluster = int(xml.getAttribute("cluster"))
 | 
			
		||||
            
 | 
			
		||||
    def export(self, doc):
 | 
			
		||||
        result = doc.createElement("multiwordExample")
 | 
			
		||||
        
 | 
			
		||||
        for comp in self.components:
 | 
			
		||||
            result.appendChild(comp.export(doc))
 | 
			
		||||
            
 | 
			
		||||
        for key, value in self.other_attributes.items():
 | 
			
		||||
            result.setAttribute(key, value)
 | 
			
		||||
        
 | 
			
		||||
        if self.cluster_valid:
 | 
			
		||||
            result.setAttribute("cluster", str(self.cluster))
 | 
			
		||||
        
 | 
			
		||||
        return result
 | 
			
		||||
        
 | 
			
		||||
    def get_cluster(self):
 | 
			
		||||
        return self.cluster
 | 
			
		||||
    
 | 
			
		||||
@ -93,3 +124,15 @@ class ComponentLexeme:
 | 
			
		||||
        for oth_attr in ["lexical_unit_lexeme_id", "slolex", "kol"]:
 | 
			
		||||
            if xml.hasAttribute(oth_attr):
 | 
			
		||||
                self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
 | 
			
		||||
    
 | 
			
		||||
    def export(self, doc):
 | 
			
		||||
        result = doc.createElement("comp")
 | 
			
		||||
        result.setAttribute("role", self.role)
 | 
			
		||||
        result.textContent = self.text
 | 
			
		||||
        
 | 
			
		||||
        for key, value in self.other_attributes.items():
 | 
			
		||||
            result.setAttribute(key, value)
 | 
			
		||||
        
 | 
			
		||||
        return result
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
from model.entry import Entry
 | 
			
		||||
from model.example import Example
 | 
			
		||||
from browser import window
 | 
			
		||||
 | 
			
		||||
class Model:
 | 
			
		||||
@ -55,3 +56,6 @@ class Model:
 | 
			
		||||
        xmlDoc = parser.parseFromString(xml_text, "text/xml")
 | 
			
		||||
        self.entry = Entry(xmlDoc.querySelector("entry"))
 | 
			
		||||
        
 | 
			
		||||
        # we need to fix the example clusters
 | 
			
		||||
        Example.add_clusters(self.entry)
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
@ -105,10 +105,35 @@ class View:
 | 
			
		||||
        if example in model.chosen_examples:
 | 
			
		||||
            example_tag += ".example-chosen"
 | 
			
		||||
        
 | 
			
		||||
        example_html = h(example_tag, {}, [
 | 
			
		||||
            h("span.example-text", {"on": {"click": msg(ShowExampleMenu(example))} }, [
 | 
			
		||||
                h("span", {}, example.text())
 | 
			
		||||
                ]),
 | 
			
		||||
            h("div.example-translation-list", {}, [
 | 
			
		||||
                h("div.example-translation", {}, [
 | 
			
		||||
                    h("span.example-arrow", {}, "↪"),
 | 
			
		||||
                    vt
 | 
			
		||||
                    ]) for vt in View.view_translations(example.translations, example, model)])])
 | 
			
		||||
                
 | 
			
		||||
        cluster = example.get_cluster()
 | 
			
		||||
        dot_attr = {"style": { "visibility": "visible" if cluster is None else "hidden"}}
 | 
			
		||||
        
 | 
			
		||||
        example_content = []
 | 
			
		||||
        if cluster is not None:
 | 
			
		||||
            example_content.append(h("span.example-cluster", {}, str(cluster)))
 | 
			
		||||
        
 | 
			
		||||
        example_content.append(h("span.example-text-inner", {}, example.text()))
 | 
			
		||||
        
 | 
			
		||||
        if "frequency" in example.other_attributes:
 | 
			
		||||
            example_content.append(h("span.example-frequency", {}, example.other_attributes["frequency"]))
 | 
			
		||||
        
 | 
			
		||||
        if "logDice" in example.other_attributes:
 | 
			
		||||
            example_content.append(h("span.example-logdice", {}, example.other_attributes["logDice"]))
 | 
			
		||||
        
 | 
			
		||||
        return h("div.example", {}, [
 | 
			
		||||
          h("div.example-dot", {}, "▣"),
 | 
			
		||||
          h("div.example-dot", dot_attr, "▣"),
 | 
			
		||||
          h(example_tag, {}, [
 | 
			
		||||
            h("span.example-text", {"on": {"click": msg(ShowExampleMenu(example))} }, example.text()),
 | 
			
		||||
            h("span.example-text", {"on": {"click": msg(ShowExampleMenu(example))} }, example_content),
 | 
			
		||||
            h("div.example-translation-list", {}, [
 | 
			
		||||
                h("div.example-translation", {}, [
 | 
			
		||||
                    h("span.example-arrow", {}, "↪"),
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user