Beispiel #1
0
Author: Zuoshuang Xiang
The University Of Michigan
He Group
Date: June 2008 - March 2013
Purpose: Remote call back of Sparql section.
-->

<?php 
//Use curl to do a post request
function curl_post_contents($url, $fields)
{
    //open connection
    $ch = curl_init();
    $fields_string = http_build_query($fields);
    //set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    //execute post
    $result = curl_exec($ch);
    //close connection
    curl_close($ch);
    return $result;
}
$fields = array();
foreach ($_REQUEST as $key => $value) {
    $fields[$key] = stripslashes($value);
}
print curl_post_contents('http://sparql.hegroup.org/sparql', $fields);
Beispiel #2
0
function json_query($querystring, $endpoint = NULL)
{
    global $settings;
    $fields = array();
    $fields['default-graph-uri'] = '';
    $fields['format'] = 'application/sparql-results+json';
    $fields['debug'] = 'on';
    $fields['query'] = $querystring;
    if ($endpoint == NULL) {
        $endpoint = $settings['remote_store_endpoint'];
    }
    //error_log($querystring, 3, '/tmp/error.log');
    $json = curl_post_contents($endpoint, $fields);
    $json = json_decode($json);
    $results = array();
    if (isset($json->results->bindings)) {
        foreach ($json->results->bindings as $binding) {
            $binding = get_object_vars($binding);
            $result = array();
            foreach ($binding as $key => $value) {
                $result[$key] = $value->value;
            }
            $results[] = $result;
        }
    }
    return $results;
}
Beispiel #3
0
 if (!empty($related_terms)) {
     foreach ($related_terms as $tmp_iri => $tmp_label) {
         $querystring = "\r\nCONSTRUCT {\r\n<{$tmp_iri}> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o.\r\n<{$tmp_iri}> <http://www.w3.org/2000/01/rdf-schema#label> ?o1\r\n}\r\n\r\nFROM <{$ontology_uri}>";
         if (isset($array_imports[$ontology_uri])) {
             foreach ($array_imports[$ontology_uri] as $import_graph_uri) {
                 $querystring .= "\r\nFROM <{$import_graph_uri}>\r\n";
             }
         }
         $querystring .= "\r\nWHERE { \r\n{<{$tmp_iri}> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o}\r\nUNION {<{$tmp_iri}> <http://www.w3.org/2000/01/rdf-schema#label> ?o1}\r\n}";
         $fields = array();
         $fields['default-graph-uri'] = $ontology_uri;
         $fields['format'] = 'application/rdf+xml';
         $fields['debug'] = 'on';
         $fields['query'] = $querystring;
         //				print("<!--$querystring-->\n");
         $rdf = curl_post_contents($server_import, $fields);
         //				print("<!--$rdf-->\n");
         if (preg_match_all('/<rdf:Description.*?rdf:Description>/', $rdf, $matches)) {
             foreach ($matches[0] as $line) {
                 $strOutput .= "\n{$line}";
             }
         }
     }
 }
 if (empty($fileNames) && sizeof($str_inputs2) == 1) {
     $fileName = $finalFile;
 } else {
     $fileName = createRandomPassword();
 }
 $tmpOutputURI = "http://ontofox.hegroup.org/{$fileName}.owl";
 if (empty($fileNames) && $outputURI != '' && sizeof($str_inputs2) == 1) {
Beispiel #4
0
<rdf:RDF';
                foreach ($outputNSs as $NSTmp => $prefixTmp) {
                    $rdf_header .= "\n  xmlns:{$prefixTmp}=\"{$NSTmp}\"";
                }
                $strOutput = "{$rdf_header} >\n<owl:Ontology rdf:about=\"" . preg_replace('/\\/obo\\//', "/obo/{$o}/about/", $iri) . "\">\n</owl:Ontology>\n{$strOutput}\n</rdf:RDF>";
                if (strpos($_SERVER['HTTP_ACCEPT'], 'application/rdf+xml') !== false) {
                    header("Content-type: application/rdf+xml");
                } elseif (strpos($_SERVER['HTTP_ACCEPT'], 'application/xml') !== false) {
                    header("Content-type: application/xml");
                } else {
                    header("Content-type: text/xml");
                }
                $filename = createRandomPassword();
                //				file_put_contents("/tmp/$filename.in", $strOutput);
                $strOutput = curl_post_contents("http://141.211.109.48:8080/Ontobee/Reformat.jsp", array("ifile" => $strOutput));
                //				$strOutput = file_get_contents("http://141.211.109.48:8080/Ontobee/Reformat.jsp?ifile=/tmp/$filename.in");
                //				$strOutput = file_get_contents("/tmp/$filename.out");
                $strOutput = str_replace('<rdf:RDF', '<?xml-stylesheet type="text/xsl" href="/browser/xslt.php?o=' . $o . '&amp;iri=' . myUrlEncode($iri) . '"?>
<rdf:RDF', $strOutput);
                $strOutput = str_replace('</owl:Ontology>', '    <owl:imports rdf:resource="' . $settings['ns_main_original'] . '"/>
    </owl:Ontology>', $strOutput);
                print $strOutput;
                //<owl:imports rdf:resource=\"".$settings['ns_main_original']."\"/>
            } else {
                // can not find this term
                header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
                include '404.php';
            }
        } else {
            header("Content-type: text/xml");
Beispiel #5
0
function json_query($querystring, $endpoint = NULL)
{
    global $settings;
    $fields = array();
    $fields['default-graph-uri'] = '';
    $fields['format'] = 'application/sparql-results+json';
    $fields['debug'] = 'on';
    $fields['query'] = $querystring;
    if ($endpoint == NULL) {
        $endpoint = $settings['remote_store_endpoint'];
    }
    //	print($querystring);
    //error_log($querystring, 3, '/tmp/error.log');
    $json = curl_post_contents($endpoint, $fields);
    //	print($json);
    return parse_json_query($json);
}
Beispiel #6
0
    $num_queries = 0;
    $settings = getSettings($o);
    $ontology_full_name = $settings['ontology_fullname'];
    $all_graphs = array($settings['ns_main'] => 1);
    $strQueryPrint = '';
    $iri = myUrlDecode($iri);
    $querystring = "\nDEFINE sql:describe-mode \"CBD\" \ndescribe <{$iri}>\nFROM <{$settings['ns_main']}>\n";
    $strQueryPrint .= $querystring . '
===================================================================		
';
    $fields = array();
    $fields['default-graph-uri'] = '';
    $fields['format'] = 'application/rdf+json';
    $fields['debug'] = 'on';
    $fields['query'] = $querystring;
    $query_results = curl_post_contents($settings['remote_store_endpoint'], $fields);
    //virtuoso bug??
    $query_results = preg_replace('/\'\\);\\ndocument.writeln\\(\'/', '', $query_results);
    $term_cbd = json_decode($query_results, true);
    if (isset($term_cbd[$iri])) {
        $main_label = getRDFjsonDetail($term_cbd, $iri, $settings['ns_rdfs'] . 'label', array(), false);
        $a_term_type = preg_split('/, /', getRDFjsonDetail($term_cbd, $iri, $settings['ns_rdf'] . 'type', array(), false));
        $term_type = 'Instance';
        for ($i = 0; $i < sizeof($a_term_type); $i++) {
            if (in_array($a_term_type[$i], array('Class', 'ObjectProperty', 'DatatypeProperty', 'AnnotationProperty'))) {
                $term_type = $a_term_type[$i];
                unset($a_term_type[$i]);
                break;
            }
        }
        if ($term_type == '') {