示例#1
0
def main():
    usage = "%prog [options] <song-set> <results-file0> [<results-file1> ...]"
    parser = OptionParser(usage=usage)
    parser.add_option("--popt", "--parser-options", dest="popts", action="append", help="specify options for the parser that interprets the gold standard annotations. Type '--popt help' to get a list of options (we use a DirectedCkyParser)")
    parser.add_option("-m", "--metric", dest="metric", action="store", help="semantics distance metric to use. Use '-m help' for a list of available metrics")
    parser.add_option("--mopt", "--metric-options", dest="mopts", action="append", help="options to pass to the semantics metric. Use with '--mopt help' with -m to see available options")
    parser.add_option("-r", "--print-results", dest="print_results", action="store", default=5, type="int", help="number of top search results to print for each query (parse result). Default: 5. Use -1 to print distances from all songs in the corpus")
    parser.add_option("-g", "--gold-only", dest="gold_only", action="store_true", help="skip results that have no gold standard sequence associated with them (we can't tell which is the right answer for these)")
    parser.add_option("--mc", "--metric-computation", dest="metric_computation", action="store_true", help="output the computation information for the metric between the parse result and each top search result")
    options, arguments = parser.parse_args()
    
    # For now, we always use the music_halfspan formalism with this script
    # If we wanted to make it generic, we'd just load the formalism according 
    #  to a command-line option
    formalism = Formalism
    
    # Process parser options
    if options.popts is not None:
        poptstr = options.popts
        if "help" in [s.strip().lower() for s in poptstr]:
            # Output this parser's option help
            print options_help_text(DirectedCkyParser.PARSER_OPTIONS, intro="Available options for gold standard interpreter")
            sys.exit(0)
        poptstr = ":".join(poptstr)
    else:
        poptstr = ""
    popts = ModuleOption.process_option_string(poptstr)
    # Check that the options are valid
    try:
        DirectedCkyParser.check_options(popts)
    except ModuleOptionError, err:
        logger.error("Problem with parser options (--popt): %s" % err)
        sys.exit(1)
示例#2
0
def main():
    usage = "%prog [options] <chord-corpus-file> <chord-labeling-model> <midi-file>"
    description = "Like findsong, but searches by chord label sequence "\
        "similarity. The input is not a results file, but a midi file, or "\
        "a midi bulk input (CSV)."
    parser = OptionParser(usage=usage)
    parser.add_option("--popt", "--parser-options", dest="popts", action="append", help="specify options for the parser that interprets the gold standard annotations. Type '--popt help' to get a list of options (we use a DirectedCkyParser)")
    parser.add_option("-r", "--print-results", dest="print_results", action="store", default=5, type="int", help="number of top search results to print for each query (parse result). Default: 5. Use -1 to print distances from all songs in the corpus")
    parser.add_option("--filetype", "--ft", dest="filetype", action="store", default="bulk-segmidi", help="filetype to read in. Use 'segmidi' to read a single midi file, or 'bulk-segmidi' (default) to read many from a CSV")
    parser.add_option("--file-options", "--fopt", dest="file_options", action="store", help="options for the input file. Type '--fopt help', using '--ft <type>' to select file type, for a list of available options.")
    parser.add_option("--labeler-options", "--lopt", dest="labeler_options", action="store", help="options for the labeler. Type '--lopt help' for a list of available options.")
    parser.add_option("-g", "--gold-only", dest="gold_only", action="store_true", help="skip results that have no gold standard sequence associated with them (we can't tell which is the right answer for these)")
    parser.add_option("--align", "--print-alignment", dest="print_alignment", action="store_true", help="print out the full alignment between the labeling and the top match")
    options, arguments = parser.parse_args()
    
    # Process parser options
    if options.popts is not None:
        poptstr = options.popts
        if "help" in [s.strip().lower() for s in poptstr]:
            # Output this parser's option help
            print options_help_text(DirectedCkyParser.PARSER_OPTIONS, intro="Available options for gold standard interpreter")
            sys.exit(0)
        poptstr = ":".join(poptstr)
    else:
        poptstr = ""
    popts = ModuleOption.process_option_string(poptstr)
    # Check that the options are valid
    try:
        DirectedCkyParser.check_options(popts)
    except ModuleOptionError, err:
        logger.error("Problem with parser options (--popt): %s" % err)
        sys.exit(1)
