New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] namespace conversion #105
Conversation
@justinsalamon give it a look. I'll whip up some tests shortly, but all you have to do now is say >>> jams.convert(annotation, 'pitch_hz') if such a conversion is possible, it will be done. If not, you get an exception. It's designed to make adding new converters pretty easy (see the |
@bmcfee just had a look (hence ninja star), looks good to me. |
Okay, cool. I'll get on with testing then. I'll also rework eval a bit to use the converters where appropriate. |
Sounds good, ping me if you'd like me to have a second look, and hopefully we can merge this pretty soon. |
added pitch_hz to midi added tag and segment openers added beat_position to beat added chord_harte to chord added namespace conversion tests fixed a bug in conversion no-op detection
added docs to ns conversion
1e294bd
to
1a170dc
Compare
Ok, I think this one's ready to go. Give it a last CR pass and I'll merge. |
raise NamespaceError('Expected namespace="{:s}", found "{:s}"' | ||
.format(namespace, ann.namespace)) | ||
|
||
ann = convert(ann, namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bmcfee am I right in understanding that you're validating the jams by converting it to the desired namespace and then checking if it validates against this namespace?
If so, doesn't this mean you're not only doing validation, but also conversion, under the hood?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test was previously
"Is this annotation of namespace X
?"
and is now
"can this annotation be interpreted as a valid instance of namespace X
".
I think for evaluation (and sonification) the latter is what we really want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. So let's say I have a pitch_midi
annotation, and I validate it against the pitch_hz
namespace, which would validate fine in this new scenario. So I then try to use this annotation with the transcription eval wrapper, which expects pitch_hz
annotations, and it breaks.
Now of course in practice I'll be adding a conversion step to the transcription eval wrapper such that any annotation provided is converted into pitch_hz
, so this wouldn't actually happen. But could this type of scenario, where you validate against a namespace different to the one your annotation actually is (but convertible to) and consequently get errors further down the line somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I then try to use this annotation with the transcription eval wrapper, which expects pitch_hz annotations, and it breaks.
Ah, I see what you're saying. I forgot to change the return type.
Perhaps this should be renamed to coerce_annotation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've updated the validation logic.
Instead of returning true
(which was never actually checked) it now returns the coerced annotation, which is what gets piped into mir_eval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I just had a look. Already added a couple of line comments for your attention.
This is safe because It wouldn't be hard to do a best-effort reverse conversion ( I'd prefer to not go down that rabbit hole though, since it opens up a lot of possibilities for attempted conversion. Better to stick with a set of well-defined converters that can keep guarantees about the output. |
d1997d2
to
25144fe
Compare
ann.validate(strict=True) | ||
|
||
return True | ||
return ann |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This look safer, yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!resolved
b35c469
to
abea7b6
Compare
Implements #28
beat_position
->beat
tag_*
->tag_open
segment_*
->segment_label_open
pitch_hz
<->pitch_midi
chord_harte
->chord
pitch_class
->pitch_midi
,pitch_hz
~~~chord_roman
->chord_harte
(?)~~~