Revision: 14954
http://sourceforge.net/p/foray/code/14954
Author: victormote
Date: 2026-07-30 17:23:12 +0000 (Thu, 30 Jul 2026)
Log Message:
-----------
Minor cleanup.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2026-07-30 17:05:44 UTC (rev 14953)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2026-07-30 17:23:12 UTC (rev 14954)
@@ -367,7 +367,6 @@
element.column = columnString == null ? -1 : Integer.parseInt(columnString);
element.xpath = XPATH_ATTRIBUTE.getValue(attributes);
this.elementStack.push(element);
-
}
@Override
@@ -375,15 +374,13 @@
if (this.elementStack.size() < 1) {
throw new SAXException("Element stack is empty but should not be.");
}
- final WritingSystem4a oldWritingSystem = getCurrentWritingSystem();
- final Element element;
+ final Element currentElement = this.elementStack.peek();
+
if ("marker".equals(localName)) {
- /* The "marker" element did not go on the stack. Don't pop it or check it. */
- element = null;
+ /* The "marker" element did not go on the stack. Don't try to check it. */
} else {
- element = this.elementStack.pop();
- if (! element.matches(uri, localName, qName)) {
+ if (! currentElement.matches(uri, localName, qName)) {
throw new SAXException("Closing element does not match top of stack.");
}
}
@@ -394,15 +391,14 @@
* startElement. What is in the text buffer right now should be exactly the content of the "word"
* element. */
final String text = getAndClearText();
- lexer.addWordToken(text, oldWritingSystem);
+ lexer.addWordToken(text, getCurrentWritingSystem());
break;
}
case ("text"): {
/* We are at the end of a terminal element. Check the spelling. */
final String text = getAndClearText();
- lexer.addUntokenized(text, oldWritingSystem);
- final TextElement textElement = (TextElement) element;
- checkWords(textElement);
+ lexer.addUntokenized(text, getCurrentWritingSystem());
+ checkWords();
break;
}
case ("marker"): {
@@ -419,14 +415,20 @@
throw new SAXException("Unexpected end element: " + localName);
}
}
+
+ if ("marker".equals(localName)) {
+ /* The "marker" element did not go on the stack. Don't pop it or check it. */
+ } else {
+ this.elementStack.pop();
+ }
+
}
/**
* Iterate the tokens from the Lexer and spell-check the words.
- * @param element The element containing the content being tokenized.
*/
- private void checkWords(final TextElement element) {
+ private void checkWords() {
this.lexer.lock();
/* Writing system should never be null, but orthography could be. */
@@ -450,7 +452,7 @@
} else {
final Word4a word = orthography.recognizeWord(token, this.lexer);
if (word == null) {
- final String message = createNotFoundMessage(token, element);
+ final String message = createNotFoundMessage(token);
this.output.println(message);
this.notFoundCounter ++;
}
@@ -463,20 +465,20 @@
/**
* Creates the text message to be reported to the user if a token is not found.
* @param token The token being reported.
- * @param element The raw element containing {@code token}.
* @return The message to be reported to the user.
*/
- String createNotFoundMessage(final Lexer.Token token, final TextElement element) {
-
+ String createNotFoundMessage(final Lexer.Token token) {
final FlowElement flowElement = getCurrentFlow();
+ final Element topElement = this.elementStack.peek();
+ final TextElement textElement = (TextElement) topElement;
final String lineAndColumn;
- if (element.line != -1
- | element.column != -1) {
- final int actualLine = element.line + token.getLine() - 1;
+ if (textElement.line != -1
+ | textElement.column != -1) {
+ final int actualLine = textElement.line + token.getLine() - 1;
int actualColumn = token.getColumn();
if (token.getLine() == 1) {
- actualColumn += element.column;
+ actualColumn += textElement.column;
}
lineAndColumn = String.format(" (%s:%s)", actualLine, actualColumn);
} else {
@@ -484,10 +486,10 @@
}
final String xpath;
- if (element.xpath == null) {
+ if (textElement.xpath == null) {
xpath = StringUtils.EMPTY_STRING;
} else {
- xpath = String.format(" (xpath: %s)", element.xpath);
+ xpath = String.format(" (xpath: %s)", textElement.xpath);
}
final String marker;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|