From 80d96b71b6e5b112892e3ffa476056386d7891fc Mon Sep 17 00:00:00 2001 From: Bryan Gruneberg Date: Fri, 15 Jan 2016 20:58:03 +0200 Subject: [PATCH] Added functionality to calculate the classpath in order to include the slf4j jar files --- src/StanfordNLP/Base.php | 20 ++++++++++++++++++++ src/StanfordNLP/Parser.php | 2 +- src/StanfordNLP/StanfordTagger.php | 6 ++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/StanfordNLP/Base.php b/src/StanfordNLP/Base.php index 558fdc9..72c996b 100644 --- a/src/StanfordNLP/Base.php +++ b/src/StanfordNLP/Base.php @@ -121,6 +121,26 @@ public function getJar() return $this->jar; } + /** + * JavaCP getter + * + * Added by bryangruneberg to fix the code that calls JAVA + * + * @return mixed + */ + public function getJarCP() + { + $osSeparator = $this->php_os == 'windows' ? ';' : ':'; + $path_parts = pathinfo($this->getJar()); + print_r($path_parts); + + $CP = $path_parts["dirname"] . DIRECTORY_SEPARATOR . "lib/slf4j-api.jar" . $osSeparator + . $path_parts["dirname"] . DIRECTORY_SEPARATOR . "lib/slf4j-simple.jar" . $osSeparator + . $this->getJar() . $osSeparator; + + return $CP; + } + /** * Models Jar setter * diff --git a/src/StanfordNLP/Parser.php b/src/StanfordNLP/Parser.php index 22f50d4..e435efd 100644 --- a/src/StanfordNLP/Parser.php +++ b/src/StanfordNLP/Parser.php @@ -91,7 +91,7 @@ public function parseSentences($sentences) $osSeparator = $this->php_os == 'windows' ? ';' : ':'; $cmd = $this->getJavaPath() . " $options -cp \"" - . $this->getJar() + . $this->getJarCP() . $osSeparator . $this->getModelsJar() . '" edu.stanford.nlp.parser.lexparser.LexicalizedParser -encoding UTF-8 -outputFormat "' diff --git a/src/StanfordNLP/StanfordTagger.php b/src/StanfordNLP/StanfordTagger.php index 29e41b4..e577375 100644 --- a/src/StanfordNLP/StanfordTagger.php +++ b/src/StanfordNLP/StanfordTagger.php @@ -132,7 +132,7 @@ public function batchTag($sentences) $cmd = escapeshellcmd( $this->getJavaPath() . " $options -cp \"" - . $this->getJar() + . $this->getJarCP() . "{$osSeparator}\" edu.stanford.nlp.tagger.maxent.MaxentTagger -model " . $this->getModel() . " -textFile " @@ -146,7 +146,7 @@ public function batchTag($sentences) $cmd = escapeshellcmd( $this->getJavaPath() . " $options -cp \"" - . $this->getJar() + . $this->getJarCP() . "{$osSeparator}\" edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier " . $this->getClassifier() . " -textFile " @@ -156,6 +156,8 @@ public function batchTag($sentences) break; } + echo "Running: " . $cmd . "\n"; + $process = proc_open($cmd, $descriptorspec, $pipes, dirname($this->getJar())); $output = null;