Select CoreNLP language model at runtime - stanford-nlp

Is it possible to select language models (among the official ones: English, Chinese, Spanish) at runtime by using the Java API?
I am currently using Gradle to define dependencies:
dependencies {
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.5.1'
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.5.1', classifier: 'models'
}
Also, are Chinese and Spanish models available on Maven as well?

The Stanford CoreNLP main JAR file (as distributed on Maven) contains properties files StanfordCoreNLP-spanish.properties, StanfordCoreNLP-chinese.properties. You can load these programmatically from the classpath and use them when instantiating the StanfordCoreNLP pipeline.
Unfortunately we don't distribute the multilingual models on Maven, though that could probably change if there is community demand.

This is more a comment than an answer, but I am new so I'm being blocked from comments! We are actively working on adding the Spanish and Chinese models to Maven, so stay tuned, they should be out fairly soon!
UPDATE
You can now get the Chinese, Spanish, and German model jars on Maven!
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
<classifier>models-chinese</classifier>
</dependency>

Another way to include stanford core NLP into gradle dependency:
compile('edu.stanford.nlp:stanford-corenlp:3.6.0')
compile('edu.stanford.nlp:stanford-corenlp:3.6.0:models')

Related

Itext7 Jars not loading in properly to javafx project

I've got this dependency in my pom.xml
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.1.18</version>
<type>pom</type>
</dependency>
And in my module-info.java file I have the following
requires transitive kernel;
which produces the following warning, "Name of automatic module 'kernel' is unstable, it is derived from the module's file name."
What can I do to get rid of this warning?
I tried changing it to
requires transitive com.itextpdf.kernel;
but then I get the following error, "com.itextpdf.kernel cannot be resolved to a module"
I tried a bunch of other similar lines of code but nothing worked. What can I change the code to in order to remove the error/warning?
itext7 currently isn't modular.
You can contact the developers and ask them to make it modular.
In the meantime, complex, non-modular systems like this are difficult to use from a modular project. Even if you get that to work via the automatic module system or hacking in module info via something like moditect, it pretty much destroys any potential benefit of the project being modular, and it runs the software in a way it was never designed to work.
So, make your project non-modular:
remove the module-info.java from your project.
source the javafx modules using either:
VM arguments pointing adding them to the module path OR
from a JRE/JDK distribution that includes them, e.g. BellSoft Liberica "Full JDK" or Azul Zulu "JDK FX".
For further instructions on working with non-modular JavaFX projects, see the getting started documentation at: openjfx.io.
I am not sure what "not modular" means but how can that be true if the itext7 website gives maven dependencies to incorporate into your pom.xml?
Non-modular means that you don't define a module-info.java in your project.
Read understanding modules and the documentation I linked at openjfx.io to understand the basics of the JavaFX module system and how it can be used in a JavaFX application.
Maven modules and Java Platform modules are different things, they have the same name "module" but one is a build-time definition and the other is a runtime definition. Also, a maven dependency is just a dependency, it is not a Maven module or a Java Platform module. Though you can depend on artifacts built by a maven module and you can execute those artifacts through the Java Platform module system (if they are compatible with it).
itext7 is not built as a Java Platform module. The software has no module-info.java and it does not define an automatic module name for itself either. Given that your software is depending on non-modular software, your software should not be modular either (in my opinion).

What does kotlin-bom library do?

I've created new Kotlin project under Gradle. By default it sets this dependencies to the Kotlin-library project. And I wonder what does this kotlin-bom lib do ?
dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
The kotlin-bom artifact is a dependency-only POM that aligns all the Kotlin SDK libraries with the same version.
See the POM content for version 1.5.31 for an example. It uses the POM's dependencyManagement section to depend on the same version of all the Kotlin SDK artifacts, like kotlin-stdlib, kotlin-stdlib-jdk8, kotlin-reflect, kotlin-test, etc.
Description of a BOM:
Software bill of materials (BOMs) don’t specify a dependency on a
module or file, but instead are a list of version constraints for
other components. They define what is called a platform, which is
basically a list of components with specific versions that are known
to play well together and/or form a useful unit of functionality. It’s
worth mentioning that not all of the dependencies listed in the BOM
actually have to be included in your projects — it’s basically a way
of saying “If you use any of these modules, use this version”.
-- A deep dive into an initial Kotlin build.gradle.kts

