예제 #1
0
 private void createBaseGrammar(
     List<GrammarNode> wordGrammarNodes, GrammarNode branchNode, GrammarNode finalNode) {
   GrammarNode currNode = branchNode;
   ListIterator<GrammarNode> iter = wordGrammarNodes.listIterator();
   while (iter.hasNext()) {
     GrammarNode nextNode = iter.next();
     currNode.add(nextNode, logMath.getLogOne());
     currNode = nextNode;
   }
   currNode.add(finalNode, logMath.getLogOne());
 }
예제 #2
0
  @Override
  protected GrammarNode createGrammar() throws IOException {

    logger.info("Creating Grammar");
    initialNode = createGrammarNode(Dictionary.SILENCE_SPELLING);
    finalNode = createGrammarNode(Dictionary.SILENCE_SPELLING);
    finalNode.setFinalNode(true);
    final GrammarNode branchNode = createGrammarNode(false);

    final List<GrammarNode> wordGrammarNodes = new ArrayList<GrammarNode>();
    final int end = tokens.size();

    logger.info("Creating Grammar nodes");
    for (final String word : tokens.subList(0, end)) {
      final GrammarNode wordNode = createGrammarNode(word.toLowerCase());
      wordGrammarNodes.add(wordNode);
    }
    logger.info("Done creating grammar node");

    // now connect all the GrammarNodes together
    initialNode.add(branchNode, LogMath.getLogOne());

    createBaseGrammar(wordGrammarNodes, branchNode, finalNode);

    if (modelDeletions) {
      addForwardJumps(wordGrammarNodes, branchNode, finalNode);
    }
    if (modelBackwardJumps) {
      addBackwardJumps(wordGrammarNodes, branchNode, finalNode);
    }
    if (modelRepetitions) {
      addSelfLoops(wordGrammarNodes);
    }
    logger.info("Done making Grammar");
    // initialNode.dumpDot("./graph.dot");
    return initialNode;
  }