Exemple #1
0
def process_lex_node_reprS(node, compress=False, gloss_iter=None, **kwargs):
    if compress:
        gloss = gloss_iter.next() if gloss_iter else None

        lex = r'\cjk{%s}' % ' '.join(
            latex_tag_for(leaf) for leaf in text(node))

        if gloss:
            # lex = r'\glosE{%s}{%s}' % (lex, gloss)
            return r'\ensuremath{\shortstack{\cf{%s}\smallskip\\ %s \medskip\\ \textit{%s} }}' % (
                sanitise_category(str(node.category)), lex, gloss)
        else:
            return "\\cf{%s} %s %s" % (sanitise_category(str(
                node.category)), "\\edge[roof]; " if node.count() > 1 else '',
                                       lex)
    if node.is_leaf():
        global Snode_id

        lex = latex_tag_for(node.lex)

        gloss = gloss_iter.next() if gloss_iter else None
        if gloss:
            # lex = r'\glosE{%s}{%s}' % (lex, gloss)
            result = r'\node(r%s){\ensuremath{\shortstack{\cf{%s}\smallskip\\ %s \medskip\\ \textit{%s}}}};' % (
                Snode_id, sanitise_category(str(node.category)), lex, gloss)
        else:
            result = "\\node(r%s){\\cf{%s} %s};" % (
                Snode_id, sanitise_category(str(node.category)), lex)
        Snode_id += 1
        return result
    else:
        return "\\cf{%s}" % sanitise_category(str(node.category))
Exemple #2
0
def process_lex_node_reprR(node, compress=False, gloss_iter=None, **kwargs):
    if compress:
        gloss = gloss_iter.next() if gloss_iter else None

        lex = r'\cjk{%s}' % ' '.join(
            latex_tag_for(leaf) for leaf in text(node))

        if gloss:
            lex = r'\glosE{%s}{%s}' % (lex, gloss)

        return "\\cf{%s} %s %s" % (sanitise_category(str(
            node.category)), "\\edge[roof]; " if node.count() > 1 else '', lex)
    if node.is_leaf():
        global Rnode_id

        lex = latex_tag_for(node.lex)

        gloss = gloss_iter.next() if gloss_iter else None
        if gloss:
            lex = r'\glosE{%s}{%s}' % (lex, gloss)

        result = "\\node(r%s){\\cf{%s} %s};" % (
            Rnode_id, sanitise_category(str(node.category)), lex)
        Rnode_id += 1
        return result
    else:
        return "\\cf{%s}" % sanitise_category(str(node.category))
Exemple #3
0
def process_lex_node_repr(node, compress=False, gloss_iter=None, **kwargs):
    if compress:
        gloss = gloss_iter.next() if gloss_iter else None

        lex = r'\cjk{%s}' % ' '.join(
            latex_tag_for(leaf) for leaf in text(node))
        if gloss:
            if node.count() > 1:
                return r'\PTag{%s} \edge[roof]; \ensuremath{\raisebox{-1.4\baselineskip}{\shortstack{{%s} \\ \\ \TGloss{%s}}}}' % (
                    node.tag, lex, gloss)
            else:
                return r'\PTag{%s} \ensuremath{\raisebox{-1\baselineskip}{\shortstack{{%s} \\ \\ \TGloss{%s}}}}' % (
                    node.tag, lex, gloss)

        return "\\PTag{%s} %s %s" % (node.tag, "\\edge[roof]; "
                                     if node.count() > 1 else '', lex)

    if node.is_leaf():
        gloss = gloss_iter.next() if gloss_iter else None
        lex = latex_tag_for(node.lex)

        if gloss:
            return r'\PTag{%s} \ensuremath{\raisebox{-1\baselineskip}{\shortstack{{%s} \\ \\ \TGloss{%s}}}}' % (
                node.tag, lex, gloss)
        else:
            return r'\PTag{%s}{%s}' % (node.tag, lex)
    else:
        return "\\PTag{%s}" % node.tag
