Created
November 27, 2016 12:32
-
-
Save themistoklik/38711aff8e0c08c1c010d219322b2ffa to your computer and use it in GitHub Desktop.
demo processing in networkx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import networkx as nx\n", | |
"\n", | |
"filenames = ['/home/themistoklik/Downloads/java-callgraph/target/dbpedia.txt']\n", | |
"for file in filenames:\n", | |
" with open(file) as f:\n", | |
" g = nx.Graph()\n", | |
"\n", | |
" #iterator for when you bite more than you can chew\n", | |
" for line in iter(f.readline,''):\n", | |
" contents = line.split()\n", | |
" if any([True if 'weka' in item else False for item in contents]):\n", | |
" assert (len(contents) == 2)\n", | |
" g.add_edge(contents[0], contents[1])\n", | |
" else:\n", | |
" continue" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"['weka.classifiers.bayes.net.estimate.MultiNomialBMAEstimator',\n 'C:weka.classifiers.pmml.consumer.TreeModel$MiningFunction',\n '(S)weka.gui.explorer.ClustererPanel:access$200',\n 'M:weka.gui.beans.StripChart:readObject',\n 'M:weka.gui.beans.KnowledgeFlowApp:detachFromLayout',\n '(O)weka.gui.PackageManager$1:<init>',\n 'M:weka.core.pmml.BuiltInArithmetic:getOutputDef',\n '(M)weka.filters.unsupervised.attribute.RandomProjection:setDistribution',\n '(M)weka.experiment.ResultMatrixSignificance:isMean',\n 'M:weka.gui.streams.InstanceJoiner:removeInstanceListener']" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"#see some nodes\n", | |
"g.nodes()[:10]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[('weka.classifiers.bayes.net.estimate.MultiNomialBMAEstimator',\n 'C:weka.classifiers.bayes.net.estimate.MultiNomialBMAEstimator'),\n ('C:weka.classifiers.pmml.consumer.TreeModel$MiningFunction',\n 'java.lang.Enum'),\n ('C:weka.classifiers.pmml.consumer.TreeModel$MiningFunction',\n 'weka.classifiers.pmml.consumer.TreeModel$MiningFunction'),\n ('C:weka.classifiers.pmml.consumer.TreeModel$MiningFunction',\n '[Lweka.classifiers.pmml.consumer.TreeModel$MiningFunction;'),\n ('C:weka.classifiers.pmml.consumer.TreeModel$MiningFunction',\n 'weka.classifiers.pmml.consumer.TreeModel'),\n ('(S)weka.gui.explorer.ClustererPanel:access$200',\n 'M:weka.gui.explorer.ClustererPanel$12:run'),\n ('M:weka.gui.beans.StripChart:readObject',\n '(M)java.lang.Exception:printStackTrace'),\n ('M:weka.gui.beans.StripChart:readObject',\n '(O)weka.gui.beans.StripChart:initPlot'),\n ('M:weka.gui.beans.StripChart:readObject',\n '(M)java.io.ObjectInputStream:defaultReadObject'),\n ('M:weka.gui.beans.KnowledgeFlowApp:detachFromLayout',\n '(M)java.util.Vector:size'),\n ('M:weka.gui.beans.KnowledgeFlowApp:detachFromLayout',\n '(M)java.util.Vector:elementAt'),\n ('M:weka.gui.beans.KnowledgeFlowApp:detachFromLayout',\n '(M)weka.gui.beans.BeanVisual:removePropertyChangeListener'),\n ('M:weka.gui.beans.KnowledgeFlowApp:detachFromLayout',\n '(M)weka.gui.beans.BeanInstance:getBean'),\n ('M:weka.gui.beans.KnowledgeFlowApp:detachFromLayout',\n '(M)weka.gui.beans.MetaBean:removePropertyChangeListenersSubFlow'),\n ('M:weka.gui.beans.KnowledgeFlowApp:detachFromLayout',\n '(M)weka.gui.beans.BeanVisual:setBackground')]" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"#see some edges in the undirected graph\n", | |
"g.edges()[:15]" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2.0 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment