Skip to content

Commit

Permalink
Merge branch 'master' into en-external-dict
Browse files Browse the repository at this point in the history
# Conflicts:
#	languagetool-language-modules/en/src/main/resources/org/languagetool/resource/en/added.txt
#	languagetool-language-modules/en/src/main/resources/org/languagetool/resource/en/hunspell/spelling.txt
  • Loading branch information
AzadehSafakish committed Jan 8, 2024
2 parents dab5a39 + 9cd0eb4 commit 9fdc834
Show file tree
Hide file tree
Showing 74 changed files with 1,900 additions and 175 deletions.
70 changes: 19 additions & 51 deletions languagetool-core/src/main/java/org/languagetool/JLanguageTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Function;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -78,17 +75,30 @@ public class JLanguageTool {
private static final Logger logger = LoggerFactory.getLogger(JLanguageTool.class);
private static final Pattern ZERO_WIDTH_NBSP = Pattern.compile("(?<=\uFEFF)|(?=\uFEFF)");

/** LanguageTool version as a string like {@code 2.3} or {@code 2.4-SNAPSHOT}. */
public static final String VERSION = "6.4-SNAPSHOT";
/** LanguageTool build date and time like {@code 2013-10-17 16:10} or {@code null} if not run from JAR. */
@Nullable public static final String BUILD_DATE = getBuildDate();
/**
* LanguageTool version as a string like {@code 2.3} or {@code 2.4-SNAPSHOT}.
* @deprecated Please use LtBuildInfo.OS.getVersion() instead.
*/
@Nullable
@Deprecated
public static final String VERSION = LtBuildInfo.OS.getVersion();

/**
* LanguageTool build date and time like {@code 2013-10-17 16:10} or {@code null} if not run from JAR.
* @deprecated Please use LtBuildInfo.OS.getBuildDate() instead.
*/
@Nullable
@Deprecated
public static final String BUILD_DATE = LtBuildInfo.OS.getBuildDate();

/**
* Abbreviated git id or {@code null} if not available.
*
* @since 4.5
* @deprecated Please use LtBuildInfo.OS.getShortGitId() instead.
*/
@Nullable
public static final String GIT_SHORT_ID = getShortGitId();
@Deprecated
public static final String GIT_SHORT_ID = LtBuildInfo.OS.getShortGitId();

/**
* The name of the file with error patterns.
Expand Down Expand Up @@ -134,48 +144,6 @@ public class JLanguageTool {

private float maxErrorsPerWordRate;

/**
* Returns the build date or {@code null} if not run from JAR.
*/
@Nullable
private static String getBuildDate() {
try {
URL res = getDataBroker().getAsURL("/" + JLanguageTool.class.getName().replace('.', '/') + ".class");
if (res == null) {
// this will happen on Android, see http://stackoverflow.com/questions/15371274/
return null;
}
Object connObj = res.openConnection();
if (connObj instanceof JarURLConnection) {
Manifest manifest = ((JarURLConnection) connObj).getManifest();
if (manifest != null) {
return manifest.getMainAttributes().getValue("Implementation-Date");
}
}
return null;
} catch (IOException e) {
throw new RuntimeException("Could not get build date from JAR", e);
}
}

/**
* Returns the abbreviated git id or {@code null}.
*/
@Nullable
private static String getShortGitId() {
try {
InputStream in = getDataBroker().getAsStream("/git.properties");
if (in != null) {
Properties props = new Properties();
props.load(in);
return props.getProperty("git.commit.id.abbrev");
}
return null;
} catch (IOException e) {
throw new RuntimeException("Could not get git id from 'git.properties'", e);
}
}

private static ResourceDataBroker dataBroker = new DefaultResourceDataBroker();
private static ClassBroker classBroker = new DefaultClassBroker();

Expand Down
74 changes: 74 additions & 0 deletions languagetool-core/src/main/java/org/languagetool/LtBuildInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* LanguageTool, a natural language style checker
* Copyright (c) 2024. Stefan Viol (https://stevio.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;

import lombok.Getter;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Properties;

public enum LtBuildInfo {

OS("/git.properties"),
PREMIUM("/git-premium.properties");

private final Logger logger = LoggerFactory.getLogger(LtBuildInfo.class);

@Getter
@Nullable
private final String buildDate;
@Getter
@Nullable
private final String shortGitId;
@Getter
@Nullable
private final String version;

LtBuildInfo(String gitPropertiesFilePath) {
InputStream in = JLanguageTool.getDataBroker().getAsStream(gitPropertiesFilePath);
Properties gitProperties = null;
if (in != null) {
gitProperties = new Properties();
try {
gitProperties.load(in);
} catch (IOException e) {
logger.warn("Failed to read {}", gitPropertiesFilePath, e);
}
}

if (gitProperties != null) {
OffsetDateTime offsetDateTime = OffsetDateTime.parse(gitProperties.getProperty("git.build.time"), DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXX"));
this.buildDate = offsetDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss Z"));
this.shortGitId = gitProperties.getProperty("git.commit.id.abbrev");
this.version = gitProperties.getProperty("git.build.version");
} else {
this.buildDate = null;
this.shortGitId = null;
this.version = null;
}
}
}
49 changes: 23 additions & 26 deletions languagetool-core/src/main/java/org/languagetool/Premium.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,15 @@
import org.languagetool.markup.AnnotatedText;
import org.languagetool.rules.Rule;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.*;
import java.util.Arrays;
import java.util.List;

@Slf4j
/**
* Information about premium-only rules.
*/
public abstract class Premium {

private Optional<Properties> gitPremiumProps;

public Premium() {
try {
InputStream in = JLanguageTool.getDataBroker().getAsStream("/git-premium.properties");
if (in != null) {
Properties props = new Properties();
props.load(in);
gitPremiumProps = Optional.of(props);
} else {
gitPremiumProps = Optional.empty();
}
} catch (IOException e) {
log.warn("Failed to read git-premium.properties file.", e);
}
}

private static final List<String> tempNotPremiumRules = Arrays.asList();

Expand Down Expand Up @@ -92,17 +74,32 @@ public static boolean isPremiumVersion() {
}

public abstract boolean isPremiumRule(Rule rule);


/**
* @deprecated Please use LtBuildInfo.PREMIUM.getBuildDate() instead.
* @return premium build date
*/
@Deprecated
public String getBuildDate() {
return gitPremiumProps.map(properties -> properties.getProperty("git.build.time")).orElse(null);
return LtBuildInfo.PREMIUM.getBuildDate();
}


/**
* @deprecated Please use LtBuildInfo.PREMIUM.getShortGitId() instead.
* @return short git ID
*/
@Deprecated
public String getShortGitId() {
return gitPremiumProps.map(properties -> properties.getProperty("git.commit.id.abbrev")).orElse(null);
return LtBuildInfo.PREMIUM.getShortGitId();
}


/**
* @deprecated Please use LtBuildInfo.PREMIUM.getVersion() instead.
* @return premium version
*/
@Deprecated
public String getVersion() {
return gitPremiumProps.map(properties -> properties.getProperty("git.build.version")).orElse(null);
return LtBuildInfo.PREMIUM.getVersion();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class RuleMatchesAsJsonSerializer {

private final int compactMode;
private final Language lang;
private Map<String, Float> ruleIdToConfidence;

public RuleMatchesAsJsonSerializer() {
this(0, null);
Expand Down Expand Up @@ -355,6 +356,12 @@ private void writeRule(JsonGenerator g, RuleMatch match) throws IOException {
}
g.writeEndArray();
}
if (ruleIdToConfidence != null) {
Float confidence = ruleIdToConfidence.get(rule.getId());
if (confidence != null) {
g.writeNumberField("confidence", confidence);
}
}
g.writeEndObject();
}

Expand All @@ -366,4 +373,7 @@ private void writeCategory(JsonGenerator g, Category category) throws IOExceptio
g.writeEndObject();
}

public void setRuleIdToConfidenceMap(Map<String, Float> ruleIdToConfidence) {
this.ruleIdToConfidence = ruleIdToConfidence;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ guiUseLtDictionary = Add LanguageTool dictionary to LibreOffice spell check
guiNoSynonymsAsSuggestions = Do not use synonyms as suggestions (faster, regards only few rules)
guiIncludeTrackedChanges = Include tracked changes
guiActivateTempOffRules = Enable temporarily disabled rules
guiEnableGoalSpecificRules = Enable goal specific rules
guiSaveCacheToFile = Save cache to file
guiUseRemoteServer = Use remote server to check text
guiUseServer = Use server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ guiUseLtDictionary = Add LanguageTool dictionary to LibreOffice spell check
guiNoSynonymsAsSuggestions = Do not use synonyms as suggestions (faster, regards only few rules)
guiIncludeTrackedChanges = Include tracked changes
guiActivateTempOffRules = Enable temporarily disabled rules
guiEnableGoalSpecificRules = Enable goal specific rules
guiSaveCacheToFile = Save cache to file
guiUseRemoteServer = Use remote server to check text
guiUseServer = Use server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20408,4 +20408,41 @@ Sieg Heil
Thomas Szasz
Thomas Stephen Szasz
John Watson
David Portnoy
David Portnoy
William Buckley
William F. Buckley
Sly Stone
Montreux Jazz Festival
Arthur Ochs Sulzberger
Arthur Gregg Sulzberger
A. G. Sulzberger
Arthur Hays Sulzberger
Adolph Ochs
Orvil Dryfoos
Pat Buchanan
Rip Van Winkle
San Vito lo Capo
Jaime Peñafiel
Roberto Saviano
Salvatore Riina
Salvatore Totò Riina
Totò Riina
Nézet-Séguin
Summerhill
Summerhill School
Trần Anh Hùng
Anh Hung Tran
Benoît Magimel
Isabelle Huppert
David Carson
Robert Michels
Vilfredo Pareto
Francis Ysidro Edgeworth
William Stanley Jevons
Daily Mail
Harriet Taylor
Yellowstone
Yellowstone National Park
Sky Store
Julien Denormandie
Sébastien Lecornu
Loading

0 comments on commit 9fdc834

Please sign in to comment.