From 2bffaf01442346709b5f68abb1381aa1e9381aaa Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Wed, 20 Nov 2024 21:04:02 +0900 Subject: [PATCH 1/3] refactor: store segmeter of the current project in the RealProject object - Add getSegmenter/setSegmenter to IProject - Update Core.getSegmenter/setSegmenter to use currentProject.getSegmenter/setSegmenter Signed-off-by: Hiroshi Miura --- src/org/omegat/core/Core.java | 6 +-- .../omegat/core/data/ExternalTMFactory.java | 12 ++--- src/org/omegat/core/data/IProject.java | 17 +++++- .../omegat/core/data/NotLoadedProject.java | 13 +++++ src/org/omegat/core/data/RealProject.java | 54 +++++++++++-------- .../omegat/core/statistics/FindMatches.java | 3 +- .../omegat/gui/main/ProjectUICommands.java | 2 - .../omegat/core/data/TmxComplianceBase.java | 8 +-- .../statistics/CalcMatchStatisticsTest.java | 2 +- .../core/statistics/FindMatchesTest.java | 2 +- 10 files changed, 74 insertions(+), 45 deletions(-) diff --git a/src/org/omegat/core/Core.java b/src/org/omegat/core/Core.java index e3ef6bc5d7..4ddbf0d542 100644 --- a/src/org/omegat/core/Core.java +++ b/src/org/omegat/core/Core.java @@ -118,7 +118,6 @@ private Core() { private static MultipleTransPane multiple; private static INotes notes; private static IComments comments; - private static Segmenter segmenter; private static Map cmdLineParams = Collections.emptyMap(); @@ -215,11 +214,11 @@ public static IDictionaries getDictionaries() { } public static Segmenter getSegmenter() { - return segmenter; + return currentProject.getSegmenter(); } public static void setSegmenter(Segmenter newSegmenter) { - segmenter = newSegmenter; + currentProject.setSegmenter(newSegmenter); } /** @@ -268,7 +267,6 @@ static void initializeGUIimpl(IMainWindow me) throws Exception { MarkerController.init(); LanguageToolWrapper.init(); - segmenter = new Segmenter(Preferences.getSRX()); filterMaster = new FilterMaster(Preferences.getFilters()); // 4. Initialize other components. They add themselves to the main window. diff --git a/src/org/omegat/core/data/ExternalTMFactory.java b/src/org/omegat/core/data/ExternalTMFactory.java index fc75eecbb9..a321111909 100644 --- a/src/org/omegat/core/data/ExternalTMFactory.java +++ b/src/org/omegat/core/data/ExternalTMFactory.java @@ -63,12 +63,10 @@ public static boolean isSupported(File file) { } public static ExternalTMX load(File file) throws Exception { - return load(file, Core.getProject().getProjectProperties(), Core.getSegmenter(), - Core.getFilterMaster()); + return load(file, Core.getProject().getProjectProperties(), Core.getSegmenter()); } - public static ExternalTMX load(File file, ProjectProperties props, Segmenter segmenter, - FilterMaster filterMaster) throws Exception { + public static ExternalTMX load(File file, ProjectProperties props, Segmenter segmenter) throws Exception { if (TMXLoader.isSupported(file)) { return new TMXLoader(file, segmenter) .setExtTmxLevel2(Preferences.isPreference(Preferences.EXT_TMX_SHOW_LEVEL2)) @@ -76,9 +74,9 @@ public static ExternalTMX load(File file, ProjectProperties props, Segmenter seg .setDoSegmenting(props.isSentenceSegmentingEnabled()) .setKeepForeignMatches(Preferences.isPreference(Preferences.EXT_TMX_KEEP_FOREIGN_MATCH)) .load(props.getSourceLanguage(), props.getTargetLanguage()); - } else if (BifileLoader.isSupported(file, filterMaster)) { - return new BifileLoader(file, segmenter, filterMaster).setRemoveTags(props.isRemoveTags()) - .setRemoveSpaces(filterMaster.getConfig().isRemoveSpacesNonseg()) + } else if (BifileLoader.isSupported(file, Core.getFilterMaster())) { + return new BifileLoader(file, segmenter, Core.getFilterMaster()).setRemoveTags(props.isRemoveTags()) + .setRemoveSpaces(Core.getFilterMaster().getConfig().isRemoveSpacesNonseg()) .setDoSegmenting(props.isSentenceSegmentingEnabled()) .load(props.getSourceLanguage(), props.getTargetLanguage()); } else { diff --git a/src/org/omegat/core/data/IProject.java b/src/org/omegat/core/data/IProject.java index b09829a585..2c20656621 100644 --- a/src/org/omegat/core/data/IProject.java +++ b/src/org/omegat/core/data/IProject.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; +import org.omegat.core.segmentation.Segmenter; import org.omegat.core.statistics.StatisticsInfo; import org.omegat.tokenizer.ITokenizer; import org.omegat.util.Language; @@ -283,11 +284,11 @@ class FileInfo { public List entries = new ArrayList(); } - public interface DefaultTranslationsIterator { + interface DefaultTranslationsIterator { void iterate(String source, TMXEntry trans); } - public interface MultipleTranslationsIterator { + interface MultipleTranslationsIterator { void iterate(EntryKey source, TMXEntry trans); } @@ -341,4 +342,16 @@ public AllTranslations getPrevious() { return previous; } } + + /** + * Set new segmenter for the current project. + * @param segmenter new segmenter. + */ + void setSegmenter(Segmenter segmenter); + + /** + * Get segmenter for the current project. + * @return segmenter currently used. + */ + Segmenter getSegmenter(); } diff --git a/src/org/omegat/core/data/NotLoadedProject.java b/src/org/omegat/core/data/NotLoadedProject.java index e15d86e29d..5abc9ecccd 100644 --- a/src/org/omegat/core/data/NotLoadedProject.java +++ b/src/org/omegat/core/data/NotLoadedProject.java @@ -31,10 +31,12 @@ import java.util.Map; import org.omegat.core.data.TMXEntry.ExternalLinked; +import org.omegat.core.segmentation.Segmenter; import org.omegat.core.statistics.StatisticsInfo; import org.omegat.filters2.TranslationException; import org.omegat.tokenizer.ITokenizer; import org.omegat.util.Language; +import org.omegat.util.Preferences; /** * Project implementation when project not really loaded. @@ -51,6 +53,8 @@ public class NotLoadedProject implements IProject { EMPTY_TRANSLATION = new TMXEntry(empty, true, null); } + protected Segmenter segmenter = new Segmenter(Preferences.getSRX()); + @Override public void compileProject(String sourcePattern) throws IOException, TranslationException { } @@ -172,6 +176,15 @@ public List getSourceFilesOrder() { public void setSourceFilesOrder(List filesList) { } + @Override + public void setSegmenter(final Segmenter segmenter) { + } + + @Override + public Segmenter getSegmenter() { + return segmenter; + } + @Override public String getTargetPathForSourceFile(String sourceFile) { return null; diff --git a/src/org/omegat/core/data/RealProject.java b/src/org/omegat/core/data/RealProject.java index 9ff304d31e..d32397a6ea 100644 --- a/src/org/omegat/core/data/RealProject.java +++ b/src/org/omegat/core/data/RealProject.java @@ -15,6 +15,7 @@ 2018 Enrique Estevez Fernandez 2019 Thomas Cordonnier 2020 Briac Pilpre + 2024 Hiroshi Miura Home page: https://www.omegat.org/ Support center: https://omegat.org/support @@ -166,12 +167,15 @@ enum PreparedStatus { private final StatisticsInfo hotStat = new StatisticsInfo(); - private final ITokenizer sourceTokenizer, targetTokenizer; + private final ITokenizer sourceTokenizer; + private final ITokenizer targetTokenizer; private DirectoryMonitor tmMonitor; private DirectoryMonitor tmOtherLanguagesMonitor; + private Segmenter segmenter; + /** * Indicates when there is an ongoing save event. Saving might take a while * during team sync: if a merge is required the save might be postponed @@ -302,7 +306,7 @@ public void createProject() { // Set project specific segmentation rules if they exist, or // defaults otherwise. SRX srx = config.getProjectSRX(); - Core.setSegmenter(new Segmenter(srx == null ? Preferences.getSRX() : srx)); + segmenter = new Segmenter(srx == null ? Preferences.getSRX() : srx); loadTranslations(); setProjectModified(true); @@ -475,12 +479,12 @@ private void loadFilterSettings() { * options */ private void loadSegmentationSettings() { - // Set project specific segmentation rules if they exist, or defaults + // Set project-specific segmentation rules if they exist, or defaults // otherwise. // This MUST happen before calling loadTranslations(), because // projectTMX needs a segmenter. SRX srx = Optional.ofNullable(config.getProjectSRX()).orElse(Preferences.getSRX()); - Core.setSegmenter(new Segmenter(srx)); + segmenter = new Segmenter(srx); } /** @@ -493,7 +497,7 @@ public Map align(final ProjectProperties props, final File File root = new File(config.getSourceRoot()); List srcFileList = FileUtil.buildFileList(root, true); - AlignFilesCallback alignFilesCallback = new AlignFilesCallback(props); + AlignFilesCallback alignFilesCallback = new AlignFilesCallback(props, segmenter); String srcRoot = config.getSourceRoot(); for (File file : srcFileList) { @@ -1238,7 +1242,6 @@ private void loadTranslations() throws Exception { */ private void loadSourceFiles() throws IOException { long st = System.currentTimeMillis(); - FilterMaster fm = Core.getFilterMaster(); File root = new File(config.getSourceRoot()); List srcPathList = FileUtil @@ -1259,7 +1262,8 @@ private void loadSourceFiles() throws IOException { try { loadFilesCallback.setCurrentFile(fi); - IFilter filter = fm.loadFile(config.getSourceRoot() + filepath, new FilterContext(config), + IFilter filter = Core.getFilterMaster().loadFile(config.getSourceRoot() + filepath, + new FilterContext(config), loadFilesCallback); loadFilesCallback.fileFinished(); @@ -1410,7 +1414,7 @@ private void loadTM() { newTransMemories.putAll(transMemories); if (file.exists()) { try { - ExternalTMX newTMX = ExternalTMFactory.load(file); + ExternalTMX newTMX = ExternalTMFactory.load(file, config, segmenter); newTransMemories.put(file.getPath(), newTMX); // Please note the use of "/". FileUtil.computeRelativePath @@ -1716,16 +1720,12 @@ public Map getOtherTargetLanguageTMs() { return Collections.unmodifiableMap(otherTargetLangTMs); } - /** - * {@inheritDoc} - */ + @Override public ITokenizer getSourceTokenizer() { return sourceTokenizer; } - /** - * {@inheritDoc} - */ + @Override public ITokenizer getTargetTokenizer() { return targetTokenizer; } @@ -1763,9 +1763,7 @@ protected ITokenizer createTokenizer(String cmdLine, Class projectPref) { return new DefaultTokenizer(); } - /** - * {@inheritDoc} - */ + @Override public List getProjectFiles() { return Collections.unmodifiableList(projectFilesList); } @@ -1876,9 +1874,7 @@ public void fileFinished() { tmBuilder = null; } - /** - * {@inheritDoc} - */ + @Override protected void addSegment(String id, short segmentIndex, String segmentSource, List protectedParts, String segmentTranslation, boolean segmentTranslationFuzzy, String[] props, String prevSegment, String nextSegment, @@ -1951,13 +1947,15 @@ protected String getSegmentTranslation(String id, int segmentIndex, String segme } static class AlignFilesCallback implements IAlignCallback { - AlignFilesCallback(ProjectProperties props) { + AlignFilesCallback(ProjectProperties props, Segmenter segmenter) { super(); this.config = props; + this.segmenter = segmenter; } Map data = new TreeMap<>(); private final ProjectProperties config; + private final Segmenter segmenter; List sources = new ArrayList<>(); @Override @@ -1978,9 +1976,9 @@ public void addTranslation(String id, String source, String translation, boolean PrepareTMXEntry tr = new PrepareTMXEntry(); if (config.isSentenceSegmentingEnabled()) { - List segmentsSource = Core.getSegmenter().segment(config.getSourceLanguage(), + List segmentsSource = segmenter.segment(config.getSourceLanguage(), sourceS, null, null); - List segmentsTranslation = Core.getSegmenter().segment(config.getTargetLanguage(), + List segmentsTranslation = segmenter.segment(config.getTargetLanguage(), transS, null, null); if (segmentsTranslation.size() != segmentsSource.size()) { if (isFuzzy) { @@ -2064,4 +2062,14 @@ public void commitSourceFiles() throws Exception { } } } + + @Override + public void setSegmenter(Segmenter segmenter) { + this.segmenter = segmenter; + } + + @Override + public Segmenter getSegmenter() { + return segmenter; + } } diff --git a/src/org/omegat/core/statistics/FindMatches.java b/src/org/omegat/core/statistics/FindMatches.java index e6cbfcedd9..0bfca124a6 100644 --- a/src/org/omegat/core/statistics/FindMatches.java +++ b/src/org/omegat/core/statistics/FindMatches.java @@ -38,7 +38,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.omegat.core.Core; import org.omegat.core.data.EntryKey; import org.omegat.core.data.ExternalTMFactory; import org.omegat.core.data.ExternalTMX; @@ -145,7 +144,7 @@ public class FindMatches { */ public FindMatches(IProject project, int maxCount, boolean allowSeparateSegmentMatch, boolean searchExactlyTheSame) { - this(project, Core.getSegmenter(), maxCount, allowSeparateSegmentMatch, searchExactlyTheSame, true, + this(project, project.getSegmenter(), maxCount, allowSeparateSegmentMatch, searchExactlyTheSame, true, Preferences.getPreferenceDefault(Preferences.EXT_TMX_FUZZY_MATCH_THRESHOLD, OConsts.FUZZY_MATCH_THRESHOLD)); } diff --git a/src/org/omegat/gui/main/ProjectUICommands.java b/src/org/omegat/gui/main/ProjectUICommands.java index bf86afcaaa..a68312d144 100644 --- a/src/org/omegat/gui/main/ProjectUICommands.java +++ b/src/org/omegat/gui/main/ProjectUICommands.java @@ -61,7 +61,6 @@ import org.omegat.core.data.ProjectProperties; import org.omegat.core.events.IProjectEventListener; import org.omegat.core.segmentation.SRX; -import org.omegat.core.segmentation.Segmenter; import org.omegat.core.spellchecker.ISpellChecker; import org.omegat.core.tagvalidation.ErrorReport; import org.omegat.core.team2.IRemoteRepository2; @@ -835,7 +834,6 @@ protected void done() { // Restore global prefs in case project had project-specific // ones Core.setFilterMaster(new FilterMaster(Preferences.getFilters())); - Core.setSegmenter(new Segmenter(Preferences.getSRX())); } }.execute(); } diff --git a/test/src/org/omegat/core/data/TmxComplianceBase.java b/test/src/org/omegat/core/data/TmxComplianceBase.java index 6fa2312e7d..1cac71dd5a 100644 --- a/test/src/org/omegat/core/data/TmxComplianceBase.java +++ b/test/src/org/omegat/core/data/TmxComplianceBase.java @@ -46,6 +46,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestName; + import org.omegat.core.Core; import org.omegat.core.segmentation.SRX; import org.omegat.core.segmentation.Segmenter; @@ -67,6 +68,7 @@ public abstract class TmxComplianceBase { static final Pattern RE_SEG = Pattern.compile("(.+)"); protected File outFile; + protected Segmenter segmenter; @Rule public TestName name = new TestName(); @@ -74,7 +76,7 @@ public abstract class TmxComplianceBase { @Before public final void setUp() throws Exception { Core.setFilterMaster(new FilterMaster(FilterMaster.createDefaultFiltersConfig())); - Core.setSegmenter(new Segmenter(SRX.getDefault())); + segmenter = new Segmenter(SRX.getDefault()); TestPreferencesInitializer.init(); outFile = new File("build/testdata/" + getClass().getSimpleName() + "-" + name.getMethodName() + ".out"); @@ -179,7 +181,7 @@ public void addEntry(String id, String source, String translation, boolean isFuz @Override public void addEntryWithProperties(String id, String source, String translation, boolean isFuzzy, String[] props, String path, IFilter filter, List protectedParts) { - result.addAll(Core.getSegmenter().segment(context.getSourceLang(), source, null, null)); + result.addAll(segmenter.segment(context.getSourceLang(), source, null, null)); } public void linkPrevNextSegments() { @@ -197,7 +199,7 @@ protected void align(IFilter filter, File sourceFile, String inCharset, File tra fc.setInEncoding(inCharset); fc.setOutEncoding(outCharset); - RealProject.AlignFilesCallback callback = new RealProject.AlignFilesCallback(props); + RealProject.AlignFilesCallback callback = new RealProject.AlignFilesCallback(props, segmenter); filter.alignFile(sourceFile, translatedFile, null, fc, callback); diff --git a/test/src/org/omegat/core/statistics/CalcMatchStatisticsTest.java b/test/src/org/omegat/core/statistics/CalcMatchStatisticsTest.java index 5da4dd3ffc..7b2755b804 100644 --- a/test/src/org/omegat/core/statistics/CalcMatchStatisticsTest.java +++ b/test/src/org/omegat/core/statistics/CalcMatchStatisticsTest.java @@ -294,7 +294,7 @@ public Map getTransMemories() { try { ExternalTMX newTMX; Path testTmx = Paths.get("test/data/tmx/test-match-stat-en-ca.tmx"); - newTMX = ExternalTMFactory.load(testTmx.toFile(), prop, segmenter, null); + newTMX = ExternalTMFactory.load(testTmx.toFile(), prop, segmenter); transMemories.put(testTmx.toString(), newTMX); } catch (Exception e) { throw new RuntimeException(e); diff --git a/test/src/org/omegat/core/statistics/FindMatchesTest.java b/test/src/org/omegat/core/statistics/FindMatchesTest.java index 46c1349c8c..c22d99ef7e 100644 --- a/test/src/org/omegat/core/statistics/FindMatchesTest.java +++ b/test/src/org/omegat/core/statistics/FindMatchesTest.java @@ -350,7 +350,7 @@ public Map getTransMemories() { Map transMemories = new TreeMap<>(); try { - ExternalTMX newTMX = ExternalTMFactory.load(externalTmx, prop, segmenter, null); + ExternalTMX newTMX = ExternalTMFactory.load(externalTmx, prop, segmenter); transMemories.put(externalTmx.getPath(), newTMX); } catch (Exception ignored) { } From 2dd73150dadaffff6fc90be6b45d4adc89f5d95e Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Thu, 21 Nov 2024 09:33:09 +0900 Subject: [PATCH 2/3] refactor: Aligner to have its own segmenter - Allow Aligner to have segmenter object without depending Core.getSegmenter() - Aligner should works without loading project, so it should have its own object - Aligner also have a feature to call SegmentationCustomizer, so when user customize the segmenter, Aligner uses new one. - SegmentetionCustomizer saves customized SRX as user preference and store it in the project, so Aligner do not need to call Core.setSegmenter() Signed-off-by: Hiroshi Miura --- .../gui/align/AlignPanelController.java | 4 +-- .../java/org/omegat/gui/align/Aligner.java | 25 ++++++++++++++----- .../org/omegat/gui/align/AlignerTest.java | 4 +-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/aligner/src/main/java/org/omegat/gui/align/AlignPanelController.java b/aligner/src/main/java/org/omegat/gui/align/AlignPanelController.java index d5d3404c35..0055e93a22 100644 --- a/aligner/src/main/java/org/omegat/gui/align/AlignPanelController.java +++ b/aligner/src/main/java/org/omegat/gui/align/AlignPanelController.java @@ -279,10 +279,10 @@ public void windowClosing(WindowEvent e) { ActionListener segmentingRulesListener = e -> { if (confirmReset(alignMenuFrame)) { SegmentationCustomizer customizer = new SegmentationCustomizer(false, SRX.getDefault(), - Core.getSegmenter().getSRX(), null); + aligner.getSegmenter().getSRX(), null); if (customizer.show(alignMenuFrame)) { customizedSRX = customizer.getResult(); - Core.setSegmenter(new Segmenter(customizedSRX)); + aligner.setSegmenter(new Segmenter(customizedSRX)); reloadBeads(); } } diff --git a/aligner/src/main/java/org/omegat/gui/align/Aligner.java b/aligner/src/main/java/org/omegat/gui/align/Aligner.java index 7d6c516a7c..57e5b7c2f0 100644 --- a/aligner/src/main/java/org/omegat/gui/align/Aligner.java +++ b/aligner/src/main/java/org/omegat/gui/align/Aligner.java @@ -61,6 +61,8 @@ import org.omegat.core.data.ParseEntry; import org.omegat.core.data.ParseEntry.ParseEntryResult; import org.omegat.core.data.ProtectedPart; +import org.omegat.core.segmentation.SRX; +import org.omegat.core.segmentation.Segmenter; import org.omegat.filters2.FilterContext; import org.omegat.filters2.IFilter; import org.omegat.filters2.IParseCallback; @@ -157,6 +159,7 @@ enum CounterType { private List trgRaw; private List> idPairs; List allowedModes; + private Segmenter segmenter; public Aligner(String srcFile, Language srcLang, String trgFile, Language trgLang) { this.srcFile = srcFile; @@ -229,6 +232,15 @@ void restoreDefaults() { } else { counterType = CounterType.WORD; } + segmenter = new Segmenter(SRX.getDefault()); + } + + void setSegmenter(Segmenter segmenter) { + this.segmenter = segmenter; + } + + Segmenter getSegmenter() { + return segmenter; } /** @@ -299,7 +311,7 @@ private void process(String text, String id) { * @return Flattened list of segments */ private List segmentAll(Language language, List rawTexts) { - return rawTexts.stream().flatMap(text -> Core.getSegmenter().segment(language, text, null, null).stream()) + return rawTexts.stream().flatMap(text -> segmenter.segment(language, text, null, null).stream()) .filter(s -> !s.isEmpty()).collect(Collectors.toList()); } @@ -330,9 +342,9 @@ private Stream alignParsewiseSegmented() { throw new UnsupportedOperationException(); } return IntStream.range(0, srcRaw.size()).mapToObj(i -> { - List source = Core.getSegmenter().segment(srcLang, srcRaw.get(i), null, null).stream() + List source = segmenter.segment(srcLang, srcRaw.get(i), null, null).stream() .filter(s -> !s.isEmpty()).collect(Collectors.toList()); - List target = Core.getSegmenter().segment(trgLang, trgRaw.get(i), null, null).stream() + List target = segmenter.segment(trgLang, trgRaw.get(i), null, null).stream() .filter(s -> !s.isEmpty()).collect(Collectors.toList()); return doAlign(algorithmClass, calculatorType, counterType, source, target); }).flatMap(List::stream); @@ -349,7 +361,8 @@ private Stream alignByIdNotSegmented() { throw new UnsupportedOperationException(); } return idPairs.stream() - .map(e -> new Alignment(Arrays.asList(e.getKey()), Arrays.asList(e.getValue()))); + .map(e -> new Alignment(Collections.singletonList(e.getKey()), + Collections.singletonList(e.getValue()))); } /** @@ -363,9 +376,9 @@ private Stream alignByIdSegmented() { throw new UnsupportedOperationException(); } return idPairs.stream().map(e -> { - List source = Core.getSegmenter().segment(srcLang, e.getKey(), null, null).stream() + List source = segmenter.segment(srcLang, e.getKey(), null, null).stream() .filter(s -> !s.isEmpty()).collect(Collectors.toList()); - List target = Core.getSegmenter().segment(trgLang, e.getValue(), null, null).stream() + List target = segmenter.segment(trgLang, e.getValue(), null, null).stream() .filter(s -> !s.isEmpty()).collect(Collectors.toList()); return doAlign(algorithmClass, calculatorType, counterType, source, target); }).flatMap(List::stream); diff --git a/aligner/src/test/java/org/omegat/gui/align/AlignerTest.java b/aligner/src/test/java/org/omegat/gui/align/AlignerTest.java index cbac49503f..e251bcb34f 100644 --- a/aligner/src/test/java/org/omegat/gui/align/AlignerTest.java +++ b/aligner/src/test/java/org/omegat/gui/align/AlignerTest.java @@ -37,9 +37,8 @@ import org.junit.Before; import org.junit.Test; + import org.omegat.core.Core; -import org.omegat.core.segmentation.SRX; -import org.omegat.core.segmentation.Segmenter; import org.omegat.filters2.master.FilterMaster; import org.omegat.filters2.text.TextFilter; import org.omegat.filters2.text.bundles.ResourceBundleFilter; @@ -52,7 +51,6 @@ public class AlignerTest { public final void setUp() { FilterMaster.setFilterClasses(Arrays.asList(TextFilter.class, ResourceBundleFilter.class)); Core.setFilterMaster(new FilterMaster(FilterMaster.createDefaultFiltersConfig())); - Core.setSegmenter(new Segmenter(SRX.getDefault())); assertTrue(Core.getFilterMaster().isFileSupported(new File("blah.txt"), true)); assertTrue(Core.getFilterMaster().isFileSupported(new File("blah.properties"), true)); } From d252a31788530f1e9ffeb8231e93f2560db2fe8c Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Mon, 25 Nov 2024 10:23:24 +0900 Subject: [PATCH 3/3] fix: avoid NPE when calling getSegmenter before provisioning current project Signed-off-by: Hiroshi Miura --- src/org/omegat/core/Core.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/org/omegat/core/Core.java b/src/org/omegat/core/Core.java index 4ddbf0d542..3d3e8025a7 100644 --- a/src/org/omegat/core/Core.java +++ b/src/org/omegat/core/Core.java @@ -98,6 +98,10 @@ public final class Core { private Core() { } + static { + currentProject = new NotLoadedProject(); + } + private static IProject currentProject; private static IMainWindow mainWindow; protected static IEditor editor;