Skip to content

Commit

Permalink
Added functionality to calculate the classpath in order to include th…
Browse files Browse the repository at this point in the history
…e slf4j jar files
  • Loading branch information
Bryan Gruneberg committed Jan 15, 2016
1 parent 51f99f1 commit 80d96b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/StanfordNLP/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/StanfordNLP/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "'
Expand Down
6 changes: 4 additions & 2 deletions src/StanfordNLP/StanfordTagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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 "
Expand All @@ -156,6 +156,8 @@ public function batchTag($sentences)
break;
}

echo "Running: " . $cmd . "\n";

$process = proc_open($cmd, $descriptorspec, $pipes, dirname($this->getJar()));

$output = null;
Expand Down

0 comments on commit 80d96b7

Please sign in to comment.