cc.mallet.types.Alphabet.lookupIndex()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中cc.mallet.types.Alphabet.lookupIndex()方法的一些代码示例,展示了Alphabet.lookupIndex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Alphabet.lookupIndex()方法的具体详情如下:
包路径:cc.mallet.types.Alphabet
类名称:Alphabet
方法名:lookupIndex

Alphabet.lookupIndex介绍

[英]Return -1 if entry isn't present.
[中]如果条目不存在,则返回-1。

代码示例

代码示例来源:origin: de.julielab/jcore-mallet-2.0.9

  1. public Alphabet (Object[] entries) {
  2. this (entries.length);
  3. for (Object entry : entries)
  4. this.lookupIndex(entry);
  5. }

代码示例来源:origin: cc.mallet/mallet

  1. public Alphabet (Object[] entries) {
  2. this (entries.length);
  3. for (Object entry : entries)
  4. this.lookupIndex(entry);
  5. }

代码示例来源:origin: cc.mallet/mallet

  1. public Transducer.TransitionIterator transitionIterator (Object o)
  2. {
  3. int inputIndex = inputAlphabet.lookupIndex (o, false);
  4. if (inputIndex == -1)
  5. throw new IllegalArgumentException ("Input not in dictionary.");
  6. return transitionIterator (inputIndex);
  7. }

代码示例来源:origin: cc.mallet/mallet

  1. public double logProbability (Object key)
  2. {
  3. if (dictionary == null)
  4. throw new IllegalStateException ("This Multinomial has no dictionary.");
  5. return logProbability (dictionary.lookupIndex (key));
  6. }

代码示例来源:origin: de.julielab/jcore-mallet-2.0.9

  1. public int location (Object entry)
  2. {
  3. if (dictionary == null)
  4. throw new IllegalStateException ("This FeatureVector has no dictionary.");
  5. int i = dictionary.lookupIndex (entry, false);
  6. if (i < 0)
  7. return -1;
  8. else
  9. return location (i);
  10. }

代码示例来源:origin: de.julielab/jcore-mallet-2.0.9

  1. /** Load an alphabet from a file, one item per line */
  2. public static Alphabet loadFromFile(File alphabetFile) throws IOException {
  3. BufferedReader reader = new BufferedReader(new FileReader(alphabetFile));
  4. Alphabet alphabet = new Alphabet();
  5. String item;
  6. while ((item = reader.readLine()) != null) {
  7. alphabet.lookupIndex(item);
  8. }
  9. reader.close();
  10. return alphabet;
  11. }

代码示例来源:origin: cc.mallet/mallet

  1. public void testReadResolve () throws IOException, ClassNotFoundException
  2. {
  3. Alphabet dict = new Alphabet ();
  4. dict.lookupIndex ("TEST1");
  5. dict.lookupIndex ("TEST2");
  6. dict.lookupIndex ("TEST3");
  7. Alphabet dict2 = (Alphabet) TestSerializable.cloneViaSerialization (dict);
  8. assertTrue (dict == dict2);
  9. }

代码示例来源:origin: cc.mallet/mallet

  1. /** Create a dummy alphabet with <code>n</code> dimensions */
  2. public static Alphabet alphabetOfSize (int n) {
  3. Alphabet alphabet = new Alphabet();
  4. for (int i = 0; i < n; i++) {
  5. alphabet.lookupIndex("d" + i);
  6. }
  7. return alphabet;
  8. }

代码示例来源:origin: cc.mallet/mallet

  1. public boolean contains (Object o)
  2. {
  3. int index = dictionary.lookupIndex (o, false);
  4. if (index == -1)
  5. return false;
  6. return contains (index);
  7. }

代码示例来源:origin: cc.mallet/mallet

  1. private static Alphabet dictOfSize (int size)
  2. {
  3. Alphabet ret = new Alphabet ();
  4. for (int i = 0; i < size; i++)
  5. ret.lookupIndex ("feature"+i);
  6. return ret;
  7. }

代码示例来源:origin: cc.mallet/mallet

  1. public double probability (Object key)
  2. {
  3. if (dictionary == null)
  4. throw new IllegalStateException ("This Multinomial has no dictionary.");
  5. return probability (dictionary.lookupIndex (key));
  6. }

