/* *Categories example (bigraph): * ISItermsAlexandrePartCountry * Authors **/ function parse(gexfPath) { var gexfhttp; gexfhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); gexfhttp.open('GET', gexfPath, false); gexfhttp.send(); gexf = gexfhttp.responseXML; } function scanCategories(){ nodesNodes = gexf.getElementsByTagName('nodes'); for(i=0; i0){ sizeNode = sizeNodes[0]; size = parseFloat(sizeNode.getAttribute('value')); } var x = 100 - 200*Math.random(); var y = 100 - 200*Math.random(); var color; var positionNodes = nodeNode.getElementsByTagName('position'); positionNodes = positionNodes.length ? positionNodes : nodeNode.getElementsByTagNameNS('*','position'); if(positionNodes.length>0){ var positionNode = positionNodes[0]; x = parseFloat(positionNode.getAttribute('x')); y = parseFloat(positionNode.getAttribute('y')); } var colorNodes = nodeNode.getElementsByTagName('color'); colorNodes = colorNodes.length ? colorNodes : nodeNode.getElementsByTagNameNS('*','color'); if(colorNodes.length>0){ colorNode = colorNodes[0]; color = '#'+sigma.tools.rgbToHex(parseFloat(colorNode.getAttribute('r')), parseFloat(colorNode.getAttribute('g')), parseFloat(colorNode.getAttribute('b'))); } var node = ({ id:id, label:label, size:size, x:x, y:y, type:"", attributes:[], color:color }); // The graph node // Attribute values var attvalueNodes = nodeNode.getElementsByTagName('attvalue'); var atts={}; for(k=0; k parseInt(maxNodeSize)) maxNodeSize= node.size; // Create Node Nodes[id] = node // The graph node //pr(node); } } //New scale for node size: now, between 2 and 5 instead [1,70] for(var it in Nodes){ Nodes[it].size = desirableNodeSizeMIN+ (parseInt(Nodes[it].size)-1)* ((desirableNodeSizeMAX-desirableNodeSizeMIN)/ (maxNodeSize-minNodeSize)); partialGraph._core.graph.nodesIndex[it].size=Nodes[it].size; } var edgeId = 0; var edgesNodes = gexf.getElementsByTagName('edges'); minEdgeWeight=5.0; maxEdgeWeight=0.0; for(i=0; i maxEdgeWeight) maxEdgeWeight= edge.weight; } edge.attributes.push({ attr:attr, val:val }); } edge.label="nodes1"; if((typeof nodes1[source])=="undefined"){ nodes1[source] = { label: Nodes[source].label, neighbours: [] }; nodes1[source].neighbours.push(target); } else nodes1[source].neighbours.push(target); if((typeof nodes1[target])=="undefined"){ nodes1[target] = { label: Nodes[target].label, neighbours: [] }; nodes1[target].neighbours.push(source); } else nodes1[target].neighbours.push(source); Edges[indice] = edge; if( (typeof partialGraph._core.graph.edgesIndex[target+";"+source])=="undefined" ){ partialGraph.addEdge(indice,source,target,edge); } } } } function fullExtract(){ var i, j, k; // Parse Attributes // This is confusing, so I'll comment heavily var nodesAttributes = []; // The list of attributes of the nodes of the graph that we build in json var edgesAttributes = []; // The list of attributes of the edges of the graph that we build in json var attributesNodes = gexf.getElementsByTagName('attributes'); // In the gexf (that is an xml), the list of xml nodes 'attributes' (note the plural 's') for(i = 0; i0){ sizeNode = sizeNodes[0]; size = parseFloat(sizeNode.getAttribute('value')); } var x = 100 - 200*Math.random(); var y = 100 - 200*Math.random(); var color; var positionNodes = nodeNode.getElementsByTagName('position'); positionNodes = positionNodes.length ? positionNodes : nodeNode.getElementsByTagNameNS('*','position'); if(positionNodes.length>0){ var positionNode = positionNodes[0]; x = parseFloat(positionNode.getAttribute('x')); y = parseFloat(positionNode.getAttribute('y')); } var colorNodes = nodeNode.getElementsByTagName('color'); colorNodes = colorNodes.length ? colorNodes : nodeNode.getElementsByTagNameNS('*','color'); if(colorNodes.length>0){ colorNode = colorNodes[0]; color = '#'+sigma.tools.rgbToHex(parseFloat(colorNode.getAttribute('r')), parseFloat(colorNode.getAttribute('g')), parseFloat(colorNode.getAttribute('b'))); } var node = ({ id:id, label:label, size:size, x:x, y:y, type:"", attributes:[], color:color }); // The graph node // Attribute values var attvalueNodes = nodeNode.getElementsByTagName('attvalue'); var atts={}; for(k=0; k parseInt(maxNodeSize)) maxNodeSize= node.size; // Create Node Nodes[id] = node // The graph node //pr(Nodes[id]); } } //New scale for node size: now, between 2 and 5 instead [1,70] for(var i in Nodes){ normalizedSize=desirableNodeSizeMIN+(Nodes[i].size-1)*((desirableNodeSizeMAX-desirableNodeSizeMIN)/(parseInt(maxNodeSize)-parseInt(minNodeSize))); Nodes[i].size = ""+normalizedSize; if(Nodes[i].type==catSem) { nodeK = Nodes[i]; nodeK.hidden=true; partialGraph.addNode(i,nodeK); delete Nodes[i].hidden; } else { partialGraph.addNode(i,Nodes[i]); unHide(i); } } var edgeId = 0; var edgesNodes = gexf.getElementsByTagName('edges'); for(i=0; i maxEdgeWeight) maxEdgeWeight= edge.weight; } edge.attributes.push({ attr:attr, val:val }); } idS=Nodes[edge.sourceID].type.charAt(0); idT=Nodes[edge.targetID].type.charAt(0); //pr(idS+";"+idT); if(idS=="D" && idT=="D"){ edge.label="nodes1"; if( (typeof partialGraph._core.graph.edgesIndex[target+";"+source])=="undefined" ){ edge.hidden=false; } else edge.hidden=true; if((typeof nodes1[source])=="undefined"){ nodes1[source] = { label: Nodes[source].label, neighbours: [] }; nodes1[source].neighbours.push(target); } else nodes1[source].neighbours.push(target); // if((typeof nodes1[target])=="undefined"){ // nodes1[target] = { // label: Nodes[target].label, // neighbours: [] // }; // nodes1[target].neighbours.push(source); // } // else nodes1[target].neighbours.push(source); } // // if(idS=="N" && idT=="N"){ edge.label="nodes2"; //pr("nodes2"); edge.hidden=true; if((typeof nodes2[source])=="undefined"){ nodes2[source] = { label: Nodes[source].label, neighbours: [] }; nodes2[source].neighbours.push(target); } else nodes2[source].neighbours.push(target); } // // if((idS=="D" && idT=="N")||(idS=="N" && idT=="D")){ edge.label="bipartite"; //pr("bipartite"); edge.hidden=true; // Document to NGram if((typeof bipartiteD2N[source])=="undefined"){ bipartiteD2N[source] = { label: Nodes[source].label, neighbours: [] }; bipartiteD2N[source].neighbours.push(target); } else bipartiteD2N[source].neighbours.push(target); // NGram to Document if((typeof bipartiteN2D[target])=="undefined"){ bipartiteN2D[target] = { label: Nodes[target].label, neighbours: [] }; bipartiteN2D[target].neighbours.push(source); } else bipartiteN2D[target].neighbours.push(source); } partialGraph.addEdge(indice,source,target,edge); delete edge.hidden; Edges[indice]=edge; } } } function extractFromJson(data,seed){ var i, j, k; rand=new RVUniformC(seed); //partialGraph.emptyGraph(); // Parse Attributes // This is confusing, so I'll comment heavily var nodesAttributes = []; // The list of attributes of the nodes of the graph that we build in json var edgesAttributes = []; // The list of attributes of the edges of the graph that we build in json //var attributesNodes = gexf.getElementsByTagName('attributes'); // In the gexf (that is an xml), the list of xml nodes 'attributes' (note the plural 's') var nodesNodes = data.nodes // The list of xml nodes 'nodes' (plural) labels = []; numberOfDocs=0; numberOfNGrams=0; categories[catSoc]=catSoc; categories[catSem]=catSem; categoriesIndex[0]=catSoc; categoriesIndex[1]=catSem; for(var i in nodesNodes){ colorRaw = nodesNodes[i].color.split(","); color = '#'+sigma.tools.rgbToHex( parseFloat(colorRaw[2]), parseFloat(colorRaw[1]), parseFloat(colorRaw[0])); //Colors inverted... Srsly?? var node = ({ id:i, label:nodesNodes[i].label, size:1, x:rand.getRandom(), y:rand.getRandom(), //x:Math.random(), //y:Math.random(), type:"", htmlCont:"", color:color }); // The graph node if(nodesNodes[i].type=="Document"){ node.htmlCont = nodesNodes[i].content; node.type="Document"; node.shape="square"; numberOfDocs++; node.size=desirableScholarSize; } else { node.type="NGram"; numberOfNGrams++; node.size=parseInt(nodesNodes[i].term_occ).toFixed(2); if(parseInt(node.size) < parseInt(minNodeSize)) minNodeSize= node.size; if(parseInt(node.size) > parseInt(maxNodeSize)) maxNodeSize= node.size; } Nodes[i] = node; } for(var i in Nodes){ if(Nodes[i].type=="NGram") { normalizedSize=desirableNodeSizeMIN+(Nodes[i].size-1)*((desirableNodeSizeMAX-desirableNodeSizeMIN)/(parseInt(maxNodeSize)-parseInt(minNodeSize))); Nodes[i].size = ""+normalizedSize; nodeK = Nodes[i]; nodeK.hidden=true;/**///should be uncommented partialGraph.addNode(i,nodeK); } else { partialGraph.addNode(i,Nodes[i]); unHide(i); } } var edgeId = 0; var edgesNodes = data.edges; for(var i in edgesNodes){ //pr(edgesNodes[i]); var indice=edgesNodes[i].s+";"+edgesNodes[i].t; var source = edgesNodes[i].s; var target = edgesNodes[i].t; var edge = { id: indice, sourceID: source, targetID: target, label: edgesNodes[i].type, weight: edgesNodes[i].w }; if(edge.weight < minEdgeWeight) minEdgeWeight= edge.weight; if(edge.weight > maxEdgeWeight) maxEdgeWeight= edge.weight; Edges[indice] = edge; if(edge.label=="nodes1"){ if( (typeof partialGraph._core.graph.edgesIndex[target+";"+source])=="undefined" ){ edge.hidden=false; } else edge.hidden=true; if((typeof nodes1[source])=="undefined"){ nodes1[source] = { label: Nodes[source].label, neighbours: [] }; nodes1[source].neighbours.push(target); } else nodes1[source].neighbours.push(target); } if(edge.label=="nodes2"){ edge.hidden=true; if((typeof nodes2[source])=="undefined"){ nodes2[source] = { label: Nodes[source].label, neighbours: [] }; nodes2[source].neighbours.push(target); } else nodes2[source].neighbours.push(target); } if(edge.label=="bipartite"){ edge.hidden=true; // Document to NGram if((typeof bipartiteD2N[source])=="undefined"){ bipartiteD2N[source] = { label: Nodes[source].label, neighbours: [] }; bipartiteD2N[source].neighbours.push(target); } else bipartiteD2N[source].neighbours.push(target); // NGram to Document if((typeof bipartiteN2D[target])=="undefined"){ bipartiteN2D[target] = { label: Nodes[target].label, neighbours: [] }; bipartiteN2D[target].neighbours.push(source); } else bipartiteN2D[target].neighbours.push(source); } //edge.hidden=false/**///should be commented partialGraph.addEdge(indice,source,target,edge); } }