예제 #1
0
 private void putCorrelation(
     HashMap<Integer, CorrelationLevel> correlationLevels,
     ReqResFieldCorrelation reqResFieldCorrelation) {
   int level = reqResFieldCorrelation.getLevel();
   CorrelationLevel correlationLevel = correlationLevels.get(level);
   if (correlationLevel == null) {
     correlationLevel = new CorrelationLevel(level);
     correlationLevels.put(level, correlationLevel);
   }
   correlationLevel.addCorrelation(reqResFieldCorrelation);
 }
예제 #2
0
  /**
   * First correlation algorithm result analysis : computes indicators on fields within single (top)
   * level, then tries to find if the exchange is like a query (and), post or get on id, and what
   * role those fields play in this pattern.
   *
   * @param correlationLevelMap
   * @param inFieldNb
   * @param outFieldNb
   */
  private void printCorrelations(
      HashMap<Integer, CorrelationLevel> correlationLevelMap, int inFieldNb, int outFieldNb) {
    System.out.println("Found correlations, sorted y level :");
    ArrayList<CorrelationLevel> correlationLevels =
        new ArrayList<CorrelationLevel>(correlationLevelMap.values());
    Collections.sort(
        correlationLevels,
        new Comparator<CorrelationLevel>() {
          @Override
          public int compare(CorrelationLevel corrLvl1, CorrelationLevel corrLvl2) {
            return -(corrLvl1.getLevel() - corrLvl2.getLevel());
          }
        });

    boolean isAnd, isPost, isGetOnId, isOr = false;
    ArrayList<String> andInPathes, orOutPathes = null;
    for (CorrelationLevel correlationLevel : correlationLevels) {
      // int levelCorrelationNb = correlationLevel.getCorrelations().size();
      System.out.println();
      System.out.println(correlationLevel.getLevel() + ":");
      for (ReqResFieldCorrelation correlation : correlationLevel.getCorrelations()) {
        System.out.println(
            "\t"
                + correlation.getInField()
                + "\t"
                + correlation.getOutField()
                + "\t"
                + correlation.getInfo());
      }

      // TODO better : all in SQL & SQL queries, or datamining...

      // for AND
      String maxInPath;
      int maxInPathNb = 0;
      // ArrayList<ReqResFieldCorrelation> maxInPathCorrelations = new
      // ArrayList<ReqResFieldCorrelation>();
      HashMap<String, Integer> inFieldPathCorrelationMap = new HashMap<String, Integer>();
      for (ReqResFieldCorrelation correlation : correlationLevel.getCorrelations()) {
        String path = correlation.getInField().getPath();
        Object found = inFieldPathCorrelationMap.get(path);
        int nb = 1;
        if (found != null) {
          nb += inFieldPathCorrelationMap.get(path);
          if (nb > maxInPathNb) {
            maxInPath = path;
            maxInPathNb = nb;
            // maxInPathCorrelations.clear();
          }
          // maxInPathCorrelations.add(correlation);
        }
        inFieldPathCorrelationMap.put(path, nb);
      }
      // ArrayList<ReqResFieldCorrelation> singleInPathCorrelations = new
      // ArrayList<ReqResFieldCorrelation>();
      // ArrayList<ReqResFieldCorrelation> otherInPathCorrelations = new
      // ArrayList<ReqResFieldCorrelation>();
      HashSet<String> maxInPathSet = new HashSet<String>();
      HashSet<String> singleInPathSet = new HashSet<String>();
      HashSet<String> otherInPathSet = new HashSet<String>();
      for (String inPath : inFieldPathCorrelationMap.keySet()) {
        Integer inPathNb = inFieldPathCorrelationMap.get(inPath);
        if (inFieldPathCorrelationMap.get(inPath) == 1) {
          singleInPathSet.add(inPath);
        } else if (inPathNb == maxInPathNb) { // except if nb == 1
          maxInPathSet.add(inPath);
        } else {
          otherInPathSet.add(inPath);
        }
      }
      isAnd =
          !maxInPathSet
              .isEmpty() /* && (outFieldNb / ((maxInPathNb == 0) ? 1 : maxInPathNb)) / inFieldNb >= 2*/; // OPTIONAL more result field than query ones ; maxInPathNb = nb of results, outFieldNb / maxInPathNb = nb of fields per item
      isPost =
          maxInPathSet.isEmpty()
              && otherInPathSet.isEmpty()
              && !singleInPathSet.isEmpty()
              && outFieldNb / inFieldNb < 2 & inFieldNb <= outFieldNb;
      isGetOnId =
          maxInPathSet.isEmpty()
              && otherInPathSet.isEmpty()
              && !singleInPathSet.isEmpty()
              && outFieldNb / inFieldNb >= 2;
      System.out.println(
          "max/other/single/diff: "
              + maxInPathSet
              + " ; "
              + otherInPathSet
              + " ; "
              + singleInPathSet
              + " ; "
              + inFieldNb
              + ", "
              + outFieldNb);
      if (isAnd) {
        System.out.println(
            "Query (and) ! on ["
                + maxInPathSet
                + "] and optional ["
                + otherInPathSet
                + " ; "
                + singleInPathSet
                + "]");
      } else if (isPost) {
        System.out.println(
            "post ! computed fields (including ids) are [out pathes which are not in correlations]");
      } else if (isGetOnId) {
        System.out.println("get on id ! id is [" + singleInPathSet + "]");
      }

      // for OR
      HashMap<String, Integer> outFieldPathCorrelationMap = new HashMap<String, Integer>();
      for (ReqResFieldCorrelation correlation : correlationLevel.getCorrelations()) {
        String path = correlation.getOutField().getPath();
        Object found = outFieldPathCorrelationMap.get(path);
        int nb = 1;
        if (found != null) {
          nb += outFieldPathCorrelationMap.get(path);
        }
        outFieldPathCorrelationMap.put(path, nb);
      }
      ArrayList<String> curOrOutPathes = new ArrayList<String>();
      for (String outPath : outFieldPathCorrelationMap.keySet()) {
        if (outFieldPathCorrelationMap.get(outPath) > 1) {
          curOrOutPathes.add(outPath);
        }
      }
      isOr = !curOrOutPathes.isEmpty();
      // TODO
    }
  }