Commit 0fe18527 authored by Romain Loth's avatar Romain Loth

minimal implementation of php reading db.json

parent 26ba9a7f
## Servermenu Configuration
#### minimal config
```json
"$$data/yourprojectdir": {
"graphs": {
"$$something.gexf":{
"node0": {"name": "$$blabla"}
}
}
}
```
#### to activate relatedDocs LocalDB queries
For a relatedDocs query, you need to add to your node entry the `reldbfile` key:
```json
"node0": {
"name": "$$blabla",
"reldbfile": "$$relpath/to/csv/or/sqlite"
}
```
......@@ -54,10 +54,8 @@
}
},
"data/politoscope": {
"dbname":null,
"title":"Politoscope",
"date":"2017",
"abstract":"",
"first" : "ProgrammeDesCandidats.enrichi.gexf",
"graphs": {
"ProgrammeDesCandidats.enrichi.gexf": {
......@@ -69,13 +67,12 @@
}
},
"data/ClimateChange": {
"abstract":"ISIABSTRACT",
"graphs": {
"Maps_S_800.gexf": {
"node0": {
"name": "ISItermsWhitelistV2Oct_5 & ISItermsWhitelistV2Oct_5",
"reldbtable": "ISItermsWhitelistV2Oct_5",
"reldbname" : "wos_climate-change_title_2014-2015.db",
"reldbfile" : "wos_climate-change_title_2014-2015.db",
"reldbtype": "CortextDB"
}
}
......
<?php
// default informations
$thedb = $graphdb;
$gexf=$_GET["gexf"];
$type = $_GET["type"];
$TITLE="ISITITLE";
$TITLE="ISITITLE"; // <=== hardcoded Cortext table /!\
$query = str_replace( '__and__', '&', $_GET["query"] );
$elems = json_decode($query);
// hardcoded CortextDB table /!\
$table = "";
$column = "";
$id="";
......@@ -19,15 +18,15 @@ $twjs="LOCALDB/"; // LOCALDB folder.
// echo("elems[0]: ".$elems[0]."<br/>");
// echo("is_array($elems): ".is_array($elems)."<br/>");
if($type=="social"){
$table = "ISIAUTHOR";
if($ndtype=="social"){
$table = "ISIAUTHOR"; // <== hardcoded CortextDB table /!\
$column = "data";
$id = "id";
$restriction='';
$factor=10;// factor for normalisation of stars
}
if($type=="semantic"){
if($ndtype=="semantic"){
$table = $_GET["index"];//"ISItermsfirstindexing";
$column = "data";
$id = "id";
......@@ -110,6 +109,7 @@ foreach ($wos_ids as $id => $score) {
if ($count<=$max_item_displayed){
$count+=1;
// hardcoded CortextDB table /!\
$sql = 'SELECT data FROM ISITITLE WHERE id='.$id.' group by data';
foreach ($base->query($sql) as $row) {
......@@ -120,7 +120,7 @@ foreach ($wos_ids as $id => $score) {
// echo '<a href="JavaScript:newPopup(\''.$twjs.'default_doc_details.php?gexf='.urlencode($gexf).'&index='.$table.'&query='.urlencode($query).'&type='.urlencode($_GET["type"]).'&id='.$id.' \')">'.$row['data']." </a> ";
}
// get the authors
// get the authors /!\ hardcoded CortextDB table /!\
$sql = 'SELECT data FROM ISIAUTHOR WHERE id='.$id;
foreach ($base->query($sql) as $row) {
$output.=($row['data']).', ';
......
<?php
// default path to ProjectExplorer root
// (where data directory and db.json file reside)
$mainpath=dirname(getcwd())."/../";
$ntypes = 2;
$project_menu_path = "db.json";
// reading db.json associations
// source graph file <=> (db, dbtype, cols) as relatedDocs php API
$project_menu_fh = fopen($mainpath.$project_menu_path, "r");
$json_st = '';
while (!feof($project_menu_fh)) {
$json_st .= fgets($project_menu_fh);
}
fclose($project_menu_fh);
$project_menu = json_decode($json_st);
// echodump("== db.json menu ==", $project_menu);
// parse db.json project menu and create a conf by file
$conf = array();
foreach ($project_menu as $project_dir => $dir_items){
// NB access by obj property (and not array key)
if (! property_exists($dir_items, 'graphs')) {
error_log("tw/phpAPI skip error: conf file ($project_menu_path)
has no 'graphs' entry for project '$project_dir' !");
continue;
}
foreach ($dir_items->graphs as $graph_file => $graph_conf){
// echodump("== $graph_file ==", $graph_conf);
# loading an associated db for a given gexf as relatedDocs php API
$gexf_db = array();
$gpath = $project_dir.'/'.$graph_file;
# £££TODO read the db.json
$gexf_db["data/ClimateChange/Maps_S_800.gexf"] = "data/ClimateChange/wos_climate-change_title_2014-2015.db";
$gexf_db["data/AXA/RiskV2PageRank1000.gexf"] = "data/AXA/data.db";
$gexf_db["data/AXA/RiskV2PageRank2500.gexf"] = "data/AXA/data.db";
$gexf_db["data/AXA/RiskV2PageRank5000.gexf"] = "data/AXA/data.db";
$gexf_db["data/test/mini_for_csv.gexf"] = "data/test/mini_for_csv.csv";
$gexf_db["data/gargistex/shale_and_ice.gexf"] = "data/gargistex/shale_and_ice.csv";
$gexf_db["data/gargistex/model_calibration.gexf"] = "data/gargistex/model_calibration.csv";
// NB a graph conf can now have different settings for each nodetype
// node0 <=> classic type 'semantic'
// node1 <=> classic type 'social'
// $gexf_db["data/ProgrammeDesCandidats.gexf"] = "foobar";
$conf[$gpath] = array($ntypes);
for ($i = 0 ; $i < $ntypes ; $i++) {
// check node0, node1, etc to see if they at least have a reldbfile
if (! property_exists($graph_conf, 'node'.$i)
|| ! property_exists($graph_conf->{'node'.$i}, 'reldbfile') ) {
$conf[$gpath][$i] = array('active' => false);
continue;
}
else {
// we have a file for this type: copy entire conf
$conf[$gpath][$i] = (array)$graph_conf->{'node'.$i};
$conf[$gpath][$i]['active'] = true;
$conf[$gpath][$i]['dir'] = $project_dir;
}
// POSS here info on higher level may be propagated for lower ones
// (ex: if dbtype is on the project level, its value should count
// for each source file in the project unless overridden)
}
}
}
// =======================================
// echodump("== READ CONF ==<br>", $conf);
// =======================================
$gexf= str_replace('"','',$_GET["gexf"]);
$ndtype = $_GET["type"];
$ntid = null;
// default path to ProjectExplorer root
// (where data directory and db.json file reside)
$mainpath=dirname(getcwd())."/../";
// legacy types => generic types
if ($ndtype == 'semantic') { $ntid = 0; }
else { $ntid = 1; }
$graphdb = $gexf_db[$gexf];
if (! $conf[$gexf][$ntid]['active']) {
echo("The relatedDocs configuration for your graph ($gexf) isn't active
(please read 00.DOCUMENTATION/A-Introduction/servermenu_config.md).<br>");
exit(1);
}
else {
$my_conf = $conf[$gexf][$ntid];
$graphdb = $my_conf['dir'].'/'.$my_conf['reldbfile'];
}
echodump("reldb", $graphdb);
// for csv parsing
$csvsep = "\t";
......@@ -39,7 +101,9 @@ $max_item_displayed = 7;
function echodump($title, $anyObj) {
echo "<br>".$title.": ";
echo (json_encode($anyObj, JSON_PRETTY_PRINT));
echo (preg_replace_callback("/\n(\s*)/", function($capt){
return('<br>'.str_repeat('&nbsp;', strlen($capt[0])));
}, json_encode($anyObj, JSON_PRETTY_PRINT)));
echo "<br>";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment