I need to use this to find the notes composing a chord starting from
its name. For example, if I give just 'C' as input, it should
recognize that it is a major chord and then use the relative rule for
the major chord.
This is just the simplest case, because chord names can be very
complex, so they need some parsing. I can have Cm for minor chords, or
C7, or Cmaj7, or Cm7.
I think it is pretty easy to parse these strings in pure python, but I
wonder if I can do the same using a rule base. What do you think? Any
suggestion?
Well, yes. But I think that doing so I have to write the rules for
every different type of chord.
For example, there are this chords:
C
C-
C 7
C- 7
C 9
C- 9
In that way I'll have to write five or six patterns to match the
different chords, while it should recognize that it is a minor chord
(with the symbol -) and then the other part based on the number.
There is an order in the symbols and numbers that may follow the chord
name, but I'm not sure if this can be coded with chaining rules.
If I wanted to prove the goal for a chord sequence (I mean, some
chords in a list) what is the best way to do this? Shall I call the
prove_1 method inside a for loop or is it better to iterate the list
inside the rule base?
This may be useful later, but I need to look a lot more into it to
really get it.
Anyway, the iterative approach solved another doubt, so to find the
type of a chord I'm doing like this:
top_level
use chord($name, $root, $output)
when
$chars = tuple($name)
note($chars, $root, $type)
type_sequence($type, $output)
type_sequence_1_more
use type_sequence($input, $output)
when
python type_list = []
forall
$type in $input
require
chord_type($type, $out_type)
python type_list.append($out_type)
$output = tuple(type_list)
note_rule
use note(($note, *$rest), $note, $rest)
major
use chord_type('M', major)
minor
use chord_type('m',minor)
seventh
use chord_type('7', seventh )
This is still incomplete (and I have to choose more appropriate names
for variables), since I need some other rules, but that should not be
a problem.
I don't know wether this is the right approach, but in this way the
type part may be as long as I need and I have the resulting type in a
single tuple. This was just to let you know.
Thanks again for your precious help,
Carlo