You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2023/12/29 11:55:09 UTC
(opennlp-sandbox) branch master updated: Updates Apache Derby to version 10.17.1.0 (#114)
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/opennlp-sandbox.git
The following commit(s) were added to refs/heads/master by this push:
new d7ccf20 Updates Apache Derby to version 10.17.1.0 (#114)
d7ccf20 is described below
commit d7ccf207151b88498a51a87d492b8c9036383289
Author: Martin Wiesner <ma...@users.noreply.github.com>
AuthorDate: Fri Dec 29 12:55:01 2023 +0100
Updates Apache Derby to version 10.17.1.0 (#114)
- Release Notes see: https://svn.apache.org/repos/asf/db/derby/code/branches/10.17/RELEASE-NOTES.html
- adjusts required Java version to 21, as Derby "10.17 does NOT support Java releases prior to Java SE 21"
- updates forbiddenapis plugin version to 3.6 to handle jdk-21 compiled classes correctly
- updates jersey to version 2.41 (see: https://github.com/eclipse-ee4j/jersey/wiki/Road-Map)
- switches use of the deprecated URL constructor as advised by JDK javadoc towards URI(..).toURL()
---
.github/workflows/maven.yml | 10 +-
.../org/apache/opennlp/caseditor/ModelUtil.java | 7 +-
.../caseditor/namefinder/MultiModelNameFinder.java | 3 +-
.../caseditor/sentdetect/SentenceDetectorJob.java | 3 +-
.../opennlp/caseditor/tokenize/TokenizerJob.java | 3 +-
corpus-server/corpus-server-impl/feature.xml | 3 +-
corpus-server/corpus-server-impl/pom.xml | 11 +-
corpus-server/pom.xml | 5 +-
.../tools/cmdline/coref/CoreferencerTool.java | 2 +-
.../review_builder/MachineTranslationWrapper.java | 8 +-
...cClassifierTrainingSetMultilingualExtender.java | 6 +-
.../tools/parse_thicket/VerbNetProcessor.java | 44 ++------
.../apps/WebSearchEngineResultsScraper.java | 41 +++----
.../tools/similarity/apps/solr/Comment.java | 121 ++++++++++-----------
.../apps/solr/NLProgram2CodeRequestHandler.java | 3 +-
.../tools/similarity/apps/solr/WordDocBuilder.java | 10 +-
.../tools/similarity/apps/utils/PageFetcher.java | 56 ++++------
pom.xml | 19 ++--
18 files changed, 156 insertions(+), 199 deletions(-)
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index ec65c3b..976fda9 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -25,12 +25,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
- java: [ 17, 21 ]
+ java: [ 21 ]
experimental: [false]
-# include:
-# - java: 18-ea
-# os: ubuntu-latest
-# experimental: true
+ include:
+ - java: 22-ea
+ os: ubuntu-latest
+ experimental: true
steps:
- uses: actions/checkout@v3
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/ModelUtil.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/ModelUtil.java
index 59aedbb..8b3a5be 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/ModelUtil.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/ModelUtil.java
@@ -19,6 +19,8 @@ package org.apache.opennlp.caseditor;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.core.resources.IFile;
@@ -33,12 +35,11 @@ public class ModelUtil {
// used to detect an updated model, if model is updated,
// load it and replace the old one!
- public static InputStream openModelIn(String modelPath) throws IOException {
+ public static InputStream openModelIn(String modelPath) throws IOException, URISyntaxException {
InputStream modelIn = null;
if (modelPath.startsWith("http://") || modelPath.startsWith("file://")) {
- URL modelURL = new URL(modelPath);
-
+ URL modelURL = new URI(modelPath).toURL();
modelIn = modelURL.openStream();
}
else {
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java
index ff44d9f..bf46789 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java
@@ -19,6 +19,7 @@ package org.apache.opennlp.caseditor.namefinder;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -109,7 +110,7 @@ public class MultiModelNameFinder implements TokenNameFinder {
sequenceValidators[i] = new RestrictedSequencesValidator(modelTypes[i]);
nameFinders[i] = new NameFinderME(model);
}
- catch (IOException e) {
+ catch (IOException | URISyntaxException e) {
// Error message should include model type
throw new IOException("Failed to load a model, path:\n" + modelPathes[i] +
"\nError Message:\n" + e.getMessage());
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorJob.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorJob.java
index 04197b9..b52de98 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorJob.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorJob.java
@@ -19,6 +19,7 @@ package org.apache.opennlp.caseditor.sentdetect;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -86,7 +87,7 @@ public class SentenceDetectorJob extends Job {
try (InputStream modelIn = ModelUtil.openModelIn(modelPath)) {
SentenceModel model = new SentenceModel(modelIn);
sentenceDetector = new SentenceDetectorME(model);
- } catch (IOException e1) {
+ } catch (IOException | URISyntaxException e1) {
return new Status(IStatus.CANCEL, OpenNLPPlugin.ID, "Failed to load sentence detector model!");
}
}
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerJob.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerJob.java
index e8d1119..a61a45e 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerJob.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerJob.java
@@ -19,6 +19,7 @@ package org.apache.opennlp.caseditor.tokenize;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URISyntaxException;
import org.apache.opennlp.caseditor.ModelUtil;
import org.apache.opennlp.caseditor.OpenNLPPlugin;
@@ -76,7 +77,7 @@ public class TokenizerJob extends Job {
try (InputStream modelIn = ModelUtil.openModelIn(modelPath)) {
TokenizerModel model = new TokenizerModel(modelIn);
tokenizer = new TokenizerME(model);
- } catch (IOException e1) {
+ } catch (IOException | URISyntaxException e1) {
return new Status(IStatus.CANCEL, OpenNLPPlugin.ID, "Failed to load tokenizer model!");
}
}
diff --git a/corpus-server/corpus-server-impl/feature.xml b/corpus-server/corpus-server-impl/feature.xml
index 6406d39..c2139a5 100644
--- a/corpus-server/corpus-server-impl/feature.xml
+++ b/corpus-server/corpus-server-impl/feature.xml
@@ -22,7 +22,8 @@
<features>
<!-- This feature.xml should be automatically be generated, all dependencies are duplicated here! -->
<feature name="opennlp-corpus-server-impl" version="0.0.1.SNAPSHOT">
- <bundle>mvn:org.apache.derby/derby/10.14.2.0</bundle>
+ <bundle>mvn:org.apache.derby/derby/10.17.1.0</bundle>
+ <bundle>mvn:org.apache.derby/derbytools/10.17.1.0</bundle>
<bundle>mvn:org.apache.opennlp/corpus-server-impl/2.3.2-SNAPSHOT</bundle>
</feature>
</features>
\ No newline at end of file
diff --git a/corpus-server/corpus-server-impl/pom.xml b/corpus-server/corpus-server-impl/pom.xml
index d1b1052..bf38e6e 100644
--- a/corpus-server/corpus-server-impl/pom.xml
+++ b/corpus-server/corpus-server-impl/pom.xml
@@ -51,10 +51,17 @@
<artifactId>org.osgi.compendium</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>${derby.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- <version>10.14.2.0</version>
+ <artifactId>derbytools</artifactId>
+ <version>${derby.version}</version>
<scope>provided</scope>
</dependency>
diff --git a/corpus-server/pom.xml b/corpus-server/pom.xml
index 9282f69..cd21464 100644
--- a/corpus-server/pom.xml
+++ b/corpus-server/pom.xml
@@ -41,7 +41,10 @@
</modules>
<properties>
- <derby.version>10.14.2.0</derby.version>
+ <derby.version>10.17.1.0</derby.version>
+ <!-- A minimum JDK version of 21 is required for modern Derby versions -->
+ <maven.compiler.source>21</maven.compiler.source>
+ <maven.compiler.target>21</maven.compiler.target>
</properties>
<dependencyManagement>
diff --git a/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/CoreferencerTool.java b/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/CoreferencerTool.java
index dbd8dcc..fffaeb9 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/CoreferencerTool.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/CoreferencerTool.java
@@ -34,10 +34,10 @@ import opennlp.tools.cmdline.SystemInputStreamFactory;
import opennlp.tools.cmdline.TerminateToolException;
import opennlp.tools.coref.DiscourseEntity;
import opennlp.tools.coref.LinkerMode;
+import opennlp.tools.coref.TreebankLinker;
import opennlp.tools.coref.mention.DefaultParse;
import opennlp.tools.coref.mention.Mention;
import opennlp.tools.coref.mention.MentionContext;
-import opennlp.tools.lang.english.TreebankLinker;
import opennlp.tools.parser.Parse;
import opennlp.tools.parser.chunking.Parser;
import opennlp.tools.util.ObjectStream;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/MachineTranslationWrapper.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/MachineTranslationWrapper.java
index a27361a..2db4f12 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/MachineTranslationWrapper.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/MachineTranslationWrapper.java
@@ -20,6 +20,8 @@ package opennlp.tools.apps.review_builder;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
@@ -31,12 +33,12 @@ import org.json.JSONObject;
public class MachineTranslationWrapper {
private static final String TRANSLATOR_URL = "http://mymemory.translated.net/api/get?q=";
- public String translate(String sentence, String lang2lang){
+ public String translate(String sentence, String lang2lang) {
if (sentence==null)
return null;
String request = TRANSLATOR_URL + sentence.replace(' ','+') + "&langpair="+lang2lang;//"en|es";
try {
- URL urlC = new URL(request);
+ URL urlC = new URI(request).toURL();
URLConnection connection = urlC.openConnection();
String line;
@@ -53,7 +55,7 @@ public class MachineTranslationWrapper {
String transl = findObject.getString("translatedText");
return URLDecoder.decode(transl, StandardCharsets.UTF_8);
- } catch (IOException | JSONException e) {
+ } catch (IOException | URISyntaxException | JSONException e) {
e.printStackTrace();
return null;
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/doc_classifier/DocClassifierTrainingSetMultilingualExtender.java b/opennlp-similarity/src/main/java/opennlp/tools/doc_classifier/DocClassifierTrainingSetMultilingualExtender.java
index 99d070f..90501ad 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/doc_classifier/DocClassifierTrainingSetMultilingualExtender.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/doc_classifier/DocClassifierTrainingSetMultilingualExtender.java
@@ -21,6 +21,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
@@ -184,7 +186,7 @@ public class DocClassifierTrainingSetMultilingualExtender {
}
}
- try (InputStream is = new URL(docUrl).openStream();
+ try (InputStream is = new URI(docUrl).toURL().openStream();
OutputStream os = new FileOutputStream(destinationFile)) {
byte[] b = new byte[2048];
@@ -193,7 +195,7 @@ public class DocClassifierTrainingSetMultilingualExtender {
while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
}
- } catch (IOException e) {
+ } catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/VerbNetProcessor.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/VerbNetProcessor.java
index c0fdc46..2bf9089 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/VerbNetProcessor.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/VerbNetProcessor.java
@@ -21,10 +21,11 @@ package opennlp.tools.parse_thicket;
import java.io.File;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -41,7 +42,8 @@ import edu.mit.jverbnet.index.VerbIndex;
public class VerbNetProcessor implements IGeneralizer<Map<String, List<String>>> {
static VerbNetProcessor instance;
- static private String pathToVerbnet = null; //new File( "." ).getCanonicalPath()+"/src/test/resources";
+ private static String pathToVerbnet = null;
+
public static VerbNetProcessor getInstance(String resourceDir) {
if (resourceDir==null)
try {
@@ -61,40 +63,14 @@ public class VerbNetProcessor implements IGeneralizer<Map<String, List<String>>>
private VerbNetProcessor() {
try {
- URL url = new URL ("file", null , pathToVerbnet ) ;
+ URL url = new URI("file", null , pathToVerbnet).toURL() ;
index = new VerbIndex ( url ) ;
index.open() ;
-
- } catch (IOException e) {
+ } catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
-
- public IVerbClass getVerbNetForAVerb_____New(String verb){
- Iterator<IVerbClass> iter = index.iterator();
- while(iter.hasNext()){
- IVerbClass v = iter.next();
-
- if (v.getID().startsWith(verb))
- return v;
- }
- iter = index.iterator();
- while(iter.hasNext()){
- IVerbClass v = iter.next();
- if (!v.getMembers().isEmpty()){
- for(IMember m: v.getMembers()) {
- if (m.getName().equals(verb)){
- return v;
- }
- }
- }
- }
- return null;
- }
-
-
-
public IVerbClass getVerbNetForAVerb(String verb){
for (IVerbClass v : index) {
if (v.getID().startsWith(verb))
@@ -113,9 +89,10 @@ public class VerbNetProcessor implements IGeneralizer<Map<String, List<String>>>
v1 = getVerbNetForAVerb((String) o1);
v2 = getVerbNetForAVerb((String) o2);
return generalize(v1, v2);
- } else
+ } else {
+ v1 = (IVerbClass) o1;
+ }
- v1 = (IVerbClass)o1;
v2 = (IVerbClass)o2;
List<Map<String, List<String>>> resList = new ArrayList<>();
@@ -257,7 +234,4 @@ public class VerbNetProcessor implements IGeneralizer<Map<String, List<String>>>
System.out.println (res);
}
-
-
-
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/WebSearchEngineResultsScraper.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/WebSearchEngineResultsScraper.java
index f870259..9ff771d 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/WebSearchEngineResultsScraper.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/WebSearchEngineResultsScraper.java
@@ -18,8 +18,10 @@
package opennlp.tools.similarity.apps;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStreamReader;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
@@ -37,35 +39,23 @@ public class WebSearchEngineResultsScraper {
protected static String fetchPageSearchEngine(String url) {
System.out.println("fetch url " + url);
- String pageContent = null;
StringBuilder buf = new StringBuilder();
try {
- URLConnection connection = new URL(url).openConnection();
+ URLConnection connection = new URI(url).toURL().openConnection();
connection.setReadTimeout(50000);
- connection
- .setRequestProperty(
- "User-Agent",
+ connection.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");
String line;
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(
- connection.getInputStream()));
- } catch (Exception e) {
- System.err.println("Unable to complete search engine request "+url);
- //e.printStackTrace();
- }
-
- while ((line = reader.readLine()) != null) {
- buf.append(line);
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
+ while ((line = reader.readLine()) != null) {
+ buf.append(line);
+ }
+ return buf.toString();
}
-
- } catch (Exception e) {
- // e.printStackTrace();
+ } catch (IOException | URISyntaxException e) {
System.err.println("error fetching url " + url);
+ return null;
}
-
- return buf.toString();
}
private static List<String> extractURLsFromPage(String content, String domain) {
@@ -127,13 +117,11 @@ public class WebSearchEngineResultsScraper {
}
private static String formRequestURL(String query) {
- String requestUrl = "http://www.hakia.com/search/web?q=" + query.replace(' ','+');
- return requestUrl;
+ return "http://www.hakia.com/search/web?q=" + query.replace(' ','+');
}
private static String formRequestURLAlt(String query) {
- String requestUrl = "https://www.google.com/search?q=" + query.replace(' ','+');
- return requestUrl;
+ return "https://www.google.com/search?q=" + query.replace(' ','+');
}
public List<String> getURLsForWebDomain(String domain) {
@@ -185,7 +173,6 @@ public class WebSearchEngineResultsScraper {
final Map<String, String[][]> cachedSearchEngineData = new HashMap<>();
-
private void buildCache(){
cachedSearchEngineData.put("remember+to+buy+milk+tomorrow+for+details", new String[][]{
{"Remember The Milk - Services / Remember The Milk for Email", "to Remember The Milk just by sending an email to a special address. Read this page to learn all the details, and if you have any questions or run into any .... email address] Buy birthday present for Mike today Pay the phone bill tomorrow Make"},
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/Comment.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/Comment.java
index 45f6657..d7903e3 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/Comment.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/Comment.java
@@ -28,45 +28,41 @@ import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.relationships.Relationship;
import org.docx4j.relationships.Relationships;
import org.docx4j.wml.Comments;
-import org.docx4j.wml.ObjectFactory;
-
-//import util.RelationshipName;
public class Comment {
- private final WordprocessingMLPackage wordMlPackage;
- private final boolean relSet = false;
+ private final WordprocessingMLPackage wordMlPackage;
+ private final boolean relSet = false;
- public Comment(WordprocessingMLPackage wordMLPack) {
- this.wordMlPackage = wordMLPack;
- setCommentRel();
- }
+ public Comment(WordprocessingMLPackage wordMLPack) {
+ this.wordMlPackage = wordMLPack;
+ setCommentRel();
+ }
- private void setCommentRel() {
- if (!commentRelSet()) {
- CommentsPart cp;
- try {
- cp = new CommentsPart();
- // Part must have minimal contents
- org.docx4j.wml.ObjectFactory wmlObjectFactory = new ObjectFactory();
- wordMlPackage.getMainDocumentPart().addTargetPart(cp);
- } catch (InvalidFormatException e) {
- e.printStackTrace();
- }
- }
+ private void setCommentRel() {
+ if (!commentRelSet()) {
+ CommentsPart cp;
+ try {
+ cp = new CommentsPart();
+ // Part must have minimal contents
+ wordMlPackage.getMainDocumentPart().addTargetPart(cp);
+ } catch (InvalidFormatException e) {
+ e.printStackTrace();
+ }
}
+ }
- private boolean commentRelSet() {
- Relationship relShip;
- boolean relSet = false;
- if (!relSet) {
- JaxbXmlPart<Relationships> jxpRelShips = wordMlPackage
- .getMainDocumentPart().getOwningRelationshipPart();
- Relationships pk = jxpRelShips.getJaxbElement();
+ private boolean commentRelSet() {
+ Relationship relShip;
+ boolean relSet = false;
+ if (!relSet) {
+ JaxbXmlPart<Relationships> jxpRelShips = wordMlPackage
+ .getMainDocumentPart().getOwningRelationshipPart();
+ Relationships pk = jxpRelShips.getJaxbElement();
- List<Relationship> mc = pk.getRelationship();
+ List<Relationship> mc = pk.getRelationship();
- Iterator<Relationship> it = mc.iterator();
+ Iterator<Relationship> it = mc.iterator();
/* while (it.hasNext() && !relSet) {
relShip = it.next();
if (relShip.getValue().equalsIgnoreCase(
@@ -74,38 +70,37 @@ public class Comment {
relSet = true;
}
}*/
- }
- return relSet;
}
-
- public static void main(String[] args) throws Exception {
-
- // Create a package
- WordprocessingMLPackage wmlPack = new WordprocessingMLPackage();
-
- // Create main document part
- MainDocumentPart wordDocumentPart = new MainDocumentPart();
-
- // Create main document part content
- org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
- org.docx4j.wml.Body body = factory.createBody();
- org.docx4j.wml.Document wmlDocumentEl = factory.createDocument();
-
- wmlDocumentEl.setBody(body);
- wordDocumentPart.setJaxbElement(wmlDocumentEl);
- wmlPack.addTargetPart(wordDocumentPart);
-
- CommentsPart cp = new CommentsPart();
- // Part must have minimal contents
- Comments comments = factory.createComments();
- cp.setJaxbElement(comments);
-
- wordDocumentPart.addTargetPart(cp);
-
- // Now you can add comments to your comments part,
- // and comment refs in your main document part
-
- wmlPack.save(new java.io.File(System.getProperty("user.dir")+ "/out-m.docx"));
- }
-
+ return relSet;
+ }
+
+ public static void main(String[] args) throws Exception {
+
+ // Create a package
+ WordprocessingMLPackage wmlPack = new WordprocessingMLPackage();
+
+ // Create main document part
+ MainDocumentPart wordDocumentPart = new MainDocumentPart();
+
+ // Create main document part content
+ org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
+ org.docx4j.wml.Body body = factory.createBody();
+ org.docx4j.wml.Document wmlDocumentEl = factory.createDocument();
+
+ wmlDocumentEl.setBody(body);
+ wordDocumentPart.setJaxbElement(wmlDocumentEl);
+ wmlPack.addTargetPart(wordDocumentPart);
+
+ CommentsPart cp = new CommentsPart();
+ // Part must have minimal contents
+ Comments comments = factory.createComments();
+ cp.setJaxbElement(comments);
+
+ wordDocumentPart.addTargetPart(cp);
+
+ // Now you can add comments to your comments part,
+ // and comment refs in your main document part
+
+ wmlPack.save(new java.io.File(System.getProperty("user.dir")+ "/out-m.docx"));
+ }
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/NLProgram2CodeRequestHandler.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/NLProgram2CodeRequestHandler.java
index 7a1d40e..42e2ecf 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/NLProgram2CodeRequestHandler.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/NLProgram2CodeRequestHandler.java
@@ -36,8 +36,7 @@ public class NLProgram2CodeRequestHandler extends SearchHandler {
private final ParseTreeChunkListScorer parseTreeChunkListScorer = new ParseTreeChunkListScorer();
private final int MAX_QUERY_LENGTH_NOT_TO_RERANK = 3;
private static final String RESOURCES = "C:/workspace/TestSolr/src/test/resources";
- //"/data1/solr/example/src/test/resources";
-
+
final NL2Obj compiler = new NL2ObjCreateAssign(RESOURCES);
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp){
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilder.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilder.java
index 461dcd0..8e767c1 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilder.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilder.java
@@ -24,7 +24,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
@@ -205,7 +206,7 @@ public class WordDocBuilder{
}
public static void saveImageFromTheWeb(String imageUrl, String destinationFile) {
- File f = new File(destinationFile);
+ final File f = new File(destinationFile);
if (!f.exists()) {
try {
f.createNewFile();
@@ -213,17 +214,16 @@ public class WordDocBuilder{
throw new RuntimeException(e);
}
}
- try (InputStream is = new URL(imageUrl).openStream();
+ try (InputStream is = new URI(imageUrl).toURL().openStream();
OutputStream os = new FileOutputStream(destinationFile)) {
byte[] b = new byte[2048];
int length;
-
while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
}
- } catch (IOException e) {
+ } catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/PageFetcher.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/PageFetcher.java
index 0d63e70..53e5a2e 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/PageFetcher.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/PageFetcher.java
@@ -20,7 +20,8 @@ package opennlp.tools.similarity.apps.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URLConnection;
import java.util.logging.Logger;
@@ -31,6 +32,7 @@ import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
import org.apache.tika.sax.BodyContentHandler;
+import org.xml.sax.SAXException;
public class PageFetcher {
private static final Logger LOG = Logger.getLogger("opennlp.tools.similarity.apps.utils.PageFetcher");
@@ -50,7 +52,7 @@ public class PageFetcher {
String pageContent = null;
URLConnection connection;
try {
- connection = new URL(fetchURL).openConnection();
+ connection = new URI(fetchURL).toURL().openConnection();
connection.setReadTimeout(DEFAULT_TIMEOUT);
// parse method parameters
Parser parser = new AutoDetectParser();
@@ -62,23 +64,22 @@ public class PageFetcher {
parser.parse(connection.getInputStream(), handler, metadata, context);
pageContent = handler.toString();
- } catch (Exception e) {
+ } catch (IOException | URISyntaxException | SAXException | TikaException e) {
LOG.severe(e.getMessage() + "\n" + e);
}
- return pageContent;
+ return pageContent;
}
-
public String fetchPage(final String url, final int timeout) {
String fetchURL = addHttp(url);
String pageContent = null;
URLConnection connection;
try {
- connection = new URL(fetchURL).openConnection();
- connection.setReadTimeout(DEFAULT_TIMEOUT);
+ connection = new URI(fetchURL).toURL().openConnection();
+ connection.setReadTimeout(timeout);
pageContent = tika.parseToString(connection.getInputStream())
.replace('\n', ' ').replace('\t', ' ');
- } catch (IOException | TikaException e) {
+ } catch (IOException | URISyntaxException | TikaException e) {
LOG.severe(e.getMessage() + "\n" + e);
}
return pageContent;
@@ -100,38 +101,20 @@ public class PageFetcher {
LOG.info("fetch url " + url);
StringBuilder buf = new StringBuilder();
try {
- URLConnection connection = new URL(url).openConnection();
+ URLConnection connection = new URI(url).toURL().openConnection();
connection.setReadTimeout(DEFAULT_TIMEOUT);
- connection
- .setRequestProperty(
- "User-Agent",
+ connection.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");
String line;
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(
- connection.getInputStream()));
- } catch (Exception e) {
- // we don't always need to log trial web pages if access fails
- LOG.severe(e.toString());
- }
-
- while ((line = reader.readLine()) != null) {
- buf.append(line);
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
+ while ((line = reader.readLine()) != null) {
+ buf.append(line);
+ }
}
-
- }
- // normal case when a hypothetical page does not exist
- catch (Exception e) {
-
- // LOG.error(e.getMessage(), e);
- // System.err.println("error fetching url " + url);
+ } catch (Exception e) {
+ // we don't always need to log trial web pages if access fails
+ LOG.severe(e.toString());
}
-/* try {
- Thread.sleep(50); // do nothing 4 sec
- } catch (InterruptedException e) {
- e.printStackTrace();
- } */
return buf.toString();
}
@@ -139,8 +122,7 @@ public class PageFetcher {
PageFetcher fetcher = new PageFetcher();
String content = fetcher.fetchPageAutoDetectParser("http://www.elastica.net/");
System.out.println(content);
- content = fetcher.
- fetchPageAutoDetectParser("http://www.cnn.com");
+ content = fetcher.fetchPageAutoDetectParser("http://www.cnn.com");
System.out.println(content);
content = new PageFetcher().fetchPage("https://github.com");
System.out.println(content);
diff --git a/pom.xml b/pom.xml
index 64a2b32..3242d17 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,7 +60,7 @@
<subscribe>users-subscribe@opennlp.apache.org</subscribe>
<unsubscribe>users-unsubscribe@opennlp.apache.org</unsubscribe>
<post>users@opennlp.apache.org</post>
- <archive>http://mail-archives.apache.org/mod_mbox/opennlp-users/</archive>
+ <archive>https://mail-archives.apache.org/mod_mbox/opennlp-users/</archive>
</mailingList>
<mailingList>
@@ -68,21 +68,21 @@
<subscribe>dev-subscribe@opennlp.apache.org</subscribe>
<unsubscribe>dev-unsubscribe@opennlp.apache.org</unsubscribe>
<post>dev@opennlp.apache.org</post>
- <archive>http://mail-archives.apache.org/mod_mbox/opennlp-dev/</archive>
+ <archive>https://mail-archives.apache.org/mod_mbox/opennlp-dev/</archive>
</mailingList>
<mailingList>
<name>Apache OpenNLP Commits</name>
<subscribe>commits-subscribe@opennlp.apache.org</subscribe>
<unsubscribe>commits-unsubscribe@opennlp.apache.org</unsubscribe>
- <archive>http://mail-archives.apache.org/mod_mbox/opennlp-commits/</archive>
+ <archive>https://mail-archives.apache.org/mod_mbox/opennlp-commits/</archive>
</mailingList>
<mailingList>
<name>Apache OpenNLP Issues</name>
<subscribe>issues-subscribe@opennlp.apache.org</subscribe>
<unsubscribe>issues-unsubscribe@opennlp.apache.org</unsubscribe>
- <archive>http://mail-archives.apache.org/mod_mbox/opennlp-issues/</archive>
+ <archive>https://mail-archives.apache.org/mod_mbox/opennlp-issues/</archive>
</mailingList>
</mailingLists>
@@ -124,11 +124,11 @@
<log4j2.version>2.20.0</log4j2.version>
<uimaj.version>3.4.1</uimaj.version>
- <jersey-client.version>2.39.1</jersey-client.version>
- <jersey-server.version>2.39.1</jersey-server.version>
+ <jersey-client.version>2.41</jersey-client.version>
+ <jersey-server.version>2.41</jersey-server.version>
<jettison.version>1.5.4</jettison.version>
- <junit.version>5.9.2</junit.version>
+ <junit.version>5.10.1</junit.version>
<enforcer.plugin.version>3.0.0-M3</enforcer.plugin.version>
<checkstyle.plugin.version>3.2.0</checkstyle.plugin.version>
@@ -136,6 +136,7 @@
<jacoco.maven.plugin>0.7.9</jacoco.maven.plugin>
<maven.surefire.plugin>3.0.0-M5</maven.surefire.plugin>
<maven.failsafe.plugin>3.0.0-M5</maven.failsafe.plugin>
+ <forbiddenapis.plugin>3.6</forbiddenapis.plugin>
<mockito.version>3.9.0</mockito.version>
</properties>
@@ -377,7 +378,7 @@
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
- <version>3.5.1</version>
+ <version>${forbiddenapis.plugin}</version>
<configuration>
<failOnUnsupportedJava>false</failOnUnsupportedJava>
<bundledSignatures>
@@ -405,7 +406,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.10.1</version>
+ <version>3.11.0</version>
<configuration>
<release>${java.version}</release>
<compilerArgument>-Xlint</compilerArgument>