PHP code to access the Java API library

I need to use the Java-based OpenNLP library in my PHP code. For example, I need to use the Sentence Detector component (en-sent.bin) to parse text variables in my PHP code.

In the documentation, this API can be obtained from Java code as follows:

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) { } } } 

How to do the same in PHP?

In other words, what is the PHP equivalent of the above Java code?

+4
source share
2 answers

The solution I'm going to implement is to write a java-based backend (because only the output of the OpenNLP tool just won't cut it) and using the PHP runtime function to run it. If you want it to be even faster, I suggest making it a daemon, forcing PHP to connect to it and send its data to return (it will probably be a unix socket). Although it is quite complex, it seems less error prone than PHP / Java Bridge.

+2
source

To access OpenNLP, there must be a PHP API. A quick search shows nothing. The only thing I can think of is to use PHP / Java Bridge, but this is more important. For example, http://php-java-bridge.sourceforge.net/pjb/ .

+1
source

Source: https://habr.com/ru/post/1447230/


All Articles