Пример #1
0
    def getalttrans(self, origin=None):
        """Returns <alt-trans> for the given origin as a list of units. No
        origin means all alternatives."""
        translist = []
        for node in self.xmlelement.iterdescendants(self.namespaced("alt-trans")):
            if self.correctorigin(node, origin):
                # We build some mini units that keep the xmlelement. This
                # makes it easier to delete it if it is passed back to us.
                newunit = base.TranslationUnit(self.source)

                # the source tag is optional
                sourcenode = node.iterdescendants(self.namespaced("source"))
                try:
                    newunit.source = lisa.getText(sourcenode.next(), getXMLspace(node, self._default_xml_space))
                except StopIteration:
                    pass

                # must have one or more targets
                targetnode = node.iterdescendants(self.namespaced("target"))
                newunit.target = lisa.getText(targetnode.next(), getXMLspace(node, self._default_xml_space))
                #TODO: support multiple targets better
                #TODO: support notes in alt-trans
                newunit.xmlelement = node

                translist.append(newunit)
        return translist
Пример #2
0
 def get_rich_target(self, lang=None):
     """retrieves the "target" text (second entry), or the entry in the
     specified language, if it exists"""
     if self._rich_target is None:
         self._rich_target = [
             xml_to_strelem(self.get_target_dom(lang), getXMLspace(self.xmlelement, self._default_xml_space))
         ]
     return self._rich_target
Пример #3
0
 def get_rich_source(self):
     #rsrc = xml_to_strelem(self.source_dom)
     #logging.debug('rich source: %s' % (repr(rsrc)))
     #from dubulib.debug.misc import print_stack_funcs
     #print_stack_funcs()
     return [
         xml_to_strelem(self.source_dom,
                        getXMLspace(self.xmlelement,
                                    self._default_xml_space))
     ]
Пример #4
0
 def getcontextgroups(self, name):
     """Returns the contexts in the context groups with the specified name"""
     groups = []
     grouptags = self.xmlelement.iterdescendants(self.namespaced("context-group"))
     #TODO: conbine name in query
     for group in grouptags:
         if group.get("name") == name:
             contexts = group.iterdescendants(self.namespaced("context"))
             pairs = []
             for context in contexts:
                 pairs.append((context.get("context-type"), lisa.getText(context, getXMLspace(self.xmlelement, self._default_xml_space))))
             groups.append(pairs) #not extend
     return groups
Пример #5
0
    def getnotelist(self, origin=None):
        """Private method that returns the text from notes matching 'origin' or all notes."""
        notenodes = self.xmlelement.iterdescendants(self.namespaced("note"))
        # TODO: consider using xpath to construct initial_list directly
        # or to simply get the correct text from the outset (just remember to
        # check for duplication.
        initial_list = [lisa.getText(note, getXMLspace(self.xmlelement, self._default_xml_space)) for note in notenodes if self.correctorigin(note, origin)]

        # Remove duplicate entries from list:
        dictset = {}
        notelist = [dictset.setdefault(note, note) for note in initial_list if note not in dictset]

        return notelist
Пример #6
0
 def getcontextgroups(self, name):
     """Returns the contexts in the context groups with the specified name"""
     groups = []
     grouptags = self.xmlelement.iterdescendants(
         self.namespaced("context-group"))
     # TODO: conbine name in query
     for group in grouptags:
         if group.get("name") == name:
             contexts = group.iterdescendants(self.namespaced("context"))
             pairs = []
             for context in contexts:
                 pairs.append((context.get("context-type"),
                               lisa.getText(
                                   context,
                                   getXMLspace(self.xmlelement,
                                               self._default_xml_space))))
             groups.append(pairs)  # not extend
     return groups
Пример #7
0
    def _getnotelist(self, origin=None):
        """Returns the text from notes matching ``origin`` or all notes.

        :param origin: The origin of the note (or note type)
        :type origin: String
        :return: The text from notes matching ``origin``
        :rtype: List
        """
        note_nodes = self.xmlelement.iterdescendants(self.namespaced("note"))
        # TODO: consider using xpath to construct initial_list directly
        # or to simply get the correct text from the outset (just remember to
        # check for duplication.
        initial_list = [lisa.getText(note, getXMLspace(self.xmlelement, self._default_xml_space)) for note in note_nodes if self.correctorigin(note, origin)]

        # Remove duplicate entries from list:
        dictset = {}
        note_list = [dictset.setdefault(note, note) for note in initial_list if note not in dictset]

        return note_list
Пример #8
0
    def _getnotelist(self, origin=None):
        """Returns the text from notes matching ``origin`` or all notes.

        :param origin: The origin of the note (or note type)
        :type origin: String
        :return: The text from notes matching ``origin``
        :rtype: List
        """
        note_nodes = self.xmlelement.iterdescendants(self.namespaced("note"))
        # TODO: consider using xpath to construct initial_list directly
        # or to simply get the correct text from the outset (just remember to
        # check for duplication.
        initial_list = [lisa.getText(note, getXMLspace(self.xmlelement, self._default_xml_space)) for note in note_nodes if self.correctorigin(note, origin)]

        # Remove duplicate entries from list:
        dictset = {}
        note_list = [dictset.setdefault(note, note) for note in initial_list if note not in dictset]

        return note_list
Пример #9
0
    def getnotelist(self, origin=None):
        """Private method that returns the text from notes matching 'origin' or all notes."""
        notenodes = self.xmlelement.iterdescendants(self.namespaced("note"))
        # TODO: consider using xpath to construct initial_list directly
        # or to simply get the correct text from the outset (just remember to
        # check for duplication.
        initial_list = [
            lisa.getText(note,
                         getXMLspace(self.xmlelement, self._default_xml_space))
            for note in notenodes if self.correctorigin(note, origin)
        ]

        # Remove duplicate entries from list:
        dictset = {}
        notelist = [
            dictset.setdefault(note, note) for note in initial_list
            if note not in dictset
        ]

        return notelist