<commit_before>/*
 * Copyright 2002-2014 The Jamocha Team
 * 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.jamocha.org/
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jamocha.languages.common;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;

import org.jamocha.dn.memory.SlotAddress;
import org.jamocha.dn.memory.SlotType;
import org.jamocha.dn.memory.Template;
import org.jamocha.filter.Path;
import org.jamocha.function.fwa.PathLeaf;
import org.jamocha.languages.common.RuleCondition.EquivalenceClass;
import org.jamocha.languages.common.ScopeStack.VariableSymbol;

/**
 * Gathers relevant information about a variable.
 * 
 * @author <NAME> <<EMAIL>>
 */
@Getter
@EqualsAndHashCode
public class SingleFactVariable {
	@NonNull
	final Template template;
	@NonNull
	final EquivalenceClass equal;
	final HashMap<SlotAddress, SingleSlotVariable> slots = new HashMap<>();

	public SingleFactVariable(final Template template, final VariableSymbol symbol) {
		this.template = template;
		assert null != symbol.equal;
		this.equal = symbol.equal;
		this.equal.add(this);
	}

	public SingleSlotVariable newSingleSlotVariable(final SlotAddress slot, final VariableSymbol symbol) {
		final SingleSlotVariable instance = slots.computeIfAbsent(slot, SingleSlotVariable::new);
		assert null != symbol.equal;
		instance.equal.add(symbol.equal);
		symbol.equal.add(instance);
		return instance;
	}

	public Collection<SingleSlotVariable> getSlotVariables() {
		return slots.values();
	}

	public PathLeaf getPathLeaf(final Map<SingleFactVariable, Path> pathMap) {
		return new PathLeaf(pathMap.get(this), null);
	}

	@Getter
	@AllArgsConstructor(access = AccessLevel.PRIVATE)
	public class SingleSlotVariable {
		@NonNull
		final SlotAddress slot;
		@NonNull
		final Set<EquivalenceClass> equal = new HashSet<>();

		public SlotType getType() {
			return template.getSlotType(slot);
		}

		public SingleFactVariable getFactVariable() {
			return SingleFactVariable.this;
		}

		public PathLeaf getPathLeaf(final Map<SingleFactVariable, Path> pathMap) {
			final Path path = pathMap.get(getFactVariable());
			return null == path ? null : new PathLeaf(path, slot);
		}
	}
}<commit_msg>SingleFactVariable: equivalence class can now be replaced, added toString<commit_after>/*
 * Copyright 2002-2014 The Jamocha Team
 * 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.jamocha.org/
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jamocha.languages.common;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;

import org.jamocha.dn.memory.SlotAddress;
import org.jamocha.dn.memory.SlotType;
import org.jamocha.dn.memory.Template;
import org.jamocha.filter.Path;
import org.jamocha.function.fwa.PathLeaf;
import org.jamocha.languages.common.RuleCondition.EquivalenceClass;
import org.jamocha.languages.common.ScopeStack.VariableSymbol;

/**
 * Gathers relevant information about a variable.
 * 
 * @author <NAME> <<EMAIL>>
 */
@Getter
@EqualsAndHashCode
@ToString(of = { "template" })
public class SingleFactVariable {
	@NonNull
	final Template template;
	@NonNull
	@Setter
	EquivalenceClass equal;
	final HashMap<SlotAddress, SingleSlotVariable> slots = new HashMap<>();

	public SingleFactVariable(final Template template, final VariableSymbol symbol) {
		this.template = template;
		assert null != symbol.equal;
		this.equal = symbol.equal;
		this.equal.add(this);
	}

	public SingleSlotVariable newSingleSlotVariable(final SlotAddress slot, final VariableSymbol symbol) {
		final SingleSlotVariable instance = slots.computeIfAbsent(slot, SingleSlotVariable::new);
		assert null != symbol.equal;
		instance.equal.add(symbol.equal);
		symbol.equal.add(instance);
		return instance;
	}

	public Collection<SingleSlotVariable> getSlotVariables() {
		return slots.values();
	}

	public PathLeaf getPathLeaf(final Map<SingleFactVariable, Path> pathMap) {
		return new PathLeaf(pathMap.get(this), null);
	}

	@Getter
	@AllArgsConstructor(access = AccessLevel.PRIVATE)
	public class SingleSlotVariable {
		@NonNull
		final SlotAddress slot;
		@NonNull
		final Set<EquivalenceClass> equal = new HashSet<>();

		public SlotType getType() {
			return template.getSlotType(slot);
		}

		public SingleFactVariable getFactVariable() {
			return SingleFactVariable.this;
		}

		public PathLeaf getPathLeaf(final Map<SingleFactVariable, Path> pathMap) {
			final Path path = pathMap.get(getFactVariable());
			return null == path ? null : new PathLeaf(path, slot);
		}

		@Override
		public String toString() {
			return "SingleSlotVariable(" + getFactVariable().toString() + "[" + slot.toString() + "])";
		}
	}
}
{'fraction_non_alphanumeric': 0.09742554265522463, 'fraction_numerical': 0.003365303718660609, 'mean_word_length': 4.961885656970913, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '977334', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1730, 'n_words': 504}