Repository navigation
OPENNLP-1991: Add a feedforward neural dependency parser #1323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -544,30 +544,145 @@ public static boolean isUnicodeBlank(CharSequence input) { | |
| return true; | ||
| } | ||
|
|
||
| /** U+03A3, GREEK CAPITAL LETTER SIGMA, the one code point whose lowering depends on context. */ | ||
| private static final int GREEK_CAPITAL_SIGMA = 0x03A3; | ||
|
|
||
| /** U+03C2, GREEK SMALL LETTER FINAL SIGMA, the lowering of the capital at the end of a word. */ | ||
| private static final int GREEK_SMALL_FINAL_SIGMA = 0x03C2; | ||
|
|
||
| /** | ||
| * Converts a {@link CharSequence} to lower case, independent of the current | ||
| * {@link java.util.Locale} via {@link Character#toLowerCase(int)} which uses | ||
| * mapping information from the UnicodeData file. | ||
| * {@link java.util.Locale}. Each code point maps through | ||
| * {@link Character#toLowerCase(int)}, the UnicodeData mapping, so no character | ||
| * expands. The one contextual rule of the Unicode | ||
| * <a href="https://www.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt">SpecialCasing</a> | ||
| * data applies as well: a Greek capital sigma at the end of a word, after a cased | ||
| * letter and before no further cased letter, becomes the final sigma U+03C2. | ||
| * | ||
| * @param string The {@link CharSequence} to transform. | ||
| * @return The lower-cased String. | ||
| */ | ||
| public static String toLowerCase(CharSequence string) { | ||
| int[] cp = string.codePoints().map(Character::toLowerCase).toArray(); | ||
| int[] cp = toLowerCaseCodePoints(string); | ||
| return new String(cp, 0, cp.length); | ||
| } | ||
|
|
||
| /** | ||
| * Converts a {@link CharSequence} to lower case into a {@link CharBuffer}, with the | ||
| * mapping of {@link #toLowerCase(CharSequence)}. | ||
| * | ||
| * @param sequence The {@link CharSequence} to transform. | ||
| * @return The lower-cased characters, positioned at the start. | ||
| */ | ||
| public static CharBuffer toLowerCaseCharBuffer(CharSequence sequence) { | ||
| CharBuffer result = CharBuffer.allocate(sequence.length()); | ||
| for (int cp : sequence.codePoints().toArray()) { | ||
| for (char c : Character.toChars(Character.toLowerCase(cp))) { | ||
| result.append(c); | ||
| for (int cp : toLowerCaseCodePoints(sequence)) { | ||
| if (Character.isBmpCodePoint(cp)) { | ||
| result.put((char) cp); | ||
| } else { | ||
| result.put(Character.highSurrogate(cp)); | ||
| result.put(Character.lowSurrogate(cp)); | ||
| } | ||
| } | ||
| result.clear(); | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Lowers every code point of a sequence, applying the Final_Sigma context. | ||
| * | ||
| * @param sequence The {@link CharSequence} to transform. | ||
| * @return The lower-cased code points. | ||
| */ | ||
| private static int[] toLowerCaseCodePoints(CharSequence sequence) { | ||
| final int[] source = sequence.codePoints().toArray(); | ||
| final int[] lowered = new int[source.length]; | ||
| for (int i = 0; i < source.length; i++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking: The final sigma rule now applies to the public |
||
| lowered[i] = source[i] == GREEK_CAPITAL_SIGMA && isFinalSigma(source, i) | ||
| ? GREEK_SMALL_FINAL_SIGMA : Character.toLowerCase(source[i]); | ||
| } | ||
| return lowered; | ||
| } | ||
|
|
||
| /** | ||
| * The Final_Sigma condition of the Unicode SpecialCasing data: the code point is | ||
| * preceded by a cased letter and then zero or more case-ignorable code points, and | ||
| * is not followed by zero or more case-ignorable code points and then a cased letter. | ||
| * | ||
| * @param cp The code points of the sequence. | ||
| * @param index The position of the capital sigma. | ||
| * @return {@code true} if the sigma at {@code index} is word-final. | ||
| */ | ||
| private static boolean isFinalSigma(int[] cp, int index) { | ||
| int before = index - 1; | ||
| while (before >= 0 && isCaseIgnorable(cp[before])) { | ||
| before--; | ||
| } | ||
| if (before < 0 || !isCased(cp[before])) { | ||
| return false; | ||
| } | ||
| int after = index + 1; | ||
| while (after < cp.length && isCaseIgnorable(cp[after])) { | ||
| after++; | ||
| } | ||
| return after == cp.length || !isCased(cp[after]); | ||
| } | ||
|
|
||
| /** | ||
| * @param cp The code point to test. | ||
| * @return {@code true} if the code point has the Unicode Cased property: an upper, | ||
| * lower, or title case letter, including the Other_Uppercase and | ||
| * Other_Lowercase code points. | ||
| */ | ||
| private static boolean isCased(int cp) { | ||
| return Character.isUpperCase(cp) || Character.isLowerCase(cp) || Character.isTitleCase(cp); | ||
| } | ||
|
|
||
| /** | ||
| * @param cp The code point to test. | ||
| * @return {@code true} if the code point has the Unicode Case_Ignorable property: the | ||
| * general categories Mn, Me, Cf, Lm, and Sk, and the | ||
| * <a href="https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/WordBreakProperty.txt">Word_Break</a> | ||
| * values MidLetter, MidNumLet, and Single_Quote. | ||
| */ | ||
| private static boolean isCaseIgnorable(int cp) { | ||
| switch (Character.getType(cp)) { | ||
| case Character.NON_SPACING_MARK: | ||
| case Character.ENCLOSING_MARK: | ||
| case Character.FORMAT: | ||
| case Character.MODIFIER_LETTER: | ||
| case Character.MODIFIER_SYMBOL: | ||
| return true; | ||
| default: | ||
| break; | ||
| } | ||
| switch (cp) { | ||
| // Single_Quote | ||
| case 0x0027: | ||
| // MidLetter | ||
| case 0x003A: | ||
| case 0x00B7: | ||
| case 0x0387: | ||
| case 0x055F: | ||
| case 0x05F4: | ||
| case 0x2027: | ||
| case 0xFE13: | ||
| case 0xFE55: | ||
| case 0xFF1A: | ||
| // MidNumLet | ||
| case 0x002E: | ||
| case 0x2018: | ||
| case 0x2019: | ||
| case 0x2024: | ||
| case 0xFE52: | ||
| case 0xFF07: | ||
| case 0xFF0E: | ||
| return true; | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| public static CharBuffer toLowerCaseCharBuffer(CharSequence string) { | ||
| int[] cp = string.codePoints().map(Character::toLowerCase).toArray(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rejecting infinity here differs from the
requireNonNegative+requireFinitecomposition used elsewhere (e.g. the trainer at:194). Intended?