<commit_before>package com.sri.ai.grinder.sgdpllt.anytime;

import static com.sri.ai.expresso.helper.Expressions.apply;
import static com.sri.ai.grinder.sgdpllt.library.FunctorConstants.EQUAL;
import static com.sri.ai.grinder.sgdpllt.library.FunctorConstants.GREATER_THAN;
import static com.sri.ai.grinder.sgdpllt.library.FunctorConstants.IF_THEN_ELSE;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import com.sri.ai.expresso.api.Expression;
import com.sri.ai.expresso.core.DefaultSymbol;

public class FactorComponent {

	public Model M;
	public Expression Phi;
	public Set<Expression> Parent;
	public ArrayList<VariableComponent> children;
	public Set<Expression> Dext;
	public Set<Expression> D;
	// public Bound B;
	public Set<Expression> Pint;

	public FactorComponent(Expression Phi, Expression Parent, Model M, Set<Expression> Pext) {

		this.Pint = new HashSet<Expression>();
		this.M = M;
		this.children = new ArrayList<VariableComponent>();
		this.Parent = new HashSet<Expression>();
		this.Parent.add(Parent);
		this.D = new HashSet<Expression>();
		this.Dext = new HashSet<Expression>();
		// this.B = new HashSet<Expression>();
		// this.B = Simplex(V)

		this.Phi = Phi;
		this.Pint.add(Phi);

		Set<Expression> intersection = new HashSet<Expression>();
		intersection.addAll(M.getNeighborsOfSet(M.getInitializedFactor()));
		Collection<Expression> S = M.getNeighbors(Phi);
		for (Expression e : this.Parent) {
			S.remove(e);
		}
		S.retainAll(intersection);
		this.Dext.addAll(S);
		M.InitializeFComponent.add(this);

	}

	public void update(Set<Expression> Pext) {

		if (this.children.isEmpty()) {
			for (Expression e : this.M.getNeighbors(Phi)) {
				if (!this.Parent.contains(e)) {
					Set<Expression> union = new HashSet<Expression>(Pext);
					union.add(Phi);

					boolean test = false;

					for (VariableComponent c : M.InitializeVComponent) {
						if (c.V.equals(e)) {
							test = true;
							this.Parent.add(c.V);
						}
					}

					if (test == false) {
						VariableComponent newV = new VariableComponent(e, Phi, M, union);
						this.children.add(newV);
						Set<Expression> intersection = new HashSet<Expression>(newV.Dext);
						intersection.retainAll(M.getNeighborsOfSet(Pext));
						Dext.addAll(intersection);

						D.addAll(newV.Dext);
					}
				}

				D.removeAll(Dext);
			}
		} else {
			int j = this.choose();
			Set<Expression> union = new HashSet<Expression>(Pext);
			for (int i = 0; i < this.children.size(); i++) {
				union.addAll(this.children.get(i).Pint);
			}
			this.children.get(j).update(union);

			Set<Expression> intersection = new HashSet<Expression>(this.children.get(j).Dext);
			intersection.retainAll(M.getNeighborsOfSet(Pext));
			Dext.addAll(intersection);

			D.addAll(this.children.get(j).Dext);
			D.removeAll(Dext);

			Pint.addAll(this.children.get(j).Pint);

			// B =
		}
	}

	public int choose() {
		Random rn = new Random();
		return rn.nextInt(this.children.size());
		// return 0;
	}

	public void print(int tabs) {
		String tab = new String();
		for (int i = 0; i < tabs; i++) {
			tab += "\t";
		}
		System.out.println(tab + "Factor : " + Phi);
		System.out.println(tab + "Dext : " + Dext);
		System.out.println(tab + "D : " + D);

		for (VariableComponent c : this.children) {
			c.print(tabs + 1);
		}

	}<commit_msg>name change<commit_after>package com.sri.ai.grinder.sgdpllt.anytime;

import static com.sri.ai.expresso.helper.Expressions.apply;
import static com.sri.ai.grinder.sgdpllt.library.FunctorConstants.EQUAL;
import static com.sri.ai.grinder.sgdpllt.library.FunctorConstants.GREATER_THAN;
import static com.sri.ai.grinder.sgdpllt.library.FunctorConstants.IF_THEN_ELSE;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import com.sri.ai.expresso.api.Expression;
import com.sri.ai.expresso.core.DefaultSymbol;

public class FactorComponent {

