如何在Scala中使用OpenNLP提取名词?

如何在Scala中使用OpenNLP提取名词?,scala,nlp,text-mining,opennlp,Scala,Nlp,Text Mining,Opennlp,我想使用openNLP提取名词短语。我有下面的Scala代码 object ParserTest1 extends Serializable { def apply(line: String): (String) = { val is = new FileInputStream("/home/akshat/en-parser-chunking.bin") val model = new ParserModel(is) val parser = ParserFacto

我想使用openNLP提取名词短语。我有下面的Scala代码

object ParserTest1 extends Serializable {

  def apply(line: String): (String) = {
    val is = new FileInputStream("/home/akshat/en-parser-chunking.bin")
    val model = new ParserModel(is)
    val parser = ParserFactory.create(model)
    var nounPhrases = ""
    val topParses = ParserTool.parseLine(line, parser, 1)
    for (p <- topParses) {
    getNounPhrases(p)
    }
  def getNounPhrases(p: Parse) {
    if (p.getType == "NN" || p.getType == "NNS" || p.getType == "NNP" || 
      p.getType == "NNPS") {
      nounPhrases += p.getCoveredText + " "
    }    

    for (child <- p.getChildren) {
      getNounPhrases(child)
    }
}
(nounPhrases)
}
}
对象ParserTest1扩展了可序列化{
def应用(行:字符串):(字符串)={
val is=newfileinputstream(“/home/akshat/en parser chunking.bin”)
val模型=新的ParserModel(is)
val parser=ParserFactory.create(模型)
var名词短语=“”
val-topParses=ParserTool.parseLine(行,解析器,1)

对于(p创建一个计数器来跟踪您找到名词的次数,并在计数器达到2时停止循环