No doubt there are many ways to do this task. In this day and age we could even program computers to do it. In considering this problem, I suggest that we remember that the root of the word "music" is "muse." In order to produce the inspired melody, one must be inspired. This is the method I've adopted to do this sort of work. (I've been setting W B Yeats to song since 1996 and have released six CD's of the material so far.) Now as to how one becomes inspired, I suspect each must discover a way suited to one's unique perspective.
Cheers to all who try it.