/** * <!-- contains(Feature) --> Returns <code>true</code> if the given feature is already in the * lexicon (whether it's past the {@link #pruneCutoff} or not) and <code>false</code> otherwise. * This does not alter or add anything to the lexicon. * * @param f The feature to look up. * @return A boolean indicating if the given feature is currently in the lexicon. **/ public boolean contains(Feature f) { lazyMapCreation(); return lexicon.containsKey(f); }
/** Simply returns the map stored in {@link #lexicon}. */ public Map getMap() { lazyMapCreation(); return Collections.unmodifiableMap(lexicon); }
/** * Used to lookup the children of conjunctive and referring features while writing the lexicon, * this method checks {@link #lexiconChildren} if the feature isn't present in {@link #lexicon} * and {@link #lexiconInv}, and will throw an exception if it still 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. Otherwise, <code>-i - 1</code> is returned, where <code>i</code> is the * index associated with the feature in {@link #lexiconChildren}. * @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(); if (lexiconChildren == null) throw new UnsupportedOperationException( "When calling Lexicon.lookupChild(Feature), the feature must be " + "present in the lexicon."); return -lexiconChildren.lookupChild(f) - 1; }
/** * 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); }
+ "training with per class feature counts."); lazyMapCreation(); Integer I = (Integer) lexicon.get(f);
lazyMapCreation(); // not so lazy at all.