public static int generateCaseTrainingExamples(Vector instances, Surrogate slot) {
    { int numInstances = instances.length();
      Vector slotValues = Vector.newVector(numInstances);
      int k = 0;
      int l = 0;
      Vector index = Vector.newVector(numInstances * Logic.$NUM_TRAINING_PER_CASE$);
      Vector matchScores = Vector.newVector(numInstances * Logic.$NUM_TRAINING_PER_CASE$);

      { int i = Stella.NULL_INTEGER;
        int iter000 = 0;
        int upperBound000 = numInstances - 1;
        LogicObject inst = null;
        Vector vector000 = instances;
        int index000 = 0;
        int length000 = vector000.length();

        for (;(iter000 <= upperBound000) &&
                  (index000 < length000); iter000 = iter000 + 1, index000 = index000 + 1) {
          i = iter000;
          inst = ((LogicObject)((vector000.theArray)[index000]));
          (slotValues.theArray)[i] = (LogicObject.getSlotValue(inst, slot));
        }
      }
      { int i = Stella.NULL_INTEGER;
        int iter001 = 0;
        int upperBound001 = numInstances - 1;

        for (;iter001 <= upperBound001; iter001 = iter001 + 1) {
          i = iter001;
          { int j = Stella.NULL_INTEGER;
            int iter002 = 1;
            int upperBound002 = Logic.$NUM_TRAINING_PER_CASE$;
            boolean unboundedP000 = upperBound002 == Stella.NULL_INTEGER;

            for (;unboundedP000 ||
                      (iter002 <= upperBound002); iter002 = iter002 + 1) {
              j = iter002;
              j = j;
              l = Stella.random(numInstances);
              while (i == l) {
                l = Stella.random(numInstances);
              }
              (index.theArray)[k] = (IntegerWrapper.wrapInteger(l));
              (matchScores.theArray)[k] = (FloatWrapper.wrapFloat(Logic.calculateCaseMatch((slotValues.theArray)[i], (slotValues.theArray)[l])));
              k = k + 1;
            }
          }
        }
      }
      k = 0;
      Logic.normalizeNumbers(matchScores);
      { int i = Stella.NULL_INTEGER;
        int iter003 = 0;
        int upperBound003 = matchScores.length() - 1;

        for (;iter003 <= upperBound003; iter003 = iter003 + 1) {
          i = iter003;
          (matchScores.theArray)[i] = (FloatWrapper.wrapFloat(1.0 - ((FloatWrapper)((matchScores.theArray)[i])).wrapperValue));
        }
      }
      { int i = Stella.NULL_INTEGER;
        int iter004 = 0;
        int upperBound004 = numInstances - 1;

        for (;iter004 <= upperBound004; iter004 = iter004 + 1) {
          i = iter004;
          { int j = Stella.NULL_INTEGER;
            int iter005 = 1;
            int upperBound005 = Logic.$NUM_TRAINING_PER_CASE$;
            boolean unboundedP001 = upperBound005 == Stella.NULL_INTEGER;

            for (;unboundedP001 ||
                      (iter005 <= upperBound005); iter005 = iter005 + 1) {
              j = iter005;
              j = j;
              { TrainingExample example = TrainingExample.newTrainingExample();

                example.query = Cons.list$(Cons.cons(Logic.SYM_PL_KERNEL_KB_CASE_MATCH, Cons.cons(Logic.logicSymbol(((LogicObject)((instances.theArray)[i]))), Cons.cons(Cons.cons(Logic.logicSymbol(((LogicObject)((instances.theArray)[(((IntegerWrapper)((index.theArray)[k])).wrapperValue)]))), Stella.NIL), Stella.NIL))));
                example.score = ((FloatWrapper)((matchScores.theArray)[k])).wrapperValue;
                Logic.$TRAINING_EXAMPLES$.push(example);
              }
              k = k + 1;
            }
          }
        }
      }
      return (numInstances);
    }
  }