// Path: edits-core/src/main/java/org/edits/engines/thread/EditsThread.java
// @Log4j
// public abstract class EditsThread<E> {
// 
// 	private boolean finnished = false;
// 	private Iterator<E> iterator;
// 	@Getter
// 	@Setter
// 	private int threads;
// 	private int workers = 0;
// 
// 	public EditsThread() {
// 		Runtime runtime = Runtime.getRuntime();
// 		threads = runtime.availableProcessors();
// 		if (threads > 24)
// 			threads = 24;
// 	}
// 
// 	public EditsThread(int threads_) {
// 		threads = threads_;
// 	}
// 
// 	public synchronized void finnished() {
// 		workers--;
// 		if (workers == 0) {
// 			finnished = true;
// 		}
// 	}
// 
// 	public synchronized void increment() {
// 		workers++;
// 	}
// 
// 	/**
// 	 * @return
// 	 * @throws Exception
// 	 */
// 	public synchronized E next() throws Exception {
// 
// 		if (iterator != null && iterator.hasNext())
// 			return iterator.next();
// 		return null;
// 	}
// 
// 	public abstract void process(E object) throws Exception;
// 
// 	public void start(Iterator<E> iterator_) {
// 		iterator = iterator_;
// 		log.debug("Started with " + threads + " threads");
// 		for (int i = 0; i < threads; i++)
// 			new Worker<E>(this).start();
// 		finnished = false;
// 		try {
// 			while (finnished == false)
// 				Thread.sleep(1000);
// 		} catch (InterruptedException e) {
// 		}
// 		iterator = null;
// 	}
// 
// }
// 
// Path: edits-core/src/main/java/org/edits/etaf/AnnotatedEntailmentPair.java
// @Data
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "AnnotatedEntailmentPair", propOrder = { "t", "h" })
// public class AnnotatedEntailmentPair {
// 
// 	public static AnnotatedEntailmentPair create(String t2, String h2, EditsTextAnnotator annotator) throws Exception {
// 		AnnotatedEntailmentPair px = new AnnotatedEntailmentPair();
// 		AnnotatedText at = new AnnotatedText();
// 		at.getAnnotation().addAll(annotator.annotate(t2));
// 		px.getT().add(at);
// 		at = new AnnotatedText();
// 		at.getAnnotation().addAll(annotator.annotate(h2));
// 		px.getH().add(at);
// 		return px;
// 	}
// 
// 	@XmlTransient
// 	private Map<String, String> attributes;
// 	@XmlAttribute
// 	protected String entailment;
// 	@XmlElement
// 	protected List<AnnotatedText> h;
// 	@XmlAttribute
// 	protected String id;
// 
// 	@XmlTransient
// 	private int order;
// 
// 	@XmlElement
// 	protected List<AnnotatedText> t;
// 
// 	@XmlAttribute
// 	protected String task;
// 
// 	public AnnotatedEntailmentPair() {
// 		t = Lists.newArrayList();
// 		h = Lists.newArrayList();
// 		attributes = Maps.newHashMap();
// 	}
// 
// }
// 
// Path: edits-core/src/main/java/org/edits/etaf/AnnotatedText.java
// @Data
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "AnnotatedText", propOrder = { "annotation" })
// public class AnnotatedText {
// 
// 	@XmlElement
// 	protected List<Annotation> annotation;
// 
// 	public AnnotatedText() {
// 		annotation = Lists.newArrayList();
// 	}
// }
// 
// Path: edits-core/src/main/java/org/edits/etaf/Annotation.java
// @Data
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "Annotation", propOrder = {})
// @XmlRootElement(name = "annotation")
// public class Annotation {
// 
// 	@XmlAttribute
// 	private String cpostag;
// 	@XmlAttribute
// 	private String deprel;
// 	@XmlAttribute
// 	private int end;
// 	@XmlAttribute
// 	private String feats;
// 	@XmlAttribute
// 	private String form;
// 	@XmlAttribute
// 	private String head;
// 	@XmlAttribute
// 	private String id;
// 	@XmlAttribute
// 	private String lemma;
// 	@XmlAttribute
// 	private String postag;
// 	@XmlAttribute
// 	private int start;
// 
// }


import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import lombok.extern.log4j.Log4j;
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.edits.engines.thread.EditsThread;
import org.edits.etaf.AnnotatedEntailmentPair;
import org.edits.etaf.AnnotatedText;
import org.edits.etaf.Annotation;
import com.google.common.collect.Sets;
package org.edits.rules;





@Log4j
public class RulesIndexGenerator extends EditsThread<AnnotatedEntailmentPair> {
	private final Set<String> cache;
	private final boolean extractRules;
	private final RulesSource rulesSource;
	private IndexWriter writer;