Exemple #4
0
def process_lex_node_reprR(node, compress=False, gloss_iter=None, **kwargs):
    if compress:
        gloss = gloss_iter.next() if gloss_iter else None

        lex = r'\cjk{%s}' % ' '.join(latex_tag_for(leaf) for leaf in text(node))

        if gloss:
            lex = r'\glosE{%s}{%s}' % (lex, gloss)

        return "\\cf{%s} %s %s" % (
            sanitise_category(str(node.category)),
            "\\edge[roof]; " if node.count()>1 else '',
            lex)
    if node.is_leaf():
        global Rnode_id

        lex = latex_tag_for(node.lex)

        gloss = gloss_iter.next() if gloss_iter else None
        if gloss:
            lex = r'\glosE{%s}{%s}' % (lex, gloss)

        result = "\\node(r%s){\\cf{%s} %s};" % (Rnode_id, sanitise_category(str(node.category)), lex)
        Rnode_id += 1
        return result
    else:
        return "\\cf{%s}" % sanitise_category(str(node.category))
Exemple #5
0
def process_lex_node_repr(node, compress=False, gloss_iter=None, **kwargs):
    if compress:
        gloss = gloss_iter.next() if gloss_iter else None
        
        lex = r'\cjk{%s}' % ' '.join(latex_tag_for(leaf) for leaf in text(node))
        if gloss:
            if node.count() > 1:
                return r'\PTag{%s} \edge[roof]; \ensuremath{\raisebox{-1.4\baselineskip}{\shortstack{{%s} \\ \\ \TGloss{%s}}}}' % (node.tag, lex, gloss)
            else:
                return r'\PTag{%s} \ensuremath{\raisebox{-1\baselineskip}{\shortstack{{%s} \\ \\ \TGloss{%s}}}}' % (node.tag, lex, gloss)
        
        return "\\PTag{%s} %s %s" % (
            node.tag, 
            "\\edge[roof]; " if node.count()>1 else '', 
            lex)
            
    if node.is_leaf():
        gloss = gloss_iter.next() if gloss_iter else None
        lex = latex_tag_for(node.lex)
        
        if gloss:
            return r'\PTag{%s} \ensuremath{\raisebox{-1\baselineskip}{\shortstack{{%s} \\ \\ \TGloss{%s}}}}' % (node.tag, lex, gloss)
        else:
            return r'\PTag{%s}{%s}' % (node.tag, lex)
    else:
        return "\\PTag{%s}" % node.tag
Exemple #6
0
def process_lex_node_reprS(node, compress=False, gloss_iter=None, **kwargs):
    if compress:
        gloss = gloss_iter.next() if gloss_iter else None

        lex = r'\cjk{%s}' % ' '.join(latex_tag_for(leaf) for leaf in text(node))

        if gloss:
            # lex = r'\glosE{%s}{%s}' % (lex, gloss)
            return r'\ensuremath{\shortstack{\cf{%s}\smallskip\\ %s \medskip\\ \textit{%s} }}' % (
               sanitise_category(str(node.category)), lex, gloss)
        else:
            return "\\cf{%s} %s %s" % (
                sanitise_category(str(node.category)),
                "\\edge[roof]; " if node.count()>1 else '',
                lex)
    if node.is_leaf():
        global Snode_id

        lex = latex_tag_for(node.lex)

        gloss = gloss_iter.next() if gloss_iter else None
        if gloss:
            # lex = r'\glosE{%s}{%s}' % (lex, gloss)
            result = r'\node(r%s){\ensuremath{\shortstack{\cf{%s}\smallskip\\ %s \medskip\\ \textit{%s}}}};' % (
                Snode_id, sanitise_category(str(node.category)), lex, gloss)
        else:
            result = "\\node(r%s){\\cf{%s} %s};" % (Snode_id, sanitise_category(str(node.category)), lex)
        Snode_id += 1
        return result
    else:
        return "\\cf{%s}" % sanitise_category(str(node.category))
Exemple #7
0
 def accept_derivation(self, bundle):
     root = bundle.derivation
     for (pattern, name) in self.Patterns:
         # print pattern, name
         for node, ctx in find_all(root, pattern, with_context=True):
             toks = self.toks.get(bundle.label(), None)
             cn_toks = text(root)
             
             trace = ctx.t
             
             if not (toks and cn_toks):
                 print >>sys.stderr, bundle.label()
                 if trace:
                     self.results[name].not_discharged += 1
             
             alignment = align(cn_toks, toks)
             
             if trace is not None:
                 trace_index = get_index_of_leaf(root, trace)
                 if alignment.get(trace_index, None) is not None:
                     self.results[name].not_discharged += 1
                 else:
                     self.results[name].discharged += 1
             else:
                 print >>sys.stderr, "t was not bound to a trace node"
