Commit 6977cfef authored by Romain Loth's avatar Romain Loth

reconnected settings choice for topPapers API 'localDB'

parent c2af00d8
<?php
// default informations
// default informations
$thedb = $graphdb;
$gexf=$_GET["gexf"];
$max_item_displayed=6;
......@@ -9,13 +9,16 @@ $TITLE="ISITITLE";
$query = str_replace( '__and__', '&', $_GET["query"] );
$elems = json_decode($query);
$table = "";
$column = "";
$id="";
$twjs=end( explode("/",getcwd()) )."/"; // LOCALDB folder.
// $twjs=end( explode("/",getcwd()) )."/"; // LOCALDB folder.
$twjs="LOCALDB/"; // LOCALDB folder.
// echo("count(elems): ".count($elems)."<br/>");
// echo("elems[0]: ".$elems[0]."<br/>");
// echo("is_array($elems): ".is_array($elems)."<br/>");
if($type=="social"){
$table = "ISIAUTHOR";
......@@ -46,7 +49,7 @@ if (count($elems)==1){// un seul mot est sélectionné, on compte les mots multi
#$querynotparsed=$sql;#####
$sql = substr($sql, 0, -3);
$sql = str_replace( ' & ', '" OR '.$column.'="', $sql );
$sql.=' COLLATE NOCASE ) '.$restriction.'
$sql.=' COLLATE NOCASE ) '.$restriction.'
GROUP BY '.$id.'
ORDER BY count('.$id.') DESC
LIMIT 1000';
......@@ -54,6 +57,7 @@ if (count($elems)==1){// un seul mot est sélectionné, on compte les mots multi
$factor=ceil(count($elems)/5); //les scores sont moins haut
$sql='';
foreach($elems as $elem){
// echo("elem: ".$elem."<br/>");
$sql.=' '.$column.'="'.$elem.'" OR ';
}
$sql=substr($sql, 0, -3);
......@@ -70,14 +74,15 @@ $sum=0;
// echo "<br>";
// echo "$sql";
// echo "<br>";
//The final query!
// array of all relevant documents with score
foreach ($base->query($sql) as $row) {
foreach ($base->query($sql) as $row) {
// on pondère le score par le nombre de termes mentionnés par l'article
//$num_rows = $result->numRows();
$wos_ids[$row[$id]] = $row["count(*)"];
$sum = $row["count(*)"] +$sum;
......@@ -86,19 +91,19 @@ foreach ($base->query($sql) as $row) {
// /// nombre de document associés $related
$total_count=0;
$count_max=500;
$count_max=500;
$number_doc=count($wos_ids);
$count=0;
$all_terms_from_selected_projects=array();// list of terms for the top 6 project selected
// to filter under some conditions
$to_display=true;
$to_display=true;
$count=0;
foreach ($wos_ids as $id => $score) {
foreach ($wos_ids as $id => $score) {
if ($total_count<$count_max) {
// retrieve publication year
if ($to_display){
$total_count+=1;
......@@ -108,9 +113,9 @@ foreach ($wos_ids as $id => $score) {
$sql = 'SELECT data FROM ISITITLE WHERE id='.$id.' group by data';
foreach ($base->query($sql) as $row) {
$external_link="<a href=http://google.com/webhp?#q=".urlencode('"'.$row['data'].'"')." target=blank>".' <img width=15px src="libs/img2/google.png"></a>';
$external_link="<a href=http://google.com/webhp?#q=".urlencode('"'.$row['data'].'"')." target=blank>".' <img width=15px src="libs/img2/google.png"></a>';
$output.="<li title='".$score."'>";
$output.=$external_link.imagestar($score,$factor,$twjs).' ';
$output.=$external_link.imagestar($score,$factor,$twjs).' ';
$output.='<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> ";
// 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> ";
}
......@@ -121,7 +126,7 @@ foreach ($wos_ids as $id => $score) {
$output.=($row['data']).', ';
}
$output = rtrim($output, ", ");
$output.="</li><br>";
$output.="</li><br>";
}
}
......@@ -163,7 +168,7 @@ $output .= "</ul>"; #####
// // if (($project_folder=='nci')&&(count($elems)<$max_selection_size)){
// // // for NCI we compare the impact and novelty score making the difference if there are more than 4 terms selected
// // $news='';//new terms
// // $terms_from_selected_projects=array_unique($all_terms_from_selected_projects);
// // $terms_from_selected_projects=array_unique($all_terms_from_selected_projects);
// // if(count($terms_from_selected_projects)>3){
// // $diff=array();
// // foreach ($terms_from_selected_projects as $key => $term) {
......@@ -179,7 +184,7 @@ $output .= "</ul>"; #####
// // }
// // $diff[$term]=info($nov,$imp); //positive si c'est un term novelty, negatif si c'est un terme impact.
// // //echo $term.'-nov: '.$nov.'- imp:'.$imp.'<br/>';//'-info'.$diff[$term].
// // }
// // }
// // if (true){
// // arsort($diff);
......@@ -189,39 +194,39 @@ $output .= "</ul>"; #####
// // for ($i=0;$i<$top_displayed;$i++){
// // // on récupère les titres du document qui a le plus for impact
// // $sql="SELECT ISIterms.id,ISIC1_1.data,count(*) from ISIterms,ISIpubdate,ISIC1_1 where ISIterms.data='".$res[$i]."' AND ISIterms.id=ISIpubdate.id AND ISIterms.id=ISIC1_1.id AND ISIpubdate.data='2011' group by ISIterms.id ORDER BY RANDOM() limit 1";
// // $sql="SELECT ISIterms.id,ISIC1_1.data,count(*) from ISIterms,ISIpubdate,ISIC1_1 where ISIterms.data='".$res[$i]."' AND ISIterms.id=ISIpubdate.id AND ISIterms.id=ISIC1_1.id AND ISIpubdate.data='2011' group by ISIterms.id ORDER BY RANDOM() limit 1";
// // //on récupère les id associés.
// // foreach ($corporadb->query($sql) as $row){
// // $sql2='SELECT ISIpubdate.id,ISIC1_1.data from ISIpubdate,ISIC1_1 where ISIC1_1.data="'.$row['data'].'" AND ISIpubdate.id=ISIC1_1.id AND ISIpubdate.data="2013" limit 1';
// // //echo $sql2;
// // foreach ($corporadb->query($sql2) as $row2){
// // $nov_string.='<a href="JavaScript:newPopup(\''.$twjs.'php/default_doc_details.php?db='.urlencode($graphdb).'&gexf='.urlencode($gexf).'&query='.urlencode('["'.$res[$i].'"]').'&type='.urlencode($_GET["type"]).'&id='.$row2['id'].' \')">'.$res[$i]."</a>, ";
// // }
// // $nov_string.='<a href="JavaScript:newPopup(\''.$twjs.'php/default_doc_details.php?db='.urlencode($graphdb).'&gexf='.urlencode($gexf).'&query='.urlencode('["'.$res[$i].'"]').'&type='.urlencode($_GET["type"]).'&id='.$row2['id'].' \')">'.$res[$i]."</a>, ";
// // }
// // }
// // }
// // }
// // $news.='<br/><b><font color="#FF0066">Top '.$top_displayed.' Novelty related terms </font></b>'.$nov_string.'<br/>';
// // asort($diff);
// // $res=array_keys($diff);
// // asort($diff);
// // $res=array_keys($diff);
// // $res_string='';
// // for ($i=0;$i<$top_displayed;$i++){
// // // on récupère les titres du document qui a le plus for impact
// // $sql="SELECT ISIterms.id,ISIC1_1.data,count(*) from ISIterms,ISIpubdate,ISIC1_1 where ISIterms.data='".$res[$i]."' AND ISIterms.id=ISIpubdate.id AND ISIterms.id=ISIC1_1.id AND ISIpubdate.data='2012' group by ISIterms.id ORDER BY RANDOM()limit 1";
// // $sql="SELECT ISIterms.id,ISIC1_1.data,count(*) from ISIterms,ISIpubdate,ISIC1_1 where ISIterms.data='".$res[$i]."' AND ISIterms.id=ISIpubdate.id AND ISIterms.id=ISIC1_1.id AND ISIpubdate.data='2012' group by ISIterms.id ORDER BY RANDOM()limit 1";
// // //on récupère les id associés.
// // foreach ($corporadb->query($sql) as $row){
// // $sql2='SELECT ISIpubdate.id,ISIC1_1.data from ISIpubdate,ISIC1_1 where ISIC1_1.data="'.$row['data'].'" AND ISIpubdate.id=ISIC1_1.id AND ISIpubdate.data="2013" limit 1';
// // //echo $sql2;
// // foreach ($corporadb->query($sql2) as $row2){
// // $res_string.='<a href="JavaScript:newPopup(\''.$twjs.'php/default_doc_details.php?db='.urlencode($graphdb).'&gexf='.urlencode($gexf).'&query='.urlencode('["'.$res[$i].'"]').'&type='.urlencode($_GET["type"]).'&id='.$row2['id'].' \')">'.$res[$i]."</a>, ";
// // }
// // $res_string.='<a href="JavaScript:newPopup(\''.$twjs.'php/default_doc_details.php?db='.urlencode($graphdb).'&gexf='.urlencode($gexf).'&query='.urlencode('["'.$res[$i].'"]').'&type='.urlencode($_GET["type"]).'&id='.$row2['id'].' \')">'.$res[$i]."</a>, ";
// // }
// // }
// // }
// // $news.='<br/><b><font color="#CF5300">Top '.$top_displayed.' Impact related terms: </font></b>'.$res_string.'<br/>';
// // $news.='<br/><b><font color="#CF5300">Top '.$top_displayed.' Impact related terms: </font></b>'.$res_string.'<br/>';
// // }
// // }
// // }
// // }
......@@ -248,21 +253,21 @@ $output .= "</ul>"; #####
// //elseif (count($elems)==1) {// on affiche les voisins
// // $terms_array=array();
// // $id_sql='SELECT ISIterms.id FROM ISIterms where ISIterms.data="'.$elems[0].'" group by id';
// // foreach ($base->query($id_sql) as $row_id) {
// // foreach ($base->query($id_sql) as $row_id) {
// // $sql2='SELECT ISIterms.data FROM ISIterms where ISIterms.id='.$row_id['id'];
// // foreach ($base->query($sql2) as $row_terms) {
// // foreach ($base->query($sql2) as $row_terms) {
// // if ($terms_array[$row_terms['data']]>0){
// // $terms_array[$row_terms['data']]=$terms_array[$row_terms['data']]+1;
// // $terms_array[$row_terms['data']]=$terms_array[$row_terms['data']]+1;
// // }else{
// // $terms_array[$row_terms['data']]=1;
// // }
// // }
// // $terms_array[$row_terms['data']]=1;
// // }
// // }
// // }
// // natsort($terms_array);
// // natsort($terms_array);
// // $terms_list=array_keys(array_slice($terms_array,-11,-1));
// // foreach ($terms_list as $first_term) {
// // $related_terms.=$first_term.', ';
// // }
// // }
// // $news.='<br/><b><font color="#CF5300">Related terms: </font></b>'.$related_terms.'<br/>';
// //}
......
......@@ -12,6 +12,9 @@
include('parameters_details.php');
$max_item_displayed=6;
echo('graphdb: '. $graphdb.'<br/>');
$base = new PDO("sqlite:../" .$graphdb);
include('default_div.php');
......
<?php
# £TODO WTF ??? => move params to settings_explorerjs ???
# loading an associated db for a given gexf as relatedDocs php API
$gexf_db = array();
# $gexf_db["data/terrorism/terrorism_bi.gexf"] = "data/terrorism/data.db";
......@@ -15,7 +14,7 @@ $gexf_db["data/AXA/RiskV2PageRank5000.gexf"] = "data/AXA/data.db";
// TESTS
$gexf_db["data/ProgrammeDesCandidats.gexf"] = "foobar";
// $gexf_db["data/ProgrammeDesCandidats.gexf"] = "foobar";
$gexf= str_replace('"','',$_GET["gexf"]);
......
......@@ -8,11 +8,11 @@
"gexfs": {
"ProgrammeDesCandidats.enrichi.gexf": {
"social": {},
"semantic": {"table":"terms"}
"semantic": {}
},
"ProgrammeDesCandidats.gexf": {
"social": {},
"semantic": {"table":"terms"}
"semantic": {}
}
}
},
......@@ -33,8 +33,14 @@
"data/AXA": {
"first" : "RiskV2PageRank1000.gexf",
"gexfs": {
"RiskV2PageRank1000.gexf": {},
"RiskV2PageRank5000.gexf": {}
"RiskV2PageRank1000.gexf": {
"social": { "table":"ISIAUTHOR" , "textCol":"data","forkeyCol":"id"},
"semantic": { "table":"ISItermsAxa_2015" , "textCol":"data","forkeyCol":"id"}
},
"RiskV2PageRank5000.gexf": {
"social": { "table":"ISIAUTHOR" , "textCol":"data","forkeyCol":"id"},
"semantic": { "table":"ISItermsAxa_2015" , "textCol":"data","forkeyCol":"id"}
}
}
}
}
......@@ -347,15 +347,11 @@ function set_ClustersLegend ( daclass, groupedByTicks ) {
// NB: this variant only for nodetype semantic
function getTopPapers(nodetypeLegacy){
if (nodetypeLegacy == 'semantic' && TW.conf.getRelatedDocs) {
if (TW.conf.getRelatedDocs) {
jsonparams=getSelections();
var joined_q = jsonparams.map(function(w) {return '('+w+')'}).join(' AND ')
// console.log(jsonparams)
// theHtml = "<p> jsonparams:"+jsonparams+" </p>"
//
if (TW.conf.relatedDocsType == "twitter") {
// POSS remove restriction on 'semantic' nodes for twitter results about authors
if (nodetypeLegacy == 'semantic') {
$.ajax({
type: 'GET',
url: TW.conf.relatedDocsAPI,
......@@ -383,7 +379,46 @@ function getTopPapers(nodetypeLegacy){
console.log('Page Not found: getTopPapers');
}
});
}
}
else if (TW.conf.relatedDocsType == "wosLocalDB") {
let thisgexf= TW.File;
let gexfinfos = TW.fields[thisgexf]
if (!gexfinfos || !gexfinfos[nodetypeLegacy]) {
$("#topPapers").show();
$("#topPapers").html(
`<p>Your settings for relatedDocsType are set on a local wos database, but your servermenu file does not provide any information about the wosLocalDB table to query for related documents on nodetype ${nodetypeLegacy}</p>`
);
}
else {
let jsonparams=JSON.stringify(TW.SystemState().selectionNids.map(function(nid){return TW.Nodes[nid].label}));
let bi=(TW.categories.length==2)?1:0;
jsonparams = jsonparams.split('&').join('__and__');
let querytable = gexfinfos[nodetypeLegacy]
let image='<img style="display:block; margin: 0px auto;" src="libs/img2/loader.gif"></img>';
$("#topPapers").show();
$("#topPapers").html(image);
$.ajax({
type: 'GET',
url: 'LOCALDB/info_div.php',
data: "type="+nodetypeLegacy+"&bi="+bi+"&query="+jsonparams+"&gexf="+thisgexf+"&index="+querytable,
//contentType: "application/json",
//dataType: 'json',
success : function(data){
console.log('LOCALDB/info_div.php?'+"type="+nodetypeLegacy+"&bi="+bi+"&query="+jsonparams+"&gexf="+thisgexf+"&index="+querytable);
$("#topPapers").html(data);
},
error: function(){
console.log('Page Not found: getTopPapers');
}
});
}
}
}
}
function newPopup(url) {
popupWindow = window.open(url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
function clickInsideTweet(e, tweetSrcUrl) {
......
......@@ -36,9 +36,8 @@ TW.conf = (function(TW){
TWConf.getRelatedDocs = true
TWConf.relatedDocsAPI = "http://127.0.0.1:5000/twitter_search"
// £TODO : allow to choose between twitter or elasticsearch topPapers (choic of post-process function in extras_explorer)
// TWConf.relatedDocsType
TWConf.relatedDocsType = "wosLocalDB" // accepted: "twitter" | "wosLocalDB"
// POSSible: "elastic"
// =======================
// DATA FACETS AND LEGENDS
......
......@@ -978,5 +978,6 @@ function jsActionOnGexfSelector(gexfBasename){
mainStartGraph(newDataRes["format"], newDataRes["data"], TW.instance)
writeLabel(gexfBasename)
TW.File = gexfPath
}
//============================= </OTHER ACTIONS > =============================//
......@@ -7,10 +7,14 @@ TW.Edges = [];
TW.Relations = {} // edges sorted by source/target type
TW.Clusters = []; // "by value" facet index built in parseCustom
TW.File = "" // remember the currently opened file
TW.partialGraph = null // will contain the sigma visible graph instance
TW.labels=[]; // fulltext search list
TW.gexfPaths={}; // for file selectors iff servermenu
TW.fields={}; // for related db tablenames
// (iff servermenu && relatedDocsType == 'wosLocalDB')
TW.categories = []; // possible node types and their inverted map
TW.catDict = {};
......@@ -217,10 +221,6 @@ function syncRemoteGraphData () {
// -> gexf file path is in the urlparam @file
// -> gexf file path is already specified in TW.conf.sourceFile
// ===================
var the_file = "";
// ===================
// menufile case : a list of source files in ./db.json
if (sourcemode == 'servermenu') {
console.log("reading from FILEMENU TW.conf.sourceMenu")
......@@ -246,11 +246,11 @@ function syncRemoteGraphData () {
// the first or a specified one (ie both mode and file params are present)
if( isUndef(getUrlParam.file) ) {
the_file = first_path+"/"+first_file
TW.File = first_path+"/"+first_file
mapLabel = first_file
} else {
// £POSS; match on the full paths from db.json
the_file = first_path+"/"+getUrlParam.file
TW.File = first_path+"/"+getUrlParam.file
mapLabel = getUrlParam.file
}
......@@ -268,18 +268,24 @@ function syncRemoteGraphData () {
if (TW.conf.debug.logFetchers)
console.log("\t\t\t"+gexfBasename)
// for associated wosLocalDBs sql queries
if (theGexfs[aGexf]) {
// -------------------------->8------------------------------------------
// £TODO this part is underspecified
// if used in some usecases, port it to nodetypes
// otherwise remove
// console.log("\t\t\ttable:"+theGexfs[aGexf]["semantic"]["table"])
// TW.field[path+"/"+aGexf] = theGexfs[aGexf]["semantic"]["table"]
// ex : data/AXA/RiskV2PageRank5000.gexf:"ISItermsAxa_2015"
// -------------------------->8------------------------------------------
let cssFileSelected = (the_file==(path+"/"+aGexf))?"selected":""
TW.fields[path+"/"+aGexf] = {"semantic":null, "social":null}
if (theGexfs[aGexf]["semantic"] && theGexfs[aGexf]["semantic"]["table"]) {
TW.fields[path+"/"+aGexf]['semantic'] = theGexfs[aGexf]["semantic"]["table"]
}
if (theGexfs[aGexf]["social"] && theGexfs[aGexf]["social"]["table"]) {
TW.fields[path+"/"+aGexf]['social'] = theGexfs[aGexf]["social"]["table"]
}
}
else {
TW.fields[path+"/"+aGexf] = null
}
// ^^^^^^ FIXME see if we got the expected behavior right
// (? specifications ?)
let cssFileSelected = (TW.File==(path+"/"+aGexf))?"selected":""
files_selector += '<option '+cssFileSelected+'>'+gexfBasename+'</option>'
}
// console.log( files_selector )
......@@ -290,23 +296,23 @@ function syncRemoteGraphData () {
// direct urlparam file case
else if( !isUndef(getUrlParam.file) ) {
the_file = getUrlParam.file
TW.File = getUrlParam.file
}
// direct file fallback case: specified file in settings_explorer
else if (TW.conf.sourceFile && linkCheck(TW.conf.sourceFile)) {
console.log("no @file arg: trying TW.conf.sourceFile from settings")
the_file = TW.conf.sourceFile;
TW.File = TW.conf.sourceFile;
}
else {
console.error(`No specified input and neither db.json nor TW.conf.sourceFile ${TW.conf.sourceFile} are present`)
}
var finalRes = AjaxSync({ url: the_file });
var finalRes = AjaxSync({ url: TW.File });
inData = finalRes["data"]
inFormat = finalRes["format"]
if (TW.conf.debug.logFetchers) {
console.warn('@the_file', finalRes["OK"], the_file)
console.warn('@TW.File', finalRes["OK"], TW.File)
console.log(' fetch result: format', inFormat)
console.log(' fetch result: typeof data', typeof inData)
console.log("\n============================\n")
......
......@@ -433,8 +433,6 @@ function updateRelatedNodesPanel( sels , same, oppos ) {
sameNodesDIV+= '</div>';
}
// getTopPapers("semantic");
informationDIV += '<br><h4>Information:</h4><ul>';
informationDIV += htmlfied_nodesatts( sels ).join("<br>\n")
informationDIV += '</ul><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