【问题标题】:Piglatin jodatime error with StanfordCoreNLP斯坦福 CoreNLP 的 Pig Latin joda 时间错误
【发布时间】:2013-06-14 10:54:10
【问题描述】:

我正在尝试创建一个 Pig UDF,它使用通过 sista Scala API 接口的 Stanford CoreNLP 包提取推文中提到的位置。使用 'sbt run' 在本地运行时工作正常,但从 Pig 调用时会抛出“java.lang.NoSuchMethodError”异常:

从标记器加载默认属性 edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-dissim.tagger 从 edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-dissim.tagger 从 edu/stanford/nlp/models/ner/english.all.3class.dissim.crf.ser.gz 加载分类器 2013-06-14 10:47:54,952 [通信线程] 信息 org.apache.hadoop.mapred.LocalJobRunner - 减少 > 减少完成 [7.5 秒]。从加载分类器 edu/stanford/nlp/models/ner/english.muc.7class.dissim.crf.ser.gz ... 2013-06-14 10:48:02,108 [内存不足检测器] 信息 org.apache.pig.impl.util.SpillableMemoryManager - 第一个内存处理程序 调用 - 收集阈值初始化 = 18546688(18112K) 已使用 = 358671232(350264K) 已提交 = 366542848(357952K) 最大值 = 699072512(682688K) 完成 [5.0 秒]。从加载分类器 edu/stanford/nlp/models/ner/english.conll.4class.dissim.crf.ser.gz ... 2013-06-14 10:48:10,522 [内存不足检测器] 信息 org.apache.pig.impl.util.SpillableMemoryManager - 第一个内存处理程序 调用-使用阈值初始化 = 18546688(18112K) 已使用 = 590012928(576184K) 已提交 = 597786624(583776K) 最大值 = 699072512(682688K) 完成 [5.6 秒]。 2013-06-14 10:48:11,469 [线程 11] 警告 org.apache.hadoop.mapred.LocalJobRunner - job_local_0001 java.lang.NoSuchMethodError: org.joda.time.Duration.compareTo(Lorg/joda/time/ReadableDuration;)I 在 edu.stanford.nlp.time.SUTime$Duration.compareTo(SUTime.java:3406) 在 edu.stanford.nlp.time.SUTime$Duration.max(SUTime.java:3488) 在 edu.stanford.nlp.time.SUTime$Time.difference(SUTime.java:1308) 在 edu.stanford.nlp.time.SUTime$Range.(SUTime.java:3793) 在 edu.stanford.nlp.time.SUTime.(SUTime.java:570)

下面是相关代码:

object CountryTokenizer {
  def tokenize(text: String): String = {
    val locations = TweetEntityExtractor.NERLocationFilter(text)
    println(locations)
    locations.map(x => Cities.country(x)).flatten.mkString(" ")
  }
}

class PigCountryTokenizer extends EvalFunc[String] {
  override def exec(tuple: Tuple): java.lang.String = {
    val text: java.lang.String = Util.cast[java.lang.String](tuple.get(0))
    CountryTokenizer.tokenize(text)
  }
}

object TweetEntityExtractor {
    val processor:Processor = new CoreNLPProcessor()


    def NERLocationFilter(text: String): List[String] =  {
        val doc = processor.mkDocument(text)

        processor.tagPartsOfSpeech(doc)
        processor.lemmatize(doc)
        processor.recognizeNamedEntities(doc)

        val locations = doc.sentences.map(sentence => {
            val entities = sentence.entities.map(List.fromArray(_)) match {
                case Some(l) => l
                case _ => List()
            }
            val words = List.fromArray(sentence.words)

            (words zip entities).filter(x => {
                x._1 != "" && x._2 == "LOCATION" 
            }).map(_._1)
        })
        List.fromArray(locations).flatten
    }
}

我正在使用 sbt-assembly 构建一个 fat-jar,因此应该可以访问 joda-time jar 文件。怎么回事?

【问题讨论】:

    标签: apache-pig stanford-nlp


    【解决方案1】:

    Pig 附带了自己的 joda-time (1.6) 版本,它与 2.x 不兼容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-03
      • 2019-03-17
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多