Gradle. Say dependency to use another version of already included dependency

Example:
implementation(group: 'org.seleniumhq.selenium', name: 'selenium-remote-driver', version: '3.13.0')
implementation(group: 'com.mypack', name: "old-library", version: '1.0')
Problem is that old-library throws
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException which is missing in newer selenium versions.
Unfortunately I have no access to source code.
Question - is it possible to say only for old-library to use old selenium version?
okay, that's not possible. as I get from the Gradle Slack chat:
than there is no way to solve it without dependency package relocation
actually, in this case problem not even on classpath level, because if 2 dependencies have the same id Gradle have to choose one of them.
If you change only dependnecy id, you will have problems on runtime, because 2 dependencies with many conflicting classes will be on the same classpath. It’s valid for Java, but which version will be choosed on classpath resolution depends on classloader and you cannot rely on this

What is the difference between an app dependency and a module dependency/plugin?

When using some 3rd party libraries, I add a dependency to my module's build.gradle file.
compile 'com.android.support:appcompat-v7:24.1.1'
Or I add a plugin
apply plugin: 'com.neenbedankt.android-apt'
Some other times, the library requires adding a dependency to my app's build.gradle file.
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
What is the difference between these dependencies and plugins?
Why can't they all be set in a single build.gradle file?
All suggestions are appreciated, I'm having trouble searching for info on this
Three things. Gradle plugin, module dependency, a build dependency which is placed on the classpath of the build tool.
A plugin is how Gradle knows what tasks to use. There are many plugins. For more info, see Gradle - Plugin Documentation
A dependency is a library that is compiled with your code. The following line makes your module depend on the Android AppCompat V7 library. For the most part, you search Maven or Jcenter for these.
compile 'com.android.support:appcompat-v7:24.1.1'
The classpath setting is needed for Gradle, not your app. For example, this allows this includes the Gradle Build Tools for Android into the classpath, and allows Gradle to build apps.
classpath 'com.android.tools.build:gradle:2.1.2'
Why can't they all be in one build.gradle file?
They probably can be. It is simply more modular to not.
I got this answer from a colleague, and this helped me understand. "A gradle plugin is like the tools you use to build the app. The dependencies are the libraries included in the app. A gradle plugin is usually the tasks - like ktlint, etc."
I didn't understand this myself so here is what i found. My answer is based on gradle build tool.
Plugins:
Add additional tasks, repositories, new DSL elements, configuration for classpaths/build/run or dependency management for subsequent development. Plugins are developed for a larger scope of development like java, kotlin or spring-boot.
Dependencies:
modules/libraries for tasks like http, serialization or database are dependencies stored remotely at repositories or locally that are needed at runTime, test or build are resolved by gradle in a configured fashion.
Sources:
Spring boot gradle plugin: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin
Gradle documentation on plugins/dependencies: https://docs.gradle.org/current/userguide/plugins.html
https://docs.gradle.org/current/userguide/core_dependency_management.html
Remote repositories:
https://mvnrepository.com/
In simple words:
Plugins are used to add some additonal features to the software/tools(like Gradle). Gradle will use the added plugins at the time of building the App.
Dependecies are used to add some addtional code to your source code, so a dependency will make some extra code (like Classes in Java) in the form of library available for your source code.

Multi-language coreNLP

Is it possible to have more than one Stanford CoreNLP instance, each of them using a different language, in the same Java project?
In the CoreNLP documentation, it seems that the only way to change language is to add a different Maven dependency: what if I want to use all of them together?
If you include a dependency for each language, you will get all of the model files for Chinese, German, and Spanish. You will now have all the resources to run on Chinese, German, and Spanish.
Within your code, you determine the language by the .properties file you use to build the StanfordCoreNLP pipeline object. So you are free to build different pipelines with different .properties files.
The appropriate .properties files for the various languages can be found in the corresponding model jars.

Resources