Commit 562de2a2 authored by Romain Loth's avatar Romain Loth

factorize cats creation from nodetypes (todo inspect extensively later)

parent 4531abfb
...@@ -316,8 +316,7 @@ else { ...@@ -316,8 +316,7 @@ else {
var initialState = buildInitialState( categories ) //[true,false]// var initialState = buildInitialState( categories ) //[true,false]//
// XML parsing from ParseCustom // XML parsing from ParseCustom
var dicts = start.makeDicts(categories); // > parseGexf, dictfyGexf var dicts = start.makeDicts(categories); // > parse json or gexf, dictfy
console.warn("parsing result:", dicts) console.warn("parsing result:", dicts)
TW.Nodes = dicts.nodes; TW.Nodes = dicts.nodes;
...@@ -336,7 +335,7 @@ else { ...@@ -336,7 +335,7 @@ else {
// relations already copied in TW.Relations at this point // relations already copied in TW.Relations at this point
// TW.nodes1 = dicts.n1;//not used // TW.nodes1 = dicts.n1;//not used
var catDict = dicts.catDict var catDict = dicts.catDict // <= FIXME was already available at scanFile time...
console.log("CategoriesDict: ") console.log("CategoriesDict: ")
console.log(catDict) console.log(catDict)
...@@ -562,6 +561,7 @@ else { ...@@ -562,6 +561,7 @@ else {
if (TW.filterSliders) { if (TW.filterSliders) {
// £TODO test with comex2
if(typestring=="0|1") { if(typestring=="0|1") {
$("#category0").hide(); $("#category0").hide();
$("#category1").show(); $("#category1").show();
...@@ -670,6 +670,7 @@ else { ...@@ -670,6 +670,7 @@ else {
// if (TW.catSem && TW.catSoc) { // if (TW.catSem && TW.catSoc) {
setTimeout(function () { setTimeout(function () {
// tabneigh: show "Related" tab
document.querySelector('.etabs a[href="#tabs2"]').click() document.querySelector('.etabs a[href="#tabs2"]').click()
}, 500); }, 500);
// } // }
......
...@@ -160,8 +160,7 @@ function gexfCheckAttributesMap (someXMLContent) { ...@@ -160,8 +160,7 @@ function gexfCheckAttributesMap (someXMLContent) {
// Level-00 // Level-00
function scanGexf(gexfContent) { function scanGexf(gexfContent) {
console.log("ParseCustom : scanGexf ======= ") console.log("ParseCustom : scanGexf ======= ")
var categoriesDict={}, categories=[]; var categoriesDict={};
// adding gexfCheckAttributesMap call // adding gexfCheckAttributesMap call
// to create a map from nodes/node/@for values to declared attribute name (title) // to create a map from nodes/node/@for values to declared attribute name (title)
...@@ -200,42 +199,61 @@ function scanGexf(gexfContent) { ...@@ -200,42 +199,61 @@ function scanGexf(gexfContent) {
} }
} }
for(var cat in categoriesDict) // console.warn("observed categoriesDict in scanGexf", categoriesDict)
// usually a just a few cats over entire node set
// ex: terms
// ex: ISItermsriskV2_140 & ISItermsriskV2_140
console.debug('>>> tr: cat', cat)
categories.push(cat);
var catDict = {} result = sortNodeTypes(categoriesDict)
if(categories.length==0) {
categories[0]="Document";
catDict["Document"] = 0;
}
if(categories.length==1) {
// if we have only one category, it gets the same code 0 as Document
// but in practice it's more often terms. anyways doesn't affect much
catDict[categories[0]] = 0;
// console.log("-----cat unique =>0")
}
// £TODO here should use TW.catSem and TW.catSoc // var catDict = result.reverse_dict
if(categories.length>1) {
var newcats = [] return result.cats_pair;
for(var i in categories) { }
c = categories[i]
if(c.indexOf("term")==-1) {// NOT a term-category // sorting observed node types into Sem/Soc (factorized 11/05/2017)
newcats[0] = c; // --------------------
catDict[c] = 0; // FIXME this factorizes what we had twice (json & gexf scanFile workflows),
} // and we just added missing TW.catSoc/Sem comparisons
else { // *but it doesn't fix the underlying logic*
newcats[1] = c; // IS a term-category // (current expected structure in 'categories' can only accomodate 2 types
catDict[c] = 1; // and the way it and catDict are used is not entirely coherent throughout
} // the project, cf. among others: - the effect on 'typestring'
} // - the way catDict recreated in dictfy
categories = newcats; // - the way default cat is handled...)
} // -------------------
return categories; // expected content: usually a just a few cats over all nodes
// ex: terms
// ex: ISItermsriskV2_140 & ISItermsriskV2_140
function sortNodeTypes(observedTypesDict) {
var observedTypes = Object.keys(observedTypesDict)
var catDict = {}
var nTypes = observedTypes.length
if(nTypes==0) {
observedTypes[0]="Document";
catDict["Document"] = 0;
}
if(nTypes==1) {
// if we have only one category, it gets the same code 0 as Document
// but in practice it's more often terms. anyways doesn't affect much
catDict[observedTypes[0]] = 0;
console.log("-----cat unique =>0")
}
if(nTypes>1) {
var newcats = []
for(var i in observedTypes) {
c = observedTypes[i]
if(c == TW.catSoc || (c != TW.catSem && c.indexOf("term")==-1)) {// NOT a term-category
newcats[0] = c;
catDict[c] = 0;
}
else {
newcats[1] = c; // IS a term-category
catDict[c] = 1;
}
}
observedTypes = newcats;
}
return {'cats_pair': observedTypes, 'reverse_dict': catDict}
} }
// Level-00 // Level-00
...@@ -367,6 +385,8 @@ function dictfyGexf( gexf , categories ){ ...@@ -367,6 +385,8 @@ function dictfyGexf( gexf , categories ){
} }
node.attributes = atts; node.attributes = atts;
// £TODO copy this logic in json case
// nodew=parseInt(attributes["weight"]); // nodew=parseInt(attributes["weight"]);
if ( atts["category"] ) { if ( atts["category"] ) {
node_cat = atts["category"]; node_cat = atts["category"];
...@@ -446,7 +466,7 @@ function dictfyGexf( gexf , categories ){ ...@@ -446,7 +466,7 @@ function dictfyGexf( gexf , categories ){
// clusters and other facets => type => name => [{label,val/range,nodeids}] // clusters and other facets => type => name => [{label,val/range,nodeids}]
TW.Clusters = {} TW.Clusters = {}
// sorting out properties in n.attributes // sorting out properties in n.attributes ==> £TODO shared function up to classvalues_fin
// -------------------------------------- // --------------------------------------
if(gotClusters) { if(gotClusters) {
...@@ -815,46 +835,23 @@ function dictfyGexf( gexf , categories ){ ...@@ -815,46 +835,23 @@ function dictfyGexf( gexf , categories ){
// Level-00 // Level-00
function scanJSON( data ) { function scanJSON( data ) {
var categoriesDict={}, categories=[]; var categoriesDict={};
var nodes = data.nodes; var nodes = data.nodes;
for(var i in nodes) { for(var i in nodes) {
n = nodes[i]; n = nodes[i];
if (i<10) console.log(n)
if(n.type) categoriesDict[n.type]=n.type; if(n.type) categoriesDict[n.type]=n.type;
if (i<10) console.debug("scanJSON node:", n)
} }
for(var cat in categoriesDict) // console.warn("observed categoriesDict in scanJSON", categoriesDict)
categories.push(cat);
var catDict = {} // sorting observed json node types into Sem/Soc
if(categories.length==0) { result = sortNodeTypes(categoriesDict)
categories[0]="Document";
catDict["Document"] = 0;
}
if(categories.length==1) {
catDict[categories[0]] = 0;
}
// £TODO here also should USE TW.catSem TW.catSoc var catDict = result.reverse_dict
if(categories.length>1) {
var newcats = []
for(var i in categories) {
c = categories[i]
if(c.indexOf("term")==-1) {// NOT a term-category
newcats[0] = c;
catDict[c] = 0;
}
else {
newcats[1] = c; // IS a term-category
catDict[c] = 1;
}
}
categories = newcats;
}
return categories; return result.cats_pair;
} }
// Level-00 // Level-00
......
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