<commit_before>package examples;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;

import gnu.trove.set.hash.TLongHashSet;
import org.openlca.core.database.CategoryDao;
import org.openlca.core.database.Derby;
import org.openlca.core.database.IDatabase;
import org.openlca.core.model.Exchange;
import org.openlca.core.model.Flow;
import org.openlca.core.model.FlowProperty;
import org.openlca.core.model.FlowType;
import org.openlca.core.model.ImpactMethod;
import org.openlca.core.model.ModelType;
import org.openlca.core.model.Process;
import org.openlca.core.model.ProcessLink;
import org.openlca.core.model.ProductSystem;
import org.openlca.core.model.Result;

public class SubResultTree {

	public static void main(String[] args) {

		// This example creates a product system that links sub-results
		// in a random tree. To run the example, import Oekobaudat as
		// ILCD+EPD results into a database.

		var db = Derby.fromDataDir("oekobaudat_results");

		// the Oekobaudat results have no methods; so first we tag the results with
		// the same indicator set with the same method.
		// var method = tagWithMethods(db);
		// var methodId = method.entity.refId;

		var massId = "93a60a56-a3c8-11da-a746-0800200b9a66";
		var mass = db.get(FlowProperty.class, massId);

		var methodId = "eb4db92d-97ac-41a7-9573-05566a319b06";
		var method = db.get(ImpactMethod.class, methodId);
		var results = db.allOf(Result.class)
			.stream()
			.filter(r -> method.equals(r.impactMethod))
			.toList();

		int depth = 5;

		int processCount = 1;
		var root = newProcess(db, mass, processCount);
		var system = ProductSystem.of(root);
		var previousLevel = new Process[]{root};
		var rand = ThreadLocalRandom.current();
		for (int i = 0; i < depth; i++) {
			int width = rand.nextInt(1, depth);
			var nextLevel = new Process[width];
			for (int j = 0; j < width; j++) {
				processCount++;
				var child = newProcess(db, mass, processCount);
				system.processes.add(child.id);

				// link to parent
				int parentIdx = rand.nextInt(0, previousLevel.length);
				var parent = previousLevel[parentIdx];
				var linkFlow = child.quantitativeReference.flow;
				parent.input(linkFlow, rand.nextInt(1, 5));
				parent = db.update(parent);
				previousLevel[parentIdx] =parent;
				var  parentLink= new ProcessLink();
				parentLink.setProviderType(ModelType.PROCESS);<commit_msg>full oekobaudat test<commit_after>package examples;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;

import gnu.trove.set.hash.TLongHashSet;
import org.openlca.core.database.CategoryDao;
import org.openlca.core.database.Derby;
import org.openlca.core.database.IDatabase;
import org.openlca.core.model.Exchange;
import org.openlca.core.model.Flow;
import org.openlca.core.model.FlowProperty;
import org.openlca.core.model.FlowType;
import org.openlca.core.model.ImpactMethod;
import org.openlca.core.model.ModelType;
import org.openlca.core.model.Process;
import org.openlca.core.model.ProcessLink;
import org.openlca.core.model.ProductSystem;
import org.openlca.core.model.Result;

public class SubResultTree {

	public static void main(String[] args) {

		// This example creates a product system that links sub-results
		// in a random tree. To run the example, import Oekobaudat as
		// ILCD+EPD results into a database.

		var db = Derby.fromDataDir("oekobaudat");

		// the Oekobaudat results have no methods; so first we tag the results with
		// the same indicator set with the same method.
		var method = tagWithMethods(db).entity;

		var massId = "93a60a56-a3c8-11da-a746-0800200b9a66";
		var mass = db.get(FlowProperty.class, massId);

		// var methodId = "eb4db92d-97ac-41a7-9573-05566a319b06";
		// var method = db.get(ImpactMethod.class, methodId);
		var results = db.allOf(Result.class)
			.stream()
			.filter(r -> method.equals(r.impactMethod))
			.toList();

		int depth = 5;

		int processCount = 1;
		var root = newProcess(db, mass, processCount);
		var system = ProductSystem.of(root);
		var previousLevel = new Process[]{root};
		var rand = ThreadLocalRandom.current();
		for (int i = 0; i < depth; i++) {
			int width = rand.nextInt(1, depth);
			var nextLevel = new Process[width];
			for (int j = 0; j < width; j++) {
				processCount++;
				var child = newProcess(db, mass, processCount);
				system.processes.add(child.id);

				// link to parent
				int parentIdx = rand.nextInt(0, previousLevel.length);
				var parent = previousLevel[parentIdx];
				var linkFlow = child.quantitativeReference.flow;
				parent.input(linkFlow, rand.nextInt(1, 5));
				parent = db.update(parent);
				previousLevel[parentIdx] =parent;
				var  parentLink= new ProcessLink();
				parentLink.setProviderType(ModelType.PROCESS);
{'fraction_non_alphanumeric': 0.12000823384108687, 'fraction_numerical': 0.02181967888019761, 'mean_word_length': 4.1147368421052635, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4224296', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1617, 'n_words': 392}