public String[] tag(String[] sentence, Object[] additionaContext) { bestSequence = model.bestSequence(sentence, additionaContext, contextGen, sequenceValidator); List<String> t = bestSequence.getOutcomes(); return t.toArray(new String[t.size()]); }
/** * Populates the specified array with the probabilities of the last decoded * sequence. The sequence was determined based on the previous call to * <code>chunk</code>. The specified array should be at least as large as the * number of tokens in the previous call to <code>chunk</code>. * * @param probs An array used to hold the probabilities of the last decoded * sequence. */ public void probs(double[] probs) { bestSequence.getProbs(probs); }
/** * Tests the copy constructor {@link Sequence#Sequence(Sequence)}. */ @Test public void testCopyConstructor() { Sequence sequence = new Sequence(); sequence.add("a", 10); sequence.add("b", 20); Sequence copy = new Sequence(sequence); Assert.assertEquals(sequence.getOutcomes(), copy.getOutcomes()); Assert.assertArrayEquals(sequence.getProbs(), copy.getProbs(), 0.0); Assert.assertTrue(sequence.compareTo(copy) == 0); }
/** * Tests {@link Sequence#compareTo(Sequence)}. */ @Test public void testCompareTo() { Sequence lowScore = new Sequence(); lowScore.add("A", 1d); lowScore.add("B", 2d); lowScore.add("C", 3d); Sequence highScore = new Sequence(); lowScore.add("A", 7d); lowScore.add("B", 8d); lowScore.add("C", 9d); Assert.assertEquals(-1, lowScore.compareTo(highScore)); Assert.assertEquals(1, highScore.compareTo(lowScore)); }
@Test public void testTokenProbArray() throws Exception { Sequence[] preds = chunker.topKSequences(toks1, tags1); Assert.assertTrue(preds.length > 0); Assert.assertEquals(expect1.length, preds[0].getProbs().length); Assert.assertEquals(Arrays.asList(expect1), preds[0].getOutcomes()); Assert.assertNotSame(Arrays.asList(expect1), preds[1].getOutcomes()); }
Queue<Sequence> next = new PriorityQueue<>(size); Queue<Sequence> tmp; prev.add(new Sequence()); List<String> tmpOutcomes = top.getOutcomes(); String[] outcomes = tmpOutcomes.toArray(new String[tmpOutcomes.size()]); String[] contexts = cg.getContext(i, sequence, outcomes, additionalContext); String out = model.getOutcome(p); if (validator.validSequence(i, sequence, outcomes, out)) { Sequence ns = new Sequence(top, out, scores[p]); if (ns.getScore() > minSequenceScore) { next.add(ns); String out = model.getOutcome(p); if (validator.validSequence(i, sequence, outcomes, out)) { Sequence ns = new Sequence(top, out, scores[p]); if (ns.getScore() > minSequenceScore) { next.add(ns);
@Test public void testTokenProbMinScore() throws Exception { Sequence[] preds = chunker.topKSequences(toks1, tags1, -5.55); Assert.assertEquals(4, preds.length); Assert.assertEquals(expect1.length, preds[0].getProbs().length); Assert.assertEquals(Arrays.asList(expect1), preds[0].getOutcomes()); Assert.assertNotSame(Arrays.asList(expect1), preds[1].getOutcomes()); }
Queue<Sequence> next = new PriorityQueue<>(size); Queue<Sequence> tmp; prev.add(new Sequence()); List<String> tmpOutcomes = top.getOutcomes(); String[] outcomes = tmpOutcomes.toArray(new String[tmpOutcomes.size()]); String[] contexts = cg.getContext(i, sequence, outcomes, additionalContext); String out = model.getOutcome(p); if (validator.validSequence(i, sequence, outcomes, out)) { Sequence ns = new Sequence(top, out, scores[p]); if (ns.getScore() > minSequenceScore) { next.add(ns); String out = model.getOutcome(p); if (validator.validSequence(i, sequence, outcomes, out)) { Sequence ns = new Sequence(top, out, scores[p]); if (ns.getScore() > minSequenceScore) { next.add(ns);
/** * Advances the parse by assigning it POS tags and returns multiple tag sequences. * @param p The parse to be tagged. * @return Parses with different POS-tag sequence assignments. */ protected Parse[] advanceTags(final Parse p) { Parse[] children = p.getChildren(); String[] words = new String[children.length]; double[] probs = new double[words.length]; for (int i = 0,il = children.length; i < il; i++) { words[i] = children[i].getCoveredText(); } Sequence[] ts = tagger.topKSequences(words); Parse[] newParses = new Parse[ts.length]; for (int i = 0; i < ts.length; i++) { String[] tags = ts[i].getOutcomes().toArray(new String[words.length]); ts[i].getProbs(probs); newParses[i] = (Parse) p.clone(); //copies top level if (createDerivationString) newParses[i].getDerivation().append(i).append("."); for (int j = 0; j < words.length; j++) { Parse word = children[j]; //System.err.println("inserting tag "+tags[j]); double prob = probs[j]; newParses[i].insert(new Parse(word.getText(), word.getSpan(), tags[j], prob,j)); newParses[i].addProb(Math.log(prob)); } } return newParses; }
/** * Returns an array with the probabilities of the last decoded sequence. The * sequence was determined based on the previous call to <code>chunk</code>. * @return An array with the same number of probabilities as tokens were sent to <code>chunk</code> * when it was last called. */ public double[] probs() { return bestSequence.getProbs(); }
/** * Predict Short Edit Script (automatically induced lemma class). * @param toks the array of tokens * @param tags the array of pos tags * @return an array containing the lemma classes */ public String[] predictSES(String[] toks, String[] tags) { bestSequence = model.bestSequence(toks, new Object[] {tags}, contextGenerator, sequenceValidator); List<String> ses = bestSequence.getOutcomes(); return ses.toArray(new String[ses.size()]); }
/** * Tests {@link Sequence#add(String, double)}, also * tests {@link Sequence#getOutcomes()} and {@link Sequence#getProbs()}. */ @Test public void testAddMethod() { Sequence sequence = new Sequence(); sequence.add("a", 10d); // check if insert was successful Assert.assertEquals("a", sequence.getOutcomes().get(0)); Assert.assertEquals(10d, sequence.getProbs()[0], 0d); }
Queue<Sequence> next = new PriorityQueue<>(size); Queue<Sequence> tmp; prev.add(new Sequence()); List<String> tmpOutcomes = top.getOutcomes(); String[] outcomes = tmpOutcomes.toArray(new String[tmpOutcomes.size()]); String[] contexts = cg.getContext(i, sequence, outcomes, additionalContext); String out = model.getOutcome(p); if (validator.validSequence(i, sequence, outcomes, out)) { Sequence ns = new Sequence(top, out, scores[p]); if (ns.getScore() > minSequenceScore) { next.add(ns); String out = model.getOutcome(p); if (validator.validSequence(i, sequence, outcomes, out)) { Sequence ns = new Sequence(top, out, scores[p]); if (ns.getScore() > minSequenceScore) { next.add(ns);
String[] tags = cs[si].getOutcomes().toArray(new String[words.length]); cs[si].getProbs(probs); int start = -1; int end = 0;
/** * Populates the specified array with the probabilities of the last decoded sequence. The * sequence was determined based on the previous call to <code>lemmatize</code>. The * specified array should be at least as large as the number of tokens in the * previous call to <code>lemmatize</code>. * * @param probs An array used to hold the probabilities of the last decoded sequence. */ public void probs(double[] probs) { bestSequence.getProbs(probs); }
/** * Returns at most the specified number of taggings for the specified sentence. * * @param numTaggings The number of tagging to be returned. * @param sentence An array of tokens which make up a sentence. * * @return At most the specified number of taggings for the specified sentence. */ public String[][] tag(int numTaggings, String[] sentence) { Sequence[] bestSequences = model.bestSequences(numTaggings, sentence, null, contextGen, sequenceValidator); String[][] tags = new String[bestSequences.length][]; for (int si = 0; si < tags.length; si++) { List<String> t = bestSequences[si].getOutcomes(); tags[si] = t.toArray(new String[t.size()]); } return tags; }
Heap<Sequence> next = new ListHeap<Sequence>(size); Heap<Sequence> tmp; prev.add(new Sequence()); List<String> tmpOutcomes = top.getOutcomes(); String[] outcomes = tmpOutcomes.toArray(new String[tmpOutcomes.size()]); String[] contexts = cg.getContext(i, sequence, outcomes, additionalContext); String out = model.getOutcome(p); if (validSequence(i, sequence, outcomes, out)) { Sequence ns = new Sequence(top, out, scores[p]); if (ns.getScore() > minSequenceScore) { next.add(ns); String out = model.getOutcome(p); if (validSequence(i, sequence, outcomes, out)) { Sequence ns = new Sequence(top, out, scores[p]); if (ns.getScore() > minSequenceScore) { next.add(ns);
int j = 0; while( j < posSequences.length && !done){ String p = posSequences[j].getOutcomes().get(i); done = j > 0 && p.equals(actPos[0].getTag()); if(!done){ actPos[j] = getPosTag(posModel,adhocTags,p,language); actProp[j] = posSequences[j].getProbs()[i]; j++;
/** * Populates the specified array with the probabilities for each tag of the last tagged sentence. * * @param probs An array to put the probabilities into. */ public void probs(double[] probs) { bestSequence.getProbs(probs); }