diff --git a/corenlp/buildinfo.sbt b/corenlp/buildinfo.sbt new file mode 100644 index 000000000..76452a168 --- /dev/null +++ b/corenlp/buildinfo.sbt @@ -0,0 +1,23 @@ +enablePlugins(BuildInfoPlugin) + +buildInfoKeys := { + val stanfordVersion = { + val Array(major, minor, revision) = libraryDependencies.value + .find(_.name == "stanford-corenlp") + .map(_.revision) + .get // It must exist + .split('.') // and be formatted + .map(_.toInt) // compatibly! + + Map( + "major" -> major, + "minor" -> minor, + "revision" -> revision + ) + } + + Seq[BuildInfoKey]( + "stanfordVersion" -> stanfordVersion + ) +} +buildInfoPackage := "org.clulab.processors.corenlp" diff --git a/corenlp/src/main/scala/org/clulab/processors/corenlp/Version.scala b/corenlp/src/main/scala/org/clulab/processors/corenlp/Version.scala new file mode 100644 index 000000000..96c72ad3e --- /dev/null +++ b/corenlp/src/main/scala/org/clulab/processors/corenlp/Version.scala @@ -0,0 +1,9 @@ +package org.clulab.processors.corenlp + +case class Version(major: Int, minor: Int, revision: Int) + +object Version { + def apply(version: Map[String, Int]): Version = Version(version("major"), version("minor"), version("revision")) + + val stanford: Version = Version(BuildInfo.stanfordVersion) +} diff --git a/corenlp/src/test/scala/org/clulab/processors/TestCoreNLPProcessor.scala b/corenlp/src/test/scala/org/clulab/processors/TestCoreNLPProcessor.scala index 551a6c2ec..145c04c0c 100644 --- a/corenlp/src/test/scala/org/clulab/processors/TestCoreNLPProcessor.scala +++ b/corenlp/src/test/scala/org/clulab/processors/TestCoreNLPProcessor.scala @@ -2,8 +2,7 @@ package org.clulab.processors import org.clulab.processors.shallownlp.ShallowNLPProcessor import org.scalatest._ - -import org.clulab.processors.corenlp.CoreNLPProcessor +import org.clulab.processors.corenlp.{CoreNLPProcessor, Version} import org.clulab.struct.CorefMention /** @@ -123,7 +122,9 @@ class TestCoreNLPProcessor extends FlatSpec with Matchers { doc.sentences(0).tags.get(0) should be ("NNP") doc.sentences(0).tags.get(1) should be ("NNP") doc.sentences(0).tags.get(2) should be ("VBD") - doc.sentences(0).tags.get(3) should be ("IN") // TODO: this used to be "TO" in older CoreNLP versions (< 4) + doc.sentences(0).tags.get(3) should be ( + if (Version.stanford.major < 4) "TO" else "IN" + ) doc.sentences(0).tags.get(4) should be ("NNP") doc.sentences(0).tags.get(5) should be (".") doc.sentences(1).tags.get(0) should be ("RB") @@ -164,7 +165,9 @@ class TestCoreNLPProcessor extends FlatSpec with Matchers { doc.sentences.head.universalBasicDependencies.get.hasEdge(1, 0, "compound") should be (true) doc.sentences.head.universalBasicDependencies.get.hasEdge(2, 1, "nsubj") should be (true) - doc.sentences.head.universalBasicDependencies.get.hasEdge(2, 4, "obl") should be (true) + doc.sentences.head.universalBasicDependencies.get.hasEdge( + 2, 4, if (Version.stanford.major < 4) "nmod" else "obl" + ) should be (true) doc.sentences.head.universalBasicDependencies.get.hasEdge(4, 3, "case") should be (true) doc.sentences.head.syntacticTree.foreach(t => { @@ -252,10 +255,11 @@ class TestCoreNLPProcessor extends FlatSpec with Matchers { println(doc.sentences.head.universalBasicDependencies.get) - // TODO: with CoreNLP > v4, this tree is completely foobar... - //doc.sentences.head.universalBasicDependencies.get.hasEdge(4, 6, "dep") should be (true) // this probably should be "appos", but oh well... - //doc.sentences.head.universalBasicDependencies.get.hasEdge(16, 18, "appos") should be (true) - + // TODO: with CoreNLP >= v4, this tree is completely foobar... so it is not tested. + if (Version.stanford.major < 4) { + doc.sentences.head.universalBasicDependencies.get.hasEdge(4, 6, "dep") should be (true) // this probably should be "appos", but oh well... + doc.sentences.head.universalBasicDependencies.get.hasEdge(16, 18, "appos") should be (true) + } } } diff --git a/corenlp/src/test/scala/org/clulab/processors/TestFastNLPProcessor.scala b/corenlp/src/test/scala/org/clulab/processors/TestFastNLPProcessor.scala index e9655e8c9..fd7728218 100644 --- a/corenlp/src/test/scala/org/clulab/processors/TestFastNLPProcessor.scala +++ b/corenlp/src/test/scala/org/clulab/processors/TestFastNLPProcessor.scala @@ -1,6 +1,7 @@ package org.clulab.processors import org.clulab.dynet.Utils +import org.clulab.processors.corenlp.Version import org.clulab.processors.shallownlp.ShallowNLPProcessor import org.scalatest._ import org.clulab.processors.fastnlp.FastNLPProcessorWithSemanticRoles @@ -19,7 +20,9 @@ class TestFastNLPProcessor extends FlatSpec with Matchers { doc.sentences.head.dependencies.get.hasEdge(1, 0, "compound") should be (true) doc.sentences.head.dependencies.get.hasEdge(2, 1, "nsubj") should be (true) - doc.sentences.head.dependencies.get.hasEdge(2, 4, "obl_to") should be (true) + doc.sentences.head.dependencies.get.hasEdge( + 2, 4, if (Version.stanford.major < 4) "nmod_to" else "obl_to" + ) should be (true) /* val it = new DirectedGraphEdgeIterator[String](doc.sentences.head.dependencies.get) @@ -79,7 +82,9 @@ class TestFastNLPProcessor extends FlatSpec with Matchers { println(doc.sentences.head.universalBasicDependencies.get) // TODO: this should be (4, 6, "appos") - CoreNLP is incorrect here - doc.sentences.head.universalBasicDependencies.get.hasEdge(2, 6, "appos") should be (true) + doc.sentences.head.universalBasicDependencies.get.hasEdge( + if (Version.stanford.major < 4) 4 else 2, 6, "appos" + ) should be (true) doc.sentences.head.universalBasicDependencies.get.hasEdge(16, 18, "appos") should be (true) } diff --git a/project/plugins.sbt b/project/plugins.sbt index a4987ee44..33af2caf1 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,6 @@ // Latest version numbers were updated on 2021 Mar 11. -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1") // up to 1.1.2-1 * -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") // up to 3.9.6 * -addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") // up to 1.0.13 +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") // up to 0.10.0 +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1") // up to 1.1.2-1 * +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") // up to 3.9.6 * +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") // up to 1.0.13 // * Held back out of an abundance of caution.