我有错误
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/