diff --git a/lib/php/n3.php b/lib/php/n3.php deleted file mode 100644 index 4ffc9fa1..00000000 --- a/lib/php/n3.php +++ /dev/null @@ -1,14 +0,0 @@ - $b) { - if(is_numeric($a)) {$prefix=$b;$base_uri="http://bio2rdf.org/$prefix:";} - else {$prefix=$a;$base_uri=$b;} - $buf .= "@prefix $prefix: <$base_uri>.".PHP_EOL; - } - //$buf .= 'dc:identifier rdfs:subPropertyOf .'.PHP_EOL;; - return $buf; -} -?> \ No newline at end of file diff --git a/lib/php/ns.php b/lib/php/ns.php deleted file mode 100644 index 0f1ec058..00000000 --- a/lib/php/ns.php +++ /dev/null @@ -1,111 +0,0 @@ - $xsd_uri, $rdf => $rdf_uri, $rdfs => $rdfs_uri, $owl => $owl_uri, $dc => $dc_uri, $skos => $skos_uri,$foaf => $foaf_uri, $ss =>$ss_uri); - -$nslist = array( - $xsd => $xsd_uri, $rdf => $rdf_uri, $rdfs => $rdfs_uri, $owl => $owl_uri, $dc => $dc_uri, $skos => $skos_uri, $foaf=>$foaf_uri, $ss =>$ss_uri, - $afcs, $apo, $bind,$biogrid, $cas, $candida, $ctd,$dbsnp, $ddbj,$dip,$drugbank, $ec, $embl, $ensembl, $eco, - $euroscarf, $flybase, $kegg, $germonline, $go, $gp, $grid, - $ipi, $iubmb, $intact,$irefindex, $mesh, $metacyc,$mi,$mint,$mips, - $ncbi_gene, $refseq, $ncbi, $omim, $ophid, $pato, $pdb,$pharmgkb, $pir,$prf, $pubchem, $pubmed, - $so, $sgd, $sgd_resource, $sp, $taxon, $tcdb, $tigr, $tpg, $trembl, $uniparc, $uniprot, - "profilescan","superfamily","patternscan","blastprodom","fprintscan","gene3d","seg","hmmsmart","hmmpanther","hmmpfam","hmmpir","hmmtigr", - $bio2rdf => $bio2rdf_uri, $bio2rdfns => $bio2rdfns_uri, $serv, $uo, $registry, $registry_dataset -); - - -/* -bio2rdf predicates - -molecule -gene -protein -chemical -disease -organism -pathway -article - -url - -interactsWith - -*/ - -?> diff --git a/lib/php/oboparser_lib.php b/lib/php/oboparser_lib.php deleted file mode 100644 index 29d751e8..00000000 --- a/lib/php/oboparser_lib.php +++ /dev/null @@ -1,54 +0,0 @@ - \ No newline at end of file diff --git a/lib/php/rdf.php b/lib/php/rdf.php deleted file mode 100644 index f8004cfc..00000000 --- a/lib/php/rdf.php +++ /dev/null @@ -1,122 +0,0 @@ -'; -} - -function Statement($s, $p, $o, $dt = NULL) -{ - if(!is_null($dt)) { -return ' -<'.$p.'>'.$o.''; - } - return ' -<'.$p.' rdf:resource="'.$o.'"/>'; -} - - -function GetHeader($filename, $namespaces = NULL) -{ - -$a = ' - - - - - - - - - '; - if(isset($namespaces)) { - foreach($namespaces AS $prefix => $ns) { - $a .= ' - '; - } - } -$a .= ' -]> - - $ns) { - $a .= ' - xmlns:'.$prefix.'="'.$ns.'"'; - } - } - $a .= ' -> -'; - return $a; -} - -function GetFooter() -{ -return ' -'; -} -?> \ No newline at end of file diff --git a/lib/php/utils.php b/lib/php/utils.php deleted file mode 100644 index c247851d..00000000 --- a/lib/php/utils.php +++ /dev/null @@ -1,95 +0,0 @@ - - * @version 1.0.1 - * @link http://aidanlister.com/repos/v/function.copyr.php - * @param string $source Source path - * @param string $dest Destination path - * @return bool Returns TRUE on success, FALSE on failure - */ -function copyr($source, $dest) -{ - // Check for symlinks - if (is_link($source)) { - return symlink(readlink($source), $dest); - } - - // Simple copy for a file - if (is_file($source)) { - return copy($source, $dest); - } - - // Make destination directory - if (!is_dir($dest)) { - mkdir($dest); - } - - // Loop through the folder - $dir = dir($source); - while (false !== $entry = $dir->read()) { - // Skip pointers - if ($entry == '.' || $entry == '..') { - continue; - } - - // Deep copy directories - copyr("$source/$entry", "$dest/$entry"); - } - - // Clean up - $dir->close(); - return true; -} - -function GetDirFiles($dir,$pattern) -{ - if(!is_dir($dir)) { - echo "$dir not a directory".PHP_EOL; - return 1; - } - - $dh = opendir($dir); - while (($file = readdir($dh)) !== false) { - if($file == '.' || $file == '..') continue; - $files[] = $file; - } - sort($files); - closedir($dh); - return $files; -} - - -?> diff --git a/lib/php/virtuoso-instance-manager.php b/lib/php/virtuoso-instance-manager.php deleted file mode 100644 index 1223f6da..00000000 --- a/lib/php/virtuoso-instance-manager.php +++ /dev/null @@ -1,171 +0,0 @@ - $i) -{ - if($ns == 'all' && ($i['server'] != $server)) continue; - if($fnx == "create") Create($i); - else if($fnx == "start") Start($i); - else if($fnx == "stop") Stop($i); - else if($fnx == "config") $buf .= Config($i); - if($ns != 'all') break; -} -if($buf) file_put_contents($config_file,$buf); - - - - -function Create($instance) -{ - global $target_dir, $default_dir; - - $ns = $instance['ns']; - echo "Creating $ns ..."; - - // create the directory if it doesn't exist - system("mkdir -p $target_dir/instance/$ns/bin"); - system("mkdir -p $target_dir/instance/$ns/db"); - if(is_dir("$target_dir/instance/$ns")) { - // delete it - system("rm -rf $target_dir/instance/$ns/db/*"); -// system("rm -rf $target_dir/instance/$ns"); -// system("rm -f $target_dir/virtuoso.db/$ns.virtuoso.db"); - } - - // copy the executable and the config file - system("cp -f ".$default_dir."/bin/virtuoso-t $target_dir/instance/$ns/bin/t-$ns"); // copy the v-default to v-$ns - // copy the database - system("cp -f ".$default_dir."/bin/virtuoso.db $target_dir/virtuoso.db/$ns.virtuoso.db"); - - // now read in the virtuoso file and modify the db, www port and isql port - $inifile = $default_dir."/bin/virtuoso.ini"; - $buf = file_get_contents($inifile); - if($buf === FALSE) { - echo "Unable to read $inifile"; - exit; - } - $v = str_replace( - array( "virtuoso.db", "1111", "8890", "http://bio2rdf.org/ns"), - array( "/opt/test/virtuoso.db/$ns.virtuoso.db", - $instance['isql_port'], - $instance['www_port'], - "" - ), - $buf - ); - file_put_contents("$target_dir/instance/$ns/bin/virtuoso.ini",$v); - echo "done.".PHP_EOL; - - return 0; -} - -function Stop($instance) -{ - $ns = $instance['ns']; - - system("pgrep t-$ns"); - system("pkill t-$ns"); -} - -function Start($instance) -{ - global $target_dir; - - Stop($instance); - - // start it up - $ns = $instance['ns']; - $cmd = "cd $target_dir/instance/$ns/bin/;./t-$ns &"; - system($cmd); - system("pgrep t-$ns"); -} - - - -function GetInstancesFromFile(&$instances) -{ - global $instance_file; - $fp = fopen($instance_file,"r"); - while($l = fgets($fp)) { - $a = explode("\t",trim($l)); - $i["isql_port"] = $a[0]; - $i["www_port"] = $a[1]; - $i["server"] = $a[2]; - $i["ns"] = $a[3]; - - if($a[3] == '') continue; - $instances[$i['ns']] = $i; - } - fclose($fp); -} - -// file format -// isql_port\twww_port\tname\tserver\n -function WriteInstancesToFile($instances) -{ - global $instance_file; - - $buf = ''; - foreach($instances AS $ns => $i) { - $buf .= $i["isql_port"]."\t".$i["www_port"]."\t".$i["server"]."\t".$i["ns"]."\n"; - } - file_put_contents($instance_file,$buf); - return 0; -} - -function GetNextInstance(&$instance) -{ - GetInstancesFromFile($instances); - // the ports are ordered, so get the last one - $i = $instance = end($instances); - $instance["isql_port"] ++; - $instance["www_port"] ++; -} - - -function Config(&$instance) -{ -$ns = $instance['ns']; -$port = $instance['www_port']; - -$buf = ' - ServerName cu.'.$ns.'.bio2rdf.org - ServerAlias '.$ns.'.bio2rdf.org - ProxyRequests Off - - Order deny,allow - Allow from all - - ProxyPass / http://cu.'.$ns.'.bio2rdf.org:'.$port.'/ - ProxyPassReverse / http://cu.'.$ns.'.bio2rdf.org:'.$port.'/ - -'; - return $buf; -} -?> diff --git a/lib/php/virtuoso_load.php b/lib/php/virtuoso_load.php deleted file mode 100644 index 9889588e..00000000 --- a/lib/php/virtuoso_load.php +++ /dev/null @@ -1,302 +0,0 @@ - "filename", - "dir" => "dirname", - "graph" => "graphname", - "port" => "1111", - "user" => "dba", - "pass" => "dba", - "flags" => "272", - "threads" => "4", - "updatefacet" => "false", - "deletegraph" => "false", - "deleteonly" => "false", - "initialize" => "false", - "setns" => "false", - "format" => "n3", - "ignoreerror" => "true", - "startat" => "" -); - - -// show options -if($argc == 1) { - echo "Usage: php $argv[0] ".PHP_EOL; - foreach($options AS $key => $value) { - echo " $key=$value ". PHP_EOL; - } -} - -// set options from user input -foreach($argv AS $i=> $arg) { - if($i==0) continue; - $b = explode("=",$arg); - if(isset($options[$b[0]])) $options[$b[0]] = $b[1]; - else {echo "unknown key $b[0]";exit;} -} - -$cmd_pre = "$isql -S ".$options['port']." -U ".$options['user']." -P ".$options['pass']." verbose=on banner=off prompt=off echo=ON errors=stdout exec=".'"'; $cmd_post = '"'; - -// associate a prefix with namespace -// http://docs.openlinksw.com/virtuoso/fn_xml_set_ns_decl.html -if($options['setns'] == 'true') { - echo "Setting namespaces for facet browser\n"; - - include('ns.php'); - $cmd = ''; - foreach($nslist AS $prefix => $base_uri) { - if($prefix == 'bio2rdf') continue; - $cmd .= "DB.DBA.XML_SET_NS_DECL ('$prefix', '$base_uri', 2);"; - } - echo $out = shell_exec($cmd_pre.$cmd.$cmd_post); - exit; -} - - -// do delete graph option -if($options['deletegraph'] == "true" && $options['graph'] != "graphname") { - $cmd = "log_enable(3,1);sparql clear graph <".$options['graph'].">"; - echo "Deleting ".$options['graph'].PHP_EOL; - echo $out = shell_exec($cmd_pre.$cmd.$cmd_post); - if($options['deleteonly'] == "true") exit; -} - -// check for valid file -if($options['dir'] == 'dirname') { - // must be a file - if(!file_exists($options['file'])) { - echo "File ".$options['file']." does not exists. Please specify a *real* file with the file=filename option\n"; - exit; - } - $files[] = $options['file']; -} else { - if(!is_dir($options['dir'])) { - echo "Directory ".$options['dir']." does not exists. Please specify a *real* directory with the dir=dirname option\n"; - exit; - } - // get the files - $files = GetFiles($options['dir']); - $files = getFileR($options['dir']); -} - - -// add file to graph -if($options['format'] == 'n3') { - // http://docs.openlinksw.com/virtuoso/fn_ttlp_mt.html - $program = "DB.DBA.TTLP_MT"; -// $program = "DB.DBA.TTLP_MT_LOCAL_FILE"; -} else { - // http://docs.openlinksw.com/virtuoso/fn_rdf_load_rdfxml_mt.html - $program = 'DB.DBA.RDF_LOAD_RDFXML_MT'; -} - -foreach($files AS $file) { - if($options['startat'] != '') { - if($options['startat'] == $file) { $options['startat'] = ''; } - else continue; - } - - echo 'Processing '.$file."\n"; - - // if the graph has not been set, then create a graph name from the file, minus path and extension - $graph = $options['graph']; - if($graph == "graphname") { - $pos = strrpos($file,"/"); - if($pos !== FALSE) { - $graph = substr($file,$pos+1); - } - $pos = strpos($graph,"."); - if($pos !== FALSE) { - $graph = substr($graph,0,$pos); - } - $graph = "http://bio2rdf.org/graph/".$graph; - } - - - // delete individual graphs - if($options['deletegraph'] == "true" && $options['graph'] == "graphname") { - $cmd = "log_enable(3,1);sparql clear graph <$graph>"; - echo "Deleting ".$graph.PHP_EOL; - echo $out = shell_exec($cmd_pre.$cmd.$cmd_post); - } - - echo 'Adding '.$file."\n"; - - $path = ''; - $pos = strrpos($file,"/"); - if($pos !== FALSE) { - $path = substr($file,0, $pos+1); - } - - $errors = 0; - $f = $file; - $fcmd = 'file_to_string_output'; - if(strstr($file,".gz")) { - $gzfile = $file; - $un = substr($file,0,-3); - - $out = fopen($un,"w"); - $in = gzopen($file,"r"); - while($l = gzgets($in)) { - fwrite($out,$l); - } - fclose($out); - gzclose($in); - - $f = $un; - } elseif(strstr($file,".bz")) { - $bzfile = $file; - $un = substr($file,0,-3); - $out = fopen($un,"w"); - $in = bzopen($file,"r"); - while($l = bzread($in)) { - fwrite($out,$l); - } - fclose($out); - bzclose($in); - $f = $un; - } - - $t1 = $path."t1.txt"; // the source - $t2 = $path."t2.txt"; // the destination - if(file_exists($t1)) unlink($t1); - if(file_exists($t2)) unlink($t2); - - do { - echo "Loading $file into $graph ...".PHP_EOL; - $cmd = $program."($fcmd ('$f'), '', '".$graph."', ".$options['flags'].", ".$options['threads']."); checkpoint;"; -// echo $cmd_pre.$cmd.$cmd_post; - $out = shell_exec($cmd_pre.$cmd.$cmd_post); - - if(strstr($out,"Error")) { - $errors ++; - if($errors > 5) { - trigger_error("Tried five times - quitting!"); - break; - } - - - // *** Error 37000: [Virtuoso Driver][Virtuoso Server]SP029: TURTLE RDF loader, line 43: syntax error - preg_match("/Error ([0-9]+)\:/",$out,$m); - if(!isset($m[1]) || (isset($m[1]) && $m[1] != '37000')) { - // some other error - echo $out; - exit; - } - - preg_match("/line\s([0-9]+)\:/",$out,$m); - if(!isset($m[1])) { - // some problem here - exit; - } - - $line = $m[1]; - // write to log? - echo "Skipping line:$line ... "; - - // we need find find the line number, and slice the file - if(!file_exists($t1)) { - // first use - echo "making copy of $f\n"; - copy($f,$t1); - } - if(file_exists($t2)) { - unlink($t1); - rename($t2,$t1); - } - $fp_in = fopen($t1,"r"); - $fp_out = fopen($t2,"w"); - $i = 0; - while($l = fgets($fp_in,4096)) { - $i++; - if($i == $line) echo "Problem in: $l\n"; - if($l[0] == '@' || $i > $line) { - fwrite($fp_out,$l); - } - } - fclose($fp_in); - fclose($fp_out); - $f=$t2; - } else { - if(file_exists($t1)) unlink($t1); - if(file_exists($t2)) unlink($t2); - echo "Done!\n"; - break; - } - } while (true); - - if(strstr($file,".gz") || strstr($file,".bz")) { - if(file_exists($f)) unlink($f); - } - echo PHP_EOL; - -} - - -// Facet update : http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtFacetBrowserInstallConfig -if($options['updatefacet'] == "true") { - $cmd = "RDF_OBJ_FT_RULE_ADD (null, null, 'All');VT_INC_INDEX_DB_DBA_RDF_OBJ ();urilbl_ac_init_db();"; - echo "Updating facet"; - echo $out = shell_exec($cmd_pre.$cmd.$cmd_post); -} - - -if($options['initialize'] == 'true') { - $cmd = "drop index RDF_QUAD_OPGS;drop index RDF_QUAD_POGS;drop index RDF_QUAD_GPOS;drop index RDF_QUAD_OGPS;checkpoint; - create table R2 (G iri_id_8, S iri_id_8, P iri_id_8, O any, primary key (S, P, O, G)); alter index R2 on R2 partition (S int (0hexffff00)); - log_enable (2); insert into R2 (G, S, P, O) select G, S, P, O from RDF_QUAD; - drop table RDF_QUAD; alter table R2 rename RDF_QUAD; checkpoint; - create bitmap index RDF_QUAD_OPGS on RDF_QUAD (O, P, G, S) partition (O varchar (-1, 0hexffff)); - create bitmap index RDF_QUAD_POGS on RDF_QUAD (P, O, G, S) partition (O varchar (-1, 0hexffff)); - create bitmap index RDF_QUAD_GPOS on RDF_QUAD (G, P, O, S) partition (O varchar (-1, 0hexffff)); - checkpoint;"; - -} - -function GetFiles($dirname) -{ - $d = dir($dirname); - while (false !== ($e = $d->read())) { - if($e == '.' || $e == '..') continue; - $files[] = $dirname.$e; - } - sort($files); - $d->close(); - return $files; -} - -function getFileR($directory, $recursive=true) { - //This function generates an array of paths to the files of extension $extension - $array_items = array(); - if ($handle = opendir($directory)) { - while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != "..") { - if (is_dir($directory. "/" . $file)) { - if($recursive) { - $array_items = array_merge($array_items, getFileR($directory. "/" . $file, $recursive)); - }//if - $file = $directory . "/" . $file; - if(is_file($file)){ - $array_items[] = preg_replace("/\/\//si", "/", $file); - } - - } else { - $file = $directory . "/" . $file; - if(is_file($file)){ - $array_items[] = preg_replace("/\/\//si", "/", $file); - } - }//else - }//if - }//while - closedir($handle); - }//if - return $array_items; -}//getFileR -?>