This is an automated email from the ASF dual-hosted git repository.
mcasters pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new 4aaa1e3bab Issues #6891 (Stanford Simple NLP XML cleanup) (#6892)
4aaa1e3bab is described below
commit 4aaa1e3babbde314ebbff6a4800ca65c87a4afa5
Author: Matt Casters <[email protected]>
AuthorDate: Fri Mar 27 13:19:26 2026 +0100
Issues #6891 (Stanford Simple NLP XML cleanup) (#6892)
---
.../nlp/simple/StanfordSimpleNlpDialog.java | 54 +++++-------
.../stanford/nlp/simple/StanfordSimpleNlpMeta.java | 95 ++++------------------
.../nlp/simple/StanfordSimpleNlpMetaTest.java | 26 +++---
.../src/test/resources/stanford-simple-nlp.xml | 25 ++++++
4 files changed, 69 insertions(+), 131 deletions(-)
diff --git
a/plugins/transforms/stanfordnlp/src/main/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpDialog.java
b/plugins/transforms/stanfordnlp/src/main/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpDialog.java
index 669689b894..13ba3290d5 100644
---
a/plugins/transforms/stanfordnlp/src/main/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpDialog.java
+++
b/plugins/transforms/stanfordnlp/src/main/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpDialog.java
@@ -27,20 +27,19 @@ import static org.eclipse.swt.SWT.READ_ONLY;
import static org.eclipse.swt.SWT.RIGHT;
import static org.eclipse.swt.SWT.SINGLE;
+import org.apache.hop.core.Const;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.pipeline.PipelineMeta;
-import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.ITransformDialog;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.dialog.BaseDialog;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -59,18 +58,19 @@ public class StanfordSimpleNlpDialog extends
BaseTransformDialog implements ITra
private CCombo wCorpusFieldName;
private Button wIncludePartOfSpeech;
private Button wParallelism;
- private Label wlOutputFieldNamePrefix;
- private FormData fdlOutputFieldNamePrefix, fdOutputFieldNamePrefix;
private Text wOutputFieldNamePrefix;
public StanfordSimpleNlpDialog(
Shell parent, IVariables variables, Object in, PipelineMeta
pipelineMeta, String sname) {
- super(parent, variables, (BaseTransformMeta) in, pipelineMeta, sname);
+ super(parent, variables, (StanfordSimpleNlpMeta) in, pipelineMeta, sname);
input = (StanfordSimpleNlpMeta) in;
}
@Override
public String open() {
+ FormData fdOutputFieldNamePrefix;
+ FormData fdlOutputFieldNamePrefix;
+ Label wlOutputFieldNamePrefix;
createShell(BaseMessages.getString(PKG,
"StanfordSimpleNlpDialog.Shell.Title"));
buildButtonBar().ok(e -> ok()).cancel(e -> cancel()).build();
@@ -96,19 +96,14 @@ public class StanfordSimpleNlpDialog extends
BaseTransformDialog implements ITra
fdCorpusFieldName.top = new FormAttachment(wSpacer, margin);
fdCorpusFieldName.right = new FormAttachment(100, -margin);
wCorpusFieldName.setLayoutData(fdCorpusFieldName);
- wCorpusFieldName.addFocusListener(
- new FocusListener() {
- @Override
- public void focusLost(FocusEvent e) {}
-
- @Override
- public void focusGained(FocusEvent e) {
- Cursor busy = new Cursor(shell.getDisplay(), CURSOR_WAIT);
- shell.setCursor(busy);
- get();
- shell.setCursor(null);
- busy.dispose();
- }
+ wCorpusFieldName.addListener(
+ SWT.FocusIn,
+ e -> {
+ Cursor busy = new Cursor(shell.getDisplay(), CURSOR_WAIT);
+ shell.setCursor(busy);
+ getPreviousFields();
+ shell.setCursor(null);
+ busy.dispose();
});
// OutputFieldNamePrefix field
@@ -122,7 +117,7 @@ public class StanfordSimpleNlpDialog extends
BaseTransformDialog implements ITra
fdlOutputFieldNamePrefix.top = new FormAttachment(wCorpusFieldName,
margin);
wlOutputFieldNamePrefix.setLayoutData(fdlOutputFieldNamePrefix);
wOutputFieldNamePrefix = new Text(shell, SINGLE | LEFT | BORDER);
- wOutputFieldNamePrefix.setText("" + input.getOutputFieldNamePrefix());
+ wOutputFieldNamePrefix.setText(Const.NVL(input.getOutputFieldNamePrefix(),
""));
PropsUi.setLook(wOutputFieldNamePrefix);
wOutputFieldNamePrefix.addModifyListener(lsMod);
fdOutputFieldNamePrefix = new FormData();
@@ -197,19 +192,10 @@ public class StanfordSimpleNlpDialog extends
BaseTransformDialog implements ITra
/** Copy information from the meta-data input to the dialog fields. */
public void getData() {
- if (input.getCorpusField() != null) {
- wCorpusFieldName.setText(input.getCorpusField());
- }
- if (input.isIncludePartOfSpeech()) {
- wIncludePartOfSpeech.setEnabled(input.isIncludePartOfSpeech());
- }
- if (input.isParallelism()) {
- wParallelism.setEnabled(input.isParallelism());
- }
-
- if (input.getOutputFieldNamePrefix() != null) {
- wOutputFieldNamePrefix.setText(input.getOutputFieldNamePrefix());
- }
+ wCorpusFieldName.setText(Const.NVL(input.getCorpusField(), ""));
+ wIncludePartOfSpeech.setEnabled(input.isIncludePartOfSpeech());
+ wParallelism.setEnabled(input.isParallelism());
+ wOutputFieldNamePrefix.setText(Const.NVL(input.getOutputFieldNamePrefix(),
""));
}
private void cancel() {
@@ -233,7 +219,7 @@ public class StanfordSimpleNlpDialog extends
BaseTransformDialog implements ITra
dispose();
}
- private void get() {
+ private void getPreviousFields() {
if (!gotPreviousFields) {
try {
String corpusField = null;
diff --git
a/plugins/transforms/stanfordnlp/src/main/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpMeta.java
b/plugins/transforms/stanfordnlp/src/main/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpMeta.java
index 733581a504..255e0b26b3 100644
---
a/plugins/transforms/stanfordnlp/src/main/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpMeta.java
+++
b/plugins/transforms/stanfordnlp/src/main/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpMeta.java
@@ -17,30 +17,27 @@
package org.apache.hop.pipeline.transforms.stanford.nlp.simple;
-import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
import static org.apache.hop.core.ICheckResult.TYPE_RESULT_ERROR;
import static org.apache.hop.core.ICheckResult.TYPE_RESULT_OK;
import static org.apache.hop.core.util.Utils.isEmpty;
-import static org.apache.hop.core.xml.XmlHandler.addTagValue;
-import static org.apache.hop.core.xml.XmlHandler.getTagValue;
import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.hop.core.CheckResult;
import org.apache.hop.core.ICheckResult;
import org.apache.hop.core.annotations.Transform;
-import org.apache.hop.core.exception.HopXmlException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
-import org.apache.hop.core.row.value.ValueMetaBoolean;
import org.apache.hop.core.row.value.ValueMetaInteger;
import org.apache.hop.core.row.value.ValueMetaString;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.api.HopMetadataProperty;
import org.apache.hop.metadata.api.IHopMetadataProvider;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.TransformMeta;
-import org.w3c.dom.Node;
@Transform(
id = "StanfordSimpleNlp",
@@ -49,40 +46,26 @@ import org.w3c.dom.Node;
description = "i18n::BaseTransform.TypeTooltipDesc.StanfordSimpleNlp",
categoryDescription =
"i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Transform",
documentationUrl = "/pipeline/transforms/stanfordnlp.html")
+@Getter
+@Setter
public class StanfordSimpleNlpMeta
extends BaseTransformMeta<StanfordSimpleNlp, StanfordSimpleNlpData> {
private static final Class<?> PKG = StanfordSimpleNlpMeta.class; // For
Translator
+ @HopMetadataProperty(key = "corpusField")
private String corpusField;
- private boolean includePartOfSpeech = false;
- private boolean parallelism = false;
+
+ @HopMetadataProperty(key = "includePartOfSpeech")
+ private boolean includePartOfSpeech;
+
+ @HopMetadataProperty(key = "parallelism")
+ private boolean parallelism;
+
+ @HopMetadataProperty(key = "outputFieldNamePrefix")
private String outputFieldNamePrefix = "sentence_";
public StanfordSimpleNlpMeta() {
super();
- }
-
- @Override
- public void loadXml(Node transformNode, IHopMetadataProvider
metadataProvider)
- throws HopXmlException {
- try {
- corpusField = getTagValue(transformNode, "corpusField");
- includePartOfSpeech =
- equalsIgnoreCase("Y", getTagValue(transformNode,
"includePartOfSpeech"));
- parallelism = equalsIgnoreCase("Y", getTagValue(transformNode,
"parallelism"));
-
- outputFieldNamePrefix = getTagValue(transformNode,
"outputFieldNamePrefix");
- } catch (Exception e) {
- throw new HopXmlException(
- BaseMessages.getString(PKG,
"StanfordSimpleNlpMeta.Exception.UnableToReadTransformMeta"),
- e);
- }
- }
-
- @Override
- public void setDefault() {
- includePartOfSpeech = false;
- parallelism = false;
outputFieldNamePrefix = "sentence_";
}
@@ -117,30 +100,12 @@ public class StanfordSimpleNlpMeta
r.addValueMeta(sText);
}
- private void valueMetaBoolean(IRowMeta r, String name, String metaName) {
- IValueMeta sText = new ValueMetaBoolean(metaName);
- sText.setOrigin(name);
- r.addValueMeta(sText);
- }
-
private void valueMetaInteger(IRowMeta r, String name, String metaName) {
IValueMeta sText = new ValueMetaInteger(metaName);
sText.setOrigin(name);
r.addValueMeta(sText);
}
- @Override
- public String getXml() {
- return " "
- + addTagValue("corpusField", corpusField)
- + " "
- + addTagValue("includePartOfSpeech", includePartOfSpeech)
- + " "
- + addTagValue("parallelism", parallelism)
- + " "
- + addTagValue("outputFieldNamePrefix", outputFieldNamePrefix);
- }
-
@Override
public void check(
List<ICheckResult> remarks,
@@ -191,36 +156,4 @@ public class StanfordSimpleNlpMeta
public boolean supportsErrorHandling() {
return true;
}
-
- public String getCorpusField() {
- return corpusField;
- }
-
- public void setCorpusField(String corpusField) {
- this.corpusField = corpusField;
- }
-
- public boolean isIncludePartOfSpeech() {
- return includePartOfSpeech;
- }
-
- public void setIncludePartOfSpeech(boolean includePartOfSpeech) {
- this.includePartOfSpeech = includePartOfSpeech;
- }
-
- public boolean isParallelism() {
- return parallelism;
- }
-
- public void setParallelism(boolean parallelism) {
- this.parallelism = parallelism;
- }
-
- public String getOutputFieldNamePrefix() {
- return outputFieldNamePrefix;
- }
-
- public void setOutputFieldNamePrefix(String outputFieldNamePrefix) {
- this.outputFieldNamePrefix = outputFieldNamePrefix;
- }
}
diff --git
a/plugins/transforms/stanfordnlp/src/test/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpMetaTest.java
b/plugins/transforms/stanfordnlp/src/test/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpMetaTest.java
index 3a3a382749..af0a2fce2e 100644
---
a/plugins/transforms/stanfordnlp/src/test/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpMetaTest.java
+++
b/plugins/transforms/stanfordnlp/src/test/java/org/apache/hop/pipeline/transforms/stanford/nlp/simple/StanfordSimpleNlpMetaTest.java
@@ -17,25 +17,19 @@
package org.apache.hop.pipeline.transforms.stanford.nlp.simple;
-import java.util.Arrays;
-import java.util.List;
-import org.apache.hop.core.exception.HopException;
-import org.apache.hop.junit.rules.RestoreHopEngineEnvironmentExtension;
-import org.apache.hop.pipeline.transforms.loadsave.LoadSaveTester;
+import org.apache.hop.pipeline.transform.TransformSerializationTestUtil;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
class StanfordSimpleNlpMetaTest {
- @RegisterExtension
- static RestoreHopEngineEnvironmentExtension env = new
RestoreHopEngineEnvironmentExtension();
-
@Test
- void testLoadSave() throws HopException {
- List<String> attributes = Arrays.asList("CorpusField",
"IncludePartOfSpeech");
-
- LoadSaveTester<StanfordSimpleNlpMeta> loadSaveTester =
- new LoadSaveTester<>(StanfordSimpleNlpMeta.class, attributes);
-
- loadSaveTester.testSerialization();
+ void testSerializationRoundTrip() throws Exception {
+ StanfordSimpleNlpMeta meta =
+ TransformSerializationTestUtil.testSerialization(
+ "/stanford-simple-nlp.xml", StanfordSimpleNlpMeta.class);
+ Assertions.assertEquals("corpusField", meta.getCorpusField());
+ Assertions.assertTrue(meta.isIncludePartOfSpeech());
+ Assertions.assertTrue(meta.isParallelism());
+ Assertions.assertEquals("sentence_", meta.getOutputFieldNamePrefix());
}
}
diff --git
a/plugins/transforms/stanfordnlp/src/test/resources/stanford-simple-nlp.xml
b/plugins/transforms/stanfordnlp/src/test/resources/stanford-simple-nlp.xml
new file mode 100644
index 0000000000..cc65960474
--- /dev/null
+++ b/plugins/transforms/stanfordnlp/src/test/resources/stanford-simple-nlp.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~
+ -->
+
+<transform>
+ <corpusField>corpusField</corpusField>
+ <includePartOfSpeech>Y</includePartOfSpeech>
+ <parallelism>Y</parallelism>
+ <outputFieldNamePrefix>sentence_</outputFieldNamePrefix>
+</transform>