代码示例来源:origin: com.github.steveash.mallet/mallet

  1. private static Alphabet dictOfSize (int n)
  2. {
  3. Alphabet dict = new Alphabet ();
  4. for (int i = 0; i < n; i++) {
  5. dict.lookupIndex ("feature"+i);
  6. }
  7. return dict;
  8. }

代码示例来源:origin: com.github.steveash.mallet/mallet

  1. private static Alphabet dictOfSize (int size)
  2. {
  3. Alphabet ret = new Alphabet ();
  4. for (int i = 0; i < size; i++)
  5. ret.lookupIndex ("feature"+i);
  6. return ret;
  7. }

代码示例来源:origin: com.github.steveash.mallet/mallet

  1. private void expandDict (Alphabet fd, int size)
  2. {
  3. fd.startGrowth ();
  4. for (int i = 0; i < size; i++)
  5. fd.lookupIndex ("feature"+i, true);
  6. }

代码示例来源:origin: com.github.steveash.mallet/mallet

  1. private static Alphabet dictOfSize (int size)
  2. {
  3. Alphabet ret = new Alphabet ();
  4. for (int i = 0; i < size; i++)
  5. ret.lookupIndex ("feature"+i);
  6. return ret;
  7. }

代码示例来源:origin: cc.mallet/mallet

  1. public void testSetRankOrder ()
  2. {
  3. Alphabet v = new Alphabet ();
  4. RankedFeatureVector rfv =
  5. new RankedFeatureVector (v, new int[] {v.lookupIndex ("a"), v.lookupIndex ("b"), v.lookupIndex ("c"), v.lookupIndex ("d") },
  6. new double[] {3.0, 1.0, 2.0, 6.0});
  7. System.out.println ("vector size ="+rfv.numLocations());
  8. for (int i = 0; i < rfv.numLocations(); i++)
  9. System.out.println ("Rank="+i+" value="+rfv.getValueAtRank(i));
  10. }

代码示例来源:origin: cc.mallet/mallet

  1. public Transducer.TransitionIterator transitionIterator (Sequence inputSequence,
  2. int inputPosition)
  3. {
  4. int inputIndex = inputAlphabet.lookupIndex (inputSequence.get(inputPosition), false);
  5. if (inputIndex == -1)
  6. throw new IllegalArgumentException ("Input not in dictionary.");
  7. return transitionIterator (inputIndex);
  8. }

代码示例来源:origin: com.github.steveash.mallet/mallet

  1. public Record (Alphabet fieldAlph, Alphabet valueAlph, String[][] vals) {
  2. this(fieldAlph, valueAlph);
  3. for (int i = 0; i < vals.length; i++) {
  4. AugmentableFeatureVector afv = new AugmentableFeatureVector(valueAlph, false);
  5. for (int j = 1; j < vals[i].length; j++)
  6. afv.add(valueAlph.lookupIndex(vals[i][j]), 1.0);
  7. field2values.put(fieldAlph.lookupIndex(vals[i][0]), afv.toFeatureVector());
  8. }
  9. }

代码示例来源:origin: cc.mallet/mallet

  1. public Alphabet getPrunedAlphabet(int minDocs, int maxDocs, int minCount, int maxCount) {
  2. Alphabet inputAlphabet = instances.getDataAlphabet();
  3. Alphabet outputAlphabet = new Alphabet();
  4. for (int inputType = 0; inputType < numFeatures; inputType++) {
  5. if (featureCounts[inputType] >= minCount && featureCounts[inputType] <= maxCount && documentFrequencies[inputType] >= minDocs && documentFrequencies[inputType] <= maxDocs) {
  6. outputAlphabet.lookupIndex(inputAlphabet.lookupObject(inputType));
  7. }
  8. }
  9. return outputAlphabet;
  10. }

代码示例来源:origin: cc.mallet/mallet

  1. public FeatureSequence toFeatureSequence (Alphabet dict) {
  2. FeatureSequence fs = new FeatureSequence( dict, this.size() );
  3. for (int i = 0; i < this.size(); i++)
  4. fs.add (dict.lookupIndex( (this.get(i)).getText()));
  5. return fs;
  6. }

相关文章