Last active
August 29, 2015 13:57
-
-
Save cmarat/9347504 to your computer and use it in GitHub Desktop.
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
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Sketch of a helper class which allows using YASGUI from a iPython notebook" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from IPython.display import HTML\n", | |
"from requests import get" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 31 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"class PyYASGUI():\n", | |
" results = None\n", | |
" def __init__(self, endpoint = 'http://dbpedia.org/sparql/'):\n", | |
" self.session_url = get('http://yasgui.laurensrietveld.nl/get_session_url').content\n", | |
" self.endpoint = endpoint\n", | |
" \n", | |
" def display(self):\n", | |
" return HTML('<iframe height=\"450\" src=\"http://yasgui.laurensrietveld.nl?jsonSettings=%7B%0A%22singleEndpointMode%22%3A%20true%0A%7D\" style=\"border:0\" width=\"100%\" height=\"100%\"></iframe>')\n", | |
" \n", | |
" def query(self):\n", | |
" return get(session_url + '/query').content\n", | |
"\n", | |
" # Optional methods\n", | |
" \n", | |
" def execute(self):\n", | |
" query = self.query()\n", | |
" # raw_results = execute SPARQL query\n", | |
" # self.results = processed raw_results\n", | |
" return self.results\n", | |
" \n", | |
" def results(self):\n", | |
" if not results:\n", | |
" self.execute()\n", | |
" return results" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 32 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"yg = PyYASGUI()\n", | |
"yg.display()\n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<iframe height=\"450\" src=\"http://yasgui.laurensrietveld.nl?jsonSettings=%7B%0A%22singleEndpointMode%22%3A%20true%0A%7D\" style=\"border:0\" width=\"100%\" height=\"100%\"></iframe>" | |
], | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 33, | |
"text": [ | |
"<IPython.core.display.HTML at 0x10efbb350>" | |
] | |
} | |
], | |
"prompt_number": 33 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# query = yg.query()\n" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment