public static Lattice<String> createStringLatticeFromString(String data,JoshuaConfiguration config){
  Map<Integer,Node<String>> nodes=new HashMap<>();
  Pattern nodePattern=Pattern.compile("(.+?)\\((\\(.+?\\),)\\)(.*)");
  Pattern arcPattern=Pattern.compile("\\('(.+?)',(\\d+.\\d+),(\\d+)\\),(.*)");
  Matcher nodeMatcher=nodePattern.matcher(data);
  int nodeID=-1;
  while (nodeMatcher.matches()) {
    String nodeData=nodeMatcher.group(2);
    String remainingData=nodeMatcher.group(3);
    nodeID++;
    Node<String> currentNode;
    if (nodes.containsKey(nodeID)) {
      currentNode=nodes.get(nodeID);
    }
 else {
      currentNode=new Node<>(nodeID);
      nodes.put(nodeID,currentNode);
    }
    LOG.debug("Node : {}",nodeID);
    Matcher arcMatcher=arcPattern.matcher(nodeData);
    while (arcMatcher.matches()) {
      String arcLabel=arcMatcher.group(1);
      float arcWeight=Float.valueOf(arcMatcher.group(2));
      int destinationNodeID=nodeID + Integer.parseInt(arcMatcher.group(3));
      Node<String> destinationNode;
      if (nodes.containsKey(destinationNodeID)) {
        destinationNode=nodes.get(destinationNodeID);
      }
 else {
        destinationNode=new Node<>(destinationNodeID);
        nodes.put(destinationNodeID,destinationNode);
      }
      String remainingArcs=arcMatcher.group(4);
      LOG.debug("\t{} {} {}",arcLabel,arcWeight,destinationNodeID);
      currentNode.addArc(destinationNode,arcWeight,arcLabel);
      arcMatcher=arcPattern.matcher(remainingArcs);
    }
    nodeMatcher=nodePattern.matcher(remainingData);
  }
  List<Node<String>> nodeList=new ArrayList<>(nodes.values());
  Collections.sort(nodeList,new NodeIdentifierComparator());
  LOG.debug("Nodelist={}",nodeList);
  return new Lattice<>(nodeList,config);
}

public static Lattice < String > createStringLatticeFromString ( String data , JoshuaConfiguration config ) { Map < Integer , Node < String > > nodes = new HashMap < > ( ) ; Pattern nodePattern = Pattern . compile ( "(.+?)\\((\\(.+?\\),)\\)(.*)" ) ; Pattern arcPattern = Pattern . compile ( "\\('(.+?)',(\\d+.\\d+),(\\d+)\\),(.*)" ) ; Matcher nodeMatcher = nodePattern . matcher ( data ) ; int nodeID = - 1 ; while ( nodeMatcher . matches ( ) ) { String nodeData = nodeMatcher . group ( 2 ) ; String remainingData = nodeMatcher . group ( 3 ) ; nodeID ++ ; Node < String > currentNode ; if ( nodes . containsKey ( nodeID ) ) { currentNode = nodes . get ( nodeID ) ; } else { currentNode = new Node < > ( nodeID ) ; nodes . put ( nodeID , currentNode ) ; } LOG . debug ( "Node : {}" , nodeID ) ; Matcher arcMatcher = arcPattern . matcher ( nodeData ) ; while ( arcMatcher . matches ( ) ) { String arcLabel = arcMatcher . group ( 1 ) ; float arcWeight = Float . valueOf ( arcMatcher . group ( 2 ) ) ; int destinationNodeID = nodeID + Integer . parseInt ( arcMatcher . group ( 3 ) ) ; Node < String > destinationNode ; if ( nodes . containsKey ( destinationNodeID ) ) { destinationNode = nodes . get ( destinationNodeID ) ; } else { destinationNode = new Node < > ( destinationNodeID ) ; nodes . put ( destinationNodeID , destinationNode ) ; } String remainingArcs = arcMatcher . group ( 4 ) ; LOG . debug ( "\t{} {} {}" , arcLabel , arcWeight , destinationNodeID ) ; currentNode . addArc ( destinationNode , arcWeight , arcLabel ) ; arcMatcher = arcPattern . matcher ( remainingArcs ) ; } nodeMatcher = nodePattern . matcher ( remainingData ) ; } List < Node < String > > nodeList = new ArrayList < > ( nodes . values ( ) ) ; Collections . sort ( nodeList , new NodeIdentifierComparator ( ) ) ; LOG . debug ( "Nodelist={}" , nodeList ) ; return new Lattice < > ( nodeList , config ) ; }
constructs a lattice from a given string representation .
