package org.topicquests.solr.documentdelegates;

import org.apache.solr.common.SolrInputDocument;
import org.apache.uima.jcas.tcas.Annotation;
import org.cleartk.ne.type.NamedEntityMention;
import org.topicquests.solr.DocumentAdderDelegate;

/**
 * Adds the named entity mention type as type(mention.getCoveredText())
 * as well as entity: mention.getCoveredText
 * @author Adam Gibson
 *
 */
public class NamedEntityMentionDelegate implements DocumentAdderDelegate {

	@Override
	public void addToDocument(Annotation annotation, SolrInputDocument doc) {
		if(!(annotation instanceof NamedEntityMention))
			return;
		
		NamedEntityMention ne = (NamedEntityMention) annotation;
		if(ne.getMentionType()!=null) {
			doc.addField("type",String.format("%s(%s)",ne.getMentionType(),ne.getCoveredText()));
		}
		doc.addField("entity",ne.getCoveredText(),1.0f);
	}

}
