我有错误

not enough arguments for constructor DictionaryLemmatizer: (x$1: java.io.InputStream)opennlp.tools.lemmatizer.DictionaryLemmatizer.
[error] Unspecified value parameter x$1.
[error] class SimpleLemmatizerModel(map: Map[String, Map[Char, Map[String, String]]]) extends DictionaryLemmatizer  {
[error]                            ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed


构建此类代码时(sbt assembly

import opennlp.tools.lemmatizer.DictionaryLemmatizer
import scala.io.Source

class SimpleLemmatizerModel(val map: Map[String, Map[Char, Map[String, String]]]) extends DictionaryLemmatizer {

  def lemmatize(word: String, tag: String): String =
    ( for( t <- map.get(tag); w <- t.get(word(0)) )
      yield {w.getOrElse(word, word)}
    ).getOrElse(word)

  def lemmatize(token: TaggedToken): String = lemmatize(token.token, token.tag)

  def transform(tokens: Array[TaggedToken]): Array[String] = tokens.map(lemmatize)

}


哪里

trait Tokens {val token: String}

trait TaggedTokens extends Tokens {val tag: String}

case class TaggedToken(token: String, tag: String) extends TaggedTokens {
  override def toString = token + ": " + tag
}

case class Token(token: String) extends Tokens {
  def tag(t: String): TaggedTokens = TaggedToken(token, t)
}


DictionaryLemmatizer是用Java编写的OpenNLP库类,可以在here中找到其代码。

如果有人解释这种错误的原因及其解决方法,我将不胜感激。

如果需要一些其他信息,我会很乐意提供。

最佳答案

DictionaryLemmatizer的构造函数需要类型为dictionary的参数java.io.InputStream

您可能要改为实现Lemmatizer接口:

class SimpleLemmatizerModel(...) extends Lemmatizer { ... }




注意:您必须实现那些lemmatize方法,以使SimpleLemmatizerModel具体化。

关于java - Scala:构造函数DictionaryLemmatizer的参数不足,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43365236/

10-10 10:09