Ejemplo n.º 1
0
         messages.append(r"\textit{No gold standard for this song}")
     if graph is None:
         messages.append(r"\textit{No successful parses}")
     
     output += r"\fbox{\raggedright"
     output += "\\\\\n".join(messages)
     output += "}\\vspace{20pt}\n"
 
 if gold_graph is not None:
     exit_status = 0
     output += r"\noindent Gold standard (Total parses: %s) \\[10pt]" % (total_parses)
     output += "\r\n"
     output += r"\noindent (%s) %s \\[10pt]" % (song_name, str(input_sequence).replace('%', '\%'))            
     output += "\r\n"
     output += dependency_graph_to_latex(gold_graph, 
                                     number_nodes=True, 
                                     fmt_lab=_fmt_label,
                                     graph_id="dependency-gold")
     output += "\n\\vspace{15pt}"
 
 if graph is not None:
     exit_status = 0
     if transpose != (0,0):
         trans_txt = ", transposed by $(%d,%d)$" % transpose
     else:
         trans_txt = ""
     output += "\r\r\n"
     output += r"\noindent Before reranking (Distance: %s) \\[10pt]" % (top_distance)
     output += "\r\n"
     output += dependency_graph_to_latex(graph, 
                                     number_nodes=True, 
                                     fmt_lab=_fmt_label,
Ejemplo n.º 2
0
def main():
    usage = "%prog [options] <results-files> <index>"
    description = "Prints a dependency tree for a parse result"
    parser = OptionParser(usage=usage, description=description)
    parser.add_option("-l", "--latex", dest="latex", action="store_true", help="output Latex for the graphs using tikz-dependency")
    parser.add_option("--file-options", "--fopt", dest="file_options", action="store", help="options for the input file (--file). Type '--fopt help' for a list of available options.")
    options, arguments = parser.parse_args()
        
    if len(arguments) < 1:
        print >>sys.stderr, "Specify a file to read the results from"
        sys.exit(1)
    filename = arguments[0]
    if len(arguments) < 2:
        print >>sys.stderr, "Specify an of the sequence to load"
        sys.exit(1)
    index = int(arguments[1])
    
    grammar = get_grammar()
    
    # We always need an index, so this is given as an argument
    # Put it in the options list for loading the file
    fopts = options.file_options
    if fopts and len(fopts):
        fopts += ":index=%d" % index
    else:
        fopts = "index=%d" % index
    # Load the sequence index file
    dbinput = command_line_input(filename=filename, filetype="db", options=fopts)
    
    name = dbinput.name
    
    anal = parse_sequence_with_annotations(dbinput, grammar)[0]
    graph, time_map = semantics_to_dependency_graph(anal.semantics)
    
    # Join together chords that are on the same dependency node
    times = iter(sorted(time_map.values()))
    dep_time = times.next()
    current_chord = []
    joined_chords = []
    finished = False
    for chord_time,chord in sorted(dbinput.sequence.time_map.items()):
        if chord_time >= dep_time and not finished:
            if len(current_chord):
                joined_chords.append(current_chord)
            current_chord = [chord]
            try:
                dep_time = times.next()
            except StopIteration:
                finished = True
        else:
            current_chord.append(chord)
    joined_chords.append(current_chord)
    
    chords = [" ".join(filter_latex(str(crd)) for crd in item) 
                                                for item in joined_chords]
    annotations = [" ".join(filter_latex(crd.category) for crd in item) 
                                                for item in joined_chords]
    graph.words = annotations
    
    if options.latex:
        # Exit with status 1 if we don't output anything
        exit_status = 1
        
        # Output a full Latex document in one go
        if name is not None:
            title = r"""\title{%s}
\author{}
\date{}""" % name.capitalize()
            maketitle = r"\maketitle\thispagestyle{empty}\vspace{-20pt}"
        else:
            title = ""
            maketitle = ""
        
        # Print the header
        print r"""\documentclass[a4paper]{article}
\usepackage{tikz-dependency}
%% You may need to set paperheight (for width) and paperwidth (for height) to get things to fit
\usepackage[landscape,margin=1cm,paperheight=50cm]{geometry}
\pagestyle{empty}

%(title)s

\begin{document}
%(maketitle)s

\tikzstyle{every picture}+=[remember picture]
\centering

""" % \
        { 'title' : title,
          'maketitle' : maketitle }
        
        if graph is not None:
            exit_status = 0
            print dependency_graph_to_latex(graph, 
                                            fmt_lab=_fmt_label,
                                            extra_rows=[chords])
            print "\n\\vspace{15pt}"
        
        # Finish off the document
        print r"""
\end{document}
"""
        sys.exit(exit_status)
    else:
        # Not outputing Latex
        print graph
Ejemplo n.º 3
0
        if gold_graph is None or graph is None:
            messages = []
            if gold_graph is None:
                messages.append(r"\textit{No gold standard for this song}")
            if graph is None:
                messages.append(r"\textit{No successful parses}")

            print r"\fbox{\raggedright"
            print "\\\\\n".join(messages)
            print "}\\vspace{20pt}\n"

        if gold_graph is not None:
            exit_status = 0
            print r"\noindent Gold standard\\[10pt]"
            print dependency_graph_to_latex(gold_graph,
                                            number_nodes=True,
                                            fmt_lab=_fmt_label,
                                            graph_id="dependency-gold")
            print "\n\\vspace{15pt}"

        if graph is not None:
            exit_status = 0
            if transpose != (0, 0):
                trans_txt = ", transposed by $(%d,%d)$" % transpose
            else:
                trans_txt = ""
            print r"\noindent Parse result%s\\[10pt]" % trans_txt
            print dependency_graph_to_latex(graph,
                                            number_nodes=True,
                                            fmt_lab=_fmt_label,
                                            graph_id="dependency-parse")
            print "\n\\vspace{15pt}"
Ejemplo n.º 4
0
def main():
    usage = "%prog [options] <results-files> <index>"
    description = "Prints a dependency tree for a parse result"
    parser = OptionParser(usage=usage, description=description)
    parser.add_option("-l",
                      "--latex",
                      dest="latex",
                      action="store_true",
                      help="output Latex for the graphs using tikz-dependency")
    parser.add_option(
        "--file-options",
        "--fopt",
        dest="file_options",
        action="store",
        help=
        "options for the input file (--file). Type '--fopt help' for a list of available options."
    )
    options, arguments = parser.parse_args()

    if len(arguments) < 1:
        print >> sys.stderr, "Specify a file to read the results from"
        sys.exit(1)
    filename = arguments[0]
    if len(arguments) < 2:
        print >> sys.stderr, "Specify an of the sequence to load"
        sys.exit(1)
    index = int(arguments[1])

    grammar = get_grammar()

    # We always need an index, so this is given as an argument
    # Put it in the options list for loading the file
    fopts = options.file_options
    if fopts and len(fopts):
        fopts += ":index=%d" % index
    else:
        fopts = "index=%d" % index
    # Load the sequence index file
    dbinput = command_line_input(filename=filename,
                                 filetype="db",
                                 options=fopts)

    name = dbinput.name

    anal = parse_sequence_with_annotations(dbinput, grammar)[0]
    graph, time_map = semantics_to_dependency_graph(anal.semantics)

    # Join together chords that are on the same dependency node
    times = iter(sorted(time_map.values()))
    dep_time = times.next()
    current_chord = []
    joined_chords = []
    finished = False
    for chord_time, chord in sorted(dbinput.sequence.time_map.items()):
        if chord_time >= dep_time and not finished:
            if len(current_chord):
                joined_chords.append(current_chord)
            current_chord = [chord]
            try:
                dep_time = times.next()
            except StopIteration:
                finished = True
        else:
            current_chord.append(chord)
    joined_chords.append(current_chord)

    chords = [
        " ".join(filter_latex(str(crd)) for crd in item)
        for item in joined_chords
    ]
    annotations = [
        " ".join(filter_latex(crd.category) for crd in item)
        for item in joined_chords
    ]
    graph.words = annotations

    if options.latex:
        # Exit with status 1 if we don't output anything
        exit_status = 1

        # Output a full Latex document in one go
        if name is not None:
            title = r"""\title{%s}
\author{}
\date{}""" % name.capitalize()
            maketitle = r"\maketitle\thispagestyle{empty}\vspace{-20pt}"
        else:
            title = ""
            maketitle = ""

        # Print the header
        print r"""\documentclass[a4paper]{article}
\usepackage{tikz-dependency}
%% You may need to set paperheight (for width) and paperwidth (for height) to get things to fit
\usepackage[landscape,margin=1cm,paperheight=50cm]{geometry}
\pagestyle{empty}

%(title)s

\begin{document}
%(maketitle)s

\tikzstyle{every picture}+=[remember picture]
\centering

""" % \
        { 'title' : title,
          'maketitle' : maketitle }

        if graph is not None:
            exit_status = 0
            print dependency_graph_to_latex(graph,
                                            fmt_lab=_fmt_label,
                                            extra_rows=[chords])
            print "\n\\vspace{15pt}"

        # Finish off the document
        print r"""
\end{document}
"""
        sys.exit(exit_status)
    else:
        # Not outputing Latex
        print graph
Ejemplo n.º 5
0
 if gold_graph is None or graph is None:
     messages = []
     if gold_graph is None:
         messages.append(r"\textit{No gold standard for this song}")
     if graph is None:
         messages.append(r"\textit{No successful parses}")
     
     print r"\fbox{\raggedright"
     print "\\\\\n".join(messages)
     print "}\\vspace{20pt}\n"
 
 if gold_graph is not None:
     exit_status = 0
     print r"\noindent Gold standard\\[10pt]"
     print dependency_graph_to_latex(gold_graph, 
                                     number_nodes=True, 
                                     fmt_lab=_fmt_label,
                                     graph_id="dependency-gold")
     print "\n\\vspace{15pt}"
 
 if graph is not None:
     exit_status = 0
     if transpose != (0,0):
         trans_txt = ", transposed by $(%d,%d)$" % transpose
     else:
         trans_txt = ""
     print r"\noindent Parse result%s\\[10pt]" % trans_txt
     print dependency_graph_to_latex(graph, 
                                     number_nodes=True, 
                                     fmt_lab=_fmt_label,
                                     graph_id="dependency-parse")
     print "\n\\vspace{15pt}"