/** * This constructor creates an UWM with empty data structures. Only * use if loading in the data separately, such as by reading in text * lines containing the data. */ public SpanishUnknownWordModel(Options op, Lexicon lex, Index<String> wordIndex, Index<String> tagIndex) { this(op, lex, wordIndex, tagIndex, new ClassicCounter<>()); }
/** * This constructor creates an UWM with empty data structures. Only * use if loading in the data separately, such as by reading in text * lines containing the data. */ public EnglishUnknownWordModel(Options op, Lexicon lex, Index<String> wordIndex, Index<String> tagIndex) { this(op, lex, wordIndex, tagIndex, new ClassicCounter<>()); }
/** * This constructor creates an UWM with empty data structures. Only * use if loading in the data separately, such as by reading in text * lines containing the data. */ public FrenchUnknownWordModel(Options op, Lexicon lex, Index<String> wordIndex, Index<String> tagIndex) { this(op, lex, wordIndex, tagIndex, new ClassicCounter<>()); }
/** * This constructor creates an UWM with empty data structures. Only * use if loading in the data separately, such as by reading in text * lines containing the data. */ public ArabicUnknownWordModel(Options op, Lexicon lex, Index<String> wordIndex, Index<String> tagIndex) { this(op, lex, wordIndex, tagIndex, new ClassicCounter<>()); }
public ObservedCorpusStats(String name) { corpusName = name; words = new ClassicCounter<>(); posTags = new ClassicCounter<>(); phrasalBranching2 = new ClassicCounter<>(); phrasalBranchingNum2 = new ClassicCounter<>(); lengths = new ArrayList<>(); depths = new ArrayList<>(); breadths = new ArrayList<>(); }
public void addFeatures(Collection<String> feat) { if(features == null){ features = new ClassicCounter<>(); } Counters.addInPlace(features, feat); }
public static<E, E2> Counter<E> flatten(Map<E2, Counter<E>> hier){ Counter<E> flat = new ClassicCounter<>(); for(Entry<E2, Counter<E>> en: hier.entrySet()){ flat.addAll(en.getValue()); } return flat; }
public void addFeature(String s, double v) { if(features == null){ features = new ClassicCounter<>(); } features.setCount(s, v); }
public MetadataWriter(boolean countWords) { this.countWords = countWords; mentionTypes = new HashMap<>(); goldClusters = new HashMap<>(); wordCounts = new ClassicCounter<>(); try { mentionPairs = IOUtils.readObjectFromFile(StatisticalCorefTrainer.datasetFile); } catch (Exception e) { throw new RuntimeException(e); } }
private static Counter<String> addSuffix(Counter<String> features, String suffix) { Counter<String> withSuffix = new ClassicCounter<>(); for (Map.Entry<String, Double> e : features.entrySet()) { withSuffix.incrementCount(e.getKey() + suffix, e.getValue()); } return withSuffix; }
public static<E> Counter<E> getCounts(Counter<E> c, Collection<E> keys){ Counter<E> newcounter = new ClassicCounter<>(); for(E k : keys) newcounter.setCount(k, c.getCount(k)); return newcounter; }
@Override public void initializeTraining(double numTrees) { lex.initializeTraining(numTrees); this.initial = new ClassicCounter<>(); this.ruleCounter = new GeneralizedCounter(2); }
public ClassicCounter<OUT> lastPrecision() { ClassicCounter<OUT> result = new ClassicCounter<>(); Counters.addInPlace(result, previousGuessedCorrect); Counters.divideInPlace(result, previousGuessed); return result; }
protected static Distribution<String> computeInputPrior(Map<String, List<List<String>>> allTrainPaths) { ClassicCounter<String> result = new ClassicCounter<>(); for (List<List<String>> pathList : allTrainPaths.values()) { for (List<String> path : pathList) { for (String input : path) { result.incrementCount(input); } } } return Distribution.laplaceSmoothedDistribution(result, result.size() * 2, 0.5); }
/** * Returns the counter with keys modified according to function F. Eager * evaluation. If two keys are same after the transformation, one of the values is randomly chosen (depending on how the keyset is traversed) */ public static <T1, T2> Counter<T2> transform(Counter<T1> c, Function<T1, T2> f) { Counter<T2> c2 = new ClassicCounter<>(); for (T1 key : c.keySet()) { c2.setCount(f.apply(key), c.getCount(key)); } return c2; }
public ClassicCounter<L> numDatumsPerLabel(){ labels = trimToSize(labels); ClassicCounter<L> numDatums = new ClassicCounter<>(); for(int i : labels){ numDatums.incrementCount(labelIndex.get(i)); } return numDatums; }
private static <F, L> Counter<Pair<F, L>> makeWeightCounter(double[] weights, Index<Pair<F, L>> weightIndex) { Counter<Pair<F,L>> weightCounter = new ClassicCounter<>(); for (int i = 0; i < weightIndex.size(); i++) { if (weights[i] == 0) { continue; // no need to save 0 weights } weightCounter.setCount(weightIndex.get(i), weights[i]); } return weightCounter; }
private static Counter<String> getFeatures(ClustererDoc doc, Pair<Integer, Integer> mentionPair, Counter<Pair<Integer, Integer>> scores) { Counter<String> features = new ClassicCounter<>(); if (!scores.containsKey(mentionPair)) { mentionPair = new Pair<>(mentionPair.second, mentionPair.first); } double score = scores.getCount(mentionPair); features.incrementCount("max", score); return features; }
@Override public Counter<CandidatePhrase> scorePhrases(String label, Set<CandidatePhrase> terms, boolean forLearningPatterns) throws IOException, ClassNotFoundException { getAllLabeledWordsCluster(); Counter<CandidatePhrase> scores = new ClassicCounter<>(); edu.stanford.nlp.classify.Classifier classifier = learnClassifier(label, forLearningPatterns, null, null); for (CandidatePhrase en : terms) { double score = this.scoreUsingClassifer(classifier, en, label, forLearningPatterns,null, null); scores.setCount(en, score); } return scores; }
public Counter<E> condLogProbsGivenPrevious(int position, int[] prevlabels) { Counter<E> c = new ClassicCounter<>(); for (int i = 0, sz = classIndex.size(); i < sz; i++) { E label = classIndex.get(i); c.incrementCount(label, condLogProbGivenPrevious(position, i, prevlabels)); } return c; }