	public RulesIndexGenerator(RulesSource rulesSource_, boolean extractRules_) {
		cache = Sets.newHashSet();
		rulesSource = rulesSource_;
		extractRules = extractRules_;
	}

// Path: edits-core/src/main/java/org/edits/engines/thread/EditsThread.java
// @Log4j
// public abstract class EditsThread<E> {
// 
// 	private boolean finnished = false;
// 	private Iterator<E> iterator;
// 	@Getter
// 	@Setter
// 	private int threads;
// 	private int workers = 0;
// 
// 	public EditsThread() {
// 		Runtime runtime = Runtime.getRuntime();
// 		threads = runtime.availableProcessors();
// 		if (threads > 24)
// 			threads = 24;
// 	}
// 
// 	public EditsThread(int threads_) {
// 		threads = threads_;
// 	}
// 
// 	public synchronized void finnished() {
// 		workers--;
// 		if (workers == 0) {
// 			finnished = true;
// 		}
// 	}
// 
// 	public synchronized void increment() {
// 		workers++;
// 	}
// 
// 	/**
// 	 * @return
// 	 * @throws Exception
// 	 */
// 	public synchronized E next() throws Exception {
// 
// 		if (iterator != null && iterator.hasNext())
// 			return iterator.next();
// 		return null;
// 	}
// 
// 	public abstract void process(E object) throws Exception;
// 
// 	public void start(Iterator<E> iterator_) {
// 		iterator = iterator_;
// 		log.debug("Started with " + threads + " threads");
// 		for (int i = 0; i < threads; i++)
// 			new Worker<E>(this).start();
// 		finnished = false;
// 		try {
// 			while (finnished == false)
// 				Thread.sleep(1000);
// 		} catch (InterruptedException e) {
// 		}
// 		iterator = null;
// 	}
// 
// }
// 
// Path: edits-core/src/main/java/org/edits/etaf/AnnotatedEntailmentPair.java
// @Data
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "AnnotatedEntailmentPair", propOrder = { "t", "h" })
// public class AnnotatedEntailmentPair {
// 
// 	public static AnnotatedEntailmentPair create(String t2, String h2, EditsTextAnnotator annotator) throws Exception {
// 		AnnotatedEntailmentPair px = new AnnotatedEntailmentPair();
// 		AnnotatedText at = new AnnotatedText();
// 		at.getAnnotation().addAll(annotator.annotate(t2));
// 		px.getT().add(at);
// 		at = new AnnotatedText();
// 		at.getAnnotation().addAll(annotator.annotate(h2));
// 		px.getH().add(at);
// 		return px;
// 	}
// 
// 	@XmlTransient
// 	private Map<String, String> attributes;
// 	@XmlAttribute
// 	protected String entailment;
// 	@XmlElement
// 	protected List<AnnotatedText> h;
// 	@XmlAttribute
// 	protected String id;
// 
// 	@XmlTransient
// 	private int order;
// 
// 	@XmlElement
// 	protected List<AnnotatedText> t;
// 
// 	@XmlAttribute
// 	protected String task;
// 
// 	public AnnotatedEntailmentPair() {
// 		t = Lists.newArrayList();
// 		h = Lists.newArrayList();
// 		attributes = Maps.newHashMap();
// 	}
// 
// }
// 
// Path: edits-core/src/main/java/org/edits/etaf/AnnotatedText.java
// @Data
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "AnnotatedText", propOrder = { "annotation" })
// public class AnnotatedText {
// 
// 	@XmlElement
// 	protected List<Annotation> annotation;
// 
// 	public AnnotatedText() {
// 		annotation = Lists.newArrayList();
// 	}
// }
// 
// Path: edits-core/src/main/java/org/edits/etaf/Annotation.java
// @Data
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "Annotation", propOrder = {})
// @XmlRootElement(name = "annotation")
// public class Annotation {
// 
// 	@XmlAttribute
// 	private String cpostag;
// 	@XmlAttribute
// 	private String deprel;
// 	@XmlAttribute
// 	private int end;
// 	@XmlAttribute
// 	private String feats;
// 	@XmlAttribute
// 	private String form;
// 	@XmlAttribute
// 	private String head;
// 	@XmlAttribute
// 	private String id;
// 	@XmlAttribute
// 	private String lemma;
// 	@XmlAttribute
// 	private String postag;
// 	@XmlAttribute
// 	private int start;
// 
// }


// Path: edits-core/src/main/java/org/edits/rules/RulesIndexGenerator.java
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import lombok.extern.log4j.Log4j;
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.edits.engines.thread.EditsThread;
import org.edits.etaf.AnnotatedEntailmentPair;
import org.edits.etaf.AnnotatedText;
import org.edits.etaf.Annotation;
import com.google.common.collect.Sets;

package org.edits.rules;





@Log4j
public class RulesIndexGenerator extends EditsThread<AnnotatedEntailmentPair> {
	private final Set<String> cache;
	private final boolean extractRules;
	private final RulesSource rulesSource;
	private IndexWriter writer;

	public RulesIndexGenerator(RulesSource rulesSource_, boolean extractRules_) {
		cache = Sets.newHashSet();
		rulesSource = rulesSource_;
		extractRules = extractRules_;
	}

	private void addRule(Annotation at, Annotation ah) {