4

我需要在我的PHP代码中使用基于Java的 OpenNLP 库。例如,我需要使用它的 Sentence Detector 组件 (en-sent.bin) 来分析我的 PHP 代码中的文本变量。

在其文档中,可以从Java代码访问该 API,如下所示:

InputStream modelIn = new FileInputStream("en-sent.bin");

try {
  SentenceModel model = new SentenceModel(modelIn);
}
catch (IOException e) {
  e.printStackTrace();
}
finally {
  if (modelIn != null) {
    try {
      modelIn.close();
    }
    catch (IOException e) {
    }
  }
}

如何在PHP中做同样的事情?

换句话说,与上述Java代码等效的PHP是什么?

4

2 回答 2

2

The solution I'm about to implement is writing a java based backend (because just the OpenNLP tool's output just won't cut it) and using PHP's execute function to run it. If you want it to be even faster, I suggest making it a daemon, making PHP connect to it and send it data to return (it'd probably be a unix socket). Although it's kinda complex, it seems less error prone than a PHP/Java Bridge.

于 2014-05-26T22:30:25.030 回答
1

必须有一个 PHP API 才能访问 OpenNLP。快速搜索不显示任何内容。我能想到的唯一另一件事是使用某种 PHP/Java 桥接器,但这涉及更多。例如,参见http://php-java-bridge.sourceforge.net/pjb/ 。

于 2012-11-20T13:58:43.933 回答