Commits

Slavko Zitnik  committed 16a8f71

Started iterative IE

  • Participants
  • Parent commits 0e46663

Comments (0)

Files changed (5)

 
 Run IOBIE:
 
-    ./assembly/../IOBIE.sh
+    ./assembly/IOBIE-1.0-SNAPSHOT-distribution/IOBIE.sh

File src/main/java/si/zitnik/research/iobie/core/collective/test/CollectiveTest.scala

 import si.zitnik.research.iobie.thirdparty.lemmagen.api.LemmaTagger
 import si.zitnik.research.iobie.domain.sampling.{ExactSampler, RandomSampler}
 import scala.collection.JavaConversions._
+import si.zitnik.research.iobie.gui.examples.ExamplesVisualizer
 
 /**
  * Created with IntelliJ IDEA.
     ACE2004Data.reloadCullota()
     val data = ACE2004Data.importTrainData()
     data.printStatistics(
-      ommitedMentionAttributes = Array(Label.OBS, Label.EXTENT, Label.COREF)
+      ommitedMentionAttributes = Array(Label.OBS, Label.EXTENT, Label.COREF, Label.ID)
     )
 
+    ExamplesVisualizer.run(data)
+
 
   }
 
 
     def reload() {
       val rawData = new ACE2004Importer(datasetPath, documentTypes = sources).importForIE()
-      //new PoSTagger().tag(rawData)
-      //new LemmaTagger().tag(rawData)
-      //new ParseTagger().tag(rawData)
+      new PoSTagger().tag(rawData)
+      new LemmaTagger().tag(rawData)
+      new ParseTagger().tag(rawData)
 
       data = RandomSampler.sample(rawData, randomSeed = 42)
     }
 
     def reloadCullota() {
       val rawData = new ACE2004Importer(datasetPath, documentTypes = sources).importForIE()
-      //new PoSTagger().tag(rawData)
-      //new LemmaTagger().tag(rawData)
-      //new ParseTagger().tag(rawData)
+      new PoSTagger().tag(rawData)
+      new LemmaTagger().tag(rawData)
+      new ParseTagger().tag(rawData)
 
       //Cullota split:
       data = ExactSampler.sampleNumber(rawData, 336)

File src/main/java/si/zitnik/research/iobie/gui/examples/ExamplesVisualizer.scala

+package si.zitnik.research.iobie.gui.examples
+
+import javafx.fxml.FXMLLoader
+import javafx.scene.{Scene, Parent}
+import si.zitnik.research.iobie.gui.coref.CorefVisualizerController
+import si.zitnik.research.iobie.domain.Examples
+import scala.collection.mutable.{HashSet, ArrayBuffer}
+import si.zitnik.research.iobie.domain.cluster.Cluster
+import javafx.embed.swing.JFXPanel
+import javafx.application.Platform
+import javafx.stage.Stage
+import si.zitnik.research.iobie.collective.test.CollectiveTest.ACE2004Data
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: slavkoz
+ * Date: 28/11/13
+ * Time: 11:21
+ * To change this template use File | Settings | File Templates.
+ */
+class ExamplesVisualizer(val examples: Examples) extends Stage {
+  val loader = new FXMLLoader(this.getClass.getClassLoader.getResource("gui/examplesView.fxml"))
+  val root = loader.load().asInstanceOf[Parent]
+  loader.getController.asInstanceOf[ExamplesVisualizerController].initListView(examples)
+  this.setTitle("Examples Visualizer")
+  this.setScene(new Scene(root))
+  this.show()
+}
+
+object ExamplesVisualizer {
+  def run(examples: Examples) {
+    //TODO: NASTY HACK (just to pass parameters to visualizer :)) - rather use application
+
+    new JFXPanel()
+    Platform.runLater(new Runnable() {
+      @Override
+      def run() {
+        new ExamplesVisualizer(examples)
+      }
+    })
+
+  }
+}
+

File src/main/java/si/zitnik/research/iobie/gui/examples/ExamplesVisualizerController.scala

