Skip to content

Commit

Permalink
Merge pull request #644 from clulab/kwalcock/modernize
Browse files Browse the repository at this point in the history
Check StanfordCoreNLP version
  • Loading branch information
kwalcock authored Jun 16, 2022
2 parents 2cda16c + 8361b53 commit 4865896
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
23 changes: 23 additions & 0 deletions corenlp/buildinfo.sbt
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
}
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
7 changes: 4 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 4865896

Please sign in to comment.