├── .gitignore ├── Docs ├── SemWeb_jupyter_guide │ ├── SemWeb_jupyter_guide.pdf │ ├── SemWeb_jupyter_guide.tex │ └── img │ │ ├── jupyterlab.png │ │ └── profiles.png └── Workflow │ ├── workflow.pdf │ └── workflow.tex ├── Eval_semweb_tool.xlsx ├── Evaluation.ipynb ├── Notebooks ├── Jupyter-RDFify-Example.ipynb ├── README.md ├── SemWebEx0.ipynb ├── SemWebEx1.ipynb ├── SemWebEx2.ipynb ├── SemWebEx3.ipynb ├── SemWebEx4.ipynb ├── SemWebEx5.ipynb └── SemWebEx6.ipynb ├── README.md ├── Scripts ├── moodle_nbgrader │ ├── LICENSE │ ├── README.md │ ├── collect_files.py │ └── update_gradesheet.py └── snippets │ └── semweb_dependencies.py └── environment.yml /.gitignore: -------------------------------------------------------------------------------- 1 | ## Latex aux 2 | *.aux 3 | *.glo 4 | *.idx 5 | *.log 6 | *.toc 7 | *.ist 8 | *.acn 9 | *.acr 10 | *.alg 11 | *.bbl 12 | *.blg 13 | *.dvi 14 | *.glg 15 | *.gls 16 | *.ilg 17 | *.ind 18 | *.lof 19 | *.lot 20 | *.maf 21 | *.mtc 22 | *.mtc1 23 | *.out 24 | *.synctex.gz -------------------------------------------------------------------------------- /Docs/SemWeb_jupyter_guide/SemWeb_jupyter_guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SemWebNotebooks/Notebooks/1f6052ddd302957fbf54809366a5c7264aeb53de/Docs/SemWeb_jupyter_guide/SemWeb_jupyter_guide.pdf -------------------------------------------------------------------------------- /Docs/SemWeb_jupyter_guide/SemWeb_jupyter_guide.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{hyperref} 4 | \usepackage{textcomp} 5 | \usepackage{xcolor} 6 | \usepackage{soul} 7 | \usepackage{graphicx} 8 | 9 | \definecolor{cmd}{RGB}{210,210,210} 10 | \newcommand{\consolecommand}[1]{ 11 | \begingroup% 12 | \sethlcolor{cmd}% 13 | \hl{\texttt{#1}}% 14 | \endgroup} 15 | %\newcommand{\clickthis}[1]{\textbf{''#1''}} 16 | %\newcommand{\pathfmt}[1]{\textbf{#1}} 17 | 18 | \title{Jupyter Notebooks: Installation and Usage} 19 | \author{Semantic Web} 20 | 21 | \begin{document} 22 | \maketitle 23 | \section{Introduction} 24 | In our lecture \emph{Semantic Web}, we will use \emph{Jupyter Notebooks} as assignments. There are many different ways to edit and run jupyter notebooks and in this document we will show you two of them. The first way is to install a local notebook server. The second way is to use the \emph{RWTH JupyterHub}. In the following sections we will guide you through both processes step-by-step. In case one of these methods does not work for you, you can still try the other one. 25 | 26 | 27 | \section{Local Installation using Anaconda} 28 | If you choose to use a local notebook server, it is highly recommended to use a brand new virtual environment with the latest python version. 29 | Install \href{https://www.anaconda.com/products/individual#Downloads}{Anaconda} if you haven't already. Then create a new virtual environment with \consolecommand{conda create --name semweb}. Every time you want to use the virtual environment you have to activate it with \consolecommand{conda activate semweb}. Activate the environment if you haven't already. Then install jupyter notebook and the graphviz interface with \consolecommand{conda install -c conda-forge notebook python-graphviz ipython=7.18.1}. Change into your desired notebook directory and start the notebook server with \consolecommand{jupyter notebook}. After that command a webbrowser with the notebook interface should open. To open a notebook, just copy it into your directory and double click it in the webbrowser. 30 | % \subsection{Python} 31 | % For this lecture you will need \href{https://graphviz.org/download/}{GraphViz}. The anaconda package also contains the graphviz binaries but when using stock python you also need to install graphviz and add its binary directory to the path. 32 | % Because the activation of virtual environments with virtualenv is platform specific we will not cover it here, please consult \href{https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/}{this guide}. After activating your virtual environment, install jupyter notebook and the graphviz interface with \consolecommand{python -m pip install notebook graphviz}. Change into your desired notebook directory and start the notebook server with \consolecommand{jupyter notebook}. After that command a webbrowser with the notebook interface should open. To open a notebook, just copy it into your directory and double click it in the webbrowser. 33 | \section{Using JupyterHub} 34 | \begin{figure}[t] 35 | \centering 36 | \includegraphics[width=.8\textwidth]{img/profiles.png} 37 | \caption{Profile selection screen. Just choose Python and click start at the bottom of the page.} 38 | \label{fig:profiles} 39 | \end{figure} 40 | Visit the \href{https://jupyter.rwth-aachen.de/hub/login}{\emph{RWTH JupyterHub}}, then login with your RWTH Shibboleth credentials. You will then be presented the profile selection screen shown in \ref{fig:profiles}. Just choose the Python profile -- should be the top one -- and click the start button at the bottom of the page to continue. Your Jupyter Notebook server will then be started up, which may take some seconds. After this you will be taken to the \emph{JupyterLab} interface of your server shown in \ref{fig:jupyterlab}. 41 | 42 | 43 | To open a notebook in JupyterLab, you first need to upload it. On the left side of the screen should be a file browser. If it isn't there, click the folder icon on the top left. There are already some folders but ignore these for now as they are not important. To upload a file, either drag and drop it from a file explorer into the file browser of the JupyterLab or click the upload file button at the top of the file browser (small arrow pointing up) and then choose the assignment's notebook file (ends in .ipynb). After you uploaded the notebook you just have to double click it in the file browser to open it. 44 | 45 | \begin{figure}[b] 46 | \centering 47 | \includegraphics[width=\textwidth]{img/jupyterlab.png} 48 | \caption{JupyterLab interface. Upload a file by either dragging it into the file browser or clicking upload file. If the file browser isn't there, click the folder icon in the top left.} 49 | \label{fig:jupyterlab} 50 | \end{figure} 51 | 52 | 53 | 54 | \end{document} -------------------------------------------------------------------------------- /Docs/SemWeb_jupyter_guide/img/jupyterlab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SemWebNotebooks/Notebooks/1f6052ddd302957fbf54809366a5c7264aeb53de/Docs/SemWeb_jupyter_guide/img/jupyterlab.png -------------------------------------------------------------------------------- /Docs/SemWeb_jupyter_guide/img/profiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SemWebNotebooks/Notebooks/1f6052ddd302957fbf54809366a5c7264aeb53de/Docs/SemWeb_jupyter_guide/img/profiles.png -------------------------------------------------------------------------------- /Docs/Workflow/workflow.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SemWebNotebooks/Notebooks/1f6052ddd302957fbf54809366a5c7264aeb53de/Docs/Workflow/workflow.pdf -------------------------------------------------------------------------------- /Docs/Workflow/workflow.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{hyperref} 4 | \usepackage{textcomp} 5 | \usepackage{soul} 6 | \usepackage{xcolor} 7 | 8 | \definecolor{cmd}{RGB}{210,210,210} 9 | \newcommand{\consolecommand}[1]{ 10 | \begingroup% 11 | \sethlcolor{cmd}% 12 | \hl{\texttt{#1}}% 13 | \endgroup} 14 | \newcommand{\clickthis}[1]{\textbf{''#1''}} 15 | \newcommand{\pathfmt}[1]{\textbf{#1}} 16 | 17 | \title{Jupyter Notebooks, Automatic Grading and Moodle Submission} 18 | \author{Lars Pieschel} 19 | 20 | \begin{document} 21 | \maketitle 22 | \section{Installation} 23 | You need a local installation of python, Anaconda with a new virtual environment is recommended. Use \consolecommand{pip install} or \consolecommand{conda install} to install the packages \consolecommand{notebook} and \consolecommand{nbgrader} (note: for \consolecommand{conda install} you need to change channel to conda-forge). If you only want to grade submissions, then you don't need the \consolecommand{notebook} package. 24 | \section{Creating Assignments with Formgrader} 25 | Choose a folder and execute the command \consolecommand{jupyter notebook}. This will start a notebook server and open a browser with the link to the server. After this click on the \clickthis{Formgrader} tab to open the formgrader interface. Click on \clickthis{Add new assignment} and enter an assignment name. Then click the name in the list of assignments to open up the assignment folder in jupyter notebook. Here create a new notebook and open it. To make metadata editing easier, click on \clickthis{View$\rightarrow$Cell Toolbar$\rightarrow$Create Assignment}. This will add a small dropdown to every cell with which you can choose the cell type for nbgrader. There are five cell types. \clickthis{Manually graded answer} and \clickthis{Manually graded task} are not interesting for us. \clickthis{Read-only} can't be edited by students. \clickthis{Autograder answer} are cells in which a task is given and \clickthis{Autograder tests} are cells for unittests for the task cells. Write code snippets in a autograder answer cell and surround the part that the student should write with two comments ''\#\#\# BEGIN SOLUTION'' and ''\#\#\# END SOLUTION''. For autograder tests use assertions to test the solution. Tests are by default visible for students. If you want to hide tests from the students then you have to surround the tests with two comments ''\#\#\# BEGIN HIDDEN TESTS'' and ''\#\#\# END HIDDEN TESTS''. Don't forget to set the amount of points a test cell gives when it doesn't fail. 26 | 27 | When you are finished editing the notebook, close it and click generate in the formgrader. This will generate the student version of the assignment in the folder \pathfmt{/release/}. 28 | \section{Distributing Notebooks via Moodle} 29 | Create a new assignment, enter a name and upload the student version of the assignment notebook. Under \clickthis{Feedback types} check the boxes \clickthis{Offline grading worksheet} and \clickthis{Feedback files}. Also change the maximum amount of points to that of the notebook. 30 | \section{Grading Notebooks} 31 | \textbf{Note: The given scripts only work when your moodle language is set to english. You can change the language in the top right.} 32 | 33 | Download the Scripts from \href{https://github.com/johnhw/moodle_nbgrader}{this repository}. In moodle select the assignment, view all submissions, reveal identities and then download all submissions and copy the zip folder to \pathfmt{/imports/\textlangle{}assignment\textrangle{}.zip} in your jupyter folder. Download the grading worksheet and do the same (\pathfmt{/imports/\textlangle{}assignment\textrangle{}.csv}). Then execute \consolecommand{python collect\_files.py \textlangle{}assignment\textrangle{} \textlangle{}workbook name\textrangle{}}. Then run \consolecommand{nbgrader autograde \textlangle{}assignment\textrangle{}} and \consolecommand{nbgrader generate\_feedback \textlangle{}assignment\textrangle{}}. Finally create a folder \pathfmt{/exports/} if it doesn't exist already and run \consolecommand{python update\_gradesheet.py \textlangle{}assignment\textrangle{}}. There should now be two files in the \pathfmt{/exports/} folder, a csv and a zip file. 34 | \section{Uploading Grades and Feedback} 35 | \textbf{Note: Uploading the gradesheet only works when your moodle language is set to english. You can change the language in the top right.} 36 | 37 | After the grading step, on the moodle submissions page, choose \clickthis{Upload grading worksheet}, choose the csv file from the exports folder and put a check in the box \clickthis{Allow updating records that have been modified more recently in Moodle than in the spreadsheet.} and submit. Then choose \clickthis{Upload multiple feedback files in a zip} and upload the zip file. 38 | \clearpage 39 | \section{Summary} 40 | \textbf{Note: Set your moodle's language to english or some steps will not work. You can change the language in the top right.} 41 | \begin{enumerate} 42 | \item Create Notebook 43 | \item Upload to moodle, check offline grading and feedback, set max points 44 | \item Download submissions, rename, put into imports 45 | \item Download grading sheet, rename, put into imports 46 | \item python collect\_files.py \textlangle{}assignment\textrangle{} \textlangle{}workbook name\textrangle{} 47 | \item nbgrader autograde \textlangle{}assignment\textrangle{} 48 | \item nbgrader generate\_feedback \textlangle{}assignment\textrangle{} 49 | \item python update\_gradesheet.py \textlangle{}assignment\textrangle{} 50 | \item Upload gradesheet csv to moodle, check overwrite box 51 | \item Upload feedback zip to moodle 52 | \end{enumerate} 53 | 54 | \section{Troubleshooting} 55 | 56 | \consolecommand{[AutogradeApp | ERROR] While processing assignment XYZ, the kernel became unresponsive and we could not interrupt it. This probably means that the students' code has an infinite loop that consumes a lot of memory or something similar. nbgrader doesn't know how to deal with this problem, so you will have to manually edit the students' code (for example, to just throw an error rather than enter an infinite loop).} 57 | 58 | When you see this error without there being an infinite loop in the notebook, it may be caused by a problem with nbconvert. Try downgrading to nbconvert version 5.6.1. 59 | 60 | \end{document} -------------------------------------------------------------------------------- /Eval_semweb_tool.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SemWebNotebooks/Notebooks/1f6052ddd302957fbf54809366a5c7264aeb53de/Eval_semweb_tool.xlsx -------------------------------------------------------------------------------- /Notebooks/Jupyter-RDFify-Example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Jupyter-RDFify Example Notebook\n", 8 | "\n", 9 | "The purpose of this notebook is to introduce you to the [Jupyter-RDFfify](https://github.com/SemWebNotebooks/Jupyter-RDFify) extension and show you many of its awesome features.\n", 10 | "\n", 11 | "## Installation\n", 12 | "\n", 13 | "
\n", 14 | " If you've already installed Jupyter-RDFify and its dependencies in your environment, you can skip this step!\n", 15 | "
\n", 16 | "\n", 17 | "Install the extension by running the following cell." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": { 24 | "scrolled": true 25 | }, 26 | "outputs": [], 27 | "source": [ 28 | "!python -m pip install --no-input jupyter-rdfify" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "The extension requires Graphviz for graph visualization. If you've already installed Graphviz and added it to your path, you're good to go! If not, either install it and add it to your path or either add \"--display table\", \"--display raw\" or \"--display none\" to all cell with graphic output.\n", 36 | "\n", 37 | "If you've the conda package manager installed, you may also run the following cell to install the graphviz binaries." 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [ 46 | "!conda install --yes -c conda-forge graphviz" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "## Loading The Extension\n", 54 | "\n", 55 | "Run the following cell to load the extension. You need to do this for every session or IPython will not recognize the rdf magic commands." 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "%reload_ext jupyter-rdfify" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "## It's A Kind Of Magic\n", 72 | "\n", 73 | "Magic commands are the way to tell IPython (the Python shell that Jupyter uses) that the following line or cell is not actual python code and should thus be treated differently. Everything in Jupyter-RDFify is controlled with the same magic, which is %rdf.\n", 74 | "\n", 75 | "Please be aware that there are line and cell magics. Line magics, which only interpret the line, start with one percent sign (e.g. `%rdf`) and cell magics, which interpret both the line and the cell, start with two percent signs (e.g. `%%rdf`). The Jupyter-RDFify uses both but in some use-cases you need to use cell magics (e.g. for parsing turtle).\n", 76 | "\n", 77 | "The rdf magic is interpreted like a command line interface so you can pass additional parameters using hyphens. If at any time you are lost or want to know which parameters you can use, use the help flag (`--help`, `-h`).\n", 78 | "\n", 79 | "To see all modules:" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "%rdf --help" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "To see the parameters of a specific module (here we show it for the turtle module):" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": null, 101 | "metadata": {}, 102 | "outputs": [], 103 | "source": [ 104 | "%rdf turtle --help" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": {}, 110 | "source": [ 111 | "## Features And Examples\n", 112 | "\n", 113 | "In the following we will present you many features that Jupyter-RDFify offers.\n", 114 | "\n", 115 | "### Serialization\n", 116 | "\n", 117 | "Jupyter-RDFify can parse many different RDF graph serializations (currently turtle, n3, json-ld and xml). After you have parsed a graph, you can later visualize, query, convert or entail it. The following cell parses a graph in Turtle notation and visualize it as a graph (this will throw an error if you do not have graphviz installed as explained in the [installation section](#Installation))." 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "%%rdf turtle\n", 127 | "@prefix ex: .\n", 128 | "ex:Jupyter-RDFify a ex:IPythonExtension .\n", 129 | "ex:Jupyter-RDFify ex:is ex:Awesome .\n", 130 | "ex:Jupyter-RDFify ex:uses ex:Graphviz .\n", 131 | "ex:Graphviz ex:is ex:Awesome ." 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "### Conversion\n", 139 | "\n", 140 | "You can easily convert a serialization into a different format using the `--serialize ` parameter together with the `--display raw` parameter. The following cell converts our example graph into JSON-LD." 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": null, 146 | "metadata": {}, 147 | "outputs": [], 148 | "source": [ 149 | "%%rdf turtle --serialize json-ld --display raw\n", 150 | "@prefix ex: .\n", 151 | "ex:Jupyter-RDFify a ex:IPythonExtension .\n", 152 | "ex:Jupyter-RDFify ex:is ex:Awesome .\n", 153 | "ex:Jupyter-RDFify ex:uses ex:Graphviz .\n", 154 | "ex:Graphviz ex:is ex:Awesome ." 155 | ] 156 | }, 157 | { 158 | "cell_type": "markdown", 159 | "metadata": {}, 160 | "source": [ 161 | "### Querying\n", 162 | "\n", 163 | "There are two possibilities to query graphs. Either we define and query a graph locally, or we use an external endpoint.\n", 164 | "\n", 165 | "#### Local\n", 166 | "\n", 167 | "To be able to reference a local graph for querying, we need to assign it a label. We can do this using the `--label