+package si.zitnik.research.iobie.gui.examples
+
+import javafx.fxml.FXML
+import javafx.scene.control._
+import si.zitnik.research.iobie.domain.{Examples, Example}
+import javafx.collections.FXCollections
+import javafx.util.Callback
+import si.zitnik.research.iobie.algorithms.crf.{Label, ExampleLabel}
+import scala.collection.JavaConversions._
+import java.net.URL
+import java.util.ResourceBundle
+import javafx.scene.input.MouseEvent
+import scala.collection.mutable.ArrayBuffer
+import java.util
+import javafx.scene.control.TableColumn.CellDataFeatures
+import javafx.beans.value.ObservableValue
+import javafx.beans.property.SimpleStringProperty
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: slavkoz
+ * Date: 28/11/13
+ * Time: 12:06
+ * To change this template use File | Settings | File Templates.
+ */
+class ExamplesVisualizerController {
+  @FXML private var fxExamples: ListView[Example] = null
+  @FXML private var fxTokenExample: TableView[Label.Value] = null
+  @FXML private var fxMentionExample: TableView[String] = null
+  @FXML private var fxRelationExample: TableView[String] = null
+
+  def initialize(p1: URL, p2: ResourceBundle) {
+    //default method
+  }
+
+
+  def initListView(examples: Examples) {
+    fxExamples.getSelectionModel().setSelectionMode(SelectionMode.SINGLE)
+    val observableList = FXCollections.observableArrayList[Example](examples)
+    fxExamples.setItems(observableList)
+
+
+    fxExamples.setCellFactory(new Callback[ListView[Example], ListCell[Example]]() {
+      override def call(list: ListView[Example]): ListCell[Example] = {
+        new ListCell[Example]() {
+          override def updateItem(item: Example, empty: Boolean) {
+            super.updateItem(item, empty)
+            if (!empty) {
+              setText(item.get(ExampleLabel.DOC_ID).toString + " - " + item.getLabeling(Label.OBS).mkString(" "))
+            }
+
+          }
+        }
+      }
+    })
+  }
+
+
+  def docIDSelected(event: MouseEvent) {
+    if (fxExamples.getSelectionModel().getSelectedIndex >= 0) {
+      updateTokens()
+      updateMentions()
+      updateRelationships()
+    }
+  }
+
+  def updateRelationships() {
+    val exampleRelationships = fxExamples.getSelectionModel().getSelectedItem()
+    val relationships = exampleRelationships.getAllRelationships()
+
+    val columns = ArrayBuffer(new TableColumn[String, String]("OBS")) ++ relationships.map(v => new TableColumn[String, String](v.relationshipName))
+
+    val keys = relationships.map(_.keySet()).flatten.toSet.-(Label.OBS).toList
+
+    //TODO: add start idx & end idx
+    val items = new util.ArrayList[String]()
+    for (key <- keys) {
+      items.add(key.toString)
+    }
+    items.add("_SUBJ")
+    items.add("_OBJ")
+    items.add("_REL_NAME")
+
+
+    fxRelationExample.getItems.clear()
+    fxRelationExample.getColumns.clear()
+    fxRelationExample.getColumns.addAll(columns)
+    fxRelationExample.getItems.addAll(items)
+
+    for ((fxColumn, idx) <- fxRelationExample.getColumns.zipWithIndex) {
+      fxColumn.asInstanceOf[TableColumn[String, String]].setCellFactory(new Callback[TableColumn[String, String], TableCell[String, String]]() {
+        override
+        def call(p1: TableColumn[String, String]): TableCell[String, String] = {
+          new TableCell[String, String]() {
+            override
+            def updateItem(item: String, empty: Boolean) {
+              super.updateItem(item, empty)
+              if (! empty ) {
+                if (idx == 0) {
+                  setText(item.toString)
+                } else {
+                  item.toString match {
+                    case "_SUBJ" => setText(relationships.get(idx-1).subj.toDetailString())
+                    case "_OBJ" => setText(relationships.get(idx-1).obj.toDetailString())
+                    case "_REL_NAME" => setText(relationships.get(idx-1).relationshipName)
+                    case _ => setText(relationships.get(idx-1).get(Label.withName(item.toString)).toString)
+                  }
+                }
+              }
+            }
+          }
+        }
+      })
+      //transform values
+      fxColumn.asInstanceOf[TableColumn[String, String]].setCellValueFactory(new Callback[CellDataFeatures[String, String], ObservableValue[String]]() {
+        override
+        def call(p: CellDataFeatures[String, String]): ObservableValue[String] = {
+          return new SimpleStringProperty(p.getValue.toString)
+        }
+      })
+    }
+  }
+  
+  def updateMentions() {
+    val exampleMentions = fxExamples.getSelectionModel().getSelectedItem()
+    val mentions = exampleMentions.getAllMentions()
+
+    val columns = ArrayBuffer(new TableColumn[String, String]("OBS")) ++ mentions.map(v => new TableColumn[String, String](v.get(Label.OBS).asInstanceOf[String]))
+
+    val keys = mentions.map(_.keySet()).flatten.toSet.-(Label.OBS).toList
+
+    //TODO: add start idx & end idx
+    val items = new util.ArrayList[String]()
+    for (key <- keys) {
+      items.add(key.toString)
+    }
+    items.add("_START_IDX")
+    items.add("_END_IDX")
+    items.add("_CLUSTER_IDX")
+
+
+    fxMentionExample.getItems.clear()
+    fxMentionExample.getColumns.clear()
+    fxMentionExample.getColumns.addAll(columns)
+    fxMentionExample.getItems.addAll(items)
+
+    for ((fxColumn, idx) <- fxMentionExample.getColumns.zipWithIndex) {
+      fxColumn.asInstanceOf[TableColumn[String, String]].setCellFactory(new Callback[TableColumn[String, String], TableCell[String, String]]() {
+        override
+        def call(p1: TableColumn[String, String]): TableCell[String, String] = {
+          new TableCell[String, String]() {
+            override
+            def updateItem(item: String, empty: Boolean) {
+              super.updateItem(item, empty)
+              if (! empty ) {
+                if (idx == 0) {
+                  setText(item.toString)
+                } else {
+                  item.toString match {
+                    case "_START_IDX" => setText(mentions.get(idx-1).startIdx.toString)
+                    case "_END_IDX" => setText(mentions.get(idx-1).endIdx.toString)
+                    case "_CLUSTER_IDX" => if (mentions.get(idx-1).cluster != null) setText(mentions.get(idx-1).cluster.toString) else setText("NULL")
+                    case _ => setText(mentions.get(idx-1).get(Label.withName(item.toString)).toString)
+                  }
+                }
+              }
+            }
+          }
+        }
+      })
+      //transform values
+      fxColumn.asInstanceOf[TableColumn[String, String]].setCellValueFactory(new Callback[CellDataFeatures[String, String], ObservableValue[String]]() {
+        override
+        def call(p: CellDataFeatures[String, String]): ObservableValue[String] = {
+          return new SimpleStringProperty(p.getValue.toString)
+        }
+      })
+    }
+  }
+
+
+  def updateTokens() {
+    val example = fxExamples.getSelectionModel().getSelectedItem()
+
+    val columns = ArrayBuffer(new TableColumn[Label.Value, String]("OBS")) ++ example.map(v => new TableColumn[Label.Value, String](v.get(Label.OBS).asInstanceOf[String]))
+
+    val keys = example.map(_.keySet()).flatten.toSet.-(Label.OBS).toList
+
+    val items = new util.ArrayList[Label.Value]()
+    for (key <- keys) {
+      items.add(key)
+    }
+
+
+    fxTokenExample.getItems.clear()
+    fxTokenExample.getColumns.clear()
+    fxTokenExample.getColumns.addAll(columns)
+    fxTokenExample.getItems.addAll(items)
+
+    for ((fxColumn, idx) <- fxTokenExample.getColumns.zipWithIndex) {
+      fxColumn.asInstanceOf[TableColumn[Label.Value, String]].setCellFactory(new Callback[TableColumn[Label.Value, String], TableCell[Label.Value, String]]() {
+        override
+        def call(p1: TableColumn[Label.Value, String]): TableCell[Label.Value, String] = {
+          new TableCell[Label.Value, String]() {
+            override
+            def updateItem(item: String, empty: Boolean) {
+              super.updateItem(item, empty)
+              if (! empty ) {
+                if (idx == 0) {
+                  setText(item.toString)
+                } else {
+                  setText(example.get(idx-1, Label.withName(item.toString)).toString)
+                }
+              }
+            }
+          }
+        }
+      })
+      //transform values
+      fxColumn.asInstanceOf[TableColumn[Label.Value, String]].setCellValueFactory(new Callback[CellDataFeatures[Label.Value, String], ObservableValue[String]]() {
+        override
+        def call(p: CellDataFeatures[Label.Value, String]): ObservableValue[String] = {
+          return new SimpleStringProperty(p.getValue.toString)
+        }
+      })
+    }
+  }
+
+}

