PHP Open Information extraction (relation extraction) to retrieve subject verb object triples by loading JAR file and passing arguments

83 views Asked by At

I have searched for PHP based information extraction approach but I could not find. Several inquiries by others remain unanswered. For example: https://www.codeproject.com/Questions/996885/how-to-extract-triples-text-in-php

I am writing a PHP script to analyse posts on a web forum. I would like to perform Open Information Extraction by extracting the triples (subject-verb object).

It seems hard to integrate NLP libraries with the necessary features in PHP. There are some NLP libraries, but none offer triple extraction (relation extraction). With this feature, I can get closer to understanding and capturing their sentiments. I was hoping to use the ClausIE tool to extract subject-verb-object triples (https://gate.d5.mpi-inf.mpg.de/ClausIEGate/ClausIEGate/). This library can capture who wants to do what, for example, it would help us extract these triple - "I" (subject) "shoot" (verb) "myself" (object) from the sentence "I want to shoot myself".

I have been trying for a week now to call this jar file from within PHP. I think the exec() function can be used. But I don't know how to call the jar file and pass arguments at the same time.

Calling the clausie.jar directly wasnt working as it does not accept arguments. So I used the sample script provided by the library - example.java and compiled it into a jar file, and I am not trying to call that jar file.

I have written some code and am trying to implement code from here but nothing prints out when I try to execute the line that executes the exec function calling the jar file.

<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
echo "Hello World!";

exec('java -jar example.jar I shot Tom' . implode(' ', $theOutput));
//######## Nothing shows up as result 
print($theOutput)

exec("java -jar example.jar 'i kill tom'", $output);
print_r($output); 
// THE ABOVE LINE OUTPUTS Array()
// Then I tried to print the elements of the array, but nothing gets printed

$newLangs = implode($output);
print_r($newLangs);

foreach ($output as $value) {
   print_r ($value);
}

//Also no output in the output file from this line
//exec("java -jar clausie.jar 'I will kill myself' > output.txt", $output);
//print_r($output);

?>
</body>
</html>

But this does not work for some reason. Nothing is output. Maybe I am not passing parameters to the clausie.jar in the right way? There is an Example.java in src directory in the ClausIE Code zip file which shows how to pass arguments - buts thats from within Java.

The same jar file executed at the command prompt works.

c:\code>java -jar example.jar "I want to kill tom"
Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ... done [0.6 sec].
# CLAUSE DETECTION
#   Dict. copular        : 25 (be, prove, sound, ...)
#   Dict. ext-copular    : 31 (love, be, prove, ...)
#   Dict. not ext.-cop.  : 2 (die, walk)
#   Dict. complex trans. : 15 (set, lay, bring, ...)
#   Dict. ignored adverb : 6 (as, thus, even, ...)
#   Dict. included adverb: 5 (seldom, barely, scarcely, ...)
#   Dict. conj adverbs   : 0
#   Conservative SVA     : true
#   Conservative SVOA    : false
#   Process all verb CCs : true
#   Process non-verb CCs : false
#   Process appositions  : true
#   Process possessives  : true
#   Process partmods     : true
#
# REPRESENTATION
#   n-ary propositions  : false
#   Min. opt. args      : 0
#   Max. opt. args      : 1
#   Lemmatize           : false
#   Appositions verb    : "is"
#   Possessive verb     : "has"
Input sentence   : I want to kill tom
Parse time       : 0.144s
Dependency parse : (ROOT
                     (S
                       (NP (PRP I))
                       (VP (VBP want)
                         (S
                           (VP (TO to)
                             (VP (VB kill)
                               (NP (NN tom))))))))
Semantic graph   : [want/VBP nsubj:I/PRP xcomp:[kill/VB aux:to/TO dobj:tom/NN]]
ClausIE time     : 0.008s
Clauses          : SVO (V: want@2, S: I@1, XCOMP: kill@4)
Propositions     : ("I", "want", "to kill tom")

I would be grateful if someone could assist in calling a jar file and passing arguments in PHP.

ClausIE tool online demo - https://gate.d5.mpi-inf.mpg.de/ClausIEGate/ClausIEGate/ Website: https://www.mpi-inf.mpg.de/departments/databases-and-information-systems/research/ambiverse-nlu/clausie ClausIE Code: http://resources.mpi-inf.mpg.de/d5/clausie/clausie-0-0-1.zip

0

There are 0 answers