<commit_before>/*******************************************************************************
 * DIANNE  - Framework for distributed artificial neural networks
 * Copyright (C) 2015  iMinds - IBCN - UGent
 *
 * This file is part of DIANNE.
 *
 * DIANNE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     <NAME>, <NAME>
 *******************************************************************************/
package be.iminds.iot.dianne.dataset;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import be.iminds.iot.dianne.api.dataset.Dataset;

/**
 * Proxy class to optimize the behavior of querying datasets that are located on a remote machine
 * 
 * @author tverbele
 *
 */
public class RemoteDatasetProxy implements InvocationHandler {

	private final Dataset proxied;
	
	private boolean dirty = true;
	private int cachedSize = -1;
	
	public RemoteDatasetProxy(Dataset d){
		this.proxied = d;
	}
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		// cache the size so we don't have to do a remote call 
		// for each time the sampling strategy wants the size for constructing batches
		if(method.getName().equals("size")){
			if(dirty){
				cachedSize = (int)method.invoke(proxied, args);
				dirty = false;
			}
			return cachedSize;
		}
		
		dirty = true;
		if(method.getParameterCount() > 0 && method.getReturnType().equals(method.getParameterTypes()[0])){
			// this is a method that has as first arg the return type
			//... in case of a remote call, set parameter[0] to null
			args[0] = null;
		}
		return method.invoke(proxied, args);
	}

}
<commit_msg>remove size caching for now - more involved approach required<commit_after>/*******************************************************************************
 * DIANNE  - Framework for distributed artificial neural networks
 * Copyright (C) 2015  iMinds - IBCN - UGent
 *
 * This file is part of DIANNE.
 *
 * DIANNE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     <NAME>, <NAME>
 *******************************************************************************/
package be.iminds.iot.dianne.dataset;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import be.iminds.iot.dianne.api.dataset.Dataset;

/**
 * Proxy class to optimize the behavior of querying datasets that are located on a remote machine
 * 
 * @author tverbele
 *
 */
public class RemoteDatasetProxy implements InvocationHandler {

	private final Dataset proxied;
	
	public RemoteDatasetProxy(Dataset d){
		this.proxied = d;
	}
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		if(method.getParameterCount() > 0 && method.getReturnType().equals(method.getParameterTypes()[0])){
			// this is a method that has as first arg the return type
			//... in case of a remote call, set parameter[0] to null
			args[0] = null;
		}
		return method.invoke(proxied, args);
	}

}

{'fraction_non_alphanumeric': 0.15549215406562053, 'fraction_numerical': 0.00451735615786971, 'mean_word_length': 4.056490384615385, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1223573', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1113, 'n_words': 461}