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

alexandredenis at users.gforge.inria.fr alexandredenis at users.gforge.inria.fr
Mar 6 Mai 10:20:43 CEST 2008


Author: alexandredenis
Date: 2008-05-06 10:20:39 +0200 (Tue, 06 May 2008)
New Revision: 32

Modified:
   trunk/src/fr/loria/led/mmil/MMILComponent.java
   trunk/src/fr/loria/led/mmil/MMILEntity.java
   trunk/src/fr/loria/led/mmil/MMILFeature.java
Log:


Modified: trunk/src/fr/loria/led/mmil/MMILComponent.java
===================================================================
--- trunk/src/fr/loria/led/mmil/MMILComponent.java	2007-11-07 12:52:32 UTC (rev 31)
+++ trunk/src/fr/loria/led/mmil/MMILComponent.java	2008-05-06 08:20:39 UTC (rev 32)
@@ -142,22 +142,51 @@
 		entities  = new ArrayList<MMILEntity>();
         relations = new ArrayList<MMILRelation>();
 
+        List<String> added = new ArrayList<String>();
+
+        // add all entities
         for(MMILEntity entity : mmil.getEntities())
+        {
             if (entity.getMMILType().equals("participant"))
                 entities.add(new MMILParticipant((MMILParticipant) entity));
             else entities.add(new MMILEvent((MMILEvent) entity));
-       
+            added.add(entity.getId());
+        }
+
+        // add all relations, don't add null source or null target relations
         for(MMILRelation rel : mmil.getRelations())
         {
-            MMILEntity sourceOrigin=rel.getSource(), targetOrigin=rel.getTarget();
-            MMILEntity sourceNew=null, targetNew=null;
-           
-            if (sourceOrigin!=null)
-                sourceNew = this.getEntity(sourceOrigin.getId());
-            if (targetOrigin!=null)
-                targetNew = this.getEntity(targetOrigin.getId());
-        
-            relations.add(new MMILRelation(rel.getType(), sourceNew, targetNew, rel.isModifierDirected()));
+            MMILEntity source,target;
+            MMILEntity sourceOrigin = rel.getSource();
+            MMILEntity targetOrigin = rel.getTarget();
+
+            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 (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()));
         }
 
         left    = mmil.getLeft();
@@ -166,6 +195,7 @@
         segment = mmil.getSegment();
     }
 
+
     /**
         Create a component from a xml file.
     */
@@ -507,11 +537,11 @@
     }
 
     /**
-        Aggregate serially the entities of this component using the index to sort them.
+        Aggregate serially the entities of this component using the index to sort them, modulo the lex features.
     */
     public void aggregateSerial(List<List<String>> synonyms)
     {
-        aggregateSerial(synonyms,true);
+        aggregateSerial(synonyms,true,true);
     }
 
     /**
@@ -520,8 +550,9 @@
         is tested with its successor. A synonyms list could be given to relax the constraints on the unification.
         @param synonyms a list of synonyms lists considered as equivalent values for a feature
         @param index if true, use the index for the sorting else use the id
+        @param modLex if true, unifies the entiy modulo the lex feature
     */
