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

alexandredenis at users.gforge.inria.fr alexandredenis at users.gforge.inria.fr
Mer 4 Oct 13:05:43 CEST 2006


Author: alexandredenis
Date: 2006-10-04 11:05:42 +0000 (Wed, 04 Oct 2006)
New Revision: 27

Modified:
   trunk/src/fr/loria/led/mmil/MMILComponent.java
   trunk/src/fr/loria/led/mmil/MMILEntity.java
   trunk/src/fr/loria/led/mmil/MMILRelation.java
   trunk/src/fr/loria/led/mmil/objects/MMILScene.java
Log:
Corrected a bug in remove methods

Modified: trunk/src/fr/loria/led/mmil/MMILComponent.java
===================================================================
--- trunk/src/fr/loria/led/mmil/MMILComponent.java	2006-10-04 08:48:21 UTC (rev 26)
+++ trunk/src/fr/loria/led/mmil/MMILComponent.java	2006-10-04 11:05:42 UTC (rev 27)
@@ -510,11 +510,9 @@
         Aggregate serially the entities of this component.
         It tries to unify the entities sorted along their left index, ie. the unification of each entity
         is tested with its successor. A synonyms list could be given to relax the constraints on the unification.
-        One can also indicates if the features of the successor should be preferred or not in the case of a synonymy.
         @param synonyms a list of synonyms lists considered as equivalent values for a feature
-        @param succPrior a boolean indicating if the features of the successor are preferred or not
     */
