当前位置: 首页>>代码示例>>Java>>正文


Java ErasureUtils类代码示例

本文整理汇总了Java中edu.stanford.nlp.util.ErasureUtils的典型用法代码示例。如果您正苦于以下问题:Java ErasureUtils类的具体用法?Java ErasureUtils怎么用?Java ErasureUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ErasureUtils类属于edu.stanford.nlp.util包,在下文中一共展示了ErasureUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: equals

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
@Override
public boolean equals(Object o) {
  if (this == o) {
    return true;
  }
  if (!(o instanceof Entry)) {
    return false;
  }
  Entry<K,V> e = ErasureUtils.<Entry<K,V>>uncheckedCast(o);

  Object key1 = e.getKey();
  if (!(key != null && key.equals(key1))) {
    return false;
  }

  Object value1 = e.getValue();
  if (!(value != null && value.equals(value1))) {
    return false;
  }

  return true;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:23,代码来源:GeneralizedCounter.java

示例2: toString

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
public static <E> String toString(Counter<E> counter, NumberFormat nf) {
  StringBuilder sb = new StringBuilder();
  sb.append('{');
  List<E> list = ErasureUtils.sortedIfPossible(counter.keySet());
  //*/
  for (Iterator<E> iter = list.iterator(); iter.hasNext();) {
    E key = iter.next();
    sb.append(key);
    sb.append('=');
    sb.append(nf.format(counter.getCount(key)));
    if (iter.hasNext()) {
      sb.append(", ");
    }
  }
  sb.append('}');
  return sb.toString();
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:18,代码来源:Counters.java

示例3: toString

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
public static <E> String toString(Counter<E> counter, NumberFormat nf) {
  StringBuilder sb = new StringBuilder();
  sb.append('{');
  List<E> list = ErasureUtils.sortedIfPossible(counter.keySet());
  // */
  for (Iterator<E> iter = list.iterator(); iter.hasNext();) {
    E key = iter.next();
    sb.append(key);
    sb.append('=');
    sb.append(nf.format(counter.getCount(key)));
    if (iter.hasNext()) {
      sb.append(", ");
    }
  }
  sb.append('}');
  return sb.toString();
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:18,代码来源:Counters.java

示例4: arcLabelsToNode

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
/**
 * Finds all arcs between this node and <code>destNode</code>,
 * and returns the <code>Set</code> of <code>Object</code>s which
 * label those arcs.  If no such arcs exist, returns an empty
 * <code>Set</code>.
 *
 * @param destNode the destination node
 * @return the <code>Set</code> of <code>Object</code>s which
 *         label arcs between this node and <code>destNode</code>
 */
public Set<Class<? extends GrammaticalRelationAnnotation>> arcLabelsToNode(TreeGraphNode destNode) {
  Set<Class<? extends GrammaticalRelationAnnotation>> arcLabels = Generics.newHashSet();
  CoreLabel cl = label();
  for (Class key : cl.keySet()) {
    if (key == null || !GrammaticalRelationAnnotation.class.isAssignableFrom(key)) {
      continue;
    }
    Class<? extends GrammaticalRelationAnnotation> typedKey = ErasureUtils.uncheckedCast(key);
    Set<TreeGraphNode> val = cl.get(typedKey);
    if (val != null && val.contains(destNode)) {
      arcLabels.add(typedKey);
    }
  }
  return arcLabels;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:26,代码来源:TreeGraphNode.java

示例5: init

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
public void init(SeqClassifierFlags flags) {
  String options = "tokenizeNLs=false,invertible=true";
  if (flags.tokenizerOptions != null) {
    options = options + "," + flags.tokenizerOptions;
  }
  TokenizerFactory<IN> factory;
  if (flags.tokenizerFactory != null) {
    try {
      Class<TokenizerFactory<? extends HasWord>> clazz = ErasureUtils.uncheckedCast(Class.forName(flags.tokenizerFactory));
      Method factoryMethod = clazz.getMethod("newCoreLabelTokenizerFactory", String.class);
      factory = ErasureUtils.uncheckedCast(factoryMethod.invoke(null, options));
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  } else {
    factory = ErasureUtils.uncheckedCast(PTBTokenizer.PTBTokenizerFactory.newCoreLabelTokenizerFactory(options));
  }
  init(flags, factory);
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:20,代码来源:PlainTextDocumentReaderAndWriter.java

示例6: checkDataStructures

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
/**
 * THIS NEEDS TO BE WRITTEN FOR ENTITIES
 * Check that if we run over the words/deps of all the documents right now (presumably after running
 * some iterations), counting how many words/deps appear will match up with the global counts.
 */
private boolean checkDataStructures() {
  double[] countedTopicCounts = new double[numTopics];
  ClassicCounter<Integer>[] countedWCountsBySlot = ErasureUtils.<ClassicCounter<Integer>>mkTArray(ClassicCounter.class,numTopics);
  ClassicCounter<Integer>[] countedDepCountsBySlot = ErasureUtils.<ClassicCounter<Integer>>mkTArray(ClassicCounter.class,numTopics);
  for (int i = 0; i < countedWCountsBySlot.length; i++) {
    countedWCountsBySlot[i] = new ClassicCounter<Integer>();
    countedDepCountsBySlot[i] = new ClassicCounter<Integer>();
  }
  for (int docNum = 0; docNum < words.length; docNum++) {
    for (int entityNum = 0; entityNum < words[docNum].length; entityNum++) {
      for (int wordNum = 0; wordNum < words[docNum].length; wordNum++) {
        int topic = zs[docNum][entityNum];
        int word = words[docNum][entityNum][wordNum];
        int dep = deps[docNum][entityNum][wordNum];
        countedTopicCounts[topic]++;
        countedWCountsBySlot[topic].incrementCount(word);
        countedDepCountsBySlot[topic].incrementCount(dep);
      }
    }
  }

  if( !Arrays.equals(countedTopicCounts, topicCounts) ) {
    System.out.println("Topic check failed: " + Arrays.toString(countedTopicCounts) + " actual " + Arrays.toString(topicCounts));
    return false;
  }

  if( !Arrays.equals(countedWCountsBySlot, wCountsBySlot) ) {
    System.out.println("WCounts check failed: " + Arrays.toString(countedWCountsBySlot) + " actual " + Arrays.toString(wCountsBySlot));
    return false;
  }

  if( !Arrays.equals(countedDepCountsBySlot, depCountsBySlot) ) {
    System.out.println("DepCounts check failed: " + Arrays.toString(countedDepCountsBySlot) + " actual " + Arrays.toString(depCountsBySlot));
    return false;
  }
  return true;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:43,代码来源:GibbsSamplerEntities.java

示例7: cloneCounter

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
/**
 * Make a copy of the array of counters.
 */
public ClassicCounter<Integer>[] cloneCounter(ClassicCounter<Integer>[] counter) {
  ClassicCounter<Integer>[] newcount = ErasureUtils.<ClassicCounter<Integer>>mkTArray(ClassicCounter.class, counter.length);
  for( int xx = 0; xx < counter.length; xx++ ) {
    ClassicCounter<Integer> cc = new ClassicCounter<Integer>();
    newcount[xx] = cc;
    for( Integer key : counter[xx].keySet() )
      cc.incrementCount(key, counter[xx].getCount(key));
  }
  return newcount;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:14,代码来源:EntityModelInstance.java

示例8: train

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
public void train(Collection<Tree> trees) {
  Numberer tagNumberer = Numberer.getGlobalNumberer("tags");
  lex.train(trees);
  ClassicCounter<String> initial = new ClassicCounter<String>();
  GeneralizedCounter ruleCounter = new GeneralizedCounter(2);
  for (Tree tree : trees) {
    List<Label> tags = tree.preTerminalYield();
    String last = null;
    for (Label tagLabel : tags) {
      String tag = tagLabel.value();
      tagNumberer.number(tag);
      if (last == null) {
        initial.incrementCount(tag);
      } else {
        ruleCounter.incrementCount2D(last, tag);
      }
      last = tag;
    }
  }
  int numTags = tagNumberer.total();
  POSes = new HashSet<String>(ErasureUtils.<Collection<String>>uncheckedCast(tagNumberer.objects()));
  initialPOSDist = Distribution.laplaceSmoothedDistribution(initial, numTags, 0.5);
  markovPOSDists = new HashMap<String, Distribution>();
  Set entries = ruleCounter.lowestLevelCounterEntrySet();
  for (Iterator iter = entries.iterator(); iter.hasNext();) {
    Map.Entry entry = (Map.Entry) iter.next();
    //      Map.Entry<List<String>, Counter> entry = (Map.Entry<List<String>, Counter>) iter.next();
    Distribution d = Distribution.laplaceSmoothedDistribution((ClassicCounter) entry.getValue(), numTags, 0.5);
    markovPOSDists.put(((List<String>) entry.getKey()).get(0), d);
  }
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:32,代码来源:ChineseMarkovWordSegmenter.java

示例9: dumpNumberer

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static void dumpNumberer(Numberer num, String name, PrintWriter pw) {
  pw.println("### Sorted contents of " + name);
  List<Comparable> lis = new ArrayList<Comparable>(ErasureUtils.<Collection<Comparable>>uncheckedCast(num.objects()));
  Collections.sort(lis);
  for (Object obj : lis) {
    pw.println(obj);
  }
  pw.println("### End sorted contents of " + name);
  pw.flush();
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:12,代码来源:Options.java

示例10: KeyLookup

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
/**
 * This constructor allows us to use reflection for loading old class keys.
 * This is useful because we can then create distributions that do not have
 * all of the classes required for all the old keys (such as trees package classes).
 */
private KeyLookup(String className, String oldKey) {
  Class<?> keyClass;
  try {
   keyClass = Class.forName(className);
  } catch(ClassNotFoundException e) {
    GenericAnnotation<Object> newKey = new GenericAnnotation<Object>() {
      public Class<Object> getType() { return Object.class;} };
    keyClass = newKey.getClass();
  }
  this.coreKey = ErasureUtils.uncheckedCast(keyClass);
  this.oldKey = oldKey;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:18,代码来源:AnnotationLookup.java

示例11: getCount

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
/**
 * A convenience method equivalent to <code>{@link
 * #getCounts}({o1,o2})</code>; works only for depth 2
 * GeneralizedCounters
 */
public double getCount(K o1, K o2) {
  if (depth != 2) {
    wrongDepth();
  }
  GeneralizedCounter<K> gc1 = ErasureUtils.<GeneralizedCounter<K>>uncheckedCast(map.get(o1));
  if (gc1 == null) {
    return 0.0;
  } else {
    return gc1.getCount(o2);
  }
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:17,代码来源:GeneralizedCounter.java

示例12: conditionalizeHelper

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
private GeneralizedCounter<K> conditionalizeHelper(K o) {
  if (depth > 1) {
    GeneralizedCounter<K> next = ErasureUtils.<GeneralizedCounter<K>>uncheckedCast(map.get(o));
    if (next == null) // adds a new GeneralizedCounter if needed
    {
      map.put(o, (next = new GeneralizedCounter<K>(depth - 1)));
    }
    return next;
  } else {
    throw new RuntimeException("Error -- can't conditionalize a distribution of depth 1");
  }
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:13,代码来源:GeneralizedCounter.java

示例13: deserializeCounter

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
public static <T> ClassicCounter<T> deserializeCounter(String filename) throws Exception {
    // reconstitute
    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(filename)));
    ClassicCounter<T> c = ErasureUtils.<ClassicCounter<T>>uncheckedCast(in.readObject());
    in.close();
    return c;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:8,代码来源:Counters.java

示例14: equalsIgnoreName

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
public boolean equalsIgnoreName(Object o) {
  if (this == o) {
    return true;
  }
  if (o instanceof Dependency<?, ?, ?>) {
    Dependency<Label, Label, Object> d = ErasureUtils.<Dependency<Label, Label, Object>>uncheckedCast(o);
    return governor().equals(d.governor()) && dependent().equals(d.dependent());
  }
  return false;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:11,代码来源:UnnamedDependency.java

示例15: equalsIgnoreName

import edu.stanford.nlp.util.ErasureUtils; //导入依赖的package包/类
public boolean equalsIgnoreName(Object o) {
  if (this == o) {
    return true;
  }
  if (o instanceof Dependency) {
    Dependency<Label, Label, Object> d = ErasureUtils.<Dependency<Label, Label, Object>>uncheckedCast(o);
    return governor().equals(d.governor()) && dependent().equals(d.dependent());
  }
  return false;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:11,代码来源:NamedDependency.java


注:本文中的edu.stanford.nlp.util.ErasureUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。