Exemple #1
0
 /** Gathers and propagates the unique values of each distributive attribute. */
 public void propagateDistributiveAttrs(Category cat, Category cat2) {
   if (_distributiveAttrs == null) return;
   resetDistrAttrVals();
   cat.forall(gatherDistrAttrVals);
   if (cat2 != null) {
     cat2.forall(gatherDistrAttrVals);
   }
   cat.forall(propagateUniqueDistrAttrVals);
   if (cat2 != null) {
     cat2.forall(propagateUniqueDistrAttrVals);
   }
 }
Exemple #2
0
 /** Expands inheritsFrom links to feature equations for those features not explicitly listed. */
 public void expandInheritsFrom(Category cat, Category cat2) {
   // index feature structures
   featStrucMap.clear();
   cat.forall(indexFeatStrucs);
   if (cat2 != null) {
     cat2.forall(indexFeatStrucs);
   }
   // add feature eqs
   cat.forall(doInheritsFrom);
   if (cat2 != null) {
     cat2.forall(doInheritsFrom);
   }
 }
Exemple #3
0
 // unify sem class with default nom var(s)
 private void unifySemClass(Category cat, String semClass) {
   if (semClass == null || cat.getLF() == null) return;
   SEMCLASS = grammar.types.getSimpleType(semClass);
   try {
     cat.getLF().deepMap(defaultNomvarUnifier);
   } catch (TypePropagationException tpe) {
     if (debugSemClasses) {
       System.err.println(
           "Warning: unable to unify types '"
               + tpe.st1
               + "' and '"
               + tpe.st2
               + "' in unifying sem class in cat: \n"
               + cat);
     }
   }
 }
Exemple #4
0
 /** Propagates types of nomvars in the given categories. */
 public void propagateTypes(Category cat, Category cat2) {
   try {
     nomvarMap.clear();
     cat.deepMap(nomvarTypePropagater);
     if (cat2 != null) cat2.deepMap(nomvarTypePropagater);
     cat.deepMap(nomvarTypePropagater);
     if (cat2 != null) cat2.deepMap(nomvarTypePropagater);
   } catch (TypePropagationException tpe) {
     if (debugSemClasses) {
       System.err.println(
           "Warning: unable to unify types '"
               + tpe.st1
               + "' and '"
               + tpe.st2
               + "' in cat: \n"
               + cat);
       if (cat2 != null) System.err.println("and cat: \n" + cat2);
     }
   }
 }
Exemple #5
0
 public void forall(Category c) {
   if (!(c instanceof AtomCat)) return;
   String type = ((AtomCat) c).getType();
   FeatureStructure fs = c.getFeatureStructure();
   if (fs == null) return;
   for (Iterator<String> it = fs.getAttributes().iterator(); it.hasNext(); ) {
     String att = it.next();
     _catsToAttrs.put(type, att);
     if (fs.getValue(att) instanceof LF) {
       _lfAttrs.add(att);
     }
   }
 }
Exemple #6
0
 @SuppressWarnings("unchecked")
 public void forall(Category c) {
   if (!(c instanceof AtomCat)) return;
   FeatureStructure fs = c.getFeatureStructure();
   if (fs == null) return;
   for (int i = 0; i < _distributiveAttrs.length; i++) {
     String attr = _distributiveAttrs[i];
     Object val = fs.getValue(attr);
     if (val != null && !distrAttrVals[i].contains(val)) {
       distrAttrVals[i].add(val);
     }
   }
 }
Exemple #7
0
 public void forall(Category c) {
   if (!(c instanceof AtomCat)) return;
   FeatureStructure fs = c.getFeatureStructure();
   if (fs == null) return;
   for (int i = 0; i < _distributiveAttrs.length; i++) {
     if (distrAttrVals[i].size() != 1) continue;
     Object distVal = distrAttrVals[i].get(0);
     String attr = _distributiveAttrs[i];
     Object val = fs.getValue(attr);
     if (val == null) {
       fs.setFeature(attr, UnifyControl.copy(distVal));
     }
   }
 }
