<commit_before>package org.drools.decisiontable.parser;

/*
 * Copyright 2005 JBoss Inc
 * 
 * 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.
 */

import java.util.Properties;

import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.decisiontable.model.DRLOutput;

/**
 * SheetListener for creating rules from a template
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ExternalSheetListener implements RuleSheetListener {

	private int startRow = -1;

	private boolean tableFinished = false;

	private Row currentRow;

	private Column[] columns;

	private StatefulSession session;

	private TemplateContainer templateContainer;

	private int startCol;

	private Generator generator;

	private WorkingMemoryFileLogger logger;

	public ExternalSheetListener(final int startRow, final int startCol,
			final String template) {
		this(startRow, startCol, new DefaultTemplateContainer(template));
	}

	public ExternalSheetListener(final int startRow, final int startCol,
			final TemplateContainer tc) {
		this(startRow, startCol, tc, new DefaultTemplateRuleBase(tc));
	}

	public ExternalSheetListener(final int startRow, final int startCol,
			final TemplateContainer tc, final TemplateRuleBase rb) {
		this(startRow, startCol, tc, rb,
				new DefaultGenerator(tc.getTemplates()));
	}

	public ExternalSheetListener(final int startRow, final int startCol,
			final TemplateContainer tc, final TemplateRuleBase ruleBase,
			final Generator generator) {
		this.startRow = startRow - 1;
		this.startCol = startCol - 1;
		columns = tc.getColumns();
		this.templateContainer = tc;
		session = ruleBase.newStatefulSession();
		logger = new WorkingMemoryFileLogger(session);
		logger.setFileName("log/event");
		this.generator = generator;
		session.setGlobal("generator", generator);
		assertColumns();
	}

	private void assertColumns() {
		for (int i = 0; i < columns.length; i++) {
			session.insert(columns[i]);			
		}
	}

	public Properties getProperties() {
		return null;
	}

	public org.drools.decisiontable.model.Package getRuleSet() {
		return null;
	}

	public void finishSheet() {
		if (currentRow != null) {
			session.insert(currentRow);
		}
		session.fireAllRules();
		logger.writeToDisk();
		session.dispose();
	}

	public void newCell(int row, int column, String value, int mergedColStart) {
		if (currentRow != null && column >= startCol && value != null
				&& value.trim().length() > 0) {

			int columnIndex = column - startCol;
			// System.out.println("asserting cell " + row + ", " + column + ": "
			// + value);
			Cell cell = currentRow.getCell(columnIndex);
			cell.setValue(value);
			cell.insert(session);
		}
	}

	public void newRow(int rowNumber, int columnCount) {
		if (!tableFinished && rowNumber >= startRow) {
			if (currentRow != null && currentRow.isEmpty()) {
				currentRow = null;
				tableFinished = true;
			} else {
				if (currentRow != null)
					session.insert(currentRow);<commit_msg>removed logging<commit_after>package org.drools.decisiontable.parser;

/*
 * Copyright 2005 JBoss Inc
 *
 * 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.
 */

import java.util.Properties;

import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.decisiontable.model.DRLOutput;

/**
 * SheetListener for creating rules from a template
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ExternalSheetListener implements RuleSheetListener {

	private int startRow = -1;

	private boolean tableFinished = false;

	private Row currentRow;

	private Column[] columns;

	private StatefulSession session;

	private TemplateContainer templateContainer;

	private int startCol;

	private Generator generator;

	//private WorkingMemoryFileLogger logger;

	public ExternalSheetListener(final int startRow, final int startCol,
			final String template) {
		this(startRow, startCol, new DefaultTemplateContainer(template));
	}

	public ExternalSheetListener(final int startRow, final int startCol,
			final TemplateContainer tc) {
		this(startRow, startCol, tc, new DefaultTemplateRuleBase(tc));
	}

	public ExternalSheetListener(final int startRow, final int startCol,
			final TemplateContainer tc, final TemplateRuleBase rb) {
		this(startRow, startCol, tc, rb,
				new DefaultGenerator(tc.getTemplates()));
	}

	public ExternalSheetListener(final int startRow, final int startCol,
			final TemplateContainer tc, final TemplateRuleBase ruleBase,
			final Generator generator) {
		this.startRow = startRow - 1;
		this.startCol = startCol - 1;
		columns = tc.getColumns();
		this.templateContainer = tc;
		session = ruleBase.newStatefulSession();
//		logger = new WorkingMemoryFileLogger(session);
//		logger.setFileName("log/event");
		this.generator = generator;
		session.setGlobal("generator", generator);
		assertColumns();
	}

	private void assertColumns() {
		for (int i = 0; i < columns.length; i++) {
			session.insert(columns[i]);
		}
	}

	public Properties getProperties() {
		return null;
	}

	public org.drools.decisiontable.model.Package getRuleSet() {
		return null;
	}

	public void finishSheet() {
		if (currentRow != null) {
			session.insert(currentRow);
		}
		session.fireAllRules();
//		logger.writeToDisk();
		session.dispose();
	}

	public void newCell(int row, int column, String value, int mergedColStart) {
		if (currentRow != null && column >= startCol && value != null
				&& value.trim().length() > 0) {

			int columnIndex = column - startCol;
			// System.out.println("asserting cell " + row + ", " + column + ": "
			// + value);
			Cell cell = currentRow.getCell(columnIndex);
			cell.setValue(value);
			cell.insert(session);
		}
	}

	public void newRow(int rowNumber, int columnCount) {
		if (!tableFinished && rowNumber >= startRow) {
			if (currentRow != null && currentRow.isEmpty()) {
				currentRow = null;
				tableFinished = true;
			} else {
				if (currentRow != null)
					session.insert(currentRow);
{'fraction_non_alphanumeric': 0.10518793768758039, 'fraction_numerical': 0.0037158782335286553, 'mean_word_length': 4.21072226358898, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 17, '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': '3145950', 'n_tokens_mistral': 2209, 'n_tokens_neox': 1994, 'n_words': 616}