Exemple #1
0
int main() {
    logmath_t *logmath;
    ngram_model_t *model;
    FILE *fp;
    char *line = NULL, *grapheme, *phoneme, *predicted_phoneme;
    int32 different_word_count = 0, fit_count = 0;
    size_t len = 0;

    err_set_logfp(NULL);
    logmath = logmath_init(1.0001f, 0, 0);
    model = ngram_model_read(NULL, "cmudict-en-us.dmp", NGRAM_AUTO, logmath);

    fp = fopen("cmudict-en-us.dict", "r");

    while (getline(&line, &len, fp) != -1) {
        grapheme = strtok(line, " ");
        phoneme = strtok(NULL, "\n");

        if (strstr(grapheme, "(")) {
            grapheme = strtok(grapheme, "(");
        } else {
            different_word_count++;
        }

        predicted_phoneme = g2p(model, grapheme, 100);
        if (predicted_phoneme && strcmp(phoneme, predicted_phoneme) == 0) {
            fit_count++;
        }

        ckd_free(predicted_phoneme);
    }

    printf("%d %d %f\n", fit_count, different_word_count, fit_count * 1.0 / different_word_count);

    ckd_free(grapheme);
    fclose(fp);
    ngram_model_free(model);
    logmath_free(logmath);
}
Exemple #2
0
/*solution = [1-8]*/
int ikKUKAArmSolverUnique(double fixedAngle, double aArray[7], double alphaArray[7],
                          double dArray[7], double thetaArray[7], double posArray[4][4],
                          double phiArray[7], int arm, int solution) {
  int phiValid = 1;
  double n1, r13, r23, r33, r21, r22, de, cosEta4, x, y, z, g1e, g2e;

  if(solution > 8 || solution < 1){
    return -1; //incorrect parameters
  }

  phiArray[2] = fixedAngle; // 2
  x = posArray[0][3];
  y = posArray[1][3];
  z = posArray[2][3];
  cosEta4 = coseta4s(x, y, z, dArray[2], dArray[4]);
  if (cosEta4 * cosEta4 <= 0.10001e1) {
    if (0.1e1 < cosEta4 * cosEta4) {
      cosEta4 = 0.1e1;
//       return -4;
    }
    phiArray[3] = solution < 5 ? acos(cosEta4) : -acos(cosEta4); // 3
  } else {
    phiValid = 0;
    return 0;
  }

  //1
  if (solution < 5){
    de = denomEta2Solve(z, dArray[2], dArray[4], phiArray[2], phiArray[3], arm);
    if (de == 0.0e0) {
      phiArray[1] = 0.3141592654e1;
      return -2;
    } else {
      n1 = numerEta2Solve1(z, dArray[2], dArray[4], phiArray[2], phiArray[3]);
      if (isnan(n1) == 0) {
        if(solution == 1 || solution == 2){ //sol 1 or 2
          phiArray[1] = 0.2e1 * atan(n1 / de);
        }else{// sol 3 or 4
          phiArray[1] = 0.2e1 * atan(numerEta2Solve2(z, dArray[2], dArray[4], phiArray[2], phiArray[3]) / de);
        }
      } else {
        phiValid = 0;
        return 0;
      }
    }
  }else{
    de = denomEta2Solve(z, dArray[2], dArray[4], phiArray[2], phiArray[3], arm);
    if (de == 0.0e0) {
      phiArray[1] = 0.3141592654e1;
      return -2;
    } else {
      n1 = numerEta2Solve1(z, dArray[2], dArray[4], phiArray[2], phiArray[3]);
      if (isnan(n1) == 0) {
        if (solution == 5 || solution == 6){// sol 5 or 6
          phiArray[1] = 0.2e1 * atan(n1 / de);
        }else{ //sol 7 or 8
          phiArray[1] = 0.2e1 * atan(numerEta2Solve2(z, dArray[2], dArray[4], phiArray[2], phiArray[3]) / de);
        }
      } else {
        phiValid = 0;
        return 0;
      }
    }
  }
  if (x == 0.0e0 && y == 0.0e0) {
    phiArray[0] = 0.0e0; // 0
    return -3;
  }else{
    if (phiValid != 0){
      g1e = g1p(dArray[2], dArray[4], phiArray[1], phiArray[2], phiArray[3]);
      g2e = g2p(dArray[2], dArray[4], phiArray[1], phiArray[2], phiArray[3]);
      phiArray[0] = atan2(g1e * y * arm - g2e * x, g1e * x + g2e * y * arm); // 0 
      r13 = r13eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0], phiArray[1], phiArray[2], phiArray[3], arm);
      r23 = r23eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0], phiArray[1], phiArray[2], phiArray[3], arm);
      r33 = r33eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0], phiArray[1], phiArray[2], phiArray[3], arm);
      r21 = r21eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0], phiArray[1], phiArray[2], phiArray[3], arm);
      r22 = r22eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0], phiArray[1], phiArray[2], phiArray[3], arm);
      if (solution == 1 || solution == 3 || solution == 5 || solution == 7){// sol = 1 or 3 or 5 or 7
        phiArray[5] = eta6SolutionA(r13, r23, r33); // 5
      }else{// sol = 2 or 4 or 6 or 8
        phiArray[5] = eta6SolutionB(r13, r23, r33); // 5
      }
      phiArray[4] = eta5Solution(r13, r33, phiArray[5]); // 4
      phiArray[6] = eta7Solution(r21, r22, phiArray[5], arm); // 6
    }
  }
  return 1;
}
Exemple #3
0
/*left arm = -1, for right arm = 1*/
int ikKUKAArmSolver(double fixedAngle, double aArray[7], double alphaArray[7],
                    double dArray[7], double thetaArray[7], double posArray[4][4],
                    double phiArray[8][7], int phiArrayValid[8], int arm) {
  int analyticError, i;
  double n1, r13, r23, r33, r21, r22, de, cosEta4, x, y, z, g1e, g2e;

  phiArray[0][2] = fixedAngle;
  phiArray[1][2] = fixedAngle;
  phiArray[2][2] = fixedAngle;
  phiArray[3][2] = fixedAngle;
  phiArray[4][2] = fixedAngle;
  phiArray[5][2] = fixedAngle;
  phiArray[6][2] = fixedAngle;
  phiArray[7][2] = fixedAngle;
  for (i = 1; i <= 8; i++)
    phiArrayValid[i - 1] = 1;
  analyticError = 0;
  x = posArray[0][3];
  y = posArray[1][3];
  z = posArray[2][3];
  cosEta4 = coseta4s(x, y, z, dArray[2], dArray[4]);
  if (cosEta4 * cosEta4 <= 0.10001e1) {
    if (0.1e1 < cosEta4 * cosEta4)
      cosEta4 = 0.1e1;
    phiArray[0][3] = acos(cosEta4);
    phiArray[1][3] = phiArray[0][3];
    phiArray[2][3] = phiArray[0][3];
    phiArray[3][3] = phiArray[0][3];
    phiArray[4][3] = -phiArray[0][3];
    phiArray[5][3] = phiArray[4][3];
    phiArray[6][3] = phiArray[4][3];
    phiArray[7][3] = phiArray[4][3];
  } else {
    for (i = 1; i <= 8; i++)
      phiArrayValid[i - 1] = 0;
    analyticError = 1;
    return(analyticError);
  }
  de = denomEta2Solve(z, dArray[2], dArray[4], phiArray[0][2], phiArray[0][3], arm);
  if (de == 0.0e0) {
    phiArray[0][1] = 0.3141592654e1;
    phiArray[1][1] = 0.3141592654e1;
    phiArray[2][1] = 0.3141592654e1;
    phiArray[3][1] = 0.3141592654e1;
  } else {
    n1 = numerEta2Solve1(z, dArray[2], dArray[4], phiArray[0][2], phiArray[0][3]);
    if (isnan(n1) == 0) {
      phiArray[0][1] = 0.2e1 * atan(n1 / de);
      phiArray[1][1] = phiArray[0][1];
      phiArray[2][1] = 0.2e1 * atan(numerEta2Solve2(z, dArray[2], dArray[4], phiArray[2][2], phiArray[2][3]) / de);
      phiArray[3][1] = phiArray[2][1];
    } else {
      phiArrayValid[0] = 0;
      phiArrayValid[1] = 0;
      phiArrayValid[2] = 0;
      phiArrayValid[3] = 0;
    }
  }
  de = denomEta2Solve(z, dArray[2], dArray[4], phiArray[4][2], phiArray[4][3], arm);
  if (de == 0.0e0) {
    phiArray[4][1] = 0.3141592654e1;
    phiArray[5][1] = 0.3141592654e1;
    phiArray[6][1] = 0.3141592654e1;
    phiArray[7][1] = 0.3141592654e1;
  } else {
    n1 = numerEta2Solve1(z, dArray[2], dArray[4], phiArray[4][2], phiArray[4][3]);
    if (isnan(n1) == 0) {
      phiArray[4][1] = 0.2e1 * atan(n1 / de);
      phiArray[5][1] = phiArray[4][1];
      phiArray[6][1] = 0.2e1 * atan(numerEta2Solve2(z, dArray[2], dArray[4], phiArray[6][2], phiArray[6][3]) / de);
      phiArray[7][1] = phiArray[6][1];
    } else {
      phiArrayValid[4] = 0;
      phiArrayValid[5] = 0;
      phiArrayValid[6] = 0;
      phiArrayValid[7] = 0;
    }
  }
  if (x == 0.0e0 && y == 0.0e0) {
    phiArray[0][0] = 0.0e0;
    phiArray[1][0] = 0.0e0;
    phiArray[2][0] = 0.0e0;
    phiArray[3][0] = 0.0e0;
    phiArray[4][0] = 0.0e0;
    phiArray[5][0] = 0.0e0;
    phiArray[6][0] = 0.0e0;
    phiArray[7][0] = 0.0e0;
  } else {
    if (phiArrayValid[0] != 0) {
      g1e = g1p(dArray[2], dArray[4], phiArray[0][1], phiArray[0][2], phiArray[0][3]);
      g2e = g2p(dArray[2], dArray[4], phiArray[0][1], phiArray[0][2], phiArray[0][3]);
      phiArray[0][0] = atan2(g1e * y * arm - g2e * x, g1e * x + g2e * y * arm);
      phiArray[1][0] = phiArray[0][0];
      g1e = g1p(dArray[2], dArray[4], phiArray[2][1], phiArray[2][2], phiArray[2][3]);
      g2e = g2p(dArray[2], dArray[4], phiArray[2][1], phiArray[2][2], phiArray[2][3]);
      phiArray[2][0] = atan2(g1e * y * arm - g2e * x, g1e * x + g2e * y * arm);
      phiArray[3][0] = phiArray[2][0];
      r13 = r13eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0][0], phiArray[0][1], phiArray[0][2], phiArray[0][3], arm);
      r23 = r23eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0][0], phiArray[0][1], phiArray[0][2], phiArray[0][3], arm);
      r33 = r33eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0][0], phiArray[0][1], phiArray[0][2], phiArray[0][3], arm);
      r21 = r21eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0][0], phiArray[0][1], phiArray[0][2], phiArray[0][3], arm);
      r22 = r22eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[0][0], phiArray[0][1], phiArray[0][2], phiArray[0][3], arm);
      phiArray[0][5] = eta6SolutionA(r13, r23, r33);
      phiArray[0][4] = eta5Solution(r13, r33, phiArray[0][5]);
      phiArray[0][6] = eta7Solution(r21, r22, phiArray[0][5], arm);
      phiArray[1][5] = eta6SolutionB(r13, r23, r33);
      phiArray[1][4] = eta5Solution(r13, r33, phiArray[1][5]);
      phiArray[1][6] = eta7Solution(r21, r22, phiArray[1][5], arm);
      r13 = r13eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[2][0], phiArray[2][1], phiArray[2][2], phiArray[2][3], arm);
      r23 = r23eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[2][0], phiArray[2][1], phiArray[2][2], phiArray[2][3], arm);
      r33 = r33eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[2][0], phiArray[2][1], phiArray[2][2], phiArray[2][3], arm);
      r21 = r21eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[2][0], phiArray[2][1], phiArray[2][2], phiArray[2][3], arm);
      r22 = r22eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[2][0], phiArray[2][1], phiArray[2][2], phiArray[2][3], arm);
      phiArray[2][5] = eta6SolutionA(r13, r23, r33);
      phiArray[2][4] = eta5Solution(r13, r33, phiArray[2][5]);
      phiArray[2][6] = eta7Solution(r21, r22, phiArray[2][5], arm);
      phiArray[3][5] = eta6SolutionB(r13, r23, r33);
      phiArray[3][4] = eta5Solution(r13, r33, phiArray[3][5]);
      phiArray[3][6] = eta7Solution(r21, r22, phiArray[3][5], arm);
    }
    if (phiArrayValid[4] != 0) {
      g1e = g1p(dArray[2], dArray[4], phiArray[4][1], phiArray[4][2], phiArray[4][3]);
      g2e = g2p(dArray[2], dArray[4], phiArray[4][1], phiArray[4][2], phiArray[4][3]);
      phiArray[4][0] = atan2(g1e * y * arm - g2e * x, g1e * x + g2e * y * arm);
      phiArray[5][0] = phiArray[4][0];
      g1e = g1p(dArray[2], dArray[4], phiArray[6][1], phiArray[6][2], phiArray[6][3]);
      g2e = g2p(dArray[2], dArray[4], phiArray[6][1], phiArray[6][2], phiArray[6][3]);
      phiArray[6][0] = atan2(g1e * y * arm - g2e * x, g1e * x + g2e * y * arm);
      phiArray[7][0] = phiArray[6][0];
      r13 = r13eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[4][0], phiArray[4][1], phiArray[4][2], phiArray[4][3], arm);
      r23 = r23eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[4][0], phiArray[4][1], phiArray[4][2], phiArray[4][3], arm);
      r33 = r33eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[4][0], phiArray[4][1], phiArray[4][2], phiArray[4][3], arm);
      r21 = r21eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[4][0], phiArray[4][1], phiArray[4][2], phiArray[4][3], arm);
      r22 = r22eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[4][0], phiArray[4][1], phiArray[4][2], phiArray[4][3], arm);
      phiArray[4][5] = eta6SolutionA(r13, r23, r33);
      phiArray[4][4] = eta5Solution(r13, r33, phiArray[4][5]);
      phiArray[4][6] = eta7Solution(r21, r22, phiArray[4][5], arm);
      phiArray[5][5] = eta6SolutionB(r13, r23, r33);
      phiArray[5][4] = eta5Solution(r13, r33, phiArray[5][5]);
      phiArray[5][6] = eta7Solution(r21, r22, phiArray[5][5], arm);
      r13 = r13eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[6][0], phiArray[6][1], phiArray[6][2], phiArray[6][3], arm);
      r23 = r23eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[6][0], phiArray[6][1], phiArray[6][2], phiArray[6][3], arm);
      r33 = r33eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[6][0], phiArray[6][1], phiArray[6][2], phiArray[6][3], arm);
      r21 = r21eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[6][0], phiArray[6][1], phiArray[6][2], phiArray[6][3], arm);
      r22 = r22eval(posArray[0][0], posArray[0][1], posArray[0][2], posArray[1][0], posArray[1][1], posArray[1][2], posArray[2][0], posArray[2][1], posArray[2][2], phiArray[6][0], phiArray[6][1], phiArray[6][2], phiArray[6][3], arm);
      phiArray[6][5] = eta6SolutionA(r13, r23, r33);
      phiArray[6][4] = eta5Solution(r13, r33, phiArray[6][5]);
      phiArray[6][6] = eta7Solution(r21, r22, phiArray[6][5], arm);
      phiArray[7][5] = eta6SolutionB(r13, r23, r33);
      phiArray[7][4] = eta5Solution(r13, r33, phiArray[7][5]);
      phiArray[7][6] = eta7Solution(r21, r22, phiArray[7][5], arm);
    }
  }
  return(analyticError);
}
Exemple #4
0
 m2::PointD convert_point(m2::PointD const & pt) const
 {
   return g2p(pt);
 }