Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter for Scala Grounders (rvacareanu/grounder) #887

Merged
merged 12 commits into from
Apr 30, 2024
Merged

Conversation

robertvacareanu
Copy link
Collaborator

Summary of Changes

Added an Adapter for the Scala Grounders package.

@myedibleenso
Copy link
Collaborator

@robertvacareanu , once #888 is merged, that failing CI test should pass.

Copy link
Contributor

@kwalcock kwalcock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point we might have to move away from the syntax like

val engine = chosenEngine getOrElse config.getString("engine")

in favor of

val engine = chosenEngine.getOrElse(config.getString("engine"))

Odersky has made comments recently about there being too many options supported, especially with the Python style included. The infix without .() may be sacrificed.

@enoriega
Copy link
Member

@kwalcock Thanks for the heads up. I always tried to make that syntax work in my mind but always felt a bit off.

Copy link
Member

@enoriega enoriega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@enoriega enoriega merged commit fe8f41f into main Apr 30, 2024
7 checks passed
@enoriega enoriega deleted the rvacareanu/grounder branch April 30, 2024 16:46
Copy link
Contributor

@kwalcock kwalcock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks really good. The only thing I'd want to change for sure is the character encoding. That has bitten us before.

def apply(groundingConcepts: Seq[GroundingConcept]): ScalaGroundersAdapter = new ScalaGroundersAdapter(groundingConcepts)
def fromDkgs(dkgs: Seq[DKG]): ScalaGroundersAdapter = new ScalaGroundersAdapter(dkgs.map(dkg => GroundingConcept(dkg.id, dkg.name, dkg.description, Option(dkg.synonyms.map(_.value)), None)))
def fromFile(groundingConceptsPath: String): ScalaGroundersAdapter = {
val concepts = using(Source.fromFile(groundingConceptsPath)) { it =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source.fromFile without an encoding specified may be a problem on machines where they have Java using an unexpected default encoding. It might be easier to play it safe here and save tracking it down later.

case "scala-grounders" =>
// Similar to `miraembeddings`
val ontologyFilePath = domainConfig.getString("ontologyPath")
ScalaGroundersAdapter.fromFile(groundingConceptsPath=ontologyFilePath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, that's Python! ;-)

groundingConceptsPath = ontologyFilePath

import org.clulab.scala_grounders.model.DKG
import org.clulab.scala_grounders.model.DKGSynonym
import com.typesafe.config.ConfigFactory
import org.clulab.scala_grounders.using
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recently we've been using the the using from

"org.scala-lang.modules" %% "scala-collection-compat" % version

often looking like Using.resource() { resource => . It's in the standard library for newer Scala versions.

.map { result =>
GroundingCandidate(fromDKGToConcept(result.dkg), result.score, details = Some(result.groundingDetails.grounderName))
}
.force.toSeq
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a clever use of Streams. IntelliJ says that the .toSeq is superfluous.

github-actions bot added a commit that referenced this pull request Apr 30, 2024
## Summary of Changes

Added an Adapter for the Scala Grounders package.

---------

Co-authored-by: Gus Hahn-Powell <[email protected]> fe8f41f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants