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

alexandredenis at users.gforge.inria.fr alexandredenis at users.gforge.inria.fr
Mar 6 Mai 17:38:30 CEST 2008


Author: alexandredenis
Date: 2008-05-06 17:38:28 +0200 (Tue, 06 May 2008)
New Revision: 34

Modified:
   trunk/src/fr/loria/led/mmil/MMILComponent.java
Log:
Improved the copy constructor by distinguishing internal entities from external entities.


Modified: trunk/src/fr/loria/led/mmil/MMILComponent.java
===================================================================
--- trunk/src/fr/loria/led/mmil/MMILComponent.java	2008-05-06 08:27:42 UTC (rev 33)
+++ trunk/src/fr/loria/led/mmil/MMILComponent.java	2008-05-06 15:38:28 UTC (rev 34)
@@ -135,9 +135,16 @@
 
     /**
         Copy constructor.
+        If includeExtern is true, include a copy of all the relations whose source or
+        target is external to the given component plus a copy of all entities that are
+        external, if false, include neither. This serious problem is caused
+        because we don't check if entities are inside a component when adding
+        relations, as such authorizing cross-components relations. It should be
+        fixed in further releases.
         @param mmil - the component to copy
+        @param excludeExtern - see above.
     */
-	public MMILComponent(MMILComponent mmil)
+	public MMILComponent(MMILComponent mmil, boolean includeExtern)
 	{
 		entities  = new ArrayList<MMILEntity>();
         relations = new ArrayList<MMILRelation>();
@@ -163,30 +170,39 @@
             if (sourceOrigin==null || targetOrigin==null)
                 continue;
             
-            // make sure that the source and target are in the component
-            if (added.contains(sourceOrigin.getId()))
-                source = getEntity(sourceOrigin.getId());
-            else 
+            if (includeExtern)
             {
-                if (sourceOrigin.getMMILType().equals("participant"))
-                    source = new MMILParticipant((MMILParticipant)sourceOrigin);
-                else source = new MMILEvent((MMILEvent)sourceOrigin);
-                entities.add(source);
-                added.add(source.getId());
+                // make sure that the source and target are in the component
+                if (added.contains(sourceOrigin.getId()))
+                    source = getEntity(sourceOrigin.getId());
+                else 
+                {
+                    if (sourceOrigin.getMMILType().equals("participant"))
+                        source = new MMILParticipant((MMILParticipant)sourceOrigin);
+                    else source = new MMILEvent((MMILEvent)sourceOrigin);
+                    entities.add(source);
+                    added.add(source.getId());
+                }
+
+                if (added.contains(targetOrigin.getId()))
+                    target = getEntity(targetOrigin.getId());
+                else 
+                {
+                    if (targetOrigin.getMMILType().equals("participant"))
+                        target = new MMILParticipant((MMILParticipant)targetOrigin);
+                    else target = new MMILEvent((MMILEvent)targetOrigin);
+                    entities.add(target);
+                    added.add(target.getId());
+                }
+            
+                relations.add(new MMILRelation(rel.getType(), source, target, rel.isModifierDirected()));
             }
-
-            if (added.contains(targetOrigin.getId()))
+            else if (added.contains(sourceOrigin.getId()) && added.contains(targetOrigin.getId()))
+            {
+                source = getEntity(sourceOrigin.getId());
                 target = getEntity(targetOrigin.getId());
-            else 
-            {
-                if (targetOrigin.getMMILType().equals("participant"))
-                    target = new MMILParticipant((MMILParticipant)targetOrigin);
-                else target = new MMILEvent((MMILEvent)targetOrigin);
-                entities.add(target);
-                added.add(target.getId());
+                relations.add(new MMILRelation(rel.getType(), source, target, rel.isModifierDirected()));
             }
-
-            relations.add(new MMILRelation(rel.getType(), source, target, rel.isModifierDirected()));
         }
 
         left    = mmil.getLeft();
@@ -420,7 +436,7 @@
     */
     public MMILComponent reduceSimilarity()
     {
-        MMILComponent reduced = new MMILComponent(this);
+        MMILComponent reduced = new MMILComponent(this,false);
 
         for(MMILRelation similar : reduced.getRelations("similar"))
         {






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