-    public void aggregateSerial(List<List<String>> synonyms, boolean index)
+    public void aggregateSerial(List<List<String>> synonyms, boolean index, boolean modLex)
     {
         if (entities.size()<=1)
             return;
@@ -535,7 +566,7 @@
         
         for(int i=1; i<entities.size(); i++)
         {
-            MMILEntity unif = entities.get(i).unify(curEntity,synonyms);
+            MMILEntity unif = entities.get(i).unifyModLex(curEntity,synonyms);
             if (unif==null)
             {
                 newEntities.add(curEntity);
@@ -557,9 +588,9 @@
         Aggregate the entities of this component serially.
         Proceed to the aggregation without synonyms.
     */
-    public void aggregateSerial(boolean index)
+    public void aggregateSerial(boolean index, boolean modLex)
     {
-        aggregateSerial(new ArrayList<List<String>>(), index);
+        aggregateSerial(new ArrayList<List<String>>(), index, modLex);
     }       
     
     
@@ -1272,7 +1303,7 @@
     */
 	public String toString()
 	{
-		String xml = "<mmil:mmilComponent "+getUsedNamespaces()+" segment=\""+segment+"\"";
+		String xml = "<mmil:mmilComponent "+getUsedNamespaces()+" segment=\""+segment.replaceAll("\"", "'")+"\"";
 
         if (left!=-1 && right!=-1)
             xml += " left=\""+left+"\" right=\""+right+"\"";

Modified: trunk/src/fr/loria/led/mmil/MMILEntity.java
===================================================================
--- trunk/src/fr/loria/led/mmil/MMILEntity.java	2007-11-07 12:52:32 UTC (rev 31)
+++ trunk/src/fr/loria/led/mmil/MMILEntity.java	2008-05-06 08:20:39 UTC (rev 32)
@@ -13,7 +13,7 @@
     entity in the component and should be unique. The features are in the "mmil" namespace by default but features
     in other namespace (for a particular application) can also be added. In addition an entity can have sub-entities 
     (elements for a set or a sequence). The entity covers a linguistic expression given 
-    by left and right borns but as these borns are defined in terms of lexical units, they should used with caution.<br/>
+    by left and right boundaries but as these boundaries are defined in terms of lexical units, they should used with caution.<br/>
     <b>Note</b>: to be convenient all the methods that modify the entity return the modified entity
     
 */
@@ -46,8 +46,8 @@
 
 
     /**
-        Create an entity with given borns.
-        <b>Note</b> : as the list of the lexical items is not accessible to the entity, using borns
+        Create an entity with given boundaries.
+        <b>Note</b> : as the list of the lexical items is not accessible to the entity, using boundaries
         cannot be safe and should actually be used only for debugging purposes. 
     */
 	public MMILEntity(int left, int right)
@@ -57,8 +57,8 @@
 	}
 
     /**
-        Create an entity with given borns and given id.
-        <b>Note</b> : as the list of the lexical items is not accessible to the entity, using borns
+        Create an entity with given boundaries and given id.
+        <b>Note</b> : as the list of the lexical items is not accessible to the entity, using boundaries
         cannot be safe and should actually be used only for debugging purposes.
         @param id - any unique String
         @param left - the left born
@@ -83,8 +83,8 @@
 	}
 
     /**
-        Create an entity with given id, features and borns.
-        <b>Note</b> : as the list of the lexical items is not accessible to the entity, using borns
+        Create an entity with given id, features and boundaries.
+        <b>Note</b> : as the list of the lexical items is not accessible to the entity, using boundaries
         cannot be safe and should actually be used only for debugging purposes.
         @param id - any unique String
         @param features - a list of MMILFeatures
@@ -111,7 +111,7 @@
 	}
 
     /**
-        Create an entity with given id, features and borns.
+        Create an entity with given id, features and boundaries.
         @deprecated Using List interface is preferred.
     */
 	public MMILEntity(String id, ArrayList features, int left, int right)
@@ -270,9 +270,9 @@
         return unify(entity, new ArrayList<List<String>>());
     }
 
+
     /**
         Unify this entity to the given entity.
-        Two entities 
         @return null if no unification was possible.
     */
     public MMILEntity unify(MMILEntity entity, List<List<String>> synonyms)
@@ -291,6 +291,7 @@
             }
             else return null;
         }
+
         for(MMILFeature feat : entity.getFeatures())
         {
             List<String> values = synonymize(getValuesOf(feat.getName()), synonyms);
@@ -304,7 +305,50 @@
         return ret;         
     }
 
