update to jdk11, fix migration issues, some typos, deprecated apis, bump up Lucene to 8.11

This commit is contained in:
Konstantin Perikov
2021-12-10 18:15:47 +00:00
parent b2fec940d0
commit 96900e334e
32 changed files with 184 additions and 198 deletions

View File

@ -6,7 +6,6 @@
<version>1.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.lucene.morphology</groupId>
<artifactId>morph</artifactId>
<name>morph</name>
<version>1.5</version>

View File

@ -21,7 +21,7 @@ import java.util.ArrayList;
public abstract class BaseLetterDecoderEncoder implements LetterDecoderEncoder {
public int[] encodeToArray(String s) {
ArrayList<Integer> integers = new ArrayList<Integer>();
ArrayList<Integer> integers = new ArrayList<>();
while (s.length() > 6) {
integers.add(encode(s.substring(0, 6)));
s = s.substring(6);
@ -37,11 +37,11 @@ public abstract class BaseLetterDecoderEncoder implements LetterDecoderEncoder {
}
public String decodeArray(int[] array) {
String result = "";
StringBuilder result = new StringBuilder();
for (int i : array) {
result += decode(i);
result.append(decode(i));
}
return result;
return result.toString();
}
public boolean checkString(String word) {

View File

@ -16,6 +16,7 @@
package org.apache.lucene.morphology;
import java.io.Serializable;
import java.util.Objects;
public class Heuristic implements Serializable {
@ -26,10 +27,10 @@ public class Heuristic implements Serializable {
public Heuristic(String s) {
String[] strings = s.split("\\|");
actualSuffixLength = Byte.valueOf(strings[0]);
actualSuffixLength = Byte.parseByte(strings[0]);
actualNormalSuffix = strings[1];
formMorphInfo = Short.valueOf(strings[2]);
normalFormMorphInfo = Short.valueOf(strings[3]);
formMorphInfo = Short.parseShort(strings[2]);
normalFormMorphInfo = Short.parseShort(strings[3]);
}
public Heuristic(byte actualSuffixLength, String actualNormalSuffix, short formMorphInfo, short normalFormMorphInfo) {
@ -70,15 +71,12 @@ public class Heuristic implements Serializable {
if (actualSuffixLength != heuristic.actualSuffixLength) return false;
if (formMorphInfo != heuristic.formMorphInfo) return false;
if (normalFormMorphInfo != heuristic.normalFormMorphInfo) return false;
if (actualNormalSuffix != null ? !actualNormalSuffix.equals(heuristic.actualNormalSuffix) : heuristic.actualNormalSuffix != null)
return false;
return true;
return Objects.equals(actualNormalSuffix, heuristic.actualNormalSuffix);
}
@Override
public int hashCode() {
int result = (int) actualSuffixLength;
int result = actualSuffixLength;
result = 31 * result + (actualNormalSuffix != null ? actualNormalSuffix.hashCode() : 0);
result = 31 * result + (int) formMorphInfo;
result = 31 * result + (int) normalFormMorphInfo;

View File

@ -17,17 +17,17 @@ package org.apache.lucene.morphology;
public interface LetterDecoderEncoder {
public Integer encode(String string);
Integer encode(String string);
public int[] encodeToArray(String s);
int[] encodeToArray(String s);
public String decodeArray(int[] array);
String decodeArray(int[] array);
public String decode(Integer suffixN);
String decode(Integer suffixN);
public boolean checkCharacter(char c);
boolean checkCharacter(char c);
public boolean checkString(String word);
boolean checkString(String word);
public String cleanString(String s);
String cleanString(String s);
}

View File

@ -34,13 +34,13 @@ public class LuceneMorphology extends MorphologyImpl {
protected void readRules(BufferedReader bufferedReader) throws IOException {
String s;
Integer amount;
int amount;
s = bufferedReader.readLine();
amount = Integer.valueOf(s);
amount = Integer.parseInt(s);
rules = new Heuristic[amount][];
for (int i = 0; i < amount; i++) {
String s1 = bufferedReader.readLine();
Integer ruleLenght = Integer.valueOf(s1);
int ruleLenght = Integer.parseInt(s1);
Heuristic[] heuristics = new Heuristic[ruleLenght];
for (int j = 0; j < ruleLenght; j++) {
heuristics[j] = new Heuristic(bufferedReader.readLine());
@ -51,7 +51,7 @@ public class LuceneMorphology extends MorphologyImpl {
private Heuristic[] modeifyHeuristic(Heuristic[] heuristics) {
ArrayList<Heuristic> result = new ArrayList<Heuristic>();
ArrayList<Heuristic> result = new ArrayList<>();
for (Heuristic heuristic : heuristics) {
boolean isAdded = true;
for (Heuristic ch : result) {
@ -61,7 +61,7 @@ public class LuceneMorphology extends MorphologyImpl {
result.add(heuristic);
}
}
return result.toArray(new Heuristic[result.size()]);
return result.toArray(new Heuristic[0]);
}
public boolean checkString(String s) {

View File

@ -17,6 +17,7 @@ package org.apache.lucene.morphology;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -47,7 +48,7 @@ public class MorphologyImpl implements Morphology {
}
public List<String> getNormalForms(String s) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
int[] ints = decoderEncoder.encodeToArray(revertWord(s));
int ruleId = findRuleId(ints);
boolean notSeenEmptyString = true;
@ -64,7 +65,7 @@ public class MorphologyImpl implements Morphology {
}
public List<String> getMorphInfo(String s) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
int[] ints = decoderEncoder.encodeToArray(revertWord(s));
int ruleId = findRuleId(ints);
for (Heuristic h : rules[rulesId[ruleId]]) {
@ -100,14 +101,14 @@ public class MorphologyImpl implements Morphology {
private int compareToInts(int[] i1, int[] i2) {
int minLength = Math.min(i1.length, i2.length);
for (int i = 0; i < minLength; i++) {
int i3 = i1[i] < i2[i] ? -1 : (i1[i] == i2[i] ? 0 : 1);
int i3 = Integer.compare(i1[i], i2[i]);
if (i3 != 0) return i3;
}
return i1.length - i2.length;
}
public void writeToFile(String fileName) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8");
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8);
writer.write(separators.length + "\n");
for (int[] i : separators) {
writer.write(i.length + "\n");
@ -138,7 +139,7 @@ public class MorphologyImpl implements Morphology {
}
private void readFromInputStream(InputStream inputStream) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
String s = bufferedReader.readLine();
Integer amount = Integer.valueOf(s);
@ -153,9 +154,9 @@ public class MorphologyImpl implements Morphology {
private void readGrammaInfo(BufferedReader bufferedReader) throws IOException {
String s;
Integer amount;
int amount;
s = bufferedReader.readLine();
amount = Integer.valueOf(s);
amount = Integer.parseInt(s);
grammarInfo = new String[amount];
for (int i = 0; i < amount; i++) {
grammarInfo[i] = bufferedReader.readLine();
@ -164,13 +165,13 @@ public class MorphologyImpl implements Morphology {
protected void readRules(BufferedReader bufferedReader) throws IOException {
String s;
Integer amount;
int amount;
s = bufferedReader.readLine();
amount = Integer.valueOf(s);
amount = Integer.parseInt(s);
rules = new Heuristic[amount][];
for (int i = 0; i < amount; i++) {
String s1 = bufferedReader.readLine();
Integer ruleLength = Integer.valueOf(s1);
int ruleLength = Integer.parseInt(s1);
rules[i] = new Heuristic[ruleLength];
for (int j = 0; j < ruleLength; j++) {
rules[i][j] = new Heuristic(bufferedReader.readLine());
@ -182,7 +183,7 @@ public class MorphologyImpl implements Morphology {
rulesId = new short[amount];
for (int i = 0; i < amount; i++) {
String s1 = bufferedReader.readLine();
rulesId[i] = Short.valueOf(s1);
rulesId[i] = Short.parseShort(s1);
}
}
@ -190,10 +191,10 @@ public class MorphologyImpl implements Morphology {
separators = new int[amount][];
for (int i = 0; i < amount; i++) {
String s1 = bufferedReader.readLine();
Integer wordLenght = Integer.valueOf(s1);
int wordLenght = Integer.parseInt(s1);
separators[i] = new int[wordLenght];
for (int j = 0; j < wordLenght; j++) {
separators[i][j] = Integer.valueOf(bufferedReader.readLine());
separators[i][j] = Integer.parseInt(bufferedReader.readLine());
}
}
}

View File

@ -73,6 +73,6 @@ public class MorphologyAnalyzer extends Analyzer {
TokenFilter filter = new LowerCaseFilter(src);
filter = new MorphologyFilter(filter, luceneMorph);
return new TokenStreamComponents(r -> src.setReader(r), filter);
return new TokenStreamComponents(src::setReader, filter);
}
}