	public Model M;
	public Expression phi;
	public Set<Expression> parent;
	public ArrayList<VariableComponent> children;
	public Set<Expression> Dext;
	public Set<Expression> D;
	// public Bound B;
	public Set<Expression> Pint;

	public FactorComponent(Expression phi, Expression Parent, Model M, Set<Expression> Pext) {

		this.Pint = new HashSet<Expression>();
		this.M = M;
		this.children = new ArrayList<VariableComponent>();
		this.parent = new HashSet<Expression>();
		this.parent.add(Parent);
		this.D = new HashSet<Expression>();
		this.Dext = new HashSet<Expression>();
		// this.B = new HashSet<Expression>();
		// this.B = Simplex(V)

		this.phi = phi;
		this.Pint.add(phi);

		Set<Expression> intersection = new HashSet<Expression>();
		intersection.addAll(M.getNeighborsOfSet(M.getInitializedFactor()));
		Collection<Expression> S = M.getNeighbors(phi);
		for (Expression e : this.parent) {
			S.remove(e);
		}
		S.retainAll(intersection);
		this.Dext.addAll(S);
		M.initializeFComponent.add(this);

	}

	public void update(Set<Expression> Pext) {

		if (this.children.isEmpty()) {
			for (Expression e : this.M.getNeighbors(phi)) {
				if (!this.parent.contains(e)) {
					Set<Expression> union = new HashSet<Expression>(Pext);
					union.add(phi);

					boolean test = false;

					for (VariableComponent c : M.initializeVComponent) {
						if (c.V.equals(e)) {
							test = true;
							this.parent.add(c.V);
						}
					}

					if (test == false) {
						VariableComponent newV = new VariableComponent(e, phi, M, union);
						this.children.add(newV);
						Set<Expression> intersection = new HashSet<Expression>(newV.Dext);
						intersection.retainAll(M.getNeighborsOfSet(Pext));
						Dext.addAll(intersection);

						D.addAll(newV.Dext);
					}
				}

				D.removeAll(Dext);
			}
		} else {
			int j = this.choose();
			Set<Expression> union = new HashSet<Expression>(Pext);
			for (int i = 0; i < this.children.size(); i++) {
				union.addAll(this.children.get(i).Pint);
			}
			this.children.get(j).update(union);

			Set<Expression> intersection = new HashSet<Expression>(this.children.get(j).Dext);
			intersection.retainAll(M.getNeighborsOfSet(Pext));
			Dext.addAll(intersection);

			D.addAll(this.children.get(j).Dext);
			D.removeAll(Dext);

			Pint.addAll(this.children.get(j).Pint);

			// B =
		}
	}

	public int choose() {
		Random rn = new Random();
		return rn.nextInt(this.children.size());
		// return 0;
	}

	public void print(int tabs) {
		String tab = new String();
		for (int i = 0; i < tabs; i++) {
			tab += "\t";
		}
		System.out.println(tab + "Factor : " + phi);
		System.out.println(tab + "Dext : " + Dext);
		System.out.println(tab + "D : " + D);

		for (VariableComponent c : this.children) {
			c.print(tabs + 1);
		}

	}
{'fraction_non_alphanumeric': 0.14890510948905109, 'fraction_numerical': 0.0011678832116788322, 'mean_word_length': 3.71831955922865, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1219908', 'n_tokens_mistral': 2786, 'n_tokens_neox': 2394, 'n_words': 453}