proj_name stringclasses 131
values | relative_path stringlengths 30 228 | class_name stringlengths 1 68 | func_name stringlengths 1 48 | masked_class stringlengths 78 9.82k | func_body stringlengths 46 9.61k | len_input int64 29 2.01k | len_output int64 14 1.94k | total int64 55 2.05k | relevant_context stringlengths 0 38.4k |
|---|---|---|---|---|---|---|---|---|---|
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/DynamicHunspellLanguage.java | DynamicHunspellLanguage | getRelevantRules | class DynamicHunspellLanguage extends DynamicLanguage {
DynamicHunspellLanguage(String name, String code, File dictPath) {
super(name, code, dictPath);
}
@Override
public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, Language motherTongue, List<Language> altLanguages) throws ... |
HunspellRule r = new HunspellRule(JLanguageTool.getMessageBundle(Languages.getLanguageForShortCode("en-US")), this, userConfig) {
@Override
public String getId() {
return code.toUpperCase() + "_SPELLER_RULE";
}
@NotNull
@Override
protected String getDictFilenameInResourc... | 111 | 165 | 276 | <methods>public java.lang.String getCommonWordsPath() ,public java.lang.String[] getCountries() ,public org.languagetool.language.Contributor[] getMaintainers() ,public java.lang.String getName() ,public List<java.lang.String> getRuleFileNames() ,public java.lang.String getShortCode() ,public boolean isSpellcheckOnlyLa... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/DynamicMorfologikLanguage.java | DynamicMorfologikLanguage | getRelevantRules | class DynamicMorfologikLanguage extends DynamicLanguage {
DynamicMorfologikLanguage(String name, String code, File dictPath) {
super(name, code, dictPath);
}
@Override
public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, Language motherTongue, List<Language> altLanguages) t... |
MorfologikSpellerRule r = new MorfologikSpellerRule(JLanguageTool.getMessageBundle(Languages.getLanguageForShortCode("en-US")), this) {
@Override
public String getFileName() {
return dictPath.getAbsolutePath();
}
@Override
public String getId() {
return code.toUpperCas... | 112 | 145 | 257 | <methods>public java.lang.String getCommonWordsPath() ,public java.lang.String[] getCountries() ,public org.languagetool.language.Contributor[] getMaintainers() ,public java.lang.String getName() ,public List<java.lang.String> getRuleFileNames() ,public java.lang.String getShortCode() ,public boolean isSpellcheckOnlyLa... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/ExtendedSentenceRange.java | ExtendedSentenceRange | equals | class ExtendedSentenceRange implements Comparable<ExtendedSentenceRange> {
@Getter
private final int fromPos;
@Getter
private final int toPos;
@Getter
private final Map<String, Float> languageConfidenceRates; //languageCode;0-1 confidenceRate from LanguageDetectionService
ExtendedSentenceRange(int fromP... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ExtendedSentenceRange extendedSentenceRange = (ExtendedSentenceRange) o;
return fromPos == extendedSentenceRange.fromPos && toPos == extendedSentenceRange.toPos;
| 420 | 81 | 501 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/FragmentWithLanguage.java | FragmentWithLanguage | toString | class FragmentWithLanguage {
private final String langCode;
private final String fragment;
FragmentWithLanguage(String langCode, String fragment) {
this.langCode = Objects.requireNonNull(langCode);
this.fragment = Objects.requireNonNull(fragment);
}
public String getLangCode() {
return la... |
return "| " + langCode + ": " + fragment + " |";
| 143 | 22 | 165 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/GlobalConfig.java | GlobalConfig | equals | class GlobalConfig {
private String grammalecteServer;
private String grammalecteUser;
private String grammalectePassword;
private File beolingusFile;
private String nerUrl;
private static boolean verbose = false;
/**
* @return whether we need to track additional information like e.g. the disambig... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GlobalConfig that = (GlobalConfig) o;
return Objects.equals(grammalecteServer, that.grammalecteServer) &&
Objects.equals(grammalecteUser, that.grammalecteUser) &&
Objects.equals(grammalectePassword, that.... | 534 | 149 | 683 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/InputSentence.java | InputSentence | equals | class InputSentence {
private final String text;
private final Language lang;
private final Language motherTongue;
private final Set<String> disabledRules;
private final Set<CategoryId> disabledRuleCategories;
private final Set<String> enabledRules;
private final Set<CategoryId> enabledRuleCategories;
... |
if (o == null) return false;
if (o == this) return true;
if (o.getClass() != getClass()) return false;
InputSentence other = (InputSentence) o;
return Objects.equals(text, other.text) &&
Objects.equals(lang, other.lang) &&
Objects.equals(motherTongue, other.motherTongue) &&
... | 908 | 265 | 1,173 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/LanguageAnnotator.java | TokenWithLanguages | equals | class TokenWithLanguages {
private final String token;
private final List<Language> langs;
TokenWithLanguages(String token, Language... langs) {
this.token = Objects.requireNonNull(token);
this.langs = new ArrayList<>(Arrays.asList(Objects.requireNonNull(langs)));
}
TokenWithLanguages(St... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TokenWithLanguages that = (TokenWithLanguages) o;
return token.equals(that.token) && langs.equals(that.langs);
| 350 | 74 | 424 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/LevelToneTagCacheKey.java | LevelToneTagCacheKey | equals | class LevelToneTagCacheKey {
private final JLanguageTool.Level level;
private final Set<ToneTag> toneTags;
public LevelToneTagCacheKey(@NotNull JLanguageTool.Level level, @NotNull Set<ToneTag> toneTags) {
this.level = level;
this.toneTags = new TreeSet<>(toneTags); //sorted by default
}
@Override
... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LevelToneTagCacheKey that = (LevelToneTagCacheKey) o;
if (getLevel() != that.getLevel()) return false;
if (!getToneTags().equals(that.getToneTags())) return false;
return true;
| 174 | 101 | 275 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/MultiThreadedJLanguageTool.java | MultiThreadedJLanguageTool | performCheck | class MultiThreadedJLanguageTool extends JLanguageTool {
private final int threadPoolSize;
private final ExecutorService threadPool;
public MultiThreadedJLanguageTool(Language language) {
this(language, null);
}
/**
* @see #shutdown()
* @param threadPoolSize the number of concurrent threads (us... |
List<Rule> allRules = ruleSet.allRules();
List<SentenceData> sentences = computeSentenceData(analyzedSentences, sentenceTexts);
Map<Rule, BitSet> map = new HashMap<>();
for (int i = 0; i < sentences.size(); i++) {
for (Rule rule : ruleSet.rulesForSentence(sentences.get(i).analyzed)) {
ma... | 1,369 | 569 | 1,938 | <methods>public void <init>(org.languagetool.Language, org.languagetool.Language) ,public void <init>(org.languagetool.Language) ,public void <init>(org.languagetool.Language, org.languagetool.Language, org.languagetool.ResultCache) ,public void <init>(org.languagetool.Language, org.languagetool.ResultCache, org.langua... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/Premium.java | Premium | isPremiumVersion | class Premium {
private static final List<String> tempNotPremiumRules = Arrays.asList();
public static boolean isTempNotPremium(Rule rule) {
return tempNotPremiumRules.contains(rule.getId());
}
public static boolean isPremiumStatusCheck(AnnotatedText text) {
final String testRuleText = "languagetoo... |
String className = "org.languagetool.PremiumOn";
try {
Class<?> aClass = JLanguageTool.getClassBroker().forName(className);
Constructor<?> constructor = aClass.getConstructor();
constructor.newInstance();
return true;
} catch (ClassNotFoundException e) {
// doesn't exist, thus... | 582 | 143 | 725 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/Range.java | Range | equals | class Range {
private final int fromPos;
private final int toPos;
private final String lang;
Range(int fromPos, int toPos, String lang) {
this.fromPos = fromPos;
this.toPos = toPos;
this.lang = Objects.requireNonNull(lang);
}
public int getFromPos() {
return fromPos;
}
public int ge... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Range range = (Range) o;
return fromPos == range.fromPos && toPos == range.toPos && lang.equals(range.lang);
| 201 | 72 | 273 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/ResourceBundleTools.java | ResourceBundleTools | getMessageBundle | class ResourceBundleTools {
private ResourceBundleTools() {
}
/**
* Gets the ResourceBundle (i18n strings) for the default language of the user's system.
*/
public static ResourceBundle getMessageBundle() {<FILL_FUNCTION_BODY>}
/**
* Gets the ResourceBundle (i18n strings) for the given user interf... |
try {
ResourceBundle bundle = JLanguageTool.getDataBroker().getResourceBundle(MESSAGE_BUNDLE, Locale.getDefault());
ResourceBundle fallbackBundle = JLanguageTool.getDataBroker().getResourceBundle(MESSAGE_BUNDLE, Locale.ENGLISH);
return new ResourceBundleWithFallback(bundle, fallbackBundle);
}... | 492 | 138 | 630 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/ResourceBundleWithFallback.java | ResourceBundleWithFallback | handleGetObject | class ResourceBundleWithFallback extends ResourceBundle {
private final ResourceBundle bundle;
private final ResourceBundle fallbackBundle;
public ResourceBundleWithFallback(ResourceBundle bundle, ResourceBundle fallbackBundle) {
this.bundle = bundle;
this.fallbackBundle = fallbackBundle;
}
@Overri... |
String s = bundle.getString(key);
if (s.trim().isEmpty()) {
return fallbackBundle.getString(key);
}
return s;
| 137 | 44 | 181 | <methods>public void <init>() ,public static final void clearCache() ,public static final void clearCache(java.lang.ClassLoader) ,public boolean containsKey(java.lang.String) ,public java.lang.String getBaseBundleName() ,public static final java.util.ResourceBundle getBundle(java.lang.String) ,public static final java.... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/ResultCache.java | MatchesWeigher | weigh | class MatchesWeigher implements Weigher<InputSentence, List<RuleMatch>> {
@Override
public int weigh(InputSentence sentence, List<RuleMatch> matches) {<FILL_FUNCTION_BODY>}
} |
// this is just a rough guesstimate so that the cacheSize given by the user
// is very roughly the number of average sentences the cache can keep:
return sentence.getText().length() / 75 + matches.size();
| 60 | 58 | 118 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/SentenceRange.java | SentenceRange | getRangesFromSentences | class SentenceRange implements Comparable<SentenceRange>{
private static final Pattern BEGINS_WITH_SPACE = Pattern.compile("^\\s*");
private static final Pattern ENDS_WITH_SPACE = Pattern.compile("\\s+$");
private final int fromPos;
private final int toPos;
SentenceRange(int fromPos, int toPos) {
this.... |
List<SentenceRange> sentenceRanges = new ArrayList<>();
int pos = 0;
int markupTextLength = annotatedText.getTextWithMarkup().length();
int diff = markupTextLength - annotatedText.getPlainText().length();
for (String sentence : sentences) {
if (sentence.trim().isEmpty()) {
//No conten... | 387 | 368 | 755 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/ShortDescriptionProvider.java | ShortDescriptionProvider | init | class ShortDescriptionProvider {
private final static Map<Language, Map<String, String>> descriptions = new ConcurrentHashMap<>();
@Nullable
public String getShortDescription(String word, Language lang) {
return getAllDescriptions(lang).get(word);
}
@VisibleForTesting
static Map<String, String> getAll... |
ResourceDataBroker dataBroker = JLanguageTool.getDataBroker();
String path = "/" + lang.getShortCode() + "/word_definitions.txt";
if (!dataBroker.resourceExists(path)) {
return Collections.emptyMap();
}
Map<String, String> wordToDef = new HashMap<>();
List<String> lines = dataBroker.getFr... | 148 | 231 | 379 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/SimpleInputSentence.java | SimpleInputSentence | equals | class SimpleInputSentence {
private final String text;
private final Language lang;
SimpleInputSentence(String text, Language lang) {
this.text = Objects.requireNonNull(text);
this.lang = Objects.requireNonNull(lang);
}
/** @since 4.1 */
public String getText() {
return text;
}
@Overri... |
if (o == null) return false;
if (o == this) return true;
if (o.getClass() != getClass()) return false;
SimpleInputSentence other = (SimpleInputSentence) o;
return Objects.equals(text, other.text) &&
Objects.equals(lang, other.lang);
| 176 | 87 | 263 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/bitext/TabBitextReader.java | TabReader | next | class TabReader implements Iterator<StringPair> {
@Override
public boolean hasNext() {
return nextLine != null;
}
@Override
public StringPair next() {<FILL_FUNCTION_BODY>}
// The file is read-only.
@Override
public void remove() {
throw new UnsupportedOperationException(... |
try {
StringPair result = nextPair;
sentencePos = nextPair.getSource().length() + 1;
if (nextLine != null) {
prevLine = nextLine;
nextLine = in.readLine();
nextPair = tab2StringPair(nextLine);
lineCount++;
if (nextLine == null) {
... | 102 | 130 | 232 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/bitext/WordFastTMReader.java | WordFastTMReader | tab2StringPair | class WordFastTMReader extends TabBitextReader {
public WordFastTMReader(String filename, String encoding) throws IOException {
super(filename, encoding);
//skip the header (first line)
if (nextLine != null) {
nextLine = in.readLine();
nextPair = tab2StringPair(nextLine);
}
}
@Nullab... |
if (line == null) {
return null;
}
String[] fields = line.split("\t");
sentencePos = fields[4].length() + 1;
return new StringPair(fields[4], fields[6]);
| 350 | 61 | 411 | <methods>public void <init>(java.lang.String, java.lang.String) ,public int getColumnCount() ,public java.lang.String getCurrentLine() ,public int getLineCount() ,public int getSentencePosition() ,public int getTargetColumnCount() ,public Iterator<org.languagetool.bitext.StringPair> iterator() <variables>protected java... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/chunking/ChunkTag.java | ChunkTag | equals | class ChunkTag {
private final String chunkTag;
private final boolean isRegexp;
public ChunkTag(String chunkTag) {
this(chunkTag, false);
}
/** @since 5.1 */
public ChunkTag(String chunkTag, boolean isRegexp) {
if (chunkTag == null || chunkTag.trim().isEmpty()) {
throw new IllegalArgumentEx... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ChunkTag other = (ChunkTag) o;
return chunkTag.equals(other.chunkTag);
| 292 | 63 | 355 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/chunking/TokenExpressionFactory.java | TokenExpressionFactory | create | class TokenExpressionFactory extends ExpressionFactory<ChunkTaggedToken> {
private final boolean caseSensitive;
/**
* @param caseSensitive whether word tokens should be compared case-sensitively - also used for regular expressions
*/
public TokenExpressionFactory(boolean caseSensitive) {
this.caseSens... |
LogicExpression<ChunkTaggedToken> logicExpression = LogicExpression.compile(expr, input -> new TokenPredicate(input, caseSensitive));
return new Expression.BaseExpression<ChunkTaggedToken>(expr) {
@Override
public boolean apply(ChunkTaggedToken token) {
return logicExpression.apply(token);
... | 131 | 95 | 226 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/chunking/TokenPredicate.java | TokenPredicate | compile | class TokenPredicate extends Expression.Arg.Pred<ChunkTaggedToken> {
private final Predicate<ChunkTaggedToken> predicate;
TokenPredicate(String description, boolean caseSensitive) {
super(description);
predicate = compile(description, caseSensitive);
}
private Predicate<ChunkTaggedToken> compile(Strin... |
String[] parts = description.split("=");
String exprType;
String exprValue;
if (parts.length == 1) {
exprType = "string";
exprValue = unquote(parts[0]);
} else if (parts.length == 2) {
exprType = parts[0];
exprValue = unquote(parts[1]);
} else {
throw new RuntimeEx... | 200 | 567 | 767 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/language/LanguageBuilder.java | LanguageBuilder | makeLanguage | class LanguageBuilder {
private LanguageBuilder() {
}
public static Language makeAdditionalLanguage(File file) throws InstantiationException, IllegalAccessException {
return makeLanguage(file, true);
}
/**
* Takes an XML file named <tt>rules-xx-language.xml</tt>,
* e.g. <tt>rules-de-German.xml</t... |
Objects.requireNonNull(file, "file cannot be null");
if (!file.getName().endsWith(".xml")) {
throw new RuleFilenameException(file);
}
String[] parts = file.getName().split("-");
boolean startsWithRules = parts[0].equals("rules");
boolean secondPartHasCorrectLength = parts.length == 3 &&
... | 1,103 | 684 | 1,787 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/language/identifier/detector/CommonWordsDetector.java | CommonWordsDetector | getKnownWordsPerLanguage | class CommonWordsDetector {
private final static Map<String, List<Language>> word2langs = Collections.synchronizedMap(new HashMap<>());
private final static Pattern numberPattern = Pattern.compile("[0-9.,%-]+");
private final static Language esLang = Languages.getLanguageForShortCode("es");
private final st... |
Map<Language,Integer> result = new HashMap<>();
String auxText = PUNCT_PATTERN.matcher(text).replaceAll(" ");
if (!auxText.endsWith(" ") && StringUtils.countMatches(auxText, " ") > 0) {
// last word might not be finished yet, so ignore
auxText = CHARS_PATTERN.matcher(auxText).replaceFirst("");
... | 1,133 | 604 | 1,737 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/language/identifier/detector/FastTextDetector.java | FastTextException | parseBuffer | class FastTextException extends RuntimeException {
private final boolean disabled;
public FastTextException(String message, boolean disabled) {
super(message);
this.disabled = disabled;
}
/**
* Should {@link FastTextDetector} be disable after this exception
*/
public boolean i... |
String[] values = WHITESPACE.split(buffer.trim());
if (!buffer.startsWith("__label__")) {
throw new FastTextException("FastText output is expected to start with '__label__': ''" + buffer + "'", true);
}
if (values.length % 2 != 0) {
throw new FastTextException("Error while parsing fasttext ... | 667 | 306 | 973 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/language/identifier/detector/UnicodeBasedDetector.java | UnicodeBasedDetector | getDominantLangCodes | class UnicodeBasedDetector {
private static final int DEFAULT_MAX_CHECK_LENGTH = 50;
private static final float THRESHOLD = 0.5f;
private final int maxCheckLength;
public UnicodeBasedDetector() {
this(DEFAULT_MAX_CHECK_LENGTH);
}
public UnicodeBasedDetector(int maxCheckLength) {
this.maxCheckLeng... |
// For a more complete list of script/language relations,
// see https://unicode-org.github.io/cldr-staging/charts/37/supplemental/scripts_and_languages.html
// Another more complete approach might be to use Character.UnicodeScript.of() for each character.
int arabicChars = 0;
int cyrillicChars = 0... | 145 | 1,377 | 1,522 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/languagemodel/LuceneLanguageModel.java | LuceneLanguageModel | validateDirectory | class LuceneLanguageModel extends BaseLanguageModel {
private final List<LuceneSingleIndexLanguageModel> lms = new ArrayList<>();
public static void validateDirectory(File topIndexDir) {<FILL_FUNCTION_BODY>}
@Nullable
private static File[] getSubDirectoriesOrNull(File topIndexDir) {
return topIndexDir.li... |
File[] subDirs = getSubDirectoriesOrNull(topIndexDir);
if (subDirs == null || subDirs.length == 0) {
LuceneSingleIndexLanguageModel.validateDirectory(topIndexDir);
}
| 572 | 60 | 632 | <methods>public void <init>() ,public abstract long getCount(java.lang.String) ,public abstract long getCount(List<java.lang.String>) ,public org.languagetool.rules.ngrams.Probability getPseudoProbability(List<java.lang.String>) ,public org.languagetool.rules.ngrams.Probability getPseudoProbabilityStupidBackoff(List<ja... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/languagemodel/MultiLanguageModel.java | MultiLanguageModel | getPseudoProbability | class MultiLanguageModel implements LanguageModel {
private final List<LanguageModel> lms;
public MultiLanguageModel(List<LanguageModel> lms) {
if (lms.isEmpty()) {
throw new IllegalArgumentException("List of language models is empty");
}
this.lms = lms;
}
@Override
public Probability get... |
double prob = 0;
float coverage = 0;
long occurrences = 0;
for (LanguageModel lm : lms) {
Probability pProb = lm.getPseudoProbability(context);
//System.out.println(i + ". " + pProb.getProb() + " (" + pProb.getCoverage() + ")");
// TODO: decide what's the proper way to combine the pro... | 170 | 169 | 339 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/languagemodel/bert/RemoteLanguageModel.java | Request | getChannel | class Request {
public String text;
public int start;
public int end;
public List<String> candidates;
public Request(String text, int start, int end, List<String> candidates) {
this.text = text;
this.start = start;
this.end = end;
this.candidates = candidates;
}
pub... |
NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress(host, port);
if (useSSL) {
SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient();
if (rootCertificate != null) {
sslContextBuilder.trustManager(new File(rootCertificate));
}
if (clientCertificate != ... | 486 | 190 | 676 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/languagemodel/bert/grpc/BertLmGrpc.java | MethodHandlers | invoke | class MethodHandlers<Req, Resp> implements
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
private final BertLmImpl... |
switch (methodId) {
case METHODID_SCORE:
serviceImpl.score((org.languagetool.languagemodel.bert.grpc.BertLmProto.ScoreRequest) request,
(io.grpc.stub.StreamObserver<org.languagetool.languagemodel.bert.grpc.BertLmProto.BertLmResponse>) responseObserver);
break;
ca... | 340 | 234 | 574 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/markup/AnnotatedText.java | AnnotatedText | getOriginalTextPositionFor | class AnnotatedText {
/**
* @since 3.9
*/
public enum MetaDataKey {
DocumentTitle,
EmailToAddress,
FullName,
EmailNumberOfAttachments
}
private final List<TextPart> parts;
private final Map<Integer, MappingValue> mapping; // plain text position to original text (with markup) position
... |
if (plainTextPosition < 0) {
throw new IllegalArgumentException("plainTextPosition must be >= 0: " + plainTextPosition);
}
if (mapping.isEmpty()) {
return 0;
}
int minDiff = Integer.MAX_VALUE;
MappingValue bestMatch = null;
// algorithm: find the closest lower position
for (... | 949 | 396 | 1,345 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/markup/AnnotatedTextBuilder.java | AnnotatedTextBuilder | addText | class AnnotatedTextBuilder {
private final static String hiddenChars = "\u00AD\u202D\u202c";
private final List<TextPart> parts = new ArrayList<>();
private final Map<AnnotatedText.MetaDataKey, String> metaData = new HashMap<>();
private final Map<String, String> customMetaData = new HashMap<>();
public An... |
StringTokenizer st = new StringTokenizer(text, hiddenChars, true);
while (st.hasMoreElements()) {
String token = (String) st.nextElement();
if (!hiddenChars.contains(token)) {
parts.add(new TextPart(token, TextPart.Type.TEXT));
} else {
parts.add(new TextPart(token, TextPart.T... | 1,192 | 116 | 1,308 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/noop/NoopLanguage.java | NoopLanguage | createDefaultSentenceTokenizer | class NoopLanguage extends Language {
public static final String SHORT_CODE = "zz";
@Override
public Locale getLocale() {
return new Locale("en");
}
@Override
public Disambiguator createDefaultDisambiguator() {
return new NoopDisambiguator();
}
@Override
public String getName() {
retur... |
return new SentenceTokenizer() {
@Override
public List<String> tokenize(String text) {
return Collections.singletonList(text);
}
@Override
public void setSingleLineBreaksMarksParagraph(boolean lineBreakParagraphs) {}
@Override
public boolean singleLineBreaksMarksPa... | 424 | 100 | 524 | <methods>public java.lang.String adaptSuggestion(java.lang.String) ,public List<org.languagetool.rules.RuleMatch> adaptSuggestions(List<org.languagetool.rules.RuleMatch>, Set<java.lang.String>) ,public org.languagetool.rules.RuleMatch adjustMatch(org.languagetool.rules.RuleMatch, List<java.lang.String>) ,public org.lan... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractDashRule.java | AbstractDashRule | match | class AbstractDashRule extends Rule {
public AbstractDashRule(ResourceBundle messages) {
super(messages);
setCategory(Categories.TYPOGRAPHY.getCategory(messages));
setTags(Collections.singletonList(Tag.picky));
}
@Override
public String getId() {
return "DASH_RULE";
}
@Override
public a... |
List<RuleMatch> matches = new ArrayList<>();
String text = sentence.getText();
List<AhoCorasickDoubleArrayTrie.Hit<String>> hits = getCompoundsData().parseText(text);
Set<Integer> startPositions = new HashSet<>();
Collections.reverse(hits); // work on longest matches first
for (AhoCorasickDoub... | 638 | 376 | 1,014 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public void addTags(List<java.lang.String>) ,public void addToneTags(List<java.lang.String>) ,public int estimateContextForSureMatch() ,public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns() ,pub... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractDateCheckFilter.java | AbstractDateCheckFilter | acceptRuleMatch | class AbstractDateCheckFilter extends RuleFilter {
private static final Logger logger = LoggerFactory.getLogger(AbstractDateCheckFilter.class);
// The day of the month may contain not only digits but also extra letters
// such as"22nd" in English or "22-an" in Esperanto. The regexp extracts
// the numerical p... |
try {
int dayOfWeekFromString = getDayOfWeek(getRequired("weekDay", args).replace("\u00AD", "")); // replace soft hyphen
Calendar dateFromDate = getDate(args);
int dayOfWeekFromDate;
try {
dayOfWeekFromDate = dateFromDate.get(Calendar.DAY_OF_WEEK);
} catch (IllegalArgumentExc... | 1,055 | 519 | 1,574 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractFillerWordsRule.java | AbstractFillerWordsRule | match | class AbstractFillerWordsRule extends TextLevelRule {
public static final String RULE_ID = "FILLER_WORDS";
private static final int DEFAULT_MIN_PERCENT = 8;
private static final Pattern OPENING_QUOTES = Pattern.compile("[\"“„”»«]");
private static final Pattern ENDING_QUOTES = Pattern.compile("[\"“”»«]");... |
List<RuleMatch> ruleMatches = new ArrayList<>();
String msg = getMessage();
List<Integer> startPos = new ArrayList<>();
List<Integer> endPos = new ArrayList<>();
List<AnalyzedSentence> relevantSentences = new ArrayList<>();
double percent;
int pos = 0;
int wordCount = 0;
boolean isD... | 798 | 782 | 1,580 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractFutureDateFilter.java | AbstractFutureDateFilter | acceptRuleMatch | class AbstractFutureDateFilter extends RuleFilter {
private static final Pattern DAY_OF_MONTH_PATTERN = Pattern.compile("(\\d+).*");
/**
* Implement so that "first" returns {@code 1}, second returns {@code 2} etc.
* @param localizedDayOfMonth name of day of the month or abbreviation thereof
*/
protected... |
Calendar dateFromDate = getDate(args);
Calendar currentDate = getCalendar();
if (TestHackHelper.isJUnitTest()) {
currentDate = new Calendar.Builder().setDate(2014, 0, 1).build();
}
try {
if (dateFromDate.after(currentDate)) {
return match;
} else {
return null;
... | 710 | 152 | 862 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractMakeContractionsFilter.java | AbstractMakeContractionsFilter | acceptRuleMatch | class AbstractMakeContractionsFilter extends RuleFilter {
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) throws IOException {<FILL_FUNCTION_BODY... |
RuleMatch newMatch = match;
List<String> newSugestions = new ArrayList<>();
for (String suggestion: match.getSuggestedReplacements()) {
newSugestions.add(fixContractions(suggestion));
}
newMatch.setSuggestedReplacements(newSugestions);
return newMatch;
| 94 | 90 | 184 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractNewYearDateFilter.java | AbstractNewYearDateFilter | getDate | class AbstractNewYearDateFilter extends RuleFilter {
// The day of the month may contain not only digits but also extra letters
// such as "22nd" in English or "22-an" in Esperanto. The regexp extracts
// the numerical part.
private static final Pattern DAY_OF_MONTH_PATTERN = Pattern.compile("(\\d+).*");
/**... |
int year = Integer.parseInt(getRequired("year", args));
int month = getMonthFromArguments(args);
int dayOfMonth = getDayOfMonthFromArguments(args);
Calendar calendar = getCalendar();
calendar.setLenient(false); // be strict about validity of dates
//noinspection MagicConstant
calendar.set... | 1,066 | 111 | 1,177 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractNumberInWordFilter.java | AbstractNumberInWordFilter | acceptRuleMatch | class AbstractNumberInWordFilter extends RuleFilter {
protected final Language language;
public static final Pattern typoPattern = Pattern.compile("[0-9]");
protected AbstractNumberInWordFilter(Language language) {
this.language = language;
}
@Nullable
@Override
public RuleMatch acceptRuleMatch(Ru... |
String word = arguments.get("word");
String wordReplacingZeroO = word.replaceAll("0","o");
String wordWithoutNumberCharacter = typoPattern.matcher(word).replaceAll("");
List<String> replacements = new ArrayList<>();
if (!isMisspelled(wordReplacingZeroO) && !word.equals(wordReplacingZeroO) ) {
... | 176 | 256 | 432 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractSpaceBeforeRule.java | AbstractSpaceBeforeRule | match | class AbstractSpaceBeforeRule extends Rule {
protected abstract Pattern getConjunctions();
public AbstractSpaceBeforeRule(ResourceBundle messages, Language language) {
super.setCategory(Categories.MISC.getCategory(messages));
}
@Override
public String getId() {
return "SPACE_BEFORE_CONJUNCTION";
... |
List<RuleMatch> ruleMatches = new ArrayList<>();
AnalyzedTokenReadings[] tokens = sentence.getTokens();
for (int i = 1; i < tokens.length; i++) {
String token = tokens[i].getToken();
Matcher matcher = getConjunctions().matcher(token);
if (matcher.matches()) {
String previousToken... | 204 | 245 | 449 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public void addTags(List<java.lang.String>) ,public void addToneTags(List<java.lang.String>) ,public int estimateContextForSureMatch() ,public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns() ,pub... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractSpecificCaseRule.java | AbstractSpecificCaseRule | loadPhrases | class AbstractSpecificCaseRule extends Rule {
// a map that has as keys the special case phrases into lowercase
// and as values the special case phrases properly spelled:
// one for each subclass
private static final ConcurrentMap<Class, Map<String,String>> lcToProperSpelling = new ConcurrentHashMap<>();
pr... |
lcToProperSpelling.computeIfAbsent(this.getClass(), (clazz) -> {
Map<String, String> properSpelling = new Object2ObjectOpenHashMap<>();
List<String> lines = phrasesListLoader.loadWords(getPhrasesPath());
for (String line : lines) {
int parts = line.split(" ").length;
maxLen = Math... | 1,108 | 148 | 1,256 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public void addTags(List<java.lang.String>) ,public void addToneTags(List<java.lang.String>) ,public int estimateContextForSureMatch() ,public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns() ,pub... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractStatisticSentenceStyleRule.java | AbstractStatisticSentenceStyleRule | match | class AbstractStatisticSentenceStyleRule extends TextLevelRule {
private static final Pattern OPENING_QUOTES = Pattern.compile("[\"“„»«]");
private static final Pattern ENDING_QUOTES = Pattern.compile("[\"“”»«]");
private static final Pattern MARKS_REGEX = Pattern.compile("[,;.:?•!-–—]");
private static final b... |
List<RuleMatch> ruleMatches = new ArrayList<>();
List<Integer> startPos = new ArrayList<>();
List<Integer> endPos = new ArrayList<>();
List<AnalyzedSentence> relevantSentences = new ArrayList<>();
double percent;
int pos = 0;
sentenceCount = 0;
boolean excludeDirectSpeech = excludeDirec... | 1,062 | 786 | 1,848 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractStatisticStyleRule.java | AbstractStatisticStyleRule | match | class AbstractStatisticStyleRule extends TextLevelRule {
private static final Pattern OPENING_QUOTES = Pattern.compile("[\"“„»«]");
private static final Pattern ENDING_QUOTES = Pattern.compile("[\"“”»«]");
private static final boolean DEFAULT_ACTIVATION = false;
private final int minPercent;
private final in... |
List<RuleMatch> ruleMatches = new ArrayList<>();
List<Integer> startPos = new ArrayList<>();
List<Integer> endPos = new ArrayList<>();
List<AnalyzedSentence> relevantSentences = new ArrayList<>();
double percent;
int pos = 0;
wordCount = 0;
boolean excludeDirectSpeech = excludeDirectSpe... | 1,061 | 695 | 1,756 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractSuppressMisspelledSuggestionsFilter.java | AbstractSuppressMisspelledSuggestionsFilter | acceptRuleMatch | class AbstractSuppressMisspelledSuggestionsFilter extends RuleFilter {
protected AbstractSuppressMisspelledSuggestionsFilter() {
}
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
AnalyzedTokenReadings[] pattern... |
RuleMatch ruleMatch = match;
Language language = ((PatternRule) match.getRule()).getLanguage();
Tagger tagger = language.getTagger();
List<String> replacements = match.getSuggestedReplacements();
List<String> newReplacements = new ArrayList<>();
String suppressMatch = getRequired("suppressMatch... | 230 | 405 | 635 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractTextToNumberFilter.java | AbstractTextToNumberFilter | format | class AbstractTextToNumberFilter extends RuleFilter {
protected static Map<String, Float> numbers = new HashMap<>();
protected static Map<String, Float> multipliers = new HashMap<>();
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
... |
String result;
if (d == (long) d) {
result = String.format("%d", (long) d);
} else {
result = String.format("%s", d);
}
if (percentage) {
result = result + "\u202F%"; // narrow non-breaking space + percentage
}
return formatResult(result);
| 780 | 96 | 876 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AbstractWordCoherencyRule.java | AbstractWordCoherencyRule | match | class AbstractWordCoherencyRule extends TextLevelRule {
/**
* Maps words in both directions, e.g. "aufwendig -> aufwändig" and "aufwändig -> aufwendig".
* @since 3.0
*/
protected abstract Map<String, Set<String>> getWordMap();
/**
* Get the message shown to the user if the rule matches.
*/
... |
List<RuleMatch> ruleMatches = new ArrayList<>();
Map<String, String> shouldNotAppearWord = new HashMap<>(); // e.g. aufwändig -> aufwendig
int pos = 0;
for (AnalyzedSentence sentence : sentences) {
AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();
for (AnalyzedTokenRe... | 305 | 611 | 916 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AdaptSuggestionsFilter.java | AdaptSuggestionsFilter | acceptRuleMatch | class AdaptSuggestionsFilter extends RuleFilter {
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) throws IOException {<FILL_FUNCTION_BODY>}
} |
Rule rule = match.getRule();
if (rule instanceof AbstractPatternRule) {
List<String> adjustedSuggestions = new ArrayList<>();
Language lang = ((AbstractPatternRule) rule).getLanguage();
for (String replacement : match.getSuggestedReplacements()) {
adjustedSuggestions.add(lang.adaptSug... | 82 | 134 | 216 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/AddCommasFilter.java | AddCommasFilter | acceptRuleMatch | class AddCommasFilter extends RuleFilter {
private static final Pattern OPENING_QUOTES = Pattern.compile("[«“\"‘'„¿¡]", Pattern.DOTALL);
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
AnalyzedTokenReadings... |
// for patterns ", aun así" suggest "; aun así," and ", aun así,"
String suggestSemicolon = getOptional("suggestSemicolon", arguments);
boolean bSuggestSemicolon = false;
if (suggestSemicolon != null && suggestSemicolon.equalsIgnoreCase("true")) {
bSuggestSemicolon = true;
}
Analyzed... | 123 | 942 | 1,065 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/BERTSuggestionRanking.java | MatchesForReordering | buildRequest | class MatchesForReordering extends RemoteRequest {
final List<AnalyzedSentence> sentences;
final List<RuleMatch> matches;
final List<RemoteLanguageModel.Request> requests;
MatchesForReordering(List<AnalyzedSentence> sentences, List<RuleMatch> matches, List<RemoteLanguageModel.Request> requests) {
... |
List<String> suggestions = match.getSuggestedReplacements();
if (suggestions != null && suggestions.size() > 1) {
return new RemoteLanguageModel.Request(
match.getSentence().getText(), match.getFromPos(), match.getToPos(), suggestions);
} else {
return null;
}
| 1,652 | 87 | 1,739 | <methods>public void <init>(org.languagetool.Language, java.util.ResourceBundle, org.languagetool.rules.RemoteRuleConfig, boolean, java.lang.String) ,public void <init>(org.languagetool.Language, java.util.ResourceBundle, org.languagetool.rules.RemoteRuleConfig, boolean) ,public CircuitBreaker circuitBreaker() ,public ... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/CategoryId.java | CategoryId | equals | class CategoryId {
private final String id;
public CategoryId(String id) {
Objects.requireNonNull(id, "Category id must not be null.");
if (id.trim().isEmpty()) {
throw new IllegalArgumentException("Category id must not be empty: '" + id + "'");
}
this.id = id;
}
@Override
public bo... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CategoryId other = (CategoryId) o;
return id.equals(other.id);
| 163 | 58 | 221 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/CleanOverlappingFilter.java | CleanOverlappingFilter | filter | class CleanOverlappingFilter implements RuleMatchFilter {
private static final int negativeConstant = Integer.MIN_VALUE + 10000;
private final Language language;
private final boolean hidePremiumMatches;
public CleanOverlappingFilter(Language lang, boolean hidePremiumMatches) {
this.language = lang;
... |
List<RuleMatch> cleanList = new ArrayList<>();
RuleMatch prevRuleMatch = null;
for (RuleMatch ruleMatch: ruleMatches) {
if (prevRuleMatch == null) { // first item
prevRuleMatch = ruleMatch;
continue;
}
if (ruleMatch.getFromPos() < prevRuleMatch.getFromPos()) {
thr... | 181 | 912 | 1,093 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/CompoundRuleData.java | CompoundRuleData | loadCompoundFile | class CompoundRuleData {
private final Set<String> incorrectCompounds = new ObjectOpenHashSet<>();
private final Set<String> joinedSuggestion = new ObjectOpenHashSet<>();
private final Set<String> joinedLowerCaseSuggestion = new ObjectOpenHashSet<>();
private final Set<String> dashSuggestion = new ObjectOpenHa... |
List<String> lines = JLanguageTool.getDataBroker().getFromResourceDirAsLines(path);
for (String line : lines) {
if (line.isEmpty() || line.startsWith("#")) {
continue; // ignore comments
}
line = line.replaceFirst("#.*$", "").trim();
List<String> expandedLines = new ArrayLis... | 622 | 457 | 1,079 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/ConfusionPair.java | ConfusionPair | getUppercaseFirstCharTerms | class ConfusionPair {
private final ConfusionString term1;
private final ConfusionString term2;
private final long factor;
private final boolean bidirectional;
public ConfusionPair(ConfusionString cs1, ConfusionString cs2, long factor, boolean bidirectional) {
this.term1 = Objects.requireNonNull(cs1);
... |
List<ConfusionString> result = new ArrayList<>();
result.add(new ConfusionString(StringTools.uppercaseFirstChar(term1.getString()), term1.getDescription()));
result.add(new ConfusionString(StringTools.uppercaseFirstChar(term2.getString()), term2.getDescription()));
return Collections.unmodifiableList(r... | 670 | 90 | 760 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/ConfusionSet.java | ConfusionSet | equals | class ConfusionSet {
private final Set<ConfusionString> set = new HashSet<>();
private final long factor;
/**
* @param factor the factor that one string must be more probable than the other to be considered a correction, must be >= 1
*/
public ConfusionSet(long factor, List<ConfusionString> confusion... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConfusionSet other = (ConfusionSet) o;
return Objects.equals(set, other.set) && Objects.equals(factor, other.factor);
| 533 | 75 | 608 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/ConfusionSetLoader.java | ConfusionSetLoader | loadConfusionPairs | class ConfusionSetLoader {
private static final String CHARSET = "utf-8";
private final ShortDescriptionProvider wordDefs;
private final Language lang;
public ConfusionSetLoader(Language lang) {
wordDefs = new ShortDescriptionProvider();
this.lang = Objects.requireNonNull(lang);
}
public Map<S... |
Map<String,List<ConfusionPair>> map = new HashMap<>();
try (
InputStreamReader reader = new InputStreamReader(stream, CHARSET);
BufferedReader br = new BufferedReader(reader)
) {
String line;
while ((line = br.readLine()) != null) {
if (line.startsWith("#") || line.trim().is... | 276 | 785 | 1,061 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/ConfusionString.java | ConfusionString | equals | class ConfusionString {
private final String str;
private final String description;
ConfusionString(String str, String description) {
this.str = Objects.requireNonNull(str);
this.description = description;
}
public String getString() {
return str;
}
@Nullable
public String getDescription... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConfusionString other = (ConfusionString) o;
return Objects.equals(str, other.str) && Objects.equals(description, other.description);
| 177 | 75 | 252 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/ConvertToSentenceCaseFilter.java | ConvertToSentenceCaseFilter | normalizedCase | class ConvertToSentenceCaseFilter extends RuleFilter {
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) throws IOException {
RuleMatch ruleMatch... |
String tokenLowercase = atr.getToken().toLowerCase();
if (atr.hasTypographicApostrophe()) {
tokenLowercase = tokenLowercase.replaceAll("'", "’");
}
if (tokenIsException(tokenLowercase)) {
// exception: the lemma is "I"
return tokenLowercase;
}
String tokenCapitalized = StringT... | 570 | 350 | 920 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/DateRangeChecker.java | DateRangeChecker | acceptRuleMatch | class DateRangeChecker extends RuleFilter {
@Nullable
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos, AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) {<FILL_FUNCTION_BODY>}
} |
try {
int x = Integer.parseInt(arguments.get("x"));
int y = Integer.parseInt(arguments.get("y"));
if (x >= y) {
return match;
}
} catch (IllegalArgumentException ignore) {
// if something's fishy with the number – ignore it silently,
// it's not a date range
re... | 77 | 109 | 186 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/DemoRule.java | DemoRule | match | class DemoRule extends Rule {
@Override
public String getId() {
return "DEMO_RULE"; // a unique id that doesn't change over time
}
@Override
public String getDescription() {
return "A demo rule that just prints the text analysis"; // shown in the configuration dialog
}
// This is the method... |
List<RuleMatch> ruleMatches = new ArrayList<>();
// Let's get all the tokens (i.e. words) of this sentence, but not the spaces:
AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();
// No let's iterate over those - note that the first token will
// be a special token that in... | 139 | 402 | 541 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public void addTags(List<java.lang.String>) ,public void addToneTags(List<java.lang.String>) ,public int estimateContextForSureMatch() ,public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns() ,pub... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/DictionaryMatchFilter.java | DictionaryMatchFilter | filter | class DictionaryMatchFilter implements RuleMatchFilter {
private final UserConfig userConfig;
public DictionaryMatchFilter(UserConfig userConfig) {
this.userConfig = userConfig;
}
@Override
public List<RuleMatch> filter(List<RuleMatch> ruleMatches, AnnotatedText text) {<FILL_FUNCTION_BODY>}
} |
Set<String> dictionary = new HashSet<>(userConfig.getAcceptedWords());
return ruleMatches.stream().filter(match -> {
// at this point, the offsets we get from match are already converted to be pointing to the text with markup
// so we need to compute the substring based on that
// using anyt... | 91 | 170 | 261 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/DictionarySpellMatchFilter.java | PhraseSearchLoader | getPhrases | class PhraseSearchLoader extends CacheLoader<UserConfig, AhoCorasickDoubleArrayTrie<String>> {
@Override
public AhoCorasickDoubleArrayTrie<String> load(UserConfig key) throws Exception {
AhoCorasickDoubleArrayTrie<String> searcher = new AhoCorasickDoubleArrayTrie<>();
Map<String, String> phrases = n... |
Map<String, List<RuleMatch>> phraseToMatches = new HashMap<>();
int prevToPos = Integer.MIN_VALUE;
List<RuleMatch> collectedMatches = new ArrayList<>();
List<String> collectedTerms = new ArrayList<>();
for (RuleMatch match : ruleMatches) {
if (match.getRule().isDictionaryBasedSpellingRule()) ... | 662 | 271 | 933 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/DoublePunctuationRule.java | DoublePunctuationRule | match | class DoublePunctuationRule extends Rule {
public DoublePunctuationRule(ResourceBundle messages) {
this(messages, null);
}
/** @since 5.9 */
public DoublePunctuationRule(ResourceBundle messages, URL url) {
super(messages);
super.setCategory(Categories.PUNCTUATION.getCategory(messages));
setLoc... |
List<RuleMatch> ruleMatches = new ArrayList<>();
AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();
int startPos = 0;
int dotCount = 0;
int commaCount = 0;
for (int i = 1; i < tokens.length; i++) {
String token = tokens[i].getToken();
String nextToken = null;
... | 303 | 661 | 964 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public void addTags(List<java.lang.String>) ,public void addToneTags(List<java.lang.String>) ,public int estimateContextForSureMatch() ,public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns() ,pub... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/EmptyLineRule.java | EmptyLineRule | match | class EmptyLineRule extends TextLevelRule {
private final Language lang;
public EmptyLineRule(ResourceBundle messages, Language lang, boolean defaultActive) {
super(messages);
super.setCategory(Categories.STYLE.getCategory(messages));
this.lang = lang;
if (!defaultActive) {
setDefaultOff()... |
List<RuleMatch> ruleMatches = new ArrayList<>();
int pos = 0;
for (int n = 0; n < sentences.size() - 1; n++) {
AnalyzedSentence sentence = sentences.get(n);
if(Tools.isParagraphEnd(sentences, n, lang)) {
if(isSecondParagraphEndMark(sentence.getText())) {
AnalyzedTokenReadings[... | 454 | 279 | 733 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/Example.java | Example | requireMarkup | class Example {
private Example() {
}
/**
* Create an example text (usually just one sentence) with an error - the error must be marked with {@code <marker>...</marker>}.
* @throws IllegalArgumentException if the {@code <marker>...</marker>} is missing
* @since 2.5
*/
public static IncorrectExampl... |
if (!example.contains("<marker>") || !example.contains("</marker>")) {
throw new IllegalArgumentException("Example text must contain '<marker>...</marker>': " + example);
}
| 260 | 59 | 319 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/GRPCRule.java | AnalyzedMLRuleRequest | prepareRequest | class AnalyzedMLRuleRequest extends RemoteRule.RemoteRequest {
final List<MLServerProto.AnalyzedMatchRequest> requests;
final List<AnalyzedSentence> sentences;
public AnalyzedMLRuleRequest(List<MLServerProto.AnalyzedMatchRequest> requests, List<AnalyzedSentence> sentences) {
this.requests = requests;... |
List<Long> ids = Collections.emptyList();
// TODO this is a temp fix to avoid sending too long sentences to the server
List<AnalyzedSentence> filteredSentences = sentences.stream()
.filter(s -> s.getText().length() <= maxSentenceLength)
.collect(Collectors.toList());
if (textSessionId != n... | 143 | 691 | 834 | <methods>public void <init>(org.languagetool.Language, java.util.ResourceBundle, org.languagetool.rules.RemoteRuleConfig, boolean, java.lang.String) ,public void <init>(org.languagetool.Language, java.util.ResourceBundle, org.languagetool.rules.RemoteRuleConfig, boolean) ,public CircuitBreaker circuitBreaker() ,public ... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/GRPCUtils.java | RuleData | toGRPC | class RuleData extends Rule {
private final Match m;
private final String sourceFile;
RuleData(Match m) {
this.m = m;
this.sourceFile = m.getRule().getSourceFile();
// keep default values from Rule baseclass
if (!m.getRule().getIssueType().isEmpty()) {
setLocQualityIssueType... |
// could add better handling for conversion errors with enums
return Match.newBuilder()
.setOffset(m.getFromPos())
.setLength(m.getToPos() - m.getFromPos())
.setId(m.getSpecificRuleId())
.setSubId(nullAsEmpty(m.getRule().getSubId()))
.addAllSuggestedReplacements(m.getSuggestedRepl... | 1,240 | 469 | 1,709 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/IncorrectExample.java | IncorrectExample | getCorrections | class IncorrectExample extends ExampleSentence {
private final Object corrections;
public IncorrectExample(String example) {
this(example, Collections.emptyList());
}
/**
* @since 2.9
*/
public IncorrectExample(String example, List<String> corrections) {
super(example);
this.corrections... |
return corrections == null ? Collections.emptyList() :
corrections instanceof String ? Collections.singletonList((String) corrections) :
Collections.unmodifiableList(Arrays.asList((String[])corrections));
| 208 | 58 | 266 | <methods>public void <init>(java.lang.String) ,public static java.lang.String cleanMarkersInExample(java.lang.String) ,public java.lang.String getExample() ,public java.lang.String toString() <variables>protected final non-sealed java.lang.String example |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/IsEnglishWordFilter.java | IsEnglishWordFilter | acceptRuleMatch | class IsEnglishWordFilter extends RuleFilter {
private Language english = null;
//private SpellingCheckRule spellingCheckRule = null;
private Tagger tagger = null;
public IsEnglishWordFilter() {
try {
english = Languages.getLanguageForShortCode("en-US");
} catch (Exception e) {
}
if (eng... |
if (tagger == null) {
return null;
}
String[] formPositions = getRequired("formPositions", args).split(",");
List<String> forms = new ArrayList<>();
for (String formPosition : formPositions) {
forms.add(patternTokens[getSkipCorrectedReference(tokenPositions, Integer.parseInt(formPositi... | 301 | 317 | 618 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/LongParagraphRule.java | LongParagraphRule | match | class LongParagraphRule extends TextLevelRule {
public static final String RULE_ID = "TOO_LONG_PARAGRAPH";
private static final boolean DEFAULT_ACTIVATION = false;
private static final int DEFAULT_MAX_WORDS = 220;
private final Language lang;
private int maxWords = DEFAULT_MAX_WORDS;
public LongParagra... |
List<RuleMatch> ruleMatches = new ArrayList<>();
int pos = 0;
int startPos = 0;
int endPos = 0;
int wordCount = 0;
boolean paraHasLinebreaks = false;
for (int n = 0; n < sentences.size(); n++) {
AnalyzedSentence sentence = sentences.get(n);
boolean paragraphEnd = Tools.isParagra... | 679 | 477 | 1,156 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/LongSentenceRule.java | LongSentenceRule | match | class LongSentenceRule extends TextLevelRule {
public static final String RULE_ID = "TOO_LONG_SENTENCE";
private static final Pattern QUOTED_SENT_END = Pattern.compile("[?!.][\"“”„»«]", Pattern.DOTALL);
private static final Pattern SENT_END = Pattern.compile("[?!.]");
private static List<String> OPENING_QUOT... |
List<RuleMatch> ruleMatches = new ArrayList<>();
int pos = 0;
for (AnalyzedSentence sentence : sentences) {
AnalyzedTokenReadings[] tokens = sentence.getTokens();
if (tokens.length < maxWords) { // just a short-circuit
pos += sentence.getCorrectedTextLength();
continue;
... | 742 | 871 | 1,613 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/MatchPosition.java | MatchPosition | equals | class MatchPosition {
private final int start;
private final int end;
MatchPosition(int start, int end) {
this.start = start;
this.end = end;
}
int getStart() {
return start;
}
int getEnd() {
return end;
}
@Override
public String toString() {
return start + "-" + end;
}
... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MatchPosition other = (MatchPosition) o;
return Objects.equals(start, other.start) && Objects.equals(end, other.end);
| 168 | 73 | 241 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/MultipleWhitespaceRule.java | MultipleWhitespaceRule | match | class MultipleWhitespaceRule extends TextLevelRule {
public MultipleWhitespaceRule(ResourceBundle messages, Language language) {
super(messages);
super.setCategory(Categories.TYPOGRAPHY.getCategory(messages));
setLocQualityIssueType(ITSIssueType.Whitespace);
}
@Override
public String getId() {
... |
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
for (int i = 1; i < tokens.length; i++) {
... | 474 | 333 | 807 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/ParagraphRepeatBeginningRule.java | ParagraphRepeatBeginningRule | match | class ParagraphRepeatBeginningRule extends TextLevelRule {
private static final Pattern QUOTES_REGEX = Pattern.compile("[’'\"„“”»«‚‘›‹()\\[\\]]");
private final Language lang;
public ParagraphRepeatBeginningRule(ResourceBundle messages, Language lang) {
super(messages);
super.setCategory(Categories.STY... |
List<RuleMatch> ruleMatches = new ArrayList<>();
if (sentences.size() < 1) {
return toRuleMatchArray(ruleMatches);
}
int nextPos = 0;
int lastPos = 0;
int endPos;
AnalyzedSentence lastSentence = sentences.get(0);
AnalyzedTokenReadings[] lastTokens = lastSentence.getTokensWithou... | 744 | 477 | 1,221 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/PartialPosTagFilter.java | PartialPosTagFilter | acceptRuleMatch | class PartialPosTagFilter extends RuleFilter {
@Nullable
protected abstract List<AnalyzedTokenReadings> tag(String token);
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> args, int patternTokenPos, AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) {<FILL_FUNC... |
if (!(args.containsKey("no") && args.containsKey("regexp") && args.containsKey("postag_regexp"))) {
throw new RuntimeException("Set 'no', 'regexp' and 'postag_regexp' for filter " + PartialPosTagFilter.class.getSimpleName());
}
int tokenPos = Integer.parseInt(args.get("no"));
Pattern pattern = Pa... | 348 | 527 | 875 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/PunctuationMarkAtParagraphEnd.java | PunctuationMarkAtParagraphEnd | match | class PunctuationMarkAtParagraphEnd extends TextLevelRule {
private final static String[] PUNCTUATION_MARKS = {".", "!", "?", ":", ",", ";"};
private final static String[] QUOTATION_MARKS = {"„", "»", "«", "\"", "”", "″", "’", "‚", "‘", "›", "‹", "′", "'"};
private final static Pattern P_NUMERIC = Pattern.compil... |
List<RuleMatch> ruleMatches = new ArrayList<>();
int lastPara = -1;
int pos = 0;
boolean isFirstWord;
for (int n = 0; n < sentences.size(); n++) {
AnalyzedSentence sentence = sentences.get(n);
if (Tools.isParagraphEnd(sentences, n, lang)) {
AnalyzedTokenReadings[] tokens = sente... | 669 | 746 | 1,415 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/PunctuationMarkAtParagraphEnd2.java | PunctuationMarkAtParagraphEnd2 | getLastNonSpaceToken | class PunctuationMarkAtParagraphEnd2 extends TextLevelRule {
// more than this many word tokens needed for a "real" paragraph that requires a period (etc) at the end:
private static final int TOKEN_THRESHOLD = 10;
private final Language lang;
public PunctuationMarkAtParagraphEnd2(ResourceBundle messages, L... |
for (int i = tokens.length-1; i >= 0; i--) {
if (!tokens[i].isWhitespace()) {
return tokens[i];
}
}
return null;
| 701 | 57 | 758 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/RemoteRule.java | RemoteRequest | run | class RemoteRequest {}
/**
* run local preprocessing steps (or just store sentences)
* @param sentences text to process
* @param textSessionId session ID for caching, partial rollout, A/B testing
* @return parameter for executeRequest/fallbackResults
*/
protected abstract RemoteRequest prepareReques... |
if (sentences.isEmpty()) {
return new FutureTask<>(() -> new RemoteRuleResult(false, true, Collections.emptyList(), sentences));
}
Map<String, String> context = MDC.getCopyOfContextMap();
return new FutureTask<>(() -> {
MDC.clear();
if (context != null) {
MDC.setContextMap(con... | 723 | 553 | 1,276 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public void addTags(List<java.lang.String>) ,public void addToneTags(List<java.lang.String>) ,public int estimateContextForSureMatch() ,public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns() ,pub... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/RemoteRuleConfig.java | RemoteRuleConfig | isRelevantConfig | class RemoteRuleConfig {
private static final int DEFAULT_PORT = 443;
private static final long DEFAULT_BASE_TIMEOUT = 1000;
private static final float DEFAULT_TIMEOUT_PER_CHAR = 0;
private static final long DEFAULT_DOWN = 5000L;
private static final float DEFAULT_FAILURE_RATE_THRESHOLD = 50f;
private stati... |
return (r) -> type.equals(r.type) &&
(r.language == null || language.getShortCodeWithCountryAndVariant().matches(r.language));
| 1,959 | 47 | 2,006 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/RemoteRuleFilters.java | RemoteRuleFilters | filterMatches | class RemoteRuleFilters {
public static final String RULE_FILE = "remote-rule-filters.xml";
private static final LoadingCache<Language, List<Map.Entry<Pattern, List<AbstractPatternRule>>>> rules =
CacheBuilder.newBuilder()
.build(CacheLoader.from((lang) -> compilePatterns(RemoteRuleFilters.load(lang))... |
if (matches.isEmpty()) {
return matches;
}
// load all relevant filters for given matches
Set<String> matchIds = matches.stream().map(m -> m.getRule().getId()).collect(Collectors.toSet());
List<AbstractPatternRule> filters = rules.get(lang).stream()
.filter(e -> matchIds.stream().anyMat... | 1,539 | 408 | 1,947 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/RemoteRuleMetrics.java | RemoteRuleMetrics | inCircuitBreaker | class RemoteRuleMetrics {
private static final Logger logger = LoggerFactory.getLogger(RemoteRuleMetrics.class);
private RemoteRuleMetrics() {
throw new IllegalStateException("RemoteRuleMetrics should only be used via static methods.");
}
public enum RequestResult {
SUCCESS,
SKIPPED,
TIMEOUT,
... |
try {
return circuitBreaker.executeCallable(fetchResults);
} catch (InterruptedException e) {
logger.info("Failed to fetch result from remote rule '{}' - interrupted.", ruleKey);
request(ruleKey, deadlineStartNanos, chars, RequestResult.INTERRUPTED);
throw e;
} catch (CancellationEx... | 770 | 508 | 1,278 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/RemoteRuleResult.java | RemoteRuleResult | matchesForSentence | class RemoteRuleResult {
private final boolean remote; // was remote needed/involved? rules may filter input sentences and only call remote on some; for metrics
private final boolean success; // successful -> for caching, so that we can cache: remote not needed for this sentence
private final List<RuleMatch> matc... |
List<RuleMatch> defaultValue = processedSentences.contains(sentence) ?
Collections.emptyList() : null;
return sentenceMatches.getOrDefault(sentence, defaultValue);
| 520 | 51 | 571 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/RuleWithMaxFilter.java | RuleWithMaxFilter | filter | class RuleWithMaxFilter implements RuleMatchFilter {
@Override
public final List<RuleMatch> filter(List<RuleMatch> ruleMatches) {<FILL_FUNCTION_BODY>}
final boolean includes(RuleMatch match, RuleMatch nextMatch) {
if (match.getFromPos() <= nextMatch.getFromPos() && match.getToPos() >= nextMatch.getToPos()) ... |
Collections.sort(ruleMatches);
List<RuleMatch> filteredRules = new ArrayList<>();
for (int i = 0; i < ruleMatches.size(); i++) {
RuleMatch match = ruleMatches.get(i);
if (i < ruleMatches.size() - 1) {
RuleMatch nextMatch = ruleMatches.get(i + 1);
while (includes(match, nextMatch... | 343 | 202 | 545 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/SameRuleGroupFilter.java | SameRuleGroupFilter | filter | class SameRuleGroupFilter implements RuleMatchFilter {
/**
* @param ruleMatches list of matches
*/
@Override
public List<RuleMatch> filter(List<RuleMatch> ruleMatches) {<FILL_FUNCTION_BODY>}
private boolean overlapAndMatch(RuleMatch match, RuleMatch nextMatch) {
return overlaps(match, nextMatch) && ... |
Collections.sort(ruleMatches);
List<RuleMatch> filteredRules = new ArrayList<>();
for (int i = 0; i < ruleMatches.size(); i++) {
RuleMatch match = ruleMatches.get(i);
while (i < ruleMatches.size() - 1 && overlapAndMatch(match, ruleMatches.get(i + 1))) {
i++; // skip next match
}
... | 237 | 130 | 367 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/ScoredConfusionSet.java | ScoredConfusionSet | equals | class ScoredConfusionSet {
private List<ConfusionString> confusionWords;
private final float score;
/**
* @param score the score that a string must get at least to be considered a correction, must be > 0
*/
public ScoredConfusionSet(float score, List<ConfusionString> words) {
if (score <= 0) {
... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
org.languagetool.rules.ScoredConfusionSet other = (org.languagetool.rules.ScoredConfusionSet) o;
return Objects.equals(confusionWords, other.confusionWords) && Objects.equals(score, other.score);
| 360 | 105 | 465 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/SentenceWhitespaceRule.java | SentenceWhitespaceRule | match | class SentenceWhitespaceRule extends TextLevelRule {
public SentenceWhitespaceRule(ResourceBundle messages) {
super(messages);
super.setCategory(Categories.TYPOGRAPHY.getCategory(messages));
setLocQualityIssueType(ITSIssueType.Whitespace);
}
@Override
public String getId() {
return "SENTENCE... |
boolean isFirstSentence = true;
boolean prevSentenceEndsWithWhitespace = false;
boolean prevSentenceEndsWithNumber = false;
List<RuleMatch> ruleMatches = new ArrayList<>();
int pos = 0;
for (AnalyzedSentence sentence : sentences) {
AnalyzedTokenReadings[] tokens = sentence.getTokens();
... | 245 | 374 | 619 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/ShortenedYearRangeChecker.java | ShortenedYearRangeChecker | acceptRuleMatch | class ShortenedYearRangeChecker extends RuleFilter {
@Nullable
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos, AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) {<FILL_FUNCTION_BODY>}
} |
try {
int x = Integer.parseInt(arguments.get("x"));
String centuryPrefix = arguments.get("x").substring(0, 2);
int y = Integer.parseInt(centuryPrefix + arguments.get("y"));
if (x >= y) {
return match;
}
} catch (IllegalArgumentException ignore) {
// if something's fi... | 81 | 132 | 213 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/SimpleReplaceDataLoader.java | SimpleReplaceDataLoader | loadWords | class SimpleReplaceDataLoader {
/**
* Load replacement rules from a utf-8 file in the classpath.
*/
public Map<String, List<String>> loadWords(String path) {<FILL_FUNCTION_BODY>}
} |
InputStream stream = JLanguageTool.getDataBroker().getFromRulesDirAsStream(path);
Map<String, List<String>> map = new HashMap<>();
try (Scanner scanner = new Scanner(stream, "utf-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.isEmpty() || line.charAt... | 65 | 334 | 399 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/SuggestedReplacement.java | SuggestedReplacement | equals | class SuggestedReplacement {
private String replacement;
private String shortDescription;
private String suffix;
private SortedMap<String, Float> features = Collections.emptySortedMap();
private Float confidence = null;
private SuggestionType type = SuggestionType.Default;
/**
classify the type of t... |
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SuggestedReplacement that = (SuggestedReplacement) o;
return replacement.equals(that.replacement) &&
Objects.equals(shortDescription, that.shortDescription);
| 1,037 | 81 | 1,118 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/SuggestionFilter.java | SuggestionFilter | filter | class SuggestionFilter {
private final Rule rule;
private final JLanguageTool lt;
public SuggestionFilter(Rule rule, Language lang) {
this.rule = Objects.requireNonNull(rule);
this.lt = lang.createDefaultJLanguageTool();
}
public List<String> filter(List<String> replacements, String template) {<FIL... |
List<String> newReplacements = new ArrayList<>();
for (String repl : replacements) {
try {
List<AnalyzedSentence> analyzedSentences = lt.analyzeText(template.replace("{}", repl));
RuleMatch[] matches = rule.match(analyzedSentences.get(0));
if (matches.length == 0) {
newR... | 111 | 144 | 255 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/SuppressIfAnyRuleMatchesFilter.java | SuppressIfAnyRuleMatchesFilter | acceptRuleMatch | class SuppressIfAnyRuleMatchesFilter extends RuleFilter {
/*
* Suppress the match if the new suggestion creates any new match with the rule IDs provided
*/
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
Anal... |
List<String> ruleIDs = Arrays.asList(getRequired("ruleIDs", arguments).split(","));
JLanguageTool lt = ((PatternRule) match.getRule()).getLanguage().createDefaultJLanguageTool();
String sentence = match.getSentence().getText();
for (String replacement : match.getSuggestedReplacements()) {
String ... | 110 | 298 | 408 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/TestHackHelper.java | TestHackHelper | isJUnitTest | class TestHackHelper {
private TestHackHelper() {
}
public static boolean isJUnitTest() {<FILL_FUNCTION_BODY>}
} |
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (StackTraceElement element : stackTrace) {
if (element.getClassName().startsWith("org.junit.") ||
element.getClassName().equals("org.languagetool.rules.patterns.PatternRuleTest")) {
return true;
}
... | 46 | 97 | 143 | <no_super_class> |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/TestRemoteRule.java | TestRemoteRequest | executeRequest | class TestRemoteRequest extends RemoteRequest {
private final List<AnalyzedSentence> sentences;
TestRemoteRequest(List<AnalyzedSentence> sentences) {
this.sentences = sentences;
}
}
@Override
protected RemoteRequest prepareRequest(List<AnalyzedSentence> sentences, Long textSessio... |
return () -> {
TestRemoteRequest req = (TestRemoteRequest) request;
List<RuleMatch> matches = req.sentences.stream().map(this::testMatch).collect(Collectors.toList());
long deadline = System.currentTimeMillis() + waitTime;
//noinspection StatementWithEmptyBody
Thread.sleep... | 180 | 137 | 317 | <methods>public void <init>(org.languagetool.Language, java.util.ResourceBundle, org.languagetool.rules.RemoteRuleConfig, boolean, java.lang.String) ,public void <init>(org.languagetool.Language, java.util.ResourceBundle, org.languagetool.rules.RemoteRuleConfig, boolean) ,public CircuitBreaker circuitBreaker() ,public ... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/UnderlineSpacesFilter.java | UnderlineSpacesFilter | acceptRuleMatch | class UnderlineSpacesFilter extends RuleFilter {
/*
* Underline the whitespaces before and/or after the marker in the pattern
*/
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
AnalyzedTokenReadings[] patternTokens, List... |
String underlineSpaces = getRequired("underlineSpaces", arguments); // before/after/both
String sentence = match.getSentence().getText();
if (underlineSpaces.equals("before") || underlineSpaces.equals("both")) {
if (match.getFromPos() - 1 >= 0
&& StringTools.isWhitespace(sentence.substring(ma... | 99 | 249 | 348 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/UnsyncStack.java | UnsyncStack | peek | class UnsyncStack<E> extends ArrayList<E> {
/** Generated automatically. */
private static final long serialVersionUID = -4984830372178073605L;
UnsyncStack() {
}
/**
* Pushes an item onto the top of this stack. This has exactly the same effect
* as: {@code add(item)}
*
* @param item the item... |
int len = size();
if (len == 0) {
throw new EmptyStackException();
}
return get(len - 1);
| 734 | 41 | 775 | <methods>public void <init>() ,public void <init>(int) ,public void <init>(Collection<? extends E>) ,public boolean add(E) ,public void add(int, E) ,public boolean addAll(Collection<? extends E>) ,public boolean addAll(int, Collection<? extends E>) ,public void clear() ,public java.lang.Object clone() ,public boolean c... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/WhiteSpaceAtBeginOfParagraph.java | WhiteSpaceAtBeginOfParagraph | match | class WhiteSpaceAtBeginOfParagraph extends Rule {
public WhiteSpaceAtBeginOfParagraph(ResourceBundle messages, boolean defaultActive) {
super(messages);
super.setCategory(Categories.STYLE.getCategory(messages));
if (!defaultActive) {
setDefaultOff();
}
setOfficeDefaultOn();
setLocQualit... |
List<RuleMatch> ruleMatches = new ArrayList<>();
AnalyzedTokenReadings[] tokens = sentence.getTokens();
int i;
for (i = 1; i < tokens.length && isWhitespaceDel(tokens[i]); i++);
if (i > 1 && i < tokens.length && !tokens[i].isLinebreak()) {
RuleMatch ruleMatch = new RuleMatch(this, sentence, t... | 335 | 189 | 524 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public void addTags(List<java.lang.String>) ,public void addToneTags(List<java.lang.String>) ,public int estimateContextForSureMatch() ,public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns() ,pub... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/WhiteSpaceBeforeParagraphEnd.java | WhiteSpaceBeforeParagraphEnd | match | class WhiteSpaceBeforeParagraphEnd extends TextLevelRule {
private final Language lang;
public WhiteSpaceBeforeParagraphEnd(ResourceBundle messages, Language lang, boolean defaultActive) {
super(messages);
super.setCategory(Categories.STYLE.getCategory(messages));
this.lang = lang;
if (!defaultA... |
List<RuleMatch> ruleMatches = new ArrayList<>();
int pos = 0;
for (int n = 0; n < sentences.size(); n++) {
AnalyzedSentence sentence = sentences.get(n);
if(Tools.isParagraphEnd(sentences, n, lang)) {
AnalyzedTokenReadings[] tokens = sentence.getTokens();
int lb;
int lw;... | 290 | 401 | 691 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMat... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/WhitespaceBeforePunctuationRule.java | WhitespaceBeforePunctuationRule | match | class WhitespaceBeforePunctuationRule extends Rule {
public WhitespaceBeforePunctuationRule(ResourceBundle messages) {
super(messages);
super.setCategory(Categories.TYPOGRAPHY.getCategory(messages));
setLocQualityIssueType(ITSIssueType.Whitespace);
}
@Override
public final String getId() {
ret... |
List<RuleMatch> ruleMatches = new ArrayList<>();
AnalyzedTokenReadings[] tokens = sentence.getTokens();
boolean prevWhite = false;
int prevLen = 0;
for (int i = 0; i < tokens.length; i++) {
String token = tokens[i].getToken();
boolean isWhitespace = tokens[i].isWhitespace() || StringToo... | 187 | 549 | 736 | <methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public void addTags(List<java.lang.String>) ,public void addToneTags(List<java.lang.String>) ,public int estimateContextForSureMatch() ,public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns() ,pub... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/WhitespaceCheckFilter.java | WhitespaceCheckFilter | acceptRuleMatch | class WhitespaceCheckFilter extends RuleFilter {
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) {<FILL_FUNCTION_BODY>}
} |
String wsChar = getRequired("whitespaceChar", arguments);
int pos = Integer.parseInt(getRequired("position", arguments));
if (pos < 1 || pos > patternTokens.length) {
throw new IllegalArgumentException("Wrong position in WhitespaceCheckFilter: " + pos + ", must be 1 to " + patternTokens.length);
... | 79 | 135 | 214 | <methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.Str... |
languagetool-org_languagetool | languagetool/languagetool-core/src/main/java/org/languagetool/rules/WordCoherencyDataLoader.java | WordCoherencyDataLoader | loadWords | class WordCoherencyDataLoader {
public Map<String, Set<String>> loadWords(String path) {<FILL_FUNCTION_BODY>}
} |
InputStream stream = JLanguageTool.getDataBroker().getFromRulesDirAsStream(path);
Map<String, Set<String>> map = new Object2ObjectOpenHashMap<>();
try (
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(reader)
) {
... | 44 | 388 | 432 | <no_super_class> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.