示例#3
0
                    (tag, word)
            else:
                # Get all signs that correspond to this tag from the grammar
                word_signs = grammar.get_signs_for_word(word,
                                                        tags=[tag],
                                                        extra_features={
                                                            'duration':
                                                            duration,
                                                            'time': time,
                                                        })
            tags.append(word_signs)
        tagger = PretaggedTagger(grammar, input.slice(start, end), tags=tags)

        # Use the directed parser to try parsing according to this tree
        parser = DirectedCkyParser(grammar,
                                   tagger,
                                   derivation_tree=sub_tree,
                                   options=popts)
        try:
            parser.parse(derivations=True)
        except DirectedParseError, err:
            # Parse failed, so we can't train on this sequence
            raise ParseError, "[Partial parse %d (%d-%d)] parsing using "\
                "the derivation tree failed: %s" % (i,start,end,err)
        # We should now have a complete parse available
        parses = parser.chart.parses
        if len(parses) == 0:
            raise ParseError, "[Partial parse %d (%d-%d)] parsing using the "\
                "derivation tree did not produce any results" % (i,start,end)
        elif len(parses) > 1:
            raise ParseError, "the annotated tree gave multiple "\
                "parse results: %s" % ", ".join(["%s" % p for p in parses])
示例#4
0
     elif tag not in grammar.families:
         raise ParseError, "could not get a sign from the "\
             "grammar for the tag %s (chord %s)" % \
             (tag, word)
     else:
         # Get all signs that correspond to this tag from the grammar
         word_signs = grammar.get_signs_for_word(word, tags=[tag],
                         extra_features={
                             'duration' : duration,
                             'time' : time,
                         })
     tags.append(word_signs)
 tagger = PretaggedTagger(grammar, input.slice(start,end), tags=tags)
     
 # Use the directed parser to try parsing according to this tree
 parser = DirectedCkyParser(grammar, tagger, derivation_tree=sub_tree, options=popts)
 try:
     parser.parse(derivations=True)
 except DirectedParseError, err:
     # Parse failed, so we can't train on this sequence
     raise ParseError, "[Partial parse %d (%d-%d)] parsing using "\
         "the derivation tree failed: %s" % (i,start,end,err)
 # We should now have a complete parse available
 parses = parser.chart.parses
 if len(parses) == 0:
     raise ParseError, "[Partial parse %d (%d-%d)] parsing using the "\
         "derivation tree did not produce any results" % (i,start,end)
 elif len(parses) > 1:
     raise ParseError, "the annotated tree gave multiple "\
         "parse results: %s" % ", ".join(["%s" % p for p in parses])
 else:
示例#5
0
def main():
    usage = "%prog [options] <song-set> <results-file0> [<results-file1> ...]"
    parser = OptionParser(usage=usage)
    parser.add_option(
        "--popt",
        "--parser-options",
        dest="popts",
        action="append",
        help=
        "specify options for the parser that interprets the gold standard annotations. Type '--popt help' to get a list of options (we use a DirectedCkyParser)"
    )
    parser.add_option(
        "-m",
        "--metric",
        dest="metric",
        action="store",
        help=
        "semantics distance metric to use. Use '-m help' for a list of available metrics"
    )
    parser.add_option(
        "--mopt",
        "--metric-options",
        dest="mopts",
        action="append",
        help=
        "options to pass to the semantics metric. Use with '--mopt help' with -m to see available options"
    )
    parser.add_option(
        "-r",
        "--print-results",
        dest="print_results",
        action="store",
        default=5,
        type="int",
        help=
        "number of top search results to print for each query (parse result). Default: 5. Use -1 to print distances from all songs in the corpus"
    )
    parser.add_option(
        "-g",
        "--gold-only",
        dest="gold_only",
        action="store_true",
        help=
        "skip results that have no gold standard sequence associated with them (we can't tell which is the right answer for these)"
    )
    parser.add_option(
        "--mc",
        "--metric-computation",
        dest="metric_computation",
        action="store_true",
        help=
        "output the computation information for the metric between the parse result and each top search result"
    )
    options, arguments = parser.parse_args()

    # For now, we always use the music_halfspan formalism with this script
    # If we wanted to make it generic, we'd just load the formalism according
    #  to a command-line option
    formalism = Formalism

    # Process parser options
    if options.popts is not None:
        poptstr = options.popts
        if "help" in [s.strip().lower() for s in poptstr]:
            # Output this parser's option help
            print options_help_text(
                DirectedCkyParser.PARSER_OPTIONS,
                intro="Available options for gold standard interpreter")
            sys.exit(0)
        poptstr = ":".join(poptstr)
    else:
        poptstr = ""
    popts = ModuleOption.process_option_string(poptstr)
    # Check that the options are valid
    try:
        DirectedCkyParser.check_options(popts)
    except ModuleOptionError, err:
        logger.error("Problem with parser options (--popt): %s" % err)
        sys.exit(1)