@Test public void testGetContextWithAbbreviations() throws Exception { SDContextGenerator sdContextGenerator = new DefaultSDContextGenerator(new HashSet<>(Arrays.asList("Mr./Inc.".split("/"))), Factory.defaultEosCharacters); String[] context = sdContextGenerator.getContext( "Mr. Smith joined RONDHUIT Inc. as a manager of sales department.", 2); Assert.assertArrayEquals("sn/eos=./x=Mr/2/xcap/xabbrev/v=/s=/n=Smith/ncap".split("/"), context); context = sdContextGenerator.getContext( "Mr. Smith joined RONDHUIT Inc. as a manager of sales department.", 29); Assert.assertArrayEquals("sn/eos=./x=Inc/3/xcap/xabbrev/v=RONDHUIT/vcap/s=/n=as".split("/"), context); }
public String[] getContext(CharSequence sb, int position) { String prefix; String previous; String suffix; String next; int lastIndex = sb.length() - 1; { if (position > 0 && StringUtil.isWhitespace(sb.charAt(position - 1))) collectFeats.add("sp"); if (position < lastIndex && StringUtil.isWhitespace(sb.charAt(position + 1))) collectFeats.add("sn"); collectFeats.add("eos=" + escapeChar(sb.charAt(position))); } int prefixStart = previousSpaceIndex(sb, position); int c = position; { while (--c > prefixStart) { if (eosCharacters.contains(sb.charAt(c))) { prefixStart = c; c++; } } prefix = String.valueOf(sb.subSequence(prefixStart, position)).trim(); } int prevStart = previousSpaceIndex(sb, prefixStart); previous = String.valueOf(sb.subSequence(prevStart, prefixStart)).trim(); int suffixEnd = nextSpaceIndex(sb, position, lastIndex); { c = position; while (++c < suffixEnd) { if (eosCharacters.contains(sb.charAt(c))) { suffixEnd = c; c--; } } } int nextEnd = nextSpaceIndex(sb, suffixEnd + 1, lastIndex + 1); if (position == lastIndex) { suffix = ""; next = ""; } else { suffix = String.valueOf(sb.subSequence(position + 1, suffixEnd)).trim(); next = String.valueOf(sb.subSequence(suffixEnd + 1, nextEnd)).trim(); } collectFeatures(prefix,suffix,previous,next, sb.charAt(position)); String[] context = new String[collectFeats.size()]; context = collectFeats.toArray(context); collectFeats.clear(); return context; }
DefaultSDContextGenerator implements SDContextGenerator { public String[] getContext(CharSequence sb, int position) { String prefix; String previous; String suffix; String next; int lastIndex = sb.length() - 1; { if (position > 0 && StringUtil.isWhitespace(sb.charAt(position - 1))) collectFeats.add("sp"); if (position < lastIndex && StringUtil.isWhitespace(sb.charAt(position + 1))) collectFeats.add("sn"); collectFeats.add("eos=" + escapeChar(sb.charAt(position))); } int prefixStart = previousSpaceIndex(sb, position); int c = position; { while (--c > prefixStart) { if (eosCharacters.contains(sb.charAt(c))) { prefixStart = c; c++; } } prefix = String.valueOf(sb.subSequence(prefixStart, position)).trim(); } int prevStart = previousSpaceIndex(sb, prefixStart); previous = String.valueOf(sb.subSequence(prevStart, prefixStart)).trim(); int suffixEnd = nextSpaceIndex(sb, position, lastIndex); { c = position; while (++c < suffixEnd) { if (eosCharacters.contains(sb.charAt(c))) { suffixEnd = c; c--; } } } int nextEnd = nextSpaceIndex(sb, suffixEnd + 1, lastIndex + 1); if (position == lastIndex) { suffix = ""; next = ""; } else { suffix = String.valueOf(sb.subSequence(position + 1, suffixEnd)).trim(); next = String.valueOf(sb.subSequence(suffixEnd + 1, nextEnd)).trim(); } collectFeatures(prefix,suffix,previous,next, sb.charAt(position)); String[] context = new String[collectFeats.size()]; context = collectFeats.toArray(context); collectFeats.clear(); return context; } }
DefaultSDContextGenerator implements SDContextGenerator { public String[] getContext(CharSequence sb, int position) { String prefix; String previous; String suffix; String next; int lastIndex = sb.length() - 1; { if (position > 0 && StringUtil.isWhitespace(sb.charAt(position - 1))) collectFeats.add("sp"); if (position < lastIndex && StringUtil.isWhitespace(sb.charAt(position + 1))) collectFeats.add("sn"); collectFeats.add("eos=" + escapeChar(sb.charAt(position))); } int prefixStart = previousSpaceIndex(sb, position); int c = position; { while (--c > prefixStart) { if (eosCharacters.contains(sb.charAt(c))) { prefixStart = c; c++; } } prefix = String.valueOf(sb.subSequence(prefixStart, position)).trim(); } int prevStart = previousSpaceIndex(sb, prefixStart); previous = String.valueOf(sb.subSequence(prevStart, prefixStart)).trim(); int suffixEnd = nextSpaceIndex(sb, position, lastIndex); { c = position; while (++c < suffixEnd) { if (eosCharacters.contains(sb.charAt(c))) { suffixEnd = c; c--; } } } int nextEnd = nextSpaceIndex(sb, suffixEnd + 1, lastIndex + 1); if (position == lastIndex) { suffix = ""; next = ""; } else { suffix = String.valueOf(sb.subSequence(position + 1, suffixEnd)).trim(); next = String.valueOf(sb.subSequence(suffixEnd + 1, nextEnd)).trim(); } collectFeatures(prefix,suffix,previous,next, sb.charAt(position)); String[] context = new String[collectFeats.size()]; context = collectFeats.toArray(context); collectFeats.clear(); return context; } DefaultSDContextGenerator(char[] eosCharacters);  DefaultSDContextGenerator(Set<String> inducedAbbreviations, char[] eosCharacters); }
DefaultSDContextGenerator implements SDContextGenerator { public String[] getContext(CharSequence sb, int position) { String prefix; String previous; String suffix; String next; int lastIndex = sb.length() - 1; { if (position > 0 && StringUtil.isWhitespace(sb.charAt(position - 1))) collectFeats.add("sp"); if (position < lastIndex && StringUtil.isWhitespace(sb.charAt(position + 1))) collectFeats.add("sn"); collectFeats.add("eos=" + escapeChar(sb.charAt(position))); } int prefixStart = previousSpaceIndex(sb, position); int c = position; { while (--c > prefixStart) { if (eosCharacters.contains(sb.charAt(c))) { prefixStart = c; c++; } } prefix = String.valueOf(sb.subSequence(prefixStart, position)).trim(); } int prevStart = previousSpaceIndex(sb, prefixStart); previous = String.valueOf(sb.subSequence(prevStart, prefixStart)).trim(); int suffixEnd = nextSpaceIndex(sb, position, lastIndex); { c = position; while (++c < suffixEnd) { if (eosCharacters.contains(sb.charAt(c))) { suffixEnd = c; c--; } } } int nextEnd = nextSpaceIndex(sb, suffixEnd + 1, lastIndex + 1); if (position == lastIndex) { suffix = ""; next = ""; } else { suffix = String.valueOf(sb.subSequence(position + 1, suffixEnd)).trim(); next = String.valueOf(sb.subSequence(suffixEnd + 1, nextEnd)).trim(); } collectFeatures(prefix,suffix,previous,next, sb.charAt(position)); String[] context = new String[collectFeats.size()]; context = collectFeats.toArray(context); collectFeats.clear(); return context; } DefaultSDContextGenerator(char[] eosCharacters);  DefaultSDContextGenerator(Set<String> inducedAbbreviations, char[] eosCharacters); String[] getContext(CharSequence sb, int position); }
DefaultSDContextGenerator implements SDContextGenerator { public String[] getContext(CharSequence sb, int position) { String prefix; String previous; String suffix; String next; int lastIndex = sb.length() - 1; { if (position > 0 && StringUtil.isWhitespace(sb.charAt(position - 1))) collectFeats.add("sp"); if (position < lastIndex && StringUtil.isWhitespace(sb.charAt(position + 1))) collectFeats.add("sn"); collectFeats.add("eos=" + escapeChar(sb.charAt(position))); } int prefixStart = previousSpaceIndex(sb, position); int c = position; { while (--c > prefixStart) { if (eosCharacters.contains(sb.charAt(c))) { prefixStart = c; c++; } } prefix = String.valueOf(sb.subSequence(prefixStart, position)).trim(); } int prevStart = previousSpaceIndex(sb, prefixStart); previous = String.valueOf(sb.subSequence(prevStart, prefixStart)).trim(); int suffixEnd = nextSpaceIndex(sb, position, lastIndex); { c = position; while (++c < suffixEnd) { if (eosCharacters.contains(sb.charAt(c))) { suffixEnd = c; c--; } } } int nextEnd = nextSpaceIndex(sb, suffixEnd + 1, lastIndex + 1); if (position == lastIndex) { suffix = ""; next = ""; } else { suffix = String.valueOf(sb.subSequence(position + 1, suffixEnd)).trim(); next = String.valueOf(sb.subSequence(suffixEnd + 1, nextEnd)).trim(); } collectFeatures(prefix,suffix,previous,next, sb.charAt(position)); String[] context = new String[collectFeats.size()]; context = collectFeats.toArray(context); collectFeats.clear(); return context; } DefaultSDContextGenerator(char[] eosCharacters);  DefaultSDContextGenerator(Set<String> inducedAbbreviations, char[] eosCharacters); String[] getContext(CharSequence sb, int position);  }