You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by al...@apache.org on 2007/01/02 20:42:09 UTC
svn commit: r491908 - in
/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer:
CasAnnotationViewer.java EntityResolver.java
Author: alally
Date: Tue Jan 2 11:42:08 2007
New Revision: 491908
URL: http://svn.apache.org/viewvc?view=rev&rev=491908
Log:
Improved the DocumentAnalyzer's interface for user-defined entity
resolver, so it can return unequal entities with the same
canonical form.
Modified:
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/EntityResolver.java
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java?view=diff&rev=491908&r1=491907&r2=491908
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java Tue Jan 2 11:42:08 2007
@@ -214,7 +214,7 @@
private Set mHiddenFeatureNames = new HashSet();
- private boolean mEntityViewEnabled;
+ private boolean mEntityViewEnabled = false;
private short mViewMode = MODE_ANNOTATIONS;
@@ -1002,25 +1002,25 @@
iter.moveToNext();
// find out what entity this annotation represents
- String entityCanonicalForm = mEntityResolver.getCanonicalForm(annot);
+ EntityResolver.Entity entity = mEntityResolver.getEntity(annot);
//if not an entity, skip it
- if (entityCanonicalForm == null)
+ if (entity == null)
continue;
// have we seen this entity before?
- JCheckBox checkbox = (JCheckBox) mEntityToCheckboxMap.get(entityCanonicalForm);
+ JCheckBox checkbox = (JCheckBox) mEntityToCheckboxMap.get(entity);
if (checkbox == null) {
// assign next available color
Color c = COLORS[mEntityToCheckboxMap.size() % COLORS.length];
// add checkbox
- checkbox = new JCheckBox(entityCanonicalForm, true);
- checkbox.setToolTipText(entityCanonicalForm);
+ checkbox = new JCheckBox(entity.getCanonicalForm(), true);
+ checkbox.setToolTipText(entity.getCanonicalForm());
checkbox.addActionListener(this);
checkbox.setBackground(c);
entityCheckboxPanel.add(checkbox);
// add to (Entity, Checkbox) map
- mEntityToCheckboxMap.put(entityCanonicalForm, checkbox);
+ mEntityToCheckboxMap.put(entity, checkbox);
}
// if checkbox is checked, assign color to text
@@ -1709,15 +1709,33 @@
/**
* Trivial entity resolver that's applied if the user turns on entity mode without
- * specifying their own entity resolver. Returns the covered text as the canonical form.
+ * specifying their own entity resolver. Returns the covered text as the canonical form,
+ * and treats annotations with equal covered text as belonging to the same entity.
*/
static class DefaultEntityResolver implements EntityResolver {
/* (non-Javadoc)
* @see org.apache.uima.tools.viewer.EntityResolver#getCanonicalForm(org.apache.uima.jcas.tcas.Annotation)
*/
- public String getCanonicalForm(Annotation aAnnotation) {
- return aAnnotation.getCoveredText();
+ public Entity getEntity(final Annotation aAnnotation) {
+ return new Entity() {
+
+ public String getCanonicalForm() {
+ return aAnnotation.getCoveredText();
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof Entity) {
+ String canon = ((Entity)obj).getCanonicalForm();
+ return getCanonicalForm().equals(canon);
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ return getCanonicalForm().hashCode();
+ }
+ };
}
}
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/EntityResolver.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/EntityResolver.java?view=diff&rev=491908&r1=491907&r2=491908
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/EntityResolver.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/EntityResolver.java Tue Jan 2 11:42:08 2007
@@ -22,27 +22,45 @@
/**
* Pluggable interface that supports Entity View mode in the CasAnnotationViewer. Users implement
- * this interface with logic that for their particular type system can return the canonical form of
- * an annotation in the CAS.
+ * this interface with logic that for their particular type system can determine which Entity an
+ * Annotation refers to.
* <p>
- * In the viewer, all annotations whose canonical form strings are <code>equal</code> will be
- * displayed in the same color, and the canonical form will be shown in the legend.
+ * In the viewer, all annotations whose Entity objects are <code>equal</code> will be
+ * displayed in the same color, and the Entity's canonical form will be shown in the legend.
*/
public interface EntityResolver {
-
+
/**
- * Returns the canonical form String for an annotation.
- * <p>
- * For two annotations that refer to the same Entity, this should return canonical form strings that
- * are <code>equal</code>.
+ * Returns the <code>Entity</code> to which an annotation refers.
+ * Returns the canonical form String for an annotation.
+ * <p>
+ * For two annotations that refer to the same Entity, this should return <code>Entity</code>
+ * objects that are <code>equal</code>.
+ * <p>
+ * If the annotation does not represent an entity at all, <code>null</code> should be returned.
+ *
+ * @param aAnnotation the annotation to resolve
+ *
+ * @return the Entity to which the annotation refers, null if the annotation does not represent an
+ */
+ Entity getEntity(Annotation aAnnotation);
+
+ /**
+ * Object representing an Entity. Annotations whose <code>Entity</code> objects are <code>equal</code>
+ * will be displayed in the same color in the viewer.
* <p>
- * If the annotation does not represent an entity at all, <code>null</code> should be returned.
- *
- * @param aAnnotation
- * the annotation to resolve
- *
- * @return the canonical form of the annotation, null if the annotation does not represent an
- * entity
+ * This means that either the <code>EntityResolver</code>
+ * must return the identical (<code>==</code>) <code>Entity</code> object for annotations belonging to the
+ * same entity, or your <code>Entity</code> objects must implement {@link Object#equals(Object)} and
+ * {@link Object#hashCode()}.
+ *
*/
- String getCanonicalForm(Annotation aAnnotation);
+ public interface Entity {
+ /**
+ * Returns the canonical form String for an Entity. This string will be displayed in the legend.
+ *
+ * @return the canonical form of the entity
+ */
+ String getCanonicalForm();
+ }
}