package org.apache.uima.graph.impl.mappings;

import java.util.Collection;

import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.fit.util.JCasUtil;
import org.apache.uima.graph.impl.DefaultIndicesNames;
import org.apache.uima.graph.impl.MappingUtils;
import org.apache.uima.jcas.tcas.Annotation;

import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Vertex;

public class DefaultAnnotationMapper extends DefaultFeatureStructureMapper {
	
	public DefaultAnnotationMapper() {
		super();
	}

	public DefaultAnnotationMapper(Collection<String> typesNotToMap,
		Collection<String> featuresNotToMap) {
		super(typesNotToMap, featuresNotToMap);
	}

	@Override
	public void fillVertex(Vertex vertexForObj, Object obj, Graph graph) {
		Annotation annot = MappingUtils.checkTypeAndCast(
			getClass(),
			Annotation.class,
			obj);

		super.fillVertex(vertexForObj, obj, graph);

		vertexForObj.setProperty(
			DefaultIndicesNames.TEXT.name(),
			annot.getCoveredText());
		vertexForObj.setProperty(
			DefaultIndicesNames.IS_NULL.name(),
			annot.getBegin() == 0 && annot.getEnd() == 0);

		for (AnnotationFS covered : JCasUtil.selectCovered(
			Annotation.class,
			annot)) {
			if (typesNotToMap.contains(covered.getType().getName()))
				continue;
			MappingUtils.addLink(
				getMappingManager(),
				graph,
				vertexForObj,
				covered,
				DefaultIndicesNames.COVERS.name());
		}
	}

}

@@ -463,17 +463,46 @@
 apper %7B%0A
-%09
+%0A%09private boolean%09mapCovered;%0A
 %0A%09public
@@ -541,16 +541,37 @@
 uper();%0A
+%09%09mapCovered = true;%0A
 %09%7D%0A%0A%09pub
@@ -669,16 +669,36 @@
 NotToMap
+, boolean mapCovered
 ) %7B%0A%09%09su
@@ -735,16 +735,48 @@
 ToMap);%0A
+%09%09this.mapCovered = mapCovered;%0A
 %09%7D%0A%0A%09@Ov
@@ -1209,16 +1209,37 @@
 == 0);%0A%0A
+%09%09if (mapCovered) %7B%0A%09
 %09%09for (A
@@ -1283,24 +1283,25 @@
 Covered(%0A%09%09%09
+%09
 Annotation.c
@@ -1306,16 +1306,17 @@
 .class,%0A
+%09
 %09%09%09annot
@@ -1323,16 +1323,17 @@
 )) %7B%0A%09%09%09
+%09
 if (type
@@ -1385,16 +1385,17 @@
 )))%0A%09%09%09%09
+%09
 continue
@@ -1396,16 +1396,17 @@
 ntinue;%0A
+%09
 %09%09%09Mappi
@@ -1422,16 +1422,17 @@
 ddLink(%0A
+%09
 %09%09%09%09getM
@@ -1456,15 +1456,17 @@
 %09%09%09%09
+%09
 graph,%0A
+%09
 %09%09%09%09
@@ -1479,16 +1479,17 @@
 ForObj,%0A
+%09
 %09%09%09%09cove
@@ -1497,16 +1497,17 @@
 ed,%0A%09%09%09%09
+%09
 DefaultI
@@ -1534,16 +1534,21 @@
 ame());%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%0A

improve filtering