// returns a macro adder for the given morph item private MacroAdder getMacAdder(MorphItem mi) { // check map MacroAdder retval = macAdderMap.get(mi); if (retval != null) return retval; // set up macro adder IntHashSetMap macrosFromLex = new IntHashSetMap(); String[] newMacroNames = mi.getMacros(); List<MacroItem> macroItems = new ArrayList<MacroItem>(); for (int i = 0; i < newMacroNames.length; i++) { Set<FeatureStructure> featStrucs = (Set<FeatureStructure>) _macros.get(newMacroNames[i]); if (featStrucs != null) { for (Iterator<FeatureStructure> fsIt = featStrucs.iterator(); fsIt.hasNext(); ) { FeatureStructure fs = fsIt.next(); macrosFromLex.put(fs.getIndex(), fs); } } MacroItem macroItem = _macroItems.get(newMacroNames[i]); if (macroItem != null) { macroItems.add(macroItem); } else { // should be checked earlier too System.err.println( "Warning: macro " + newMacroNames[i] + " not found for word '" + mi.getWord() + "'"); } } retval = new MacroAdder(macrosFromLex, macroItems); // update map and return macAdderMap.put(mi, retval); return retval; }
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); } } }
@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); } } }
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)); } } }
public void modify(Mutable m) { if (m instanceof Proposition) { Proposition prop = (Proposition) m; if (prop.getName().equals(DEFAULT_VAL)) prop.setAtomName(REPLACEMENT); } else if (m instanceof FeatureStructure) { FeatureStructure fs = (FeatureStructure) m; for (Iterator<String> it = fs.getAttributes().iterator(); it.hasNext(); ) { String attr = it.next(); Object val = fs.getValue(attr); if (val instanceof SimpleType && ((SimpleType) val).getName().equals(DEFAULT_VAL)) { fs.setFeature(attr, grammar.types.getSimpleType(REPLACEMENT)); } } } }
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); } }
public void forall(Category c) { FeatureStructure fs = c.getFeatureStructure(); if (fs != null && fs.getIndex() != 0) featStrucMap.put(fs.getIndex(), fs); }