lib/phonetics/code_generator.rb in phonetics-1.9.0 vs lib/phonetics/code_generator.rb in phonetics-2.0.1

- old
+ new

@@ -93,11 +93,11 @@ # switch like the following: # # switch (phoneme1) { # case 'ɪ': // two bytes: [201, 170] # // vowel features: {"F1":300,"F2":2100,"rounded":false} - # + # # switch(phoneme2) { # 'i': // one byte: [105] # // vowel features: {"F1":240,"F2":2400,"rounded":false} # return (float) 0.14355381904337383; # break; @@ -107,26 +107,31 @@ def generate write(<<-HEADER.gsub(/^ {6}/, '')) // This is compiled from Ruby, in #{ruby_source} #include <stdint.h> + #include <stdio.h> + #include <inttypes.h> float phonetic_cost(int64_t phoneme1, int64_t phoneme2) { + if (phoneme1 == phoneme2) { + return (float) 0.0; + } HEADER write ' switch (phoneme1) {' Phonetics.phonemes.each do |phoneme1| write " case #{binary(phoneme1)}:" describe(phoneme1, 2) - write " switch(phoneme2) {" + write ' switch(phoneme2) {' Phonetics.distance_map[phoneme1].each do |phoneme2, distance| write " case #{binary(phoneme2)}:" describe(phoneme2, 6) write " return (float) #{distance};" write ' break;' end - write " }" + write ' }' write ' break;' end write ' }' write ' return (float) 1.0;' write '};' @@ -154,9 +159,10 @@ # - return 0 # def generate write(<<-HEADER.gsub(/^ {6}/, '')) // This is compiled from Ruby, in #{ruby_source} + #include <stdio.h> int next_phoneme_length(int *string, int cursor, int length) { int max_length; max_length = length - cursor;