コード例 #1
0
  ////////////////////////////////   CONCLUSION   ////////////////////////////////////////////////
  public String conclusionString(FORule tgd, MappingTask mappingTask, String indent) {
    // giannisk
    // find target paths that have a constant value correspondence
    List<VariablePathExpression> constantTargetPaths = new ArrayList<VariablePathExpression>();
    HashMap<VariablePathExpression, ISourceValue> constantValueMap =
        new HashMap<VariablePathExpression, ISourceValue>();
    for (VariableCorrespondence varCor : tgd.getCoveredCorrespondences()) {
      if (varCor.isConstant()) {
        constantTargetPaths.add(varCor.getTargetPath());
        constantValueMap.put(varCor.getTargetPath(), varCor.getSourceValue());
      }
    }

    StringBuilder result = new StringBuilder();
    List<FormulaVariable> universalVariables = tgd.getUniversalFormulaVariables(mappingTask);
    List<FormulaVariable> existentialVariables = tgd.getExistentialFormulaVariables(mappingTask);
    if (!useSaveFormat
        && (!existentialVariables.isEmpty() || mappingTask.getTargetProxy().isNested())) {
      result.append("exist ");
      if (mappingTask.getTargetProxy().isNested()) {
        utility.printOIDVariables(tgd.getTargetView());
      }
      if (!existentialVariables.isEmpty()) {
        result.append(utility.printVariables(existentialVariables));
      }
    }
    result.append("\n");
    for (int i = 0; i < tgd.getTargetView().getGenerators().size(); i++) {
      SetAlias targetVariable = tgd.getTargetView().getGenerators().get(i);
      result.append(indent).append(utility.INDENT);
      if (!useSaveFormat) {
        result.append(
            utility.printAtomName(targetVariable, mappingTask.getTargetProxy().isNested()));
      } else {
        result.append(
            utility.printAtomNameForSaveFormat(
                targetVariable, mappingTask.getTargetProxy().isNested()));
      }
      List<VariablePathExpression> attributePaths =
          targetVariable.getFirstLevelAttributes(
              mappingTask.getTargetProxy().getIntermediateSchema());
      for (int j = 0; j < attributePaths.size(); j++) {
        VariablePathExpression attributePath = attributePaths.get(j);
        result.append(attributePath.getLastStep()).append(": ");
        FormulaVariable attributeVariable =
            findUniversalVariableForTargetPath(attributePath, universalVariables);
        Expression transformation = null;
        if (!constantTargetPaths.contains(attributePath)) {
          if (attributeVariable == null) {
            attributeVariable =
                findExistentialVariable(
                    attributePath, tgd.getExistentialFormulaVariables(mappingTask));
          }
          transformation = attributeVariable.getTransformationFunction(attributePath);
        }
        if (transformation == null) {
          if (!constantTargetPaths.contains(attributePath)) {
            if (useSaveFormat) {
              result.append("$");
            }
            result.append(attributeVariable.toShortString());
          } else { // constant
            result.append(constantValueMap.get(attributePath));
          }
        } else { // function
          List<List<FormulaVariable>> variables = new ArrayList<List<FormulaVariable>>();
          variables.add(tgd.getUniversalFormulaVariables(mappingTask));
          utility.setVariableDescriptions(transformation, variables);
          result.append(transformation);
        }
        if (j != attributePaths.size() - 1) {
          result.append(", ");
        }
      }
      result.append(")");
      if (i != tgd.getTargetView().getGenerators().size() - 1) {
        result.append(", \n");
      }
    }
    return result.toString();
  }