Question

I am trying to use a Scala library in a Clojure project but running into some issues. How would you implement the following Scala code in Clojure?

object LabelDomain extends CategoricalDomain[String]
class Label(val token: Token, s: String) extends LabeledCategoricalVariable(s) {
  def domain = LabelDomain
}

object FeaturesDomain extends CategoricalDimensionTensorDomain[String]
class Features(val token: Token) extends BinaryFeatureVectorVariable[String] {
  def domain = FeaturesDomain
}

object model extends ChainModel[Label,  Features, Token](
      LabelDomain,
      FeaturesDomain,
      l => l.token.attr[Features],
      l => l.token,
      t => t.attr[Label])

CategoricalDomain and CategoricalDimensionTensorDomain are traits. LabeledCategoricalVariable and BinaryFeatureVectorVariable are abstract classes. ChainModel is a class.

Was it helpful?

Solution

It looks like you are trying to use FACTORIE with clojure. As someone who both loves clojure and works at the lab that builds FACTORIE, I wouldn't recommend this. FACTORIE's codebase is written in a very imperative style, and is filled with mutable state. If I got my hands on a FACTORIE object in clojure I would find it very disorienting. FACTORIE also makes aggressive use of scala features in ways that won't translate well to compiled java (which is the level at which clojure and scala must interact).

If you already have a large clojure codebase and need a good implementation of a linear-chain CRF (based on your use of ChainModel above), I'd recommend looking at MALLET. It's pure java and was developed by the same lab.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top