Example #1
0
def main():
    usage = "%prog [options] <seq-file> <index>"
    description = "Displays a tree for the annotated derivation of a chord "\
        "sequence in the gold standard"
    parser = OptionParser(usage=usage, description=description)
    options, arguments = parser.parse_args()

    if len(arguments) < 2:
        print "You must specify a sequence file and index"
        sys.exit(1)

    index = int(arguments[1])
    # Get the chord sequence
    sequence = SequenceIndex.from_file(arguments[0]).sequence_by_index(index)

    try:
        # Show the song name
        print "Tree for '%s'" % sequence.string_name
        tree = build_tree_for_sequence(sequence)
        # Output the linear textual form of the tree
        print tree
        # Display the tree using NLTK
        ntree = tree_to_nltk(tree)
        ntree.draw()
    except TreeBuildError, err:
        print >> sys.stderr, "Error parsing: %s" % err
        sys.exit(1)
Example #2
0
def main():
    parser = OptionParser()
    parser.add_option("-s", "--debug-stack", dest="debug_stack", action="store_true", help="print out the stack before each input is processed")
    parser.add_option("-d", "--draw", dest="draw", action="store_true", help="use NLTK to draw the tree for the sequence")
    options, arguments = parser.parse_args()
    
    if len(arguments) == 0:
        print >>sys.stderr, "You need to specify a sequence ID to parse"
        sys.exit(1)
        
    try:
        # Try getting a chord sequence for the given ID
        try:
            sequence = ChordSequence.objects.get(id=int(arguments[0]))
            if sequence.analysis_omitted:
                print >>sys.stderr, "Ignoring %s, since it's marked as unannotated" % sequence.name.encode('ascii','ignore')
                return
        except ChordSequence.DoesNotExist:
            raise TreeBuildError, "there is no chord sequence with ID %s" % arguments[0]
            
        # Build the explicit tree
        print "Building tree for '%s'" % sequence.string_name
        # Use the sequence's mirror
        sequence = sequence.mirror
        tree = build_tree_for_sequence(sequence, debug_stack=options.debug_stack)
        # Output the linear textual form of the tree
        print tree
        if options.draw:
            # Display the tree using NLTK
            ntree = tree_to_nltk(tree)
            ntree.draw()
    except TreeBuildError, err:
        print >>sys.stderr, "Error parsing: %s" % err
        sys.exit(1)
Example #3
0
def main():
    usage = "%prog [options] <seq-file> <index>"
    description = "Displays a tree for the annotated derivation of a chord "\
        "sequence in the gold standard"
    parser = OptionParser(usage=usage, description=description)
    options, arguments = parser.parse_args()
    
    if len(arguments) < 2:
        print "You must specify a sequence file and index"
        sys.exit(1)
        
    index = int(arguments[1])
    # Get the chord sequence
    sequence = SequenceIndex.from_file(arguments[0]).sequence_by_index(index)
    
    try:
        # Show the song name
        print "Tree for '%s'" % sequence.string_name
        tree = build_tree_for_sequence(sequence)
        # Output the linear textual form of the tree
        print tree
        # Display the tree using NLTK
        ntree = tree_to_nltk(tree)
        ntree.draw()
    except TreeBuildError, err:
        print >>sys.stderr, "Error parsing: %s" % err
        sys.exit(1)
Example #4
0
def main():
    parser = OptionParser()
    parser.add_option(
        "-s",
        "--debug-stack",
        dest="debug_stack",
        action="store_true",
        help="print out the stack before each input is processed")
    parser.add_option("-d",
                      "--draw",
                      dest="draw",
                      action="store_true",
                      help="use NLTK to draw the tree for the sequence")
    options, arguments = parser.parse_args()

    if len(arguments) == 0:
        print >> sys.stderr, "You need to specify a sequence ID to parse"
        sys.exit(1)

    try:
        # Try getting a chord sequence for the given ID
        try:
            sequence = ChordSequence.objects.get(id=int(arguments[0]))
            if sequence.analysis_omitted:
                print >> sys.stderr, "Ignoring %s, since it's marked as unannotated" % sequence.name.encode(
                    'ascii', 'ignore')
                return
        except ChordSequence.DoesNotExist:
            raise TreeBuildError, "there is no chord sequence with ID %s" % arguments[
                0]

        # Build the explicit tree
        print "Building tree for '%s'" % sequence.string_name
        # Use the sequence's mirror
        sequence = sequence.mirror
        tree = build_tree_for_sequence(sequence,
                                       debug_stack=options.debug_stack)
        # Output the linear textual form of the tree
        print tree
        if options.draw:
            # Display the tree using NLTK
            ntree = tree_to_nltk(tree)
            ntree.draw()
    except TreeBuildError, err:
        print >> sys.stderr, "Error parsing: %s" % err
        sys.exit(1)