+
     /**
+        Unify this entity to the given entity modulo the lex features.
+        If unification is possible, concatenates lex features.
+        @return null if no unification was possible.
+    */
+    public MMILEntity unifyModLex(MMILEntity entity, List<List<String>> synonyms)
+    {
+        if (!getMMILType().equals(entity.getMMILType()))
+            return null;
+
+        MMILEntity ret = entity instanceof MMILParticipant ? new MMILParticipant(entity.getId()) : new MMILEvent(entity.getId());
+        for(MMILFeature feat : features)
+        {
+            if (feat.getName().equalsIgnoreCase("lex"))
+                continue;
+            List<String> values = synonymize(entity.getValuesOf(feat.getName()), synonyms);
+            if (values.isEmpty() || containsIgnoreCase(values, feat.getValue()))
+            {
+                if (!ret.hasFeature(feat.getNamespace(), feat.getName(), feat.getValue()))
+                    ret.add(feat);
+            }
+            else return null;
+        }
+
+        for(MMILFeature feat : entity.getFeatures())
+        {
+            if (feat.getName().equalsIgnoreCase("lex"))
+                continue;
+            List<String> values = synonymize(getValuesOf(feat.getName()), synonyms);
+            if (values.isEmpty() || containsIgnoreCase(values, feat.getValue()))
+            {
+                if (!ret.hasFeature(feat.getNamespace(), feat.getName(), feat.getValue()))
+                    ret.add(feat);
+            }
+            else return null;
+        }
+        
+        ret.replaceFeature("lex", (entity.getValueOf("lex")+" "+getValueOf("lex")).trim());
+        return ret;         
+    }
+
+
+    /**
         Completes the given list of strings with synonyms.
         It searches for synonyms for each element of the list and adds them to the list.
     */
@@ -349,7 +393,7 @@
 
     /**
         Test if this entity equals the given entity.
-        Two entities are equal if they have the same ids (case insensitive), left and right borns, 
+        Two entities are equal if they have the same ids (case insensitive), left and right boundaries, 
         the same features (without ordering) and the same sub-entities (without ordering).
         @return true if these conditions are satisfied
     */
@@ -672,7 +716,7 @@
 
 	/**
 		Test if this entity contains exactly the given feature.
-        @return true if a feature with the same name, value, namespace and borns is found.
+        @return true if a feature with the same name, value, namespace and boundaries is found.
 	*/
 	public boolean hasFeature(MMILFeature feature)
 	{
@@ -932,7 +976,16 @@
 	}
 
 
+//////// QUALIFIED FEATURES
 
+    /**
+        Remove qualification names from features value.
+    */
+    public void unQualify()
+    {
+        for(MMILFeature feat : features)
+            feat.unQualify();
+    }
 
 
 //////// ATTACHMENT TO FATHER COMPONENT

Modified: trunk/src/fr/loria/led/mmil/MMILFeature.java
===================================================================
--- trunk/src/fr/loria/led/mmil/MMILFeature.java	2007-11-07 12:52:32 UTC (rev 31)
+++ trunk/src/fr/loria/led/mmil/MMILFeature.java	2008-05-06 08:20:39 UTC (rev 32)
@@ -326,4 +326,28 @@
 
 		return getIndex()-f.getIndex();
 	}
+
+
+//////// QUALIFIED FEATURES
+//////// As feature values are pcdata, they are not qualified by default,
+//////// but it sometimes required to qualify them |Namespace#value|, so this remove the qualification
+
+    /**
+        Remove the optional namespace in qualified value.
+        It removes the namespace if the value looks like |Namespace#value|.
+    */
+    public void unQualify()
+    {
+        int i = value.indexOf("#");
+		if (i!=-1)
+        {
+            // strangely Racer codes the upper case qualified names without pipes
+            // but with \# ??
+            int j = value.indexOf("\\#");
+
+            if (j==-1)
+                value = value.substring(i+1,value.length()-1);
+            else value = value.substring(i+1);
+        }
+    }
 }






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