File src/main/resources/gui/examplesView.fxml

+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import java.lang.*?>
+<?import javafx.scene.control.*?>
+<?import javafx.scene.layout.*?>
+
+<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="si.zitnik.research.iobie.gui.examples.ExamplesVisualizerController">
+<children><SplitPane dividerPositions="0.2562814070351759" focusTraversable="true" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
+  <items>
+    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
+<children><ListView fx:id="fxExamples" layoutX="27.861785888671875" layoutY="-57.28960418701172" onMouseClicked="#docIDSelected" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
+</children></AnchorPane>
+    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
+<children><Accordion AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns:fx="http://javafx.com/fxml">
+  <panes>
+    <TitledPane animated="false" text="Tokens">
+      <content>
+        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
+<children><TableView fx:id="fxTokenExample" layoutX="147.93136596679688" layoutY="25.39117431640625" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns:fx="http://javafx.com/fxml" />
+</children></AnchorPane>
+      </content>
+    </TitledPane>
+    <TitledPane animated="false" text="Mentions">
+      <content>
+        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
+            <children><TableView fx:id="fxMentionExample" layoutX="147.93136596679688" layoutY="25.39117431640625" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns:fx="http://javafx.com/fxml" />
+            </children></AnchorPane>
+      </content>
+    </TitledPane>
+    <TitledPane animated="false" text="Relationships">
+      <content>
+        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
+            <children><TableView fx:id="fxRelationExample" layoutX="147.93136596679688" layoutY="25.39117431640625" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns:fx="http://javafx.com/fxml" />
+            </children></AnchorPane>
+      </content>
+    </TitledPane>
+  </panes>
+</Accordion>
+</children></AnchorPane>
+  </items>
+</SplitPane>
+</children></AnchorPane>