package gr.iti.mklab.sfc.processors;

import java.io.IOException;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import gr.iti.mklab.framework.common.domain.Item;
import gr.iti.mklab.framework.common.domain.config.Configuration;
import gr.iti.mklab.sfc.utils.MinHash;
import gr.iti.mklab.sfc.utils.TextUtils;

public class MinHashExtractor extends Processor {

	private MinHash minHash;
	private MinHash singatureHash;
	
	public MinHashExtractor(Configuration configuration) {
		super(configuration);
		
		int bitset = Integer.getInteger(configuration.getParameter("bitset", "1"));
		int minhashNum = Integer.getInteger(configuration.getParameter("minhashNum", "32"));
		int singatureNum = Integer.getInteger(configuration.getParameter("singatureNum", "128"));
		
		this.minHash = MinHash.getInstance(bitset, minhashNum);
		this.singatureHash = MinHash.getInstance(bitset, singatureNum);
	}

	@Override
	public void process(Item item) {
		String title = item.getTitle();
		if(title != null) {
			try {
				
				title = TextUtils.clean(title);
				title = title.toLowerCase();
				title = TextUtils.normalize(title);
				
				List<String> tokens = TextUtils.tokenize(title);
				TextUtils.cleanTokens(tokens);
				
				title = StringUtils.join(tokens, " ");
				
				byte[] hashdata = minHash.calculate(title);
				byte[] signaturedata = singatureHash.calculate(title);
				
				String minhash = MinHash.toBinaryString(hashdata);
				String signature = MinHash.toBinaryString(signaturedata);
				
				
				item.setMinhash(minhash);
				item.setSignature(signature);
				
			} catch (IOException e) {
				
			}
			
		}
	}

}

@@ -376,16 +376,18 @@
 ssor %7B%0A%0A
+%09%0A
 %09private
@@ -404,16 +404,16 @@
 inHash;%0A
-
 %09private
@@ -525,86 +525,8 @@
 %0A%09%09%0A
-%09%09int bitset = Integer.getInteger(configuration.getParameter(%22bitset%22, %221%22));%0A
 %09%09in
@@ -740,22 +740,17 @@
 nstance(
-bitset
+1
 , minhas
@@ -803,14 +803,9 @@
 nce(
-bitset
+1
 , si

fix min hash extractor