Пример #1
0
  /**
   * A local sort at a particular node along the deep sorting operation. This is a recursive
   * function.
   *
   * @param currentFeatureIdx The currently tested feature.
   * @param currentNode The current node, holding the currently processed zone in the array of
   *     feature vectors.
   */
  private void sortNode(int currentFeatureIdx, MaryNode currentNode) {
    /* If we have reached a leaf, do a final sort according to the unit index and return: */
    if (currentFeatureIdx == featureSequence.length) {
      Arrays.sort(featureVectors, currentNode.from, currentNode.to, cui);
      numberOfLeaves++;
      /*System.out.print( "LEAF ! (" + (currentNode.to-currentNode.from) + " units)" );
      for ( int i = currentNode.from; i < currentNode.to; i++ ) {
          System.out.print( " (" + featureVectors[i].getUnitIndex() + " 0)" );
      }
      System.out.println( "" );*/
      return;
    }
    /* Else: */
    int currentFeature = featureSequence[currentFeatureIdx];
    FeatureVector.FeatureType featureType = featureVectors[0].getFeatureType(currentFeature);
    /* Register the feature currently used for the splitting */
    currentNode.setFeatureIndex(currentFeature);
    /* Perform the sorting according to the currently considered feature: */
    /* 1) position the comparator onto the right feature */
    c.setFeatureIdx(currentFeature, featureType);
    /* 2) do the sorting */
    Arrays.sort(featureVectors, currentNode.from, currentNode.to, c);

    /* Then, seek for the zones where the feature value is the same,
     * and launch the next sort level on these. */
    int nVal = featureDefinition.getNumberOfValues(currentFeature);
    currentNode.split(nVal);
    int nextFrom = currentNode.from;
    int nextTo = currentNode.from;
    for (int i = 0; i < nVal; i++) {
      nextFrom = nextTo;
      // System.out.print( "Next node begins at " + nextFrom );
      while ((nextTo < currentNode.to)
          && (featureVectors[nextTo].getFeatureAsInt(currentFeature) == i)) {
        // System.out.print( " " + featureVectors[nextTo].getFeatureAsInt( currentFeature ) );
        nextTo++;
      }
      // System.out.println( " and ends at " + nextTo + " for a total of " + (nextTo-nextFrom) + "
      // units." );
      if ((nextTo - nextFrom) != 0) {
        MaryNode nod = new MaryNode(nextFrom, nextTo);
        currentNode.setChild(i, nod);
        // System.out.print("(" + i + " isByteOf " + currentFeature + ")" );
        sortNode(currentFeatureIdx + 1, nod);
      } else currentNode.setChild(i, null);
    }
  }
Пример #2
0
 public FeatureFileIndexingResult retrieve(FeatureVector v, int condition, int parameter) {
   int level = 0;
   /* Check if the tree is there */
   if (tree == null) {
     throw new RuntimeException(
         "Can't retrieve candidate units if a tree has not been built."
             + " (Run this.deepSort(int[]) or this.deepFill(MaryNode) first.)");
   }
   //      /**/
   //      /* TODO: Do we want the warning below? */
   //      /*if ( (condition == MAXLEVEL) && (featureSequence != null) && (parameter >
   // featureSequence.length) ) {
   //          System.out.println( "WARNING: you asked for more levels [" + maxLevel
   //                  + "] than the length of the underlying feature sequence[" +
   // featureSequence.length + "]. Proceeding anyways." );
   //      }*/
   /* Walk down the tree */
   MaryNode n = tree;
   MaryNode next = null;
   while (!n.isLeaf()) {
     next = n.getChild(v.getFeatureAsInt(n.getFeatureIndex()));
     /* Check for the number of units in the next node */
     if ((condition == MINUNITS) && ((next.to - next.from) < parameter)) break;
     /* Check if the next node is a dead branch */
     if (next != null) {
       n = next;
       level++;
     } else break;
     /* Check for the current level */
     if ((condition == MAXLEVEL) && (level == parameter)) break;
   }
   /* Dereference the reached node or leaf */
   FeatureFileIndexingResult qr =
       new FeatureFileIndexingResult(getFeatureVectors(n.from, n.to), level);
   return (qr);
 }
Пример #3
0
 /**
  * Retrieve an array of unit features which complies with a specific target specification,
  * according to an underlying tree.
  *
  * @param v A feature vector for which to send back an array of complying unit indexes.
  * @return A query result, comprising an array of feature vectors and the depth level which was
  *     actually reached.
  * @see FeatureArrayIndexer#deepSort(int[])
  * @see FeatureArrayIndexer#deepFill(MaryNode)
  */
 public FeatureFileIndexingResult retrieve(FeatureVector v) {
   int level = 0;
   /* Check if the tree is there */
   if (tree == null) {
     throw new RuntimeException(
         "Can't retrieve candidate units if a tree has not been built."
             + " (Run this.deepSort(int[]) or this.deepFill(MaryNode) first.)");
   }
   /* Walk down the tree */
   MaryNode n = tree;
   MaryNode next = null;
   while (!n.isLeaf()) {
     next = n.getChild(v.getFeatureAsInt(n.getFeatureIndex()));
     /* Check if the next node is a dead branch */
     if (next != null) {
       n = next;
       level++;
     } else break;
   }
   /* Dereference the reached node or leaf */
   FeatureFileIndexingResult qr =
       new FeatureFileIndexingResult(getFeatureVectors(n.from, n.to), level);
   return (qr);
 }