package gr.iti.mklab.sfc.processors;

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

import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

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 Logger logger = LogManager.getLogger(MinHashExtractor.class);
	
	private MinHash minHash = null;
	private MinHash singatureHash = null;
	
	public MinHashExtractor(Configuration configuration) {
		super(configuration);
		
		int minhashNum = Integer.getInteger(configuration.getParameter("minhashNum", "32"));
		int singatureNum = Integer.getInteger(configuration.getParameter("singatureNum", "128"));
		
		logger.info("minhash length: " + minhashNum + ", singature length: " + singatureNum);
		
		this.minHash = MinHash.getInstance(1, minhashNum);
		this.singatureHash = MinHash.getInstance(1, 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);
				
				item.setCleanTitle(title);
				
			} catch (IOException e) {
				logger.error("Exception in minhash extractor for items " + item.getId(), e);
			}
			
		}
	}

}

@@ -697,44 +697,41 @@
 %09%0A%09%09
-int minhashNum = Integer.getInteger(
+logger.info(%22minhash length: %22 + 
 conf
@@ -776,16 +776,13 @@
 32%22)
-);%0A%09%09int
+ + %22,
  sin
@@ -791,33 +791,21 @@
 ture
-Num = Integer.getInteger(
+ length: %22 + 
 conf
@@ -861,79 +861,157 @@
 %09%0A%09%09
-logger.info(%22minhash length: %22 + minhashNum + %22, singature length: %22 + 
+int minhashNum = Integer.parseInt(configuration.getParameter(%22minhashNum%22, %2232%22));%0A%09%09int singatureNum = Integer.parseInt(configuration.getParameter(%22
 sing
@@ -1014,24 +1014,33 @@
 singatureNum
+%22, %22128%22)
 );%0A%09%09%0A%09%09this

Fix min hash extractor