forked from languagetool-org/languagetool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Pipeline | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
generate-package: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
security-events: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK | ||
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 | ||
with: | ||
java-version: "21.0" | ||
distribution: "temurin" | ||
- name: Build backend image | ||
run: mvn clean package -DskipTests | ||
- name: List package | ||
run: ls -1 languagetool-standalone/target/LanguageTool*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM alpine:3.20 | ||
RUN apk add --no-cache fasttext openjdk21-jre | ||
|
||
RUN mkdir /home/languageTool | ||
WORKDIR /home/languageTool | ||
|
||
COPY libs/ libs | ||
COPY META-INF/ META-INF | ||
COPY org/ org | ||
COPY languagetool-server.jar . | ||
COPY lid.176.bin . | ||
COPY server.properties . | ||
|
||
EXPOSE 8081/tcp | ||
|
||
ENTRYPOINT [ "java", "-cp", "languagetool-server.jar", "org.languagetool.server.HTTPServer", "--config", "server.properties", "--port", "8081", "--allow-origin" ] |
101 changes: 101 additions & 0 deletions
101
languagetool-core/src/main/java/org/languagetool/rules/BorderNumberRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* LanguageTool, a natural language style checker | ||
* Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de) | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 | ||
* USA | ||
*/ | ||
|
||
package org.languagetool.rules; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.ResourceBundle; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.languagetool.AnalyzedSentence; | ||
import org.languagetool.AnalyzedTokenReadings; | ||
import org.languagetool.Language; | ||
|
||
public class BorderNumberRule extends TextLevelRule { | ||
|
||
public BorderNumberRule(ResourceBundle messages, Language language) { | ||
super(messages); | ||
super.setCategory(Categories.TYPOGRAPHY.getCategory(messages)); | ||
setLocQualityIssueType(ITSIssueType.Whitespace); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return "BORDER_NUMBER"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Nummern gefolgt von 3 Leerzeichen sind Randnummern und beginnen nach den Leerzeichen mit einem Großbuchstaben"; | ||
} | ||
|
||
@Override | ||
public RuleMatch[] match(List<AnalyzedSentence> sentences) { | ||
List<RuleMatch> ruleMatches = new ArrayList<>(); | ||
int pos = 0; | ||
for (AnalyzedSentence sentence : sentences) { | ||
AnalyzedTokenReadings[] tokens = sentence.getTokens(); | ||
//note: we start from token 1 | ||
//token no. 0 is guaranteed to be SENT_START | ||
|
||
int i = 1; | ||
int whiteSpaceCount = 0; | ||
while (i < tokens.length) { | ||
if (StringUtils.isNumeric(tokens[i].getToken())) { | ||
int startIndex = i; | ||
if (i + 1 < tokens.length) { | ||
while (tokens[++i].isWhitespace()) { | ||
whiteSpaceCount++; | ||
} | ||
|
||
if (whiteSpaceCount > 0) { | ||
char firstCharacter = tokens[i].getToken().charAt(0); | ||
if (whiteSpaceCount != 3 && (firstCharacter >= 65 && firstCharacter <= 90)) { | ||
ruleMatches.add(new RuleMatch(this, sentence, pos + tokens[startIndex].getStartPos(), pos + tokens[i].getEndPos(), "No border number.")); | ||
} | ||
whiteSpaceCount = 0; | ||
} | ||
} | ||
} | ||
i++; | ||
// if(isFirstWhite(tokens[i])) { | ||
// int nFirst = i; | ||
// for (i++; i < tokens.length && isRemovableWhite(tokens[i]); i++); | ||
// i--; | ||
// if (i > nFirst) { | ||
// String message = messages.getString("whitespace_repetition"); | ||
// RuleMatch ruleMatch = new RuleMatch(this, sentence, pos + tokens[nFirst].getStartPos(), | ||
// pos + tokens[i].getEndPos(), message); | ||
// ruleMatch.setSuggestedReplacement(tokens[nFirst].getToken()); | ||
// ruleMatches.add(ruleMatch); | ||
// } | ||
// } else if (tokens[i].isLinebreak()) { | ||
// for (i++; i < tokens.length && isRemovableWhite(tokens[i]); i++); | ||
// } | ||
} | ||
pos += sentence.getCorrectedTextLength(); | ||
} | ||
return toRuleMatchArray(ruleMatches); | ||
} | ||
|
||
@Override | ||
public int minToCheckParagraph() { | ||
return 0; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
languagetool-core/src/test/java/org/languagetool/rules/BorderNumberRuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* LanguageTool, a natural language style checker | ||
* Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de) | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 | ||
* USA | ||
*/ | ||
package org.languagetool.rules; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.languagetool.JLanguageTool; | ||
import org.languagetool.TestTools; | ||
|
||
public class BorderNumberRuleTest { | ||
private JLanguageTool lt; | ||
|
||
@Before | ||
public void setUp() { | ||
lt = new JLanguageTool(TestTools.getDemoLanguage()); | ||
|
||
for (Rule rule : lt.getAllRules()) { | ||
lt.disableRule(rule.getId()); | ||
} | ||
|
||
BorderNumberRule rule = new BorderNumberRule(TestTools.getEnglishMessages(), TestTools.getDemoLanguage()); | ||
|
||
lt.addRule(rule); | ||
} | ||
|
||
@Test | ||
public void testRule_happyPath_noMatchFound() throws IOException { | ||
List<RuleMatch> matches; | ||
|
||
matches = lt.check("1000 Das ist eine Randnummer."); | ||
|
||
assertEquals(0, matches.size()); | ||
} | ||
|
||
@Test | ||
public void testRule_noBorderNumber_MatchFound() throws IOException { | ||
List<RuleMatch> matches; | ||
|
||
matches = lt.check("Das ist das 1000 Mal, dass ich sage es ist keine Randnummer."); | ||
|
||
assertEquals(1, matches.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters