Exemple #1
0
 def test_malody(self):
     model = Parncutt(segmenter=ManualDSegmenter(),
                      segment_combiner="cost")
     d_corpus = DCorpus(paths=["/Users/dave/malody.abcd"])
     model.load_corpus(d_corpus=d_corpus)
     advice = model.advise()
     print(advice)
     # Gold-standard embedded in input file.
     hamming_dists = model.evaluate_strike_distance()
     print(hamming_dists)
Exemple #2
0
    def test_distance_metrics():
        parncutt = Parncutt()
        d_corpus = DCorpus(corpus_str=TestConstant.A_MAJ_SCALE_SHORT)
        parncutt.load_corpus(d_corpus=d_corpus)
        complete_rh_advice = parncutt.advise(staff="upper")
        complete_rh_advice_len = len(complete_rh_advice)
        right_re = re.compile('^>\d+$')
        assert right_re.match(complete_rh_advice), "Bad right-hand, upper-staff advice"
        rh_advice = parncutt.advise(staff="upper", offset=3, first_digit=4)
        short_advice_len = len(rh_advice)
        assert complete_rh_advice_len - 3 == short_advice_len, "Bad offset for advise() call"
        ff_re = re.compile('^>4\d+$')
        assert ff_re.match(rh_advice), "Bad first finger constraint"

        rh_advice = parncutt.advise(staff="upper", offset=10, first_digit=1, last_digit=3)
        short_advice_len = len(rh_advice)
        assert complete_rh_advice_len - 10 == short_advice_len, "Bad offset for advise() call"
        ff_re = re.compile('^>1\d+3$')
        assert ff_re.match(rh_advice), "Bad first and last finger constraints"

        lh_advice = parncutt.advise(staff="lower")
        left_re = re.compile('^<\d+$')
        assert left_re.match(lh_advice), "Bad left-hand, lower-staff advice"
        combo_advice = parncutt.advise(staff="both")
        clean_combo_advice = re.sub('[><&]', '',  combo_advice)
        d_score = d_corpus.d_score_by_index(index=0)
        gold_fingering = d_score.abcdf(index=0)
        clean_gold_fingering = re.sub('[><&]', '',  gold_fingering)

        combo_re = re.compile('^>\d+@<\d+$')
        assert combo_re.match(combo_advice), "Bad combined advice"
        hamming_evaluations = parncutt.evaluate_strike_distance(method="hamming", staff="both")
        assert hamming_evaluations[0] > 0, "Undetected Hamming costs"
        assert hamming_evaluations[3] == 0, "Bad fish in Hamming barrel"

        natural_evaluations = parncutt.evaluate_strike_distance(method="natural", staff="both")
        assert natural_evaluations[0] > 0, "Undetected natural costs"
        assert natural_evaluations[3] == 0, "Bad fish in natural barrel"

        pivot_evaluations = parncutt.evaluate_strike_distance(method="pivot", staff="both")
        assert pivot_evaluations[0] > 0, "Undetected pivot costs"
        assert pivot_evaluations[3] == 0, "Bad fish in pivot barrel"
Exemple #3
0
    def test_parncutt_edges():
        parncutt = Parncutt()
        d_corpus = DCorpus(corpus_str=TestConstant.ONE_NOTE)
        parncutt.load_corpus(d_corpus=d_corpus)
        upper_rh_advice = parncutt.advise(staff="upper")
        right_re = re.compile('^>\d$')
        assert right_re.match(upper_rh_advice), "Bad one-note, right-hand, upper-staff advice"
        # both_advice = parncutt.advise(staff="both")
        # both_re = re.compile('^>\d@$')
        # assert both_re.match(both_advice), "Bad one-note, segregated, both-staff advice"

        parncutt = Parncutt()
        d_corpus = DCorpus(corpus_str=TestConstant.ONE_BLACK_NOTE_PER_STAFF)
        parncutt.load_corpus(d_corpus=d_corpus)
        upper_advice = parncutt.advise(staff="upper")

        right_re = re.compile('^>2$')
        assert right_re.match(upper_advice), "Bad black-note, upper-staff advice"
        lower_advice = parncutt.advise(staff="lower")
        left_re = re.compile('^<2$')
        assert left_re.match(lower_advice), "Bad black-note, upper-staff advice"
        both_advice = parncutt.advise(staff="both")
        both_re = re.compile('^>2@<2$')
        assert both_re.match(both_advice), "Bad black-note, both-staff advice"
        lower_advice = parncutt.advise(staff="lower", first_digit=3)
        lower_re = re.compile('^<3$')
        assert lower_re.match(lower_advice), "Bad preset black-note, both-staff advice"

        parncutt = Parncutt()
        d_corpus = DCorpus(corpus_str=TestConstant.TWO_WHITE_NOTES_PER_STAFF)
        parncutt.load_corpus(d_corpus=d_corpus)
        upper_advice = parncutt.advise(staff="upper")
        right_re = re.compile('^>\d\d$')
        assert right_re.match(upper_advice), "Bad two white-note, upper-staff advice"
        upper_advice = parncutt.advise(staff="upper", first_digit=2, last_digit=4)
        right_re = re.compile('^>24$')
        assert right_re.match(upper_advice), "Bad preset two white-note, upper-staff advice"
Exemple #4
0
#!/usr/bin/env python3
import pprint
from pydactyl.dactyler.Parncutt import Parncutt
from pydactyl.dcorpus.DCorpus import DCorpus
from pydactyl.dcorpus.ManualDSegmenter import ManualDSegmenter

model = Parncutt(segmenter=ManualDSegmenter(), segment_combiner="cost")
# d_corpus = DCorpus(paths=["/Users/dave/malody.abcd"])
d_corpus = DCorpus(paths=["/tmp/malody.abcd"])
model.load_corpus(d_corpus=d_corpus)
advice = model.advise()
print("Best advice: {0}".format(advice))
# Gold-standard embedded in input file.
hamming_dists = model.evaluate_strike_distance()
print("Hamming distance from gold standard: {0}".format(hamming_dists[0]))

suggestions, costs, details = model.generate_advice(staff="upper", k=9)
print("Ranked advice:\n\t{0}".format("\n\t".join(suggestions)))
print("Ranked costs :\n\t{0}".format("\n\t".join(str(x) for x in costs)))

# pp = pprint.PrettyPrinter(width=120)
# pp.pprint(details)