You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2011/07/19 20:28:11 UTC

svn commit: r1148473 - in /incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder: Entity.java EntityContentProvider.java EntityLabelProvider.java NameFinderViewPage.java

Author: joern
Date: Tue Jul 19 18:28:11 2011
New Revision: 1148473

URL: http://svn.apache.org/viewvc?rev=1148473&view=rev
Log:
OPENNLP-235 Added columns to the table viewer and it shows now a sample entity

Added:
    incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/Entity.java   (with props)
    incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java   (with props)
    incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityLabelProvider.java   (with props)
Modified:
    incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java

Added: incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/Entity.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/Entity.java?rev=1148473&view=auto
==============================================================================
--- incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/Entity.java (added)
+++ incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/Entity.java Tue Jul 19 18:28:11 2011
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.opennlp.caseditor.namefinder;
+
+public class Entity {
+  
+  private final int beginIndex;
+  private final int endIndex;
+  
+  private final String entityText;
+ 
+  private Double confidence;
+  
+  Entity(int beginIndex, int endIndex, String entityText, Double confidence) {
+    this.beginIndex = beginIndex;
+    this.endIndex = endIndex;
+    
+    this.entityText = entityText;
+    
+    this.confidence = confidence;
+  }
+  
+  int getBeginIndex() {
+    return beginIndex;
+  }
+  
+  int getEndIndex() {
+    return endIndex;
+  }
+  
+  String getEntityText() {
+    return entityText;
+  }
+  
+  void setConfidence(Double confidence) {
+    this.confidence = confidence;
+  }
+  
+  Double getConfidence() {
+    return confidence;
+  }
+  
+  @Override
+  public String toString() {
+    return entityText;
+  }
+}
\ No newline at end of file

Propchange: incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/Entity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java?rev=1148473&view=auto
==============================================================================
--- incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java (added)
+++ incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java Tue Jul 19 18:28:11 2011
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.opennlp.caseditor.namefinder;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+
+public class EntityContentProvider implements IStructuredContentProvider {
+
+  private TableViewer entityList;
+  
+  EntityContentProvider(TableViewer entityList) {
+    this.entityList = entityList;
+  }
+  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+  }
+  
+  public Object[] getElements(Object inputElement) {
+    // return test element
+    return new Entity[] {new Entity(0, 5, "test", 0d)};
+  }
+  
+  public void dispose() {
+  }
+}

Propchange: incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityLabelProvider.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityLabelProvider.java?rev=1148473&view=auto
==============================================================================
--- incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityLabelProvider.java (added)
+++ incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityLabelProvider.java Tue Jul 19 18:28:11 2011
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.opennlp.caseditor.namefinder;
+
+import java.text.DecimalFormat;
+
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+public class EntityLabelProvider implements ITableLabelProvider {
+
+  private DecimalFormat df = new DecimalFormat("#.#");
+  
+  public void addListener(ILabelProviderListener listener) {
+  }
+
+  public void removeListener(ILabelProviderListener listener) {
+  }
+
+  public boolean isLabelProperty(Object element, String property) {
+    return false;
+  }
+
+  public Image getColumnImage(Object element, int columnIndex) {
+    return null;
+  }
+
+  public String getColumnText(Object element, int columnIndex) {
+    String result = null;
+    
+    Entity entity = (Entity) element;
+    
+    if (columnIndex == 0) {
+      if (entity.getConfidence() != null)
+        result = df.format(entity.getConfidence() * 100);
+      else
+        result = "";
+    }
+    else if (columnIndex == 1) {
+      result = entity.getEntityText();
+    }
+    
+    return result;
+  }
+
+  public void dispose() {
+  }
+}

Propchange: incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityLabelProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java?rev=1148473&r1=1148472&r2=1148473&view=diff
==============================================================================
--- incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java (original)
+++ incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java Tue Jul 19 18:28:11 2011
@@ -21,9 +21,12 @@ import org.apache.uima.caseditor.editor.
 import org.apache.uima.caseditor.editor.ICasEditor;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.part.Page;
@@ -40,6 +43,26 @@ class NameFinderViewPage extends Page im
 
   public void createControl(Composite parent) {
     entityList = new TableViewer(parent, SWT.NONE);
+    
+    Table entityTable = entityList.getTable();
+    entityTable.setHeaderVisible(true);
+    entityTable.setLinesVisible(true);
+    
+    TableViewerColumn confidenceViewerColumn = new TableViewerColumn(entityList, SWT.NONE);
+    TableColumn confidenceColumn = confidenceViewerColumn.getColumn();
+    confidenceColumn.setText("%");
+    confidenceColumn.setWidth(40);
+    
+    TableViewerColumn entityViewerColumn = new TableViewerColumn(entityList, SWT.NONE);
+    TableColumn entityColumn = entityViewerColumn.getColumn();
+    entityColumn.setText("Entity");
+    entityColumn.setWidth(135);
+    
+    entityList.setLabelProvider(new EntityLabelProvider());
+    entityList.setContentProvider(new EntityContentProvider(entityList));
+    getSite().setSelectionProvider(entityList);
+    
+    entityList.setInput(editor.getDocument());
   }
 
   public void selectionChanged(IWorkbenchPart part, ISelection selection) {
@@ -52,5 +75,4 @@ class NameFinderViewPage extends Page im
   public void setFocus() {
     entityList.getControl().setFocus();
   }
-
 }