Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
<version>1.9.1</version>
<version>2.5.9</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/util/Organizations.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilderFactory;
import opennlp.tools.namefind.NameFinderME;
import opennlp.tools.namefind.TokenNameFinderModel;
import opennlp.tools.tokenize.TokenizerME;
Expand All @@ -30,6 +31,7 @@ class Organizations {
};

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

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

organizationNameFinders.add(new NameFinderME(organizationModel));
String documentBuilderFactoryProperty = DocumentBuilderFactory.class.getName();
String previousDocumentBuilderFactory = System.getProperty(documentBuilderFactoryProperty);
try {
// OpenNLP 2.x sets JAXP security attributes that the external Xerces dependency does not recognize.
System.setProperty(documentBuilderFactoryProperty, JDK_DOCUMENT_BUILDER_FACTORY);
organizationNameFinders.add(new NameFinderME(organizationModel));
} finally {
if (previousDocumentBuilderFactory == null) {
System.clearProperty(documentBuilderFactoryProperty);
} else {
System.setProperty(documentBuilderFactoryProperty, previousDocumentBuilderFactory);
}
}
}
}
Loading