/** * Does a feature-type-specific lookup of this feature in the given {@link ChildLexicon}. * * @param lex The child lexicon this feature is being looked up in. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(ChildLexicon lex, int label) { return lex.childLexiconLookup(this, label); }
/** * Takes care of any feature-type-specific tasks that need to be taken care of when removing a * feature of this type from a {@link ChildLexicon}, in particular updating parent counts and * removing children of this feature if necessary. * * @param lex The child lexicon this feature is being removed from. **/ public void removeFromChildLexicon(ChildLexicon lex) { lex.decrementParentCounts(left); lex.decrementParentCounts(right); }
/** * Updates the counts in {@link #parents} for the children of <code>f</code>. * * @param f The feature to look up. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(Feature f, int label) { return lookup(f, true, label); }
/** * Updates the counts in {@link #parents} for the children of <code>f</code>. * * @param f The feature to look up. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(RealReferrer f, int label) { int oldSize = lexiconInv.size(); int result = lookup(f, true, label); if (oldSize < lexiconInv.size()) incrementParentCounts(f.getReferent(), label); return result; }
/** * Used to lookup the children of conjunctive and referring features during training, this * method checks {@link #lexiconChildren} if the feature isn't present in {@link #lexicon} and * {@link #lexiconInv}, and then stores the given feature in {@link #lexiconChildren} if it * wasn't present anywhere. * * @param f The feature to look up. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return A feature equivalent to <code>f</code> that is stored in this lexicon. **/ public Feature getChildFeature(Feature f, int label) { lazyMapCreation(); Integer I = (Integer) lexicon.get(f); if (I != null) { int index = I.intValue(); incrementCount(index, label); return lexiconInv.get(index); } if (lexiconChildren == null) lexiconChildren = new ChildLexicon(this); return lexiconChildren.getChildFeature(f, -1); }
/** * Removes the mapping for the given feature from this lexicon and returns the feature object * representing it that was stored here. * * @param f The feature to remove. * @return The representation of <code>f</code> that used to be stored here, or * <code>null</code> if it wasn't present. **/ public Feature remove(Feature f) { if (contains(f)) { // contains(Feature) calls lazyMapCreation() int index = lookup(f); int count = parents.get(index); if (count == 0) { f.removeFromChildLexicon(this); // Calls decrementParentCounts lexicon.remove(f); return lexiconInv.set(index, null); } else if (count > 0) { parents.set(index, -count); return lexiconInv.get(index); } else { System.err .println("LBJava ERROR: Marking feature as removable for the second time: " + f); new Exception().printStackTrace(); System.exit(1); } } return null; }
/** * Unlike the overridden method in {@link Lexicon}, this method simply checks {@link #lexicon} * for the feature and will throw an exception if it can't be found. * * @param f The feature to look up. * @return If the feature was found in {@link #lexicon}, its associated integer index is * returned. * @throws UnsupportedOperationException If the feature isn't found anywhere in the lexicon. **/ public int lookupChild(Feature f) { lazyMapCreation(); Integer I = (Integer) lexicon.get(f); if (I != null) return I.intValue(); throw new UnsupportedOperationException( "When calling ChildLexicon.lookupChild(Feature), the feature must " + "be present in the lexicon. (" + f + ")"); }
/** Returns whether the given Lexicon object is equal to this one. */ public boolean equals(Object o) { if (!o.getClass().equals(getClass())) return false; Lexicon l = (Lexicon) o; return pruneCutoff == l.pruneCutoff && (lexicon == null ? l.lexicon == null : lexicon.equals(l.lexicon)) && (featureCounts == null ? l.featureCounts == null : featureCounts .equals(l.featureCounts)) && (perClassFeatureCounts == null ? l.perClassFeatureCounts == null : perClassFeatureCounts.equals(l.perClassFeatureCounts)) && (lexiconChildren == null ? l.lexiconChildren == null : lexiconChildren .equals(l.lexiconChildren)); }
/** * <!-- clone() --> Returns a deep clone of this lexicon implemented as a <code>HashMap</code>. **/ public Object clone() { Lexicon clone = null; try { clone = (Lexicon) super.clone(); } catch (Exception e) { System.err.println("Error cloning Lexicon: " + e); e.printStackTrace(); System.exit(1); } if (lexicon != null) { clone.lexicon = new HashMap(); clone.lexicon.putAll(lexicon); } clone.lexiconInv = (FVector) lexiconInv.clone(); if (featureCounts != null) clone.featureCounts = (IVector) featureCounts.clone(); if (perClassFeatureCounts != null) clone.perClassFeatureCounts = (IVector2D) perClassFeatureCounts.clone(); if (lexiconChildren != null) clone.lexiconChildren = (ChildLexicon) lexiconChildren.clone(); return clone; }
/** * Updates the counts in {@link #parents} for the children of <code>f</code>. * * @param f The feature to look up. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(DiscreteConjunctiveFeature f, int label) { int oldSize = lexiconInv.size(); int result = lookup(f, true, label); if (oldSize < lexiconInv.size()) { incrementParentCounts(f.getLeft(), label); incrementParentCounts(f.getRight(), label); } return result; }
/** * Updates the counts in {@link #parents} for the children of <code>f</code>. * * @param f The feature to look up. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(DiscreteReferrer f, int label) { int oldSize = lexiconInv.size(); int result = lookup(f, true, label); if (oldSize < lexiconInv.size()) incrementParentCounts(f.getReferent(), label); return result; }
/** * Does a feature-type-specific lookup of this feature in the given {@link ChildLexicon}. * * @param lex The child lexicon this feature is being looked up in. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(ChildLexicon lex, int label) { return lex.childLexiconLookup(this, label); }
/** * Takes care of any feature-type-specific tasks that need to be taken care of when removing a * feature of this type from a {@link ChildLexicon}, in particular updating parent counts and * removing children of this feature if necessary. * * @param lex The child lexicon this feature is being removed from. **/ public void removeFromChildLexicon(ChildLexicon lex) { lex.decrementParentCounts(referent); }
/** * The parent of feature <code>f</code> is being removed, so we decrement <code>f</code>'s * parent counts and remove it if it's ready. * * @param f The child feature whose parent counts need updating and which may be removed as * well. **/ public void decrementParentCounts(Feature f) { int index = lookup(f); int count = parents.get(index); if (count == 0) { System.err.println("LBJava ERROR: Parent count incorrect for feature " + f); new Exception().printStackTrace(); System.exit(1); } else if (count < 0) { parents.increment(index); if (count == -1) { f.removeFromChildLexicon(this); lexicon.remove(f); lexiconInv.set(index, null); } } else parents.decrement(index); }
/** * Updates the counts in {@link #parents} for the children of <code>f</code>. * * @param f The feature to look up. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(RealConjunctiveFeature f, int label) { int oldSize = lexiconInv.size(); int result = lookup(f, true, label); if (oldSize < lexiconInv.size()) { incrementParentCounts(f.getLeft(), label); incrementParentCounts(f.getRight(), label); } return result; }
/** * Does a feature-type-specific lookup of this feature in the given {@link ChildLexicon}. * * @param lex The child lexicon this feature is being looked up in. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(ChildLexicon lex, int label) { return lex.childLexiconLookup(this, label); }
/** * Takes care of any feature-type-specific tasks that need to be taken care of when removing a * feature of this type from a {@link ChildLexicon}, in particular updating parent counts and * removing children of this feature if necessary. * * @param lex The child lexicon this feature is being removed from. **/ public void removeFromChildLexicon(ChildLexicon lex) { lex.decrementParentCounts(left); lex.decrementParentCounts(right); }
/** * Does a feature-type-specific lookup of this feature in the given {@link ChildLexicon}. * * @param lex The child lexicon this feature is being looked up in. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(ChildLexicon lex, int label) { return lex.childLexiconLookup(this, label); }
/** * Takes care of any feature-type-specific tasks that need to be taken care of when removing a * feature of this type from a {@link ChildLexicon}, in particular updating parent counts and * removing children of this feature if necessary. * * @param lex The child lexicon this feature is being removed from. **/ public void removeFromChildLexicon(ChildLexicon lex) { lex.decrementParentCounts(referent); }
/** * Does a feature-type-specific lookup of this feature in the given {@link ChildLexicon}. * * @param lex The child lexicon this feature is being looked up in. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return The index of <code>f</code> in this lexicon. **/ public int childLexiconLookup(ChildLexicon lex, int label) { return lex.childLexiconLookup(this, label); }