package net.ssehub.kernel_haven.fe_analysis.relations;

import net.ssehub.kernel_haven.analysis.AnalysisComponent;
import net.ssehub.kernel_haven.config.Configuration;
import net.ssehub.kernel_haven.fe_analysis.relations.PotentialParentRelationFinder.PotentialParentRelation;
import net.ssehub.kernel_haven.fe_analysis.relations.VariableWithPotentialParents.PotentialParent;
import net.ssehub.kernel_haven.util.io.TableElement;
import net.ssehub.kernel_haven.util.io.TableRow;
import net.ssehub.kernel_haven.util.null_checks.NonNull;

/**
 * Analysis component to convert the results of the {@link PotentialParentFinder} into a relational data base scheme.
 * @author El-Sharkawy
 *
 */
public class PotentialParentRelationFinder extends AnalysisComponent<PotentialParentRelation> {

    /**
     * Data object to store a single {@link PotentialParent} as Strings and manageable by a relation DB.
     * @author El-Sharkawy
     *
     */
    @TableRow(isRelation = true)
    public static class PotentialParentRelation {
        private String feature;
        
        private String parent;

        /**
         * Creates this object.
         * @param feature Value 1.
         * @param parent Value 2.
         */
        public PotentialParentRelation(String feature, String parent) {
            this.feature = feature;
            this.parent = parent;
        }

        /**
         * The (dependent) feature variable.
         * 
         * @return The (dependent) feature variable.
         */
        @TableElement(index = 1, name = "Feature")
        public String getFeature() {
            return feature;
        }
        
        /**
         * A feature variable from which the first feature depends on.
         * 
         * @return A feature variable from which the first feature depends on.
         */
        @TableElement(index = 2, name = "Parent")
        public String getParent() {
            return parent;
        }
    }

    private @NonNull AnalysisComponent<VariableWithPotentialParents> parentFinder;
    
    /**
     * Sole constructor.
     * @param config The pipeline configuration
     * @param parentFinder The actual analysis computing the parent probabilities.
     */
    public PotentialParentRelationFinder(@NonNull Configuration config,
        @NonNull AnalysisComponent<VariableWithPotentialParents> parentFinder) {
        
        super(config);
        this.parentFinder = parentFinder;
    }


    @Override
    protected void execute() {
        VariableWithPotentialParents var;
        while ((var = parentFinder.getNextResult()) != null) {
            for (PotentialParent pp : var) {
                addResult(new PotentialParentRelation(var.getVariable(), pp.toString()));
            }
        }
    }

    @Override
    public @NonNull String getResultName() {
        return "Potential Parent Relations";
    }
}

@@ -1015,16 +1015,25 @@
 ation %7B%0A
+        %0A
         
@@ -1095,16 +1095,61 @@
  parent;
+%0A        %0A        private double probability;
 %0A%0A      
@@ -1186,16 +1186,28 @@
 object.%0A
+         * %0A
         
@@ -1267,16 +1267,55 @@
 alue 2.%0A
+         * @param probability Value 3.%0A
         
@@ -1386,16 +1386,36 @@
 g parent
+, double probability
 ) %7B%0A    
@@ -1472,32 +1472,76 @@
 arent = parent;%0A
+            this.probability = probability;%0A
         %7D%0A%0A     
@@ -2105,32 +2105,339 @@
 rent;%0A        %7D%0A
+        %0A        /**%0A         * Returns the probability that this parent-child relation is correct.%0A         * %0A         * @return The probability.%0A         */%0A        @TableElement(index = 3, name = %22Probability%22)%0A        public double getProbability() %7B%0A            return probability;%0A        %7D%0A        %0A
     %7D%0A%0A    priva
@@ -3197,16 +3197,40 @@
  pp.
-toString
+getVariable(), pp.getProbability
 ()))

Move probability if PotentialParent to own column in SQL table