public NGram history() { return new NGram(Arrays.copyOfRange(ngram, 0, ngram.length-1)); }
@Override public int compareTo(NGram o) { if(o.ngram.length < this.ngram.length) { return -1; } else if(o.ngram.length > this.ngram.length) { return +1; } else { for(int i = 0; i < this.ngram.length; i++) { final int c = compare(this.ngram[i], o.ngram[i]); if(c != 0) { return c; } } return 0; } }
public NGram(int[] ngram) { this.ngram = ngram; assert ngramNonnegative(ngram); }
@Override public int compare(NGram o1, NGram o2) { final double salience1 = salience.getDouble(o1); final double salience2 = salience.getDouble(o2); if(salience1 < salience2) { return +1; } else if(salience1 > salience2) { return -1; } else { return o1.compareTo(o2); } } });
outs[n].println(Arrays.toString(ngram.ngram) + " " + betaScore); if (n > 0) { outs[n + N].print(Arrays.toString(ngram.future().ngram) + " "); outs[n + N].println(ngram.ngram[0] + " " + betaScore);
public NGram future() { return new NGram(Arrays.copyOfRange(ngram, 1, ngram.length)); }
/** * Get the most recently read n-gram * @param n The length of the n-gram * @return The NGram (as a hashable object) */ public NGram ngram(int n) { if(n > N || n > b) { throw new IllegalArgumentException("NGram not in carousel"); } if(n < 0) { throw new IllegalArgumentException("Negative n"); } return new NGram(Arrays.copyOfRange(carousel, b-n, b)); } }
public static SalienceMetric fromFile(final File salienceFile) throws IOException { final DataInputStream in = new DataInputStream(CLIOpts.openInputAsMaybeZipped(salienceFile)); final Object2DoubleMap<NGram> ngrams = new Object2DoubleRBTreeMap<NGram>(); int N = 0; while (true) { try { int n = in.readInt(); N = Math.max(N, n); int[] ng = new int[n]; for (int i = 0; i < n; i++) { ng[i] = in.readInt(); } ngrams.put(new NGram(ng), in.readDouble()); } catch (EOFException x) { break; } } in.close(); return new SalienceMetric(ngrams,N); }
ng[i] = in.readInt(); ngrams.put(new NGram(ng), in.readDouble()); } catch (EOFException x) { break;