public int[] lookupIndices (Object[] objects, boolean addIfNotPresent) { int[] ret = new int[objects.length]; for (int i = 0; i < objects.length; i++) ret[i] = lookupIndex (objects[i], addIfNotPresent); return ret; }
public int lookupIndex (Object entry) { return lookupIndex (entry, true); }
public static int[] getObjectIndices(Object[] entries, Alphabet dict, boolean addIfNotPresent) { int[] feats = new int[entries.length]; for (int i = 0; i < entries.length; i++) { feats[i] = dict.lookupIndex (entries[i], addIfNotPresent); if (feats[i] == -1) throw new IllegalArgumentException ("Object is not in dictionary."); } return feats; }
private static Alphabet dictOfSize (int n) { Alphabet dict = new Alphabet (); for (int i = 0; i < n; i++) { dict.lookupIndex ("feature"+i); } return dict; }
private void expandDict (Alphabet fd, int size) { fd.startGrowth (); for (int i = 0; i < size; i++) fd.lookupIndex ("feature"+i, true); }
public void add (Object key) { int fi = dictionary.lookupIndex (key); if (fi >= 0) // This will happen if the dictionary is frozen, // and key is not already in the dictionary. add (fi); // xxx Should we raise an exception if the appending doesn't happen? }
public void add (Object key, double value) { //System.out.println ("AugmentableFeatureVector dictionary = "+dictionary+", size = "+dictionary.size()); int index = dictionary.lookupIndex (key); //System.out.println ("AugmentableFeatureVector index("+key+") = "+index); assert (index != -1); add (index, value); }
public double probability (Object key) { if (dictionary == null) throw new IllegalStateException ("This Multinomial has no dictionary."); return probability (dictionary.lookupIndex (key)); }
public int getCountWithFeature (Object feature) { int index = ilist.getDataAlphabet().lookupIndex (feature, false); if (index == -1) throw new IllegalArgumentException ("Feature "+feature+" not contained in InvertedIndex"); ArrayList a = ii[index]; return a == null ? 0 : a.size(); }
int leftIndexFromStateName (CRF4 crf, String name) { String leftName = leftNameOfState (name); int idx = originalStateNames.lookupIndex (leftName, false); if (idx == -1) throw new IllegalStateException ("Could not extract left state name from "+name+" Tried "+leftName); return idx; }
public int lookupIndex (Object entry, boolean addIfNotPresent) { int index = super.lookupIndex (entry, addIfNotPresent); if (index >= labels.size() && addIfNotPresent) labels.add (new Label (entry, this, index)); return index; }
public double logProbability (Object key) { if (dictionary == null) throw new IllegalStateException ("This Multinomial has no dictionary."); return logProbability (dictionary.lookupIndex (key)); }
private static Alphabet dictOfSize (int size) { Alphabet ret = new Alphabet (); for (int i = 0; i < size; i++) ret.lookupIndex ("feature"+i); return ret; }
public int location (Object entry) { if (dictionary == null) throw new IllegalStateException ("This FeatureVector has no dictionary."); int i = dictionary.lookupIndex (entry, false); if (i < 0) return -1; else return location (i); }
public int location (Object o) { int i = dictionary.lookupIndex (o, false); if (i == -1) throw new IllegalArgumentException ("Object not in dictionary."); return location (i); }
public Transducer.TransitionIterator transitionIterator (Object o) { int inputIndex = inputAlphabet.lookupIndex (o, false); if (inputIndex == -1) throw new IllegalArgumentException ("Input not in dictionary."); return transitionIterator (inputIndex); }
private static Alphabet dictOfSize (int size) { Alphabet ret = new Alphabet (); for (int i = 0; i < size; i++) ret.lookupIndex ("feature"+i); return ret; }
public void testSetRankOrder () { Alphabet v = new Alphabet (); RankedFeatureVector rfv = new RankedFeatureVector (v, new int[] {v.lookupIndex ("a"), v.lookupIndex ("b"), v.lookupIndex ("c"), v.lookupIndex ("d") }, new double[] {3.0, 1.0, 2.0, 6.0}); System.out.println ("vector size ="+rfv.numLocations()); for (int i = 0; i < rfv.numLocations(); i++) System.out.println ("Rank="+i+" value="+rfv.getValueAtRank(i)); }
public FeatureSequence toFeatureSequence(Alphabet dict) { FeatureSequence fs = new FeatureSequence( dict, tokens.size() ); for (int i = 0; i < tokens.size(); i++) fs.add( dict.lookupIndex( ((Token)tokens.get( i )).getText() ) ); return fs; }
public Transducer.TransitionIterator transitionIterator (Sequence inputSequence, int inputPosition) { int inputIndex = inputAlphabet.lookupIndex (inputSequence.get(inputPosition), false); if (inputIndex == -1) throw new IllegalArgumentException ("Input not in dictionary."); return transitionIterator (inputIndex); }