0

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

从标注器 edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distim.tagger 加载默认属性 从 edu/stanford/nlp/models/pos-tagger/english-left3words/english 读取 POS 标注器模型-left3words-distim.tagger 从 edu/stanford/nlp/models/ner/english.all.3class.distim.crf.ser.gz 2013-06-14 10:47:54,952 [通信线程] INFO 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 [Low Memory Detector] INFO 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 [Low Memory Detector] INFO org.apache.pig .impl.util.SpillableMemoryManager - 第一个内存处理程序调用 - 使用阈值初始化 = 18546688(18112K) 已使用 = 590012928(576184K) 已提交 = 597786624(583776K) 最大值 = 699072512(682688K) 已完成 [5.6 秒]。2013-06-14 10:48:11,469 [Thread-11] 警告 org.apache.hadoop.mapred.LocalJobRunner - job_local_0001 java.lang.NoSuchMethodError: org.joda.time.Duration.compareTo(Lorg/joda/time/ReadableDuration ;)我在 edu.stanford.nlp.time.SUTime$Duration.max(SUTime.java:3488) 在 edu.stanford.的 edu.stanford.nlp.time.SUTime$Duration.compareTo(SUTime.java:3406)。 nlp.time.SUTime$Time.difference(SUTime.java:1308) 在 edu.stanford.nlp.time.SUTime$Range.(SUTime.java:3793) 在 edu。

以下是相关代码:

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 文件。到底是怎么回事?

4

1 回答 1

0

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

于 2013-07-03T12:12:54.690 回答