Exemple #8
0
    def accept_derivation(self, bundle):
        root = bundle.derivation
        for (pattern, name) in self.Patterns:
            # print pattern, name
            for node, ctx in find_all(root, pattern, with_context=True):
                toks = self.toks.get(bundle.label(), None)
                cn_toks = text(root)

                trace = ctx.t

                if not (toks and cn_toks):
                    print >> sys.stderr, bundle.label()
                    if trace:
                        self.results[name].not_discharged += 1

                alignment = align(cn_toks, toks)

                if trace is not None:
                    trace_index = get_index_of_leaf(root, trace)
                    if alignment.get(trace_index, None) is not None:
                        self.results[name].not_discharged += 1
                    else:
                        self.results[name].discharged += 1
                else:
                    print >> sys.stderr, "t was not bound to a trace node"
Exemple #9
0
    def insert_quote(self, deriv, tokens, at, quote, quote_type):
        '''Performs the actual quote insertion. Returns the root of the newly quoted derivation (which may differ
from the root of the input derivation).'''

        if quote == "begin": direction = "forwards"
        elif quote == "end": direction = "backwards"
        
        double = (quote_type == "``")
        
        node = get_leaf(deriv, at, direction)
        
        if (at is not None) and node:
            if quote == "end": # Process absorbed punctuation
                if self.punct_class:
                    node = self.punct_class.process_punct(deriv, node, at)
            
            if node and is_sublist(smaller=text(node), larger=tokens):
                attachment_node = node
                
                while (attachment_node.parent and is_sublist(smaller=text(attachment_node.parent),
                                                             larger=tokens)):
                    attachment_node = attachment_node.parent
                    
                prev_parent = attachment_node.parent
                was_left_child = (attachment_node.parent) and (attachment_node.parent.lch is attachment_node)
                
                if quote == "begin":
                    new_node = Node(attachment_node.cat, 0, 2, 
                                    parent=None, lch=make_open_quote_leaf(None, double),
                                    rch=attachment_node)
                elif quote == "end":
                    new_node = Node(attachment_node.cat, 0, 2,
                                    parent=None, lch=attachment_node,
                                    rch=make_closed_quote_leaf(None, double))
                                    
                if prev_parent:
                    if was_left_child:
                        prev_parent.lch = new_node
                    else:
                        prev_parent.rch = new_node
                else:
                    return new_node # Replace the old root

        return deriv
Exemple #10
0
def process_lex_node_reprL(node, compress=False, **kwargs):
    if compress:
        lex = r'\cjk{%s}' % ' '.join(
            latex_tag_for(leaf) for leaf in text(node))

        return "\\PTag{%s} %s %s" % (node.tag, "\\edge[roof]; "
                                     if node.count() > 1 else '', lex)
    if node.is_leaf():
        if is_trace(node.tag):
            result = "\\node{\\PTag{%s} %s};" % (node.tag,
                                                 latex_tag_for(node.lex))
        else:
            global Lnode_id
            result = "\\node(l%s){\\PTag{%s} %s};" % (Lnode_id, node.tag,
                                                      latex_tag_for(node.lex))
            Lnode_id += 1

        return result
    else:
        return "\\PTag{%s}" % node.tag
Exemple #11
0
def process_lex_node_reprL(node, compress=False, **kwargs):
    if compress:
        lex = r'\cjk{%s}' % ' '.join(latex_tag_for(leaf) for leaf in text(node))

        return "\\PTag{%s} %s %s" % (
            node.tag,
            "\\edge[roof]; " if node.count()>1 else '',
            lex)
    if node.is_leaf():
        if is_trace(node.tag):
            result = "\\node{\\PTag{%s} %s};" % (node.tag, latex_tag_for(node.lex))
        else:
            global Lnode_id
            result = "\\node(l%s){\\PTag{%s} %s};" % (Lnode_id, node.tag, latex_tag_for(node.lex))
            Lnode_id += 1


        return result
    else:
        return "\\PTag{%s}" % node.tag
Exemple #12
0
 def text(self):
     '''Returns a list of text tokens corresponding to the leaves under this node.'''
     return traverse.text(self)
Exemple #13
0
 def text(self):
     '''Returns a list of text tokens corresponding to the leaves under this node.'''
     return traverse.text(self)