List of usage examples for opennlp.tools.util Span Span
public Span(int s, int e, double prob)
From source file:com.civis.utils.opennlp.models.address.AddressFinderMe.java
private Span[] find(String[] tokens, String[][] additionalContext) { this.additionalContextFeatureGenerator.setCurrentContext(additionalContext); this.bestSequence = this.beam.bestSequence(tokens, additionalContext); List<String> c = this.bestSequence.getOutcomes(); this.contextGenerator.updateAdaptiveData(tokens, c.toArray(new String[c.size()])); int start = -1; int end = -1; ArrayList<Span> spans = new ArrayList<>(tokens.length); for (int li = 0; li < c.size(); ++li) { String chunkTag = c.get(li); if (chunkTag.endsWith("start")) { if (start != -1) { spans.add(new Span(start, end, c.get(li - 1))); }//from www. j av a2 s .c om start = li; end = li + 1; } else if (chunkTag.endsWith("cont")) { end = li + 1; } else if (chunkTag.endsWith("other") && start != -1) { spans.add(new Span(start, end, c.get(li - 1))); start = -1; end = -1; } } if (start != -1) { spans.add(new Span(start, end, c.get(c.size() - 1))); } return spans.toArray(new Span[spans.size()]); }