Skip to content

Commit 359e476

Browse files
pdurbinstevenwinship
authored andcommitted
bump opennlp-tools version
1 parent 199057d commit 359e476

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@
655655
<dependency>
656656
<groupId>org.apache.opennlp</groupId>
657657
<artifactId>opennlp-tools</artifactId>
658-
<version>1.9.1</version>
658+
<version>2.5.9</version>
659659
</dependency>
660660
<dependency>
661661
<groupId>org.xmlunit</groupId>

src/main/java/edu/harvard/iq/dataverse/util/Organizations.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Locale;
88
import java.util.logging.Level;
99
import java.util.logging.Logger;
10+
import javax.xml.parsers.DocumentBuilderFactory;
1011
import opennlp.tools.namefind.NameFinderME;
1112
import opennlp.tools.namefind.TokenNameFinderModel;
1213
import opennlp.tools.tokenize.TokenizerME;
@@ -30,6 +31,7 @@ class Organizations {
3031
};
3132

3233
private static final Logger logger = Logger.getLogger(FirstNames.class.getCanonicalName());
34+
private static final String JDK_DOCUMENT_BUILDER_FACTORY = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
3335
private static List<NameFinderME> organizationNameFinders = new ArrayList<NameFinderME>();
3436
private static List<TokenizerME> tokenizers = new ArrayList<TokenizerME>();
3537

@@ -189,6 +191,18 @@ private void loadOrganizationModel(String modelFileName) throws IOException {
189191
InputStream fis = this.getClass().getClassLoader().getResourceAsStream(modelFileName);
190192
TokenNameFinderModel organizationModel = new TokenNameFinderModel(fis);
191193

192-
organizationNameFinders.add(new NameFinderME(organizationModel));
194+
String documentBuilderFactoryProperty = DocumentBuilderFactory.class.getName();
195+
String previousDocumentBuilderFactory = System.getProperty(documentBuilderFactoryProperty);
196+
try {
197+
// OpenNLP 2.x sets JAXP security attributes that the external Xerces dependency does not recognize.
198+
System.setProperty(documentBuilderFactoryProperty, JDK_DOCUMENT_BUILDER_FACTORY);
199+
organizationNameFinders.add(new NameFinderME(organizationModel));
200+
} finally {
201+
if (previousDocumentBuilderFactory == null) {
202+
System.clearProperty(documentBuilderFactoryProperty);
203+
} else {
204+
System.setProperty(documentBuilderFactoryProperty, previousDocumentBuilderFactory);
205+
}
206+
}
193207
}
194208
}

0 commit comments

Comments
 (0)