{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "bpbGI60IiIOH"
      },
      "outputs": [],
      "source": [
        "from SPARQLWrapper import SPARQLWrapper, JSON"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "URL4SPARQLENDPIOINT = \"http://FILL_YOUR_IP:8890/sparql\""
      ],
      "metadata": {
        "id": "T7FUQc7BiVFx"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "sparql = SPARQLWrapper(URL4SPARQLENDPIOINT)"
      ],
      "metadata": {
        "id": "GicSKzW2iS73"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "query = \"\"\"\n",
        "PREFIX sio: <http://semanticscience.org/resource/>\n",
        "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n",
        "PREFIX sio: <http://semanticscience.org/resource/>\n",
        "PREFIX mb: <https://registry.identifiers.org/registry/massbank>\n",
        "PREFIX co: <http://classyfire.wishartlab.com/tax_nodes>\n",
        "PREFIX mbo: <http://www.massbank.jp/ontology/>\n",
        "PREFIX obo: <http://purl.obolibrary.org/obo/>\n",
        "SELECT DISTINCT ?compound ?name\n",
        "WHERE {\n",
        " ?compound a sio:CHEMINF_000043 .\n",
        "?compound sio:SIO_000300 ?name\n",
        "}LIMIT 10\n",
        "\"\"\""
      ],
      "metadata": {
        "id": "fa4ECVTLigzj"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "default_graph_uri = \"http://localhost:8890/oka\""
      ],
      "metadata": {
        "id": "XlUPxG9-iigE"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "sparql.setQuery(query)"
      ],
      "metadata": {
        "id": "LgPZtGUsij1C"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "sparql.addParameter(\"default-graph-uri\", default_graph_uri)"
      ],
      "metadata": {
        "id": "LdeRj9TRilNp"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "sparql.setReturnFormat(JSON)"
      ],
      "metadata": {
        "id": "_1f4EGnXimbq"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "results = sparql.query().convert()"
      ],
      "metadata": {
        "id": "ASRByrspiptG"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "for result in results[\"results\"][\"bindings\"]:\n",
        "    print(result)"
      ],
      "metadata": {
        "id": "lFrnD6ajirld"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}