/** * 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); }
/** * 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); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }