Commit 5a45a43c authored by Romain Loth's avatar Romain Loth

WIP bipart: comments on refactoring strategy for categories and minor fixes in parseCustom

parent 562de2a2
......@@ -333,15 +333,39 @@ else {
if (inData.clusters) TW.Clusters = inData.clusters
// relations already copied in TW.Relations at this point
// £TODO also test with comex2 for bipart case
// TW.nodes1 = dicts.n1;//not used
var catDict = dicts.catDict // <= FIXME was already available at scanFile time...
console.log("CategoriesDict: ")
console.log(catDict)
// a posteriori categories diagnostic
// ----------------------------------
// by default TW.categories now match user-suggested catSoc/Sem if present
// so we just need to handle mismatches here (when user-suggested cats were absent)
if (TW.categories.length == 2) {
console.log("== 'bipartite' case ==")
if (TW.catSoc != TW.categories[0]) {
console.warn(`Observed social category "${TW.categories[0]}" overwrites user-suggested TW.catSoc ("${TW.catSoc}")`)
TW.catSoc = TW.categories[0]
}
if (TW.catSem != TW.categories[1]) {
console.warn(`Observed semantic category "${TW.categories[1]}" overwrites user-suggested TW.catSem "(${TW.catSem})"`)
TW.catSem = TW.categories[1]
}
}
else if (TW.categories.length == 1) {
console.log("== monopartite case ==")
// FIXME it would be more coherent with all tina usecases (like gargantext or tweetoscope) for the default category to by catSem instead of Soc
if (TW.catSoc != TW.categories[0]) {
console.warn(`Observed unique category "${TW.categories[0]}" overwrites user-suggested TW.catSoc ("${TW.catSoc}")`)
TW.catSoc = TW.categories[0]
}
}
else {
console.error("== currently unhandled categorization of node types ==", TW.categories)
}
TW.categoriesIndex = categories;//to_remove
TW.catSoc = categories[0];//to_remove
TW.catSem = (categories[1])?categories[1]:false;//to_remove
// FIXME generalize the use of these two TW.* variants instead of window-scoped 'categories' and 'catDict'
TW.categories = categories;
TW.categoriesIndex = catDict;
for(var i in categories) {
TW.Filters[i] = {}
......
......@@ -467,7 +467,7 @@ function updateRelatedNodesPanel( sels , same, oppos ) {
$("#information").html(informationDIV);
$("#tips").html("");
if(TW.categoriesIndex.length==1) getTopPapers("semantic");
if(TW.categories.length==1) getTopPapers("semantic");
else getTopPapers(swclickActual);
}
......
......@@ -4,15 +4,23 @@
// Level-01
ParseCustom = function ( format , data ) {
this.data = data;
console.debug("ParseCustom init format, data", format, data)
if (format == 'gexf') {
this.data = $.parseXML(data)
}
else {
this.data = data
}
this.format = format;
this.nbCats = 0;
// input = GEXFstring
this.getGEXFCategories = function(aGexfFile) {
this.data = $.parseXML(aGexfFile) // <===================== (XML parse)
this.getGEXFCategories = function() {
return scanGexf( this.data );
}// output = [ "cat1" , "cat2" , ...]
}// output = {'cats':[ "cat1" , "cat2" , ...], 'rev': {cat1: 0, cat2: 1...}}
// input = [ "cat1" , "cat2" , ...]
......@@ -24,9 +32,8 @@ ParseCustom = function ( format , data ) {
// input = JSONstring
this.getJSONCategories = function(json) {
this.data = json;
return scanJSON( this.data );
}// output = [ "cat1" , "cat2" , ...]
}// output = {'cats':[ "cat1" , "cat2" , ...], 'rev': {cat1: 0, cat2: 1...}}
// input = [ "cat1" , "cat2" , ...]
......@@ -199,13 +206,10 @@ function scanGexf(gexfContent) {
}
}
// console.warn("observed categoriesDict in scanGexf", categoriesDict)
// sorting observed json node types into Sem (=> 1)/Soc (=> 0)
result = sortNodeTypes(categoriesDict)
// var catDict = result.reverse_dict
return result.cats_pair;
return result;
}
// sorting observed node types into Sem/Soc (factorized 11/05/2017)
......@@ -216,8 +220,8 @@ function scanGexf(gexfContent) {
// (current expected structure in 'categories' can only accomodate 2 types
// 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
// - the way default cat is handled...)
// - the effect on 'swclickActual'
// - the way default cat is handled as 0...)
// -------------------
// expected content: usually a just a few cats over all nodes
// ex: terms
......@@ -240,6 +244,8 @@ function sortNodeTypes(observedTypesDict) {
}
if(nTypes>1) {
var newcats = []
// POSSible: allow more than 2 cats
for(var i in observedTypes) {
c = observedTypes[i]
if(c == TW.catSoc || (c != TW.catSem && c.indexOf("term")==-1)) {// NOT a term-category
......@@ -253,7 +259,7 @@ function sortNodeTypes(observedTypesDict) {
}
observedTypes = newcats;
}
return {'cats_pair': observedTypes, 'reverse_dict': catDict}
return {'categories': observedTypes, 'reverse_dict': catDict}
}
// Level-00
......@@ -841,17 +847,12 @@ function scanJSON( data ) {
for(var i in nodes) {
n = nodes[i];
if(n.type) categoriesDict[n.type]=n.type;
if (i<10) console.debug("scanJSON node:", n)
}
// console.warn("observed categoriesDict in scanJSON", categoriesDict)
// sorting observed json node types into Sem/Soc
// sorting observed json node types into Sem (=> 1)/Soc (=> 0)
result = sortNodeTypes(categoriesDict)
var catDict = result.reverse_dict
return result.cats_pair;
return result;
}
// 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