-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding test notebook and sample code
- Loading branch information
Showing
4 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Requirement already satisfied: rdflib in /opt/conda/lib/python3.8/site-packages (5.0.0)\n", | ||
"Requirement already satisfied: pygraphviz in /opt/conda/lib/python3.8/site-packages (1.6)\n", | ||
"Requirement already satisfied: six in /opt/conda/lib/python3.8/site-packages (from rdflib) (1.15.0)\n", | ||
"Requirement already satisfied: isodate in /opt/conda/lib/python3.8/site-packages (from rdflib) (0.6.0)\n", | ||
"Requirement already satisfied: pyparsing in /opt/conda/lib/python3.8/site-packages (from rdflib) (2.4.7)\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"!pip install rdflib pygraphviz" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import datajourney as DJ\n", | ||
"import networkx.drawing, networkx.drawing.nx_agraph as ag" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"import pandas as pd\n", | ||
"#import time\n", | ||
"#import torchvision\n", | ||
"\n", | ||
"#var1 = time.dosomething()\n", | ||
"#var2 = torchvision.doit()\n", | ||
"var3 = pd.start()\n", | ||
"\n", | ||
"#output = var1 + var2 + var3\n", | ||
"\n", | ||
"output = var3\n", | ||
"\n", | ||
"print(output)\n", | ||
"Skipping start type: <class 'str'>\n", | ||
"digraph { \n", | ||
"\"pandas\" -> \"simple-notebook\" [label = \"importedBy\"]\n", | ||
"\"pd(0)\" -> \"simple-notebook\" [label = \"appearsIn\"]\n", | ||
"\"pd(0)\" -> \"pandas\" [label = \"assignedFrom\"]\n", | ||
"\"var3(0)$0\" -> \"pd(0)\" [label = \"start\"]\n", | ||
"\"output(0)$0\" -> \"var3(0)$0\" [label = \"assignedFrom\"]\n", | ||
"\"print[0]\" -> \"output(0)$0\" [label = \"print\"]\n", | ||
"}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"f=\"simple-notebook.py\"\n", | ||
"src = open(f, \"r\").read()\n", | ||
"print(src)\n", | ||
"# Generate digraph from source\n", | ||
"collector = DJ.FindDependencies(f[:-3])\n", | ||
"collector.collect(src)\n", | ||
"gs = collector.getStringCollected()\n", | ||
"print(gs)\n", | ||
"o = open( f[:-2] + \"digraph\", \"w\")\n", | ||
"o.write(gs)\n", | ||
"o.close()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"@prefix dj: <http://purl.org/dj/> .\n", | ||
"@prefix k: <http://purl.org/dj/kaggle/> .\n", | ||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n", | ||
"\n", | ||
"<http://purl.org/dj/kaggle/simple-notebook#-8524247128405682818> rdfs:label \"print[0]\" ;\n", | ||
" dj:print <http://purl.org/dj/kaggle/simple-notebook#-2846434743430924692> .\n", | ||
"\n", | ||
"<http://purl.org/dj/kaggle/simple-notebook#-135686107301404705> rdfs:label \"var3(0)$0\" ;\n", | ||
" dj:start <http://purl.org/dj/kaggle/simple-notebook#5063491273276520289> .\n", | ||
"\n", | ||
"<http://purl.org/dj/kaggle/simple-notebook#-2846434743430924692> rdfs:label \"output(0)$0\" ;\n", | ||
" dj:assignedFrom <http://purl.org/dj/kaggle/simple-notebook#-135686107301404705> .\n", | ||
"\n", | ||
"<http://purl.org/dj/kaggle/simple-notebook#5063491273276520289> rdfs:label \"pd(0)\" ;\n", | ||
" dj:appearsIn k:simple-notebook ;\n", | ||
" dj:assignedFrom <http://purl.org/dj/python/lib/6084625367154981728> .\n", | ||
"\n", | ||
"<http://purl.org/dj/python/lib/6084625367154981728> rdfs:label \"pandas\" ;\n", | ||
" dj:importedBy k:simple-notebook .\n", | ||
"\n", | ||
"k:simple-notebook a k:Notebook ;\n", | ||
" rdfs:label \"simple-notebook\" .\n", | ||
"\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"\n", | ||
"# # Read digraph \n", | ||
"g = ag.read_dot( f[:-2] + \"digraph\")\n", | ||
"\n", | ||
"\n", | ||
"# # Generate RDF\n", | ||
"ns = f[:-3]\n", | ||
"rdfg = DJ.toRDF(ns, g)\n", | ||
"s=rdfg.serialize(format=\"turtle\").decode(\"utf-8\")\n", | ||
"\n", | ||
"o = open( f[:-2] + \"ttl\", \"w\")\n", | ||
"o.write(s)\n", | ||
"o.close()\n", | ||
"\n", | ||
"# Read and print ttl\n", | ||
"o = open( f[:-2] + \"ttl\", \"r\" )\n", | ||
"print(o.read())\n", | ||
"o.close()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'images/simple-notebook.png'" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"\n", | ||
"from graphviz import Source\n", | ||
"src = Source(gs)\n", | ||
"src.format = \"png\"\n", | ||
"src.render(\"images/\" + f[:-3])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
digraph { | ||
"pandas" -> "simple-notebook" [label = "importedBy"] | ||
"pd(0)" -> "simple-notebook" [label = "appearsIn"] | ||
"pd(0)" -> "pandas" [label = "assignedFrom"] | ||
"var3(0)$0" -> "pd(0)" [label = "start"] | ||
"output(0)$0" -> "var3(0)$0" [label = "assignedFrom"] | ||
"print[0]" -> "output(0)$0" [label = "print"] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pandas as pd | ||
#import time | ||
#import torchvision | ||
|
||
#var1 = time.dosomething() | ||
#var2 = torchvision.doit() | ||
var3 = pd.start() | ||
|
||
#output = var1 + var2 + var3 | ||
|
||
output = var3 | ||
|
||
print(output) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@prefix dj: <http://purl.org/dj/> . | ||
@prefix k: <http://purl.org/dj/kaggle/> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
|
||
<http://purl.org/dj/kaggle/simple-notebook#-8524247128405682818> rdfs:label "print[0]" ; | ||
dj:print <http://purl.org/dj/kaggle/simple-notebook#-2846434743430924692> . | ||
|
||
<http://purl.org/dj/kaggle/simple-notebook#-135686107301404705> rdfs:label "var3(0)$0" ; | ||
dj:start <http://purl.org/dj/kaggle/simple-notebook#5063491273276520289> . | ||
|
||
<http://purl.org/dj/kaggle/simple-notebook#-2846434743430924692> rdfs:label "output(0)$0" ; | ||
dj:assignedFrom <http://purl.org/dj/kaggle/simple-notebook#-135686107301404705> . | ||
|
||
<http://purl.org/dj/kaggle/simple-notebook#5063491273276520289> rdfs:label "pd(0)" ; | ||
dj:appearsIn k:simple-notebook ; | ||
dj:assignedFrom <http://purl.org/dj/python/lib/6084625367154981728> . | ||
|
||
<http://purl.org/dj/python/lib/6084625367154981728> rdfs:label "pandas" ; | ||
dj:importedBy k:simple-notebook . | ||
|
||
k:simple-notebook a k:Notebook ; | ||
rdfs:label "simple-notebook" . | ||
|