<commit_before>/*
 * #%L
 * Eureka Services
 * %%
 * Copyright (C) 2012 Emory University
 * %%
 * 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.apache.org/licenses/LICENSE-2.0
 * 
 * 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.
 * #L%
 */
package edu.emory.cci.aiw.cvrg.eureka.services.packaging;

import edu.emory.cci.aiw.cvrg.eureka.common.entity.ValueThresholdEntity;
import edu.emory.cci.aiw.cvrg.eureka.common.entity.Proposition;
import edu.emory.cci.aiw.cvrg.eureka.common.entity.SimpleParameterConstraint;
import org.protempa.LowLevelAbstractionDefinition;
import org.protempa.LowLevelAbstractionValueDefinition;
import org.protempa.proposition.value.NumberValue;
import org.protempa.proposition.value.ValueComparator;

import static edu.emory.cci.aiw.cvrg.eureka.services.packaging.PropositionDefinitionPackagerUtil.unit;

public final class LowLevelAbstractionPackager
        implements
        PropositionDefinitionPackager<ValueThresholdEntity, LowLevelAbstractionDefinition> {

	static final String COMPLEMENT_SUFFIX = "_COMPLEMENT";


	@Override
	public LowLevelAbstractionDefinition pack(ValueThresholdEntity proposition) {
		LowLevelAbstractionDefinition result = new LowLevelAbstractionDefinition(
		        proposition.getId().toString());

		result.addPrimitiveParameterId(proposition.getAbstractedFrom().getKey());

		constraintToValueDefinition(proposition.getKey(),
				proposition.getUserConstraint(), result);
		constraintToValueDefinition(proposition.getKey() + COMPLEMENT_SUFFIX,
				proposition.getComplementConstraint(), result);

		result.setMinimumNumberOfValues(proposition.getMinValues());
		result.setMinimumGapBetweenValues(proposition.getMinGapValues());
		result.setMinimumGapBetweenValuesUnits(unit(proposition
				.getMinGapValuesUnits()));
		result.setMaximumGapBetweenValues(proposition.getMaxGapValues());
		result.setMinimumGapBetweenValuesUnits(unit(proposition
				.getMaxGapValuesUnits()));

		return result;
	}

	private static void
			constraintToValueDefinition(String name,
												SimpleParameterConstraint
												constraint,
										LowLevelAbstractionDefinition def) {
		LowLevelAbstractionValueDefinition valueDef = new
				LowLevelAbstractionValueDefinition(def, name);
		if (constraint.getMinValueThreshold() != null && constraint
				.getMinValueComp() != null) {
			valueDef.setParameterValue("minThreshold",
					NumberValue.getInstance(constraint.getMinValueThreshold()
							.longValue()));
			valueDef.setParameterComp("minThreshold", ValueComparator.parse
					(constraint.getMinValueComp().getName()));
		}
		if (constraint.getMaxValueThreshold() != null && constraint
				.getMaxValueComp() != null) {
			valueDef.setParameterValue("maxThreshold",
					NumberValue.getInstance(constraint.getMaxValueThreshold()
							.longValue()));
			valueDef.setParameterComp("maxThreshold", ValueComparator.parse
					(constraint.getMaxValueComp().getName()));
		}
	}

}
<commit_msg>fixed a couple bugs; changed prop def id to be proposition key<commit_after>/*
 * #%L
 * Eureka Services
 * %%
 * Copyright (C) 2012 Emory University
 * %%
 * 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.apache.org/licenses/LICENSE-2.0
 * 
 * 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.
 * #L%
 */
package edu.emory.cci.aiw.cvrg.eureka.services.packaging;

import edu.emory.cci.aiw.cvrg.eureka.common.entity.ValueThresholdEntity;
import edu.emory.cci.aiw.cvrg.eureka.common.entity.Proposition;
import edu.emory.cci.aiw.cvrg.eureka.common.entity.SimpleParameterConstraint;
import org.protempa.LowLevelAbstractionDefinition;
import org.protempa.LowLevelAbstractionValueDefinition;
import org.protempa.proposition.value.NumberValue;
import org.protempa.proposition.value.ValueComparator;

import static edu.emory.cci.aiw.cvrg.eureka.services.packaging.PropositionDefinitionPackagerUtil.unit;

public final class LowLevelAbstractionPackager
        implements
        PropositionDefinitionPackager<ValueThresholdEntity, LowLevelAbstractionDefinition> {

	static final String COMPLEMENT_SUFFIX = "_COMPLEMENT";

	@Override
	public LowLevelAbstractionDefinition pack(ValueThresholdEntity proposition) {
		LowLevelAbstractionDefinition result = new LowLevelAbstractionDefinition(
		        proposition.getKey());

		result.setAlgorithmId("stateDetector");
		result.addPrimitiveParameterId(proposition.getAbstractedFrom().getKey());

		constraintToValueDefinition(proposition.getName(),
		        proposition.getUserConstraint(), result);
		constraintToValueDefinition(proposition.getName() + COMPLEMENT_SUFFIX,
		        proposition.getComplementConstraint(), result);

		result.setMinimumNumberOfValues(proposition.getMinValues());
		result.setMinimumGapBetweenValues(proposition.getMinGapValues());
		result.setMinimumGapBetweenValuesUnits(unit(proposition
		        .getMinGapValuesUnits()));
		result.setMaximumGapBetweenValues(proposition.getMaxGapValues());
		result.setMaximumGapBetweenValuesUnits(unit(proposition
		        .getMaxGapValuesUnits()));

		return result;
	}

	private void constraintToValueDefinition(String name,
	        SimpleParameterConstraint constraint,
	        LowLevelAbstractionDefinition def) {
		LowLevelAbstractionValueDefinition valueDef = new LowLevelAbstractionValueDefinition(
		        def, name);
		if (constraint.getMinValueThreshold() != null
		        && constraint.getMinValueComp() != null) {
			valueDef.setParameterValue("minThreshold", NumberValue
			        .getInstance(constraint.getMinValueThreshold().longValue()));
			valueDef.setParameterComp("minThreshold", ValueComparator
			        .parse(constraint.getMinValueComp().getName()));
		}
		if (constraint.getMaxValueThreshold() != null
		        && constraint.getMaxValueComp() != null) {
			valueDef.setParameterValue("maxThreshold", NumberValue
			        .getInstance(constraint.getMaxValueThreshold().longValue()));
			valueDef.setParameterComp("maxThreshold", ValueComparator
			        .parse(constraint.getMaxValueComp().getName()));
		}
	}

}

{'fraction_non_alphanumeric': 0.09487666034155598, 'fraction_numerical': 0.0023354254853306085, 'mean_word_length': 5.101513802315227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7666278', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1875, 'n_words': 378}