public Alphabet (Object[] entries) { this (entries.length); for (Object entry : entries) this.lookupIndex(entry); }
public Alphabet (Object[] entries) { this (entries.length); for (Object entry : entries) this.lookupIndex(entry); }
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); }
public double logProbability (Object key) { if (dictionary == null) throw new IllegalStateException ("This Multinomial has no dictionary."); return logProbability (dictionary.lookupIndex (key)); }
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); }
/** Load an alphabet from a file, one item per line */ public static Alphabet loadFromFile(File alphabetFile) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(alphabetFile)); Alphabet alphabet = new Alphabet(); String item; while ((item = reader.readLine()) != null) { alphabet.lookupIndex(item); } reader.close(); return alphabet; }
public void testReadResolve () throws IOException, ClassNotFoundException { Alphabet dict = new Alphabet (); dict.lookupIndex ("TEST1"); dict.lookupIndex ("TEST2"); dict.lookupIndex ("TEST3"); Alphabet dict2 = (Alphabet) TestSerializable.cloneViaSerialization (dict); assertTrue (dict == dict2); }
/** Create a dummy alphabet with <code>n</code> dimensions */ public static Alphabet alphabetOfSize (int n) { Alphabet alphabet = new Alphabet(); for (int i = 0; i < n; i++) { alphabet.lookupIndex("d" + i); } return alphabet; }
public boolean contains (Object o) { int index = dictionary.lookupIndex (o, false); if (index == -1) return false; return contains (index); }
private static Alphabet dictOfSize (int size) { Alphabet ret = new Alphabet (); for (int i = 0; i < size; i++) ret.lookupIndex ("feature"+i); return ret; }
public double probability (Object key) { if (dictionary == null) throw new IllegalStateException ("This Multinomial has no dictionary."); return probability (dictionary.lookupIndex (key)); }
private static Alphabet dictOfSize (int n) { Alphabet dict = new Alphabet (); for (int i = 0; i < n; i++) { dict.lookupIndex ("feature"+i); } return dict; }
private static Alphabet dictOfSize (int size) { Alphabet ret = new Alphabet (); for (int i = 0; i < size; i++) ret.lookupIndex ("feature"+i); return ret; }
private void expandDict (Alphabet fd, int size) { fd.startGrowth (); for (int i = 0; i < size; i++) fd.lookupIndex ("feature"+i, true); }
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 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); }
public Record (Alphabet fieldAlph, Alphabet valueAlph, String[][] vals) { this(fieldAlph, valueAlph); for (int i = 0; i < vals.length; i++) { AugmentableFeatureVector afv = new AugmentableFeatureVector(valueAlph, false); for (int j = 1; j < vals[i].length; j++) afv.add(valueAlph.lookupIndex(vals[i][j]), 1.0); field2values.put(fieldAlph.lookupIndex(vals[i][0]), afv.toFeatureVector()); } }
public Alphabet getPrunedAlphabet(int minDocs, int maxDocs, int minCount, int maxCount) { Alphabet inputAlphabet = instances.getDataAlphabet(); Alphabet outputAlphabet = new Alphabet(); for (int inputType = 0; inputType < numFeatures; inputType++) { if (featureCounts[inputType] >= minCount && featureCounts[inputType] <= maxCount && documentFrequencies[inputType] >= minDocs && documentFrequencies[inputType] <= maxDocs) { outputAlphabet.lookupIndex(inputAlphabet.lookupObject(inputType)); } } return outputAlphabet; }
public FeatureSequence toFeatureSequence (Alphabet dict) { FeatureSequence fs = new FeatureSequence( dict, this.size() ); for (int i = 0; i < this.size(); i++) fs.add (dict.lookupIndex( (this.get(i)).getText())); return fs; }