示例#1
0
 /**
  * Unifies this feature map with another feature map. Two feature maps can unify if and only if
  * all values of common feature name unify. If the unification fails, a UnificationFailedException
  * is thrown. In this case, the two feature maps remain partly unified, i.e. no backtracking is
  * done. Thus, this operation should be perfomed only if it is certain that the unification
  * succeeds, or if the operation is performed on copies of objects that are not used anymore
  * afterwards.
  *
  * @param featureMap The feature map to be unified with this feature map.
  * @throws UnificationFailedException If unification fails.
  */
 public void unify(FeatureMap featureMap) throws UnificationFailedException {
   for (String f : features.keySet()) {
     getFeature(f).unify(featureMap.getFeature(f));
   }
   for (String f : featureMap.features.keySet()) {
     getFeature(f).unify(featureMap.getFeature(f));
   }
 }
示例#2
0
 /**
  * This method detects whether this feature map can unify with the given feature map. Neither of
  * the two feature maps are changed.
  *
  * @param featureMap The feature map for the unification check.
  * @return true if the two feature map can unify.
  */
 public boolean canUnify(FeatureMap featureMap) {
   if (!isSimilar(featureMap)) return false;
   FeatureMap thisC = deepCopy();
   FeatureMap otherC = featureMap.deepCopy();
   try {
     thisC.tryToUnify(otherC);
   } catch (UnificationFailedException ex) {
     return false;
   }
   return true;
 }
示例#3
0
 /**
  * Creates a deep copy of this feature map using the given string objects. This method is usually
  * called form another deepCopy-method.
  *
  * @param stringObjs The string objects to be used.
  * @return A deep copy.
  */
 FeatureMap deepCopy(HashMap<Integer, StringObject> stringObjs) {
   FeatureMap fm = new FeatureMap();
   for (String feature : features.keySet()) {
     StringRef s = features.get(feature);
     StringObject se = stringObjs.get(s.getID());
     if (se != null) {
       fm.setFeature(feature, se.newStringRef());
     } else {
       StringRef sr = new StringRef(s.getString());
       fm.setFeature(feature, sr);
       stringObjs.put(s.getID(), sr.getStringObject());
     }
   }
   return fm;
 }
示例#4
0
 /**
  * Tries to unify this feature map with another feature map. If unification is not possible, an
  * exception is thrown. In the case unification would be possible, the unification is not
  * performed completely. In any case the two feature maps remain in an unconsistent state
  * afterwards. Thus, this operation should be performed only on copies of objects that are not
  * used anymore afterwards.
  *
  * @param featureMap The feature map to be unified with this feature map.
  * @throws UnificationFailedException If unification fails.
  */
 public void tryToUnify(FeatureMap featureMap) throws UnificationFailedException {
   if (featureMap == null) {
     throw new UnificationFailedException();
   }
   for (String f : features.keySet()) {
     features.get(f).unify(featureMap.getFeature(f));
   }
 }