Ejemplo n.º 1
0
 /**
  * This methods checks whether two feature maps are similar. Two feature maps are similar if and
  * only if they do not share a feature with the same name but with values that do not unify
  * locally (i.e. without considering the unifications entailed by other features).
  *
  * @param fm The category for which similarity with this category should be checked.
  * @return true if the two categories are similar.
  */
 public boolean isSimilar(FeatureMap fm) {
   if (fm == null) return false;
   for (String v : features.keySet()) {
     String s1 = features.get(v).getString();
     String s2 = null;
     StringRef sr2 = fm.features.get(v);
     if (sr2 != null) s2 = sr2.getString();
     if (s1 != null && s2 != null && !s1.equals(s2)) return false;
   }
   return true;
 }
Ejemplo n.º 2
0
 /** Skolemizes the feature values of this feature map. */
 public void skolemize() {
   for (String feature : features.keySet()) {
     StringRef s = features.get(feature);
     if (s.getString() == null) {
       try {
         s.unify(new StringRef("$SK" + skNumber++));
       } catch (UnificationFailedException ex) {
       }
     }
   }
 }
Ejemplo n.º 3
0
 @Override
 public List<T> getValuesForKeysContaining(String str) {
   int size = size();
   if (size == 0) {
     return Collections.emptyList();
   }
   List<T> results = new ArrayList<T>();
   for (int i = 0; i < size; i++) {
     StringRef key = keys.get(i);
     if (key.indexOf(str) != -1) {
       results.add(values.get(i));
     }
   }
   return results;
 }
Ejemplo n.º 4
0
 String getIdentifier(List<Integer> mvars, String[] usedFeatureNames) {
   String s = "(";
   int i = 0;
   for (String n : usedFeatureNames) {
     i++;
     if (!getFeatureNames().contains(n)) continue;
     StringRef v = getFeature(n);
     if (v.getString() == null) {
       if (mvars.contains(v.getID())) {
         s += i + ":" + mvars.indexOf(v.getID()) + ",";
       }
     } else {
       s += i + ":" + v.getString() + ",";
     }
   }
   return s + ")";
 }
Ejemplo n.º 5
0
 @Override
 public void put(StringRef str, T value) {
   if (str == null || str.length() == 0) {
     return;
   }
   keys.add(str);
   values.add(value);
 }
Ejemplo n.º 6
0
 public String toString() {
   String s = "";
   Set<String> featureKeys = features.keySet();
   if (featureKeys.size() > 0) s += "(";
   for (String feature : new TreeSet<String>(features.keySet())) {
     // traverse the feature names in alphabetical order
     StringRef sr = features.get(feature);
     s += feature + ":";
     if (sr.getString() == null) {
       s += sr.getID();
     } else {
       s += sr.getString();
     }
     s += ",";
   }
   if (featureKeys.size() > 0) {
     s = s.substring(0, s.length() - 1) + ")";
   }
   return s;
 }
Ejemplo n.º 7
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;
 }