Exemple #8
0
 public void forall(Category c) {
   // get feature structures
   if (!(c instanceof AtomCat)) return;
   String type = ((AtomCat) c).getType();
   FeatureStructure fs = c.getFeatureStructure();
   GFeatStruc gfs = (GFeatStruc) fs;
   if (gfs == null || gfs.getInheritsFrom() == 0) return;
   int inhf = gfs.getInheritsFrom();
   FeatureStructure inhfFS = (FeatureStructure) featStrucMap.get(inhf);
   if (inhfFS != null) {
     // copy values of features from inhfFS not already present
     for (Iterator<String> it = inhfFS.getAttributes().iterator(); it.hasNext(); ) {
       String att = it.next();
       if (gfs.hasAttribute(att)) continue;
       gfs.setFeature(att, UnifyControl.copy(inhfFS.getValue(att)));
     }
     // for each possible attr used with this type and not already present,
     // add feature equation
     Collection<String> attrs = (Collection<String>) _catsToAttrs.get(type);
     if (attrs == null) return;
     for (Iterator<String> it = attrs.iterator(); it.hasNext(); ) {
       String att = it.next();
       if (gfs.hasAttribute(att)) continue;
       String varName = att.toUpperCase() + inhf;
       if (_lfAttrs.contains(att)) {
         gfs.setFeature(att, new HyloVar(varName));
         inhfFS.setFeature(att, new HyloVar(varName));
       } else {
         gfs.setFeature(att, new GFeatVar(varName));
         inhfFS.setFeature(att, new GFeatVar(varName));
       }
     }
   } else {
     System.err.println(
         "Warning: no feature structure with inheritsFrom index of "
             + inhf
             + " found in category "
             + c);
   }
 }
Exemple #9
0
  // given EntriesItem
  private void getWithEntriesItem(
      Word w,
      MorphItem mi,
      String stem,
      String pred,
      String targetPred,
      String targetRel,
      EntriesItem item,
      MacroAdder macAdder,
      Map<String, Double> supertags,
      Set<String> supertagsFound,
      SignHash result) {
    // ensure apropos
    if (targetPred != null && !targetPred.equals(pred)) return;
    if (targetRel != null
        && !targetRel.equals(item.getIndexRel())
        && !targetRel.equals(item.getCoartRel())) return;
    if (!item.getActive().booleanValue()) return;
    if (mi.excluded(item)) return;

    try {
      // copy and add macros
      Category cat = item.getCat().copy();
      macAdder.addMacros(cat);

      // replace DEFAULT_VAL with pred, after first
      // unifying type of associated nom var(s) with sem class
      unifySemClass(cat, mi.getWord().getSemClass());
      REPLACEMENT = pred;
      cat.deepMap(defaultReplacer);

      // check supertag
      // TODO: think about earlier checks for efficiency, for grammars where macros and preds don't
      // matter
      // Double lexprob = null; // nb: skipping lex log probs, don't seem to be helpful
      if (supertags != null) {
        // skip if not found
        String stag = cat.getSupertag();
        if (!supertags.containsKey(stag)) return;
        // otherwise update found supertags
        supertagsFound.add(stag);
        // get lex prob
        // lexprob = supertags.get(stag);
      }

      // propagate types of nom vars
      propagateTypes(cat);

      // handle distrib attrs and inherits-from
      propagateDistributiveAttrs(cat);
      expandInheritsFrom(cat);

      // merge stem, pos, sem class from morph item, plus supertag from cat
      Word word = Word.createFullWord(w, mi.getWord(), cat.getSupertag());

      // set origin and lexprob
      Sign sign = new Sign(word, cat);
      sign.setOrigin();
      // if (lexprob != null) {
      //	sign.addData(new SupertaggerAdapter.LexLogProb((float) Math.log10(lexprob)));
      // }
      // return sign
      result.insert(sign);
    } catch (RuntimeException exc) {
      System.err.println(
          "Warning: ignoring entry: "
              + item.getName()
              + " of family: "
              + item.getFamilyName()
              + " for stem: "
              + stem
              + " b/c: "
              + exc.toString());
    }
  }
Exemple #10
0
 public void forall(Category c) {
   FeatureStructure fs = c.getFeatureStructure();
   if (fs != null && fs.getIndex() != 0) featStrucMap.put(fs.getIndex(), fs);
 }