Skip to content

Commit

Permalink
New rule and pipeline start
Browse files Browse the repository at this point in the history
  • Loading branch information
rvp-c committed Feb 12, 2025
1 parent ba921cd commit 0aee691
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/pipeline.yml
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
16 changes: 16 additions & 0 deletions Dockerfile.neuris
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" ]
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;
}
}
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.languagetool.language;

import javax.swing.border.Border;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.languagetool.*;
Expand Down Expand Up @@ -198,7 +199,8 @@ public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfi
new GermanRepeatedWordsRule(messages),
new StyleTooOftenUsedVerbRule(messages, this, userConfig),
new StyleTooOftenUsedNounRule(messages, this, userConfig),
new StyleTooOftenUsedAdjectiveRule(messages, this, userConfig)
new StyleTooOftenUsedAdjectiveRule(messages, this, userConfig),
new BorderNumberRule(messages, this)
);
}

Expand Down

0 comments on commit 0aee691

Please sign in to comment.