set_include_path(get_include_path() . PATH_SEPARATOR . './easyrdf-0.9.0/lib/');
require_once "EasyRdf.php";
if($_POST['submit']=='Upload NIF file') {
$target_dir = "./uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$ok = 0;
$textFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// delete file
unlink($target_file);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.
";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 1000000) {
echo "Sorry, your file is too large.
";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.
";
// if everything is ok, try to upload file
} else {
if(is_uploaded_file($_FILES["fileToUpload"]["tmp_name"])) {
if(!copy($_FILES["fileToUpload"]["tmp_name"],$target_file)) {
echo "Sorry, there was an error uploading your file.
";
}
else {
$output_file = fopen("output.ttl","w");
$graph = new EasyRdf_Graph();
$graph->parseFile($target_file);
$resources = $graph->resources();
foreach($resources as $id) {
$text = $graph->getLiteral($id, new EasyRdf_Resource('http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#isString'));
if($text!=null) {
//echo "String:".$text." - Subject:".$id."
";
$fred_url = "http://wit.istc.cnr.it/stlab-tools/fred";
$sentence = $text;
$do_wsd = false;
$ask_semantic_subgraph = true;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $fred_url . "?text=" . urlencode($sentence) . "&wsd=" . $do_wsd . "&semantic-subgraph=" . $ask_semantic_subgraph);
curl_setopt($curl, CURLOPT_HEADER, 0);
$headers = array();
$headers[0] = "Accept: text/turtle";
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
fwrite($output_file,$output);
$ok = 1;
}
}
fclose($output_file);
}
}
}
}
//echo "CIAO".$graph->dump('html');
?>