-    public void aggregateSerial(List<List<String>> synonyms, boolean succPrior)
+    public void aggregateSerial(List<List<String>> synonyms)
     {
         if (entities.size()<=1)
             return;
@@ -526,7 +524,7 @@
         
         for(int i=1; i<entities.size(); i++)
         {
-            MMILEntity unif = succPrior ? entities.get(i).unify(curEntity,synonyms) : curEntity.unify(entities.get(i),synonyms);
+            MMILEntity unif = entities.get(i).unify(curEntity,synonyms);
             if (unif==null)
             {
                 newEntities.add(curEntity);
@@ -546,12 +544,26 @@
 
     /**
         Aggregate the entities of this component serially.
-        Proceed to the aggregation without synonyms and a preference for successor features.
+        Proceed to the aggregation without synonyms.
     */
     public void aggregateSerial()
     {
-        aggregateSerial(new ArrayList<List<String>>(),true);
+        aggregateSerial(new ArrayList<List<String>>());
     }       
+    
+    
+    /**
+        Return the list of the mmilId feature of the given entities.
+        If the entity does not have a mmilId, the returned String will be empty.
+    */
+    public static List<String> getMMILIds(List<MMILEntity> entities)
+    {
+        List<String> ret = new ArrayList<String>();
+        for(MMILEntity e : entities)
+            ret.add(e.getValueOf("mmilId"));
+        return ret;
+    }
+ 
 
 
 /////////////////////
@@ -664,8 +676,54 @@
         return null;
     }
 
+    /**
+        Return all the entities which have the given feature.
+        @param featName  a name of a feature
+        @return an empty list if none is found
+    */
+    public List<MMILEntity> getEntitiesByFeature(String featName)
+    {
+        List<MMILEntity> ret = new ArrayList<MMILEntity>();
+        for(MMILEntity e : entities)
+            if (e.hasFeature(featName))
+                ret.add(e);
+        return ret;
+    }
 
+
     /**
+        Return all the entities which have the given feature.
+        @param featName  a name of a feature
+        @param featValue  a value of a feature
+        @return an empty list if none is found
+    */
+    public List<MMILEntity> getEntitiesByFeature(String featName, String featValue)
+    {
+        List<MMILEntity> ret = new ArrayList<MMILEntity>();
+        for(MMILEntity e : entities)
+            if (e.hasFeature(featName, featValue))
+                ret.add(e);
+        return ret;
+    }
+
+    
+    /**
+		Retrieve the entities which have the given type.
+        @param type the type (objType or evtType) of an entity
+		@return	entities in this component, empty list if not found.
+	*/
+	public List<MMILEntity> getEntitiesByType(String type)
+	{
+        List<MMILEntity> ret = new ArrayList<MMILEntity>();
+		for(MMILEntity entity : entities)
+			if (entity.getType().equalsIgnoreCase(type))
+				ret.add(entity);
+		return ret;
+	}
+
+
+
+    /**
         Retrieve all the connected entities to the given entity.
         @param entity - an entity
         @return the list of entities of this component which are related to the given entity or an empty list
@@ -927,6 +985,20 @@
 		return ret;
 	}
 
+    /**
+        Test if there exists a relation between the two entities without direction.
+        @param e1 an entity
+        @param e1 an entity
+        @return true if there is a relation between these entities.
+    */
+    public boolean hasLinkBetween(MMILEntity e1, MMILEntity e2)
+    {
+       	for(MMILRelation rel : relations)
+            if ((rel.getSource()==e1 && rel.getTarget()==e2) || (rel.getSource()==e2 && rel.getTarget()==e1))
+			return true;
+        
+        return false;
+    }       
 
     /**
         Return all the relations between entity source and entity target.

Modified: trunk/src/fr/loria/led/mmil/MMILEntity.java
===================================================================
--- trunk/src/fr/loria/led/mmil/MMILEntity.java	2006-10-04 08:48:21 UTC (rev 26)
+++ trunk/src/fr/loria/led/mmil/MMILEntity.java	2006-10-04 11:05:42 UTC (rev 27)
@@ -145,7 +145,6 @@
 			this.right = -1;
 		else this.right = Integer.parseInt(node.getAttribute("right"));
 
-
 		this.features = new ArrayList<MMILFeature>();
         this.subEntities = new ArrayList<MMILEntity>();
 
@@ -211,10 +210,6 @@
     }
 
 
-
-
- 
-
     /**
         Add all the features of the given entity to this entity and replace their value if they already exist.
         @param entity - any entity
@@ -484,9 +479,9 @@
     {
         for(MMILFeature feat : features)
 			if (feat.getName().equalsIgnoreCase(name))
-                if (feat.getValue().equals("true"))
+                if (feat.getValue().equalsIgnoreCase("true"))
                     return true;
-                else if (feat.getValue().equals("false"))
+                else if (feat.getValue().equalsIgnoreCase("false"))
                     return false;
                 else throw new UnexpectedMMILException("Feature "+name+" of entity "+this+" is not a boolean");
             
@@ -554,9 +549,9 @@
     {
         for(MMILFeature feat : features)
 			if (feat.getName().equalsIgnoreCase(name))
-                if (feat.getValue().equals("true"))
+                if (feat.getValue().equalsIgnoreCase("true"))
                     return true;
-                else if (feat.getValue().equals("false"))
+                else if (feat.getValue().equalsIgnoreCase("false"))
                     return false;
                 else throw new UnexpectedMMILException("Feature "+name+" of entity "+this+" is not a boolean");
             
@@ -832,15 +827,28 @@
     */
 	public void remove(String name)
 	{
-		for(MMILFeature feat : features)
-			if (feat.getName().equals(name))
-			{
-				features.remove(feat);
-				return;
-			}
+		for(Iterator<MMILFeature> it = features.iterator(); it.hasNext();)
+           	if (it.next().getName().equalsIgnoreCase(name))
+				it.remove();
 	}
 
+    
+    /**
+        Remove all the features which have the given name and value.
+        @param name a name of a feature
+        @param value a value of a feature
+    */
+	public void remove(String name, String value)
+	{
+		for(Iterator<MMILFeature> it = features.iterator(); it.hasNext();)
+        {
+            MMILFeature feat = it.next();
+           	if (feat.getName().equalsIgnoreCase(name) && feat.getValue().equalsIgnoreCase(value))
+				it.remove();
+        }
+	}
 
+
     /**
 		Returns all the values of a given feature's name.
         @param name - the name of a feature

Modified: trunk/src/fr/loria/led/mmil/MMILRelation.java
===================================================================
--- trunk/src/fr/loria/led/mmil/MMILRelation.java	2006-10-04 08:48:21 UTC (rev 26)
+++ trunk/src/fr/loria/led/mmil/MMILRelation.java	2006-10-04 11:05:42 UTC (rev 27)
@@ -9,10 +9,15 @@
 /**
     A MMILRelation links to entities.
     It has a given type (or called name sometimes) which links two entities in a component.
+    The scope of a relation is whether it is presupposed (part of the description of the entity itself) or
+    predicated (asserted by the component). Ex : The car of my friend versus The car belongs to my friend.
 */
 public class MMILRelation implements Serializable
 {
+	public enum MMILScope { PRESUPPOSED, PREDICATED }
+
 	private String type = "";
+    private MMILScope scope = MMILScope.PRESUPPOSED;
 	private MMILEntity source = null, target = null;
 
     /**
@@ -309,6 +314,52 @@
             (target!=null && relation.getTarget()!=null && !target.equals(relation.getTarget())))
             return false;
 
+        if (scope!=relation.getScope())
+            return false;
+
         return true;
     }
+    
+    /**
+        Set the scope of the relation.
+    */
+    public void setScope(String scp)
+    {
+        if (scp.equals("pres") || scp.equals(""))
+            scope = MMILScope.PRESUPPOSED;
+        else scope = MMILScope.PREDICATED;
+    }
+
+    /**
+        Set the scope of the relation.
+    */
+    public void setScope(MMILScope scope)
+    {
+        this.scope = scope;
+    }
+
+    /**
+        Get the scope of the relation.
+    */
+    public MMILScope getScope()
+    {
+        return scope;
+    }
+
+
+    /**
+        Test if this relation is presupposed.
+    */
+    public boolean isPresupposed()
+    {
+        return scope == MMILScope.PRESUPPOSED;
+    }
+
+    /**
+        Test if this relation is predicated.
+    */
+    public boolean isPredicated()
+    {
+        return scope == MMILScope.PREDICATED;
+    }
 }

Modified: trunk/src/fr/loria/led/mmil/objects/MMILScene.java
===================================================================
--- trunk/src/fr/loria/led/mmil/objects/MMILScene.java	2006-10-04 08:48:21 UTC (rev 26)
+++ trunk/src/fr/loria/led/mmil/objects/MMILScene.java	2006-10-04 11:05:42 UTC (rev 27)
@@ -79,9 +79,9 @@
     */
     public void remove(String id)
     {
-        for(int i=0; i<size(); i++)
-            if (get(i).getValueOf("mmilId").equalsIgnoreCase(id))
-                remove(i);
+        for(Iterator<MMILPercept> it = iterator(); it.hasNext();)
+            if (it.next().getValueOf("mmilId").equalsIgnoreCase(id))
+                it.remove();
     }
 
 






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