[Mmil-commits] r33 - trunk/src/fr/loria/led/mmil

alexandredenis at users.gforge.inria.fr alexandredenis at users.gforge.inria.fr
Mar 6 Mai 10:27:44 CEST 2008


Author: alexandredenis
Date: 2008-05-06 10:27:42 +0200 (Tue, 06 May 2008)
New Revision: 33

Added:
   trunk/src/fr/loria/led/mmil/MMILDirectedIterator.java
Log:
Added MMILDirectedIterator


Added: trunk/src/fr/loria/led/mmil/MMILDirectedIterator.java
===================================================================
--- trunk/src/fr/loria/led/mmil/MMILDirectedIterator.java	2008-05-06 08:20:39 UTC (rev 32)
+++ trunk/src/fr/loria/led/mmil/MMILDirectedIterator.java	2008-05-06 08:27:42 UTC (rev 33)
@@ -0,0 +1,87 @@
+package fr.loria.led.mmil;
+
+import java.util.*;
+
+/**
+    An iterator over a mmil component which iterates through the entities in their order along the utterance.
+    It takes care of the relation direction for adding entities : entities which are modified by successor entities
+    are placed BEFORE the modified entity.
+*/
+public class MMILDirectedIterator implements Iterator
+{
+    private int marker;
+    private MMILComponent mmil;
+    private List<MMILEntity> entities;
+   
+    /**
+        Create a postfix iterator on a mmil component.
+    */
+    public MMILDirectedIterator(MMILComponent mmil)
+    {
+        marker = 0;
+        this.mmil = mmil;
+        entities = new ArrayList<MMILEntity>();       
+
+        mmil.sortEntities();
+
+        MMILEntity entity = null;
+        while((entity = firstNotInsertedEntity()) != null)
+        {
+            entities.add(entity);
+            addSub(entity);
+        }
+    }
+
+    public boolean hasNext()
+    {
+        return marker<entities.size();
+    }
+
+    public Object next()
+    {
+        if (marker>=entities.size())
+            return null;
+        else return entities.get(marker++);
+    }
+
+    public void remove()
+    {
+        entities.remove(marker);
+    }
+    
+    /**
+        Return the first not yet inserted entity.
+        @return null if there is none
+    */
+    private MMILEntity firstNotInsertedEntity()
+    {
+        for(MMILEntity entity : mmil.getEntities())
+            if (!entities.contains(entity))
+                return entity;
+        return null;
+    }
+
+
+    /**
+        Insert all the entities that are situated after this entity before this entity if they modify it.
+    */
+    private void addSub(MMILEntity entity)
+    {
+        for(MMILRelation rel : mmil.getRelationsByEntityTarget(entity))
+            if (rel.isModifierDirected() && !rel.sourceNull() && rel.getSource().getIndex() > entity.getIndex())
+            {
+                int index = entities.indexOf(entity);
+                entities.add(index, rel.getSource());
+                addSub(rel.getSource());
+            }
+
+       for(MMILRelation rel : mmil.getRelationsByEntitySource(entity))
+            if (!rel.isModifierDirected() && !rel.targetNull() && rel.getTarget().getIndex() > entity.getIndex())
+            {
+                int index = entities.indexOf(entity);
+                entities.add(index, rel.getTarget());
+                addSub(rel.getTarget());
+            }
+    }
+}
+






Plus d'informations sur la liste de diffusion Mmil-commits