You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2011/07/14 20:00:02 UTC
svn commit: r1146822 - in
/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor:
AbstractDocument.java AnnotationDocument.java AnnotationEditor.java
DocumentUimaImpl.java ICasDocument.java
Author: joern
Date: Thu Jul 14 18:00:02 2011
New Revision: 1146822
URL: http://svn.apache.org/viewvc?rev=1146822&view=rev
Log:
UIMA-2168 Moved getAnnotations depending on type and span to the Annotation Editor.
Modified:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AbstractDocument.java
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasDocument.java
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AbstractDocument.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AbstractDocument.java?rev=1146822&r1=1146821&r2=1146822&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AbstractDocument.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AbstractDocument.java Thu Jul 14 18:00:02 2011
@@ -154,35 +154,4 @@ public abstract class AbstractDocument i
return Collections.unmodifiableMap(viewMap);
}
-
- /**
- * Retrieves annotations of the given type in the given bounds.
- */
- public Collection<AnnotationFS> getAnnotation(Type type, Span span) {
- Map<Integer, AnnotationFS> view = getView(type);
-
- LinkedList<AnnotationFS> annotations = new LinkedList<AnnotationFS>();
-
- for (int i = span.getStart(); i < span.getEnd(); i++) {
- AnnotationFS annotation = view.get(i);
-
- if (annotation == null) {
- continue;
- }
-
- if (!annotation.getType().equals(type)) {
- continue;
- }
-
- annotations.addLast(annotation);
- }
-
- TreeSet<AnnotationFS> set = new TreeSet<AnnotationFS>();
-
- for (AnnotationFS annotation : annotations) {
- set.add(annotation);
- }
-
- return Collections.unmodifiableSet(set);
- }
}
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java?rev=1146822&r1=1146821&r2=1146822&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java Thu Jul 14 18:00:02 2011
@@ -204,18 +204,6 @@ public class AnnotationDocument extends
}
/**
- * Call is forwarded to the set document.
- *
- * @param type
- * @param span
- * @return the annotations
- */
- @Deprecated
- public Collection<AnnotationFS> getAnnotation(Type type, Span span) {
- return mDocument.getAnnotation(type, span);
- }
-
- /**
* Wrap words at next space after lineLengthHint chars in a line.
* If the line is shorter than lineLengthHint nothing happens.
* The space char is replaced with an line feed char.
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?rev=1146822&r1=1146821&r2=1146822&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java Thu Jul 14 18:00:02 2011
@@ -30,6 +30,12 @@ import java.util.Set;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASRuntimeException;
+import org.apache.uima.cas.ConstraintFactory;
+import org.apache.uima.cas.FSIndex;
+import org.apache.uima.cas.FSIntConstraint;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FSMatchConstraint;
+import org.apache.uima.cas.FeaturePath;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.TypeSystem;
import org.apache.uima.cas.text.AnnotationFS;
@@ -51,6 +57,7 @@ import org.apache.uima.caseditor.editor.
import org.apache.uima.caseditor.editor.util.AnnotationSelection;
import org.apache.uima.caseditor.editor.util.FeatureStructureTransfer;
import org.apache.uima.caseditor.editor.util.Span;
+import org.apache.uima.caseditor.editor.util.StrictTypeConstraint;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.Action;
@@ -166,7 +173,7 @@ public final class AnnotationEditor exte
// get old annotations of current type for this area
// if there is something ... the delete them and add
- Collection<AnnotationFS> oldAnnotations = getDocument().getAnnotation(
+ Collection<AnnotationFS> oldAnnotations = getAnnotation(getDocument().getCAS(),
getAnnotationMode(), new Span(selection.x, selection.y));
if (!oldAnnotations.isEmpty()) {
@@ -1141,7 +1148,7 @@ public final class AnnotationEditor exte
Span selecectedSpan = new Span(selectedText.x, selectedText.y);
- Collection<AnnotationFS> selectedAnnotations = getDocument().getAnnotation(
+ Collection<AnnotationFS> selectedAnnotations = getAnnotation(getDocument().getCAS(),
getAnnotationMode(), selecectedSpan);
for (AnnotationFS annotation : selectedAnnotations) {
@@ -1536,4 +1543,42 @@ public final class AnnotationEditor exte
return super.createStatusControl(parent, status);
}
}
+
+ /**
+ * Retrieves the annotations in the given span.
+ */
+ static Collection<AnnotationFS> getAnnotation(CAS cas, Type type, Span span) {
+ ConstraintFactory cf = cas.getConstraintFactory();
+
+ Type annotationType = cas.getAnnotationType();
+
+ FeaturePath beginPath = cas.createFeaturePath();
+ beginPath.addFeature(annotationType.getFeatureByBaseName("begin"));
+ FSIntConstraint beginConstraint = cf.createIntConstraint();
+ beginConstraint.geq(span.getStart());
+
+ FSMatchConstraint embeddedBegin = cf.embedConstraint(beginPath, beginConstraint);
+
+ FeaturePath endPath = cas.createFeaturePath();
+ endPath.addFeature(annotationType.getFeatureByBaseName("end"));
+ FSIntConstraint endConstraint = cf.createIntConstraint();
+ endConstraint.leq(span.getEnd());
+
+ FSMatchConstraint embeddedEnd = cf.embedConstraint(endPath, endConstraint);
+
+ FSMatchConstraint strictType = new StrictTypeConstraint(type);
+
+ FSMatchConstraint annotatioInSpanConstraint = cf.and(embeddedBegin, embeddedEnd);
+
+ FSMatchConstraint annotationInSpanAndStrictTypeConstraint =
+ cf.and(annotatioInSpanConstraint, strictType);
+
+ FSIndex<AnnotationFS> allAnnotations = cas.getAnnotationIndex(type);
+
+ FSIterator<AnnotationFS> annotationInsideSpanIndex =
+ cas.createFilteredIterator(allAnnotations.iterator(),
+ annotationInSpanAndStrictTypeConstraint);
+
+ return DocumentUimaImpl.fsIteratorToCollection(annotationInsideSpanIndex);
+ }
}
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java?rev=1146822&r1=1146821&r2=1146822&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java Thu Jul 14 18:00:02 2011
@@ -182,7 +182,7 @@ public class DocumentUimaImpl extends Ab
return fsIteratorToCollection(strictTypeIterator);
}
- private Collection<AnnotationFS> fsIteratorToCollection(FSIterator<AnnotationFS> iterator) {
+ static Collection<AnnotationFS> fsIteratorToCollection(FSIterator<AnnotationFS> iterator) {
LinkedList<AnnotationFS> annotations = new LinkedList<AnnotationFS>();
while (iterator.hasNext()) {
AnnotationFS annotation = (AnnotationFS) iterator.next();
@@ -194,45 +194,6 @@ public class DocumentUimaImpl extends Ab
}
/**
- * Retrieves the annotations in the given span.
- */
- @Override
- public Collection<AnnotationFS> getAnnotation(Type type, Span span) {
- ConstraintFactory cf = getCAS().getConstraintFactory();
-
- Type annotationType = getCAS().getAnnotationType();
-
- FeaturePath beginPath = getCAS().createFeaturePath();
- beginPath.addFeature(annotationType.getFeatureByBaseName("begin"));
- FSIntConstraint beginConstraint = cf.createIntConstraint();
- beginConstraint.geq(span.getStart());
-
- FSMatchConstraint embeddedBegin = cf.embedConstraint(beginPath, beginConstraint);
-
- FeaturePath endPath = getCAS().createFeaturePath();
- endPath.addFeature(annotationType.getFeatureByBaseName("end"));
- FSIntConstraint endConstraint = cf.createIntConstraint();
- endConstraint.leq(span.getEnd());
-
- FSMatchConstraint embeddedEnd = cf.embedConstraint(endPath, endConstraint);
-
- FSMatchConstraint strictType = new StrictTypeConstraint(type);
-
- FSMatchConstraint annotatioInSpanConstraint = cf.and(embeddedBegin, embeddedEnd);
-
- FSMatchConstraint annotationInSpanAndStrictTypeConstraint =
- cf.and(annotatioInSpanConstraint, strictType);
-
- FSIndex<AnnotationFS> allAnnotations = getCAS().getAnnotationIndex(type);
-
- FSIterator<AnnotationFS> annotationInsideSpanIndex =
- getCAS().createFilteredIterator(allAnnotations.iterator(),
- annotationInSpanAndStrictTypeConstraint);
-
- return fsIteratorToCollection(annotationInsideSpanIndex);
- }
-
- /**
* Retrieves the given type from the {@link TypeSystem}.
*/
public Type getType(String type) {
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasDocument.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasDocument.java?rev=1146822&r1=1146821&r2=1146822&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasDocument.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/ICasDocument.java Thu Jul 14 18:00:02 2011
@@ -140,19 +140,6 @@ public interface ICasDocument {
void switchView(String viewName);
/**
- * Retrieves the annotations of the given type inside the given span.
- *
- * @param type
- * @param span
- * @return the annotations
- *
- * @deprecated add new method to retrieve feature structures,
- * until then get the annotation from the CAS
- */
- @Deprecated
- Collection<AnnotationFS> getAnnotation(Type type, Span span);
-
- /**
* Retrieves the requested type.
*
* @param type