Raw File
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is an experimental (stub...) Schema.org dashboard using Jupyter/iPython\n",
    "\n",
    "See corresponding Github [issue #896](https://github.com/schemaorg/schemaorg/issues/896). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/Users/danbri/sdo/official/schemaorg\n",
      "Working from:  /Users/danbri/sdo/official/schemaorg\n",
      "GAE:  /Users/danbri/google-cloud-sdk/platform/google_appengine/\n"
     ]
    }
   ],
   "source": [
    "# Import libraries\n",
    "\n",
    "import unittest\n",
    "import os\n",
    "import pprint\n",
    "from os import path, getenv\n",
    "from os.path import expanduser\n",
    "import logging # https://docs.python.org/2/library/logging.html#logging-levels\n",
    "import glob\n",
    "import argparse\n",
    "import StringIO\n",
    "import sys\n",
    "\n",
    "# 3rd party, see e.g. http://pbpython.com/simple-graphing-pandas.html\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "pd.__version__\n",
    "%matplotlib inline\n",
    "\n",
    "# Locally,\n",
    "\n",
    "print os.getcwd()\n",
    "if os.getcwd().endswith('schemaorg'):\n",
    "    print \"Working from: \", os.getcwd()\n",
    "else:\n",
    "    #print \"cd ..\"\n",
    "    os.chdir(\"..\")\n",
    "\n",
    "# We'll need our lib/ dir, plus AppEngine's files:\n",
    "sys.path.append( os.getcwd() ) \n",
    "sdk_path = getenv('APP_ENGINE',  expanduser(\"~\") + '/google-cloud-sdk/platform/google_appengine/')\n",
    "sys.path.insert(0, sdk_path) \n",
    "print \"GAE: \", sdk_path\n",
    "\n",
    "# previous useful:\n",
    "import dev_appserver\n",
    "dev_appserver.fix_sys_path()\n",
    "# pprint.pprint(os.environ.copy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import rdflib\n",
    "from rdflib import Graph\n",
    "from rdflib import RDF, RDFS\n",
    "from rdflib.term import URIRef, Literal\n",
    "from rdflib.parser import Parser\n",
    "from rdflib.serializer import Serializer\n",
    "from rdflib.plugins.sparql import prepareQuery\n",
    "from rdflib.compare import graph_diff\n",
    "import threading\n",
    "from api import inLayer,read_file, full_path, read_schemas, read_extensions, read_examples, namespaces, DataCache, getMasterStore\n",
    "from api import  setInTestHarness, GetAllTypes, Unit, GetImmediateSubtypes # old API\n",
    "from apirdflib import getNss\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Setup\n",
    "setInTestHarness(True)\n",
    "import sdoapp\n",
    "\n",
    "rdflib.plugin.register(\"json-ld\", Serializer, \"rdflib_jsonld.serializer\", \"JsonLDSerializer\")\n",
    "\n",
    "store = getMasterStore()\n",
    "read_schemas(loadExtensions=True)\n",
    "read_extensions(sdoapp.ENABLED_EXTENSIONS)\n",
    "graphs = list(store.graphs())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Utilities\n",
    "\n",
    "def findGraph(guri):\n",
    "    myg = \"\"\n",
    "    for g in graphs:\n",
    "      #print g.identifier\n",
    "      if str(g.identifier) == guri:\n",
    "          myg = g\n",
    "          # print \"Found graph %s for graph URI %s\" % (g, guri)\n",
    "    # print myg\n",
    "    if myg == \"\":\n",
    "        print \"Didn't find graph %s.\" % guri\n",
    "        return None\n",
    "    else:\n",
    "        return myg\n",
    "\n",
    "# Convert SPARQL results to Pandas DataFrame:\n",
    "from pandas import DataFrame\n",
    "\n",
    "def sparql2df(a, cast_to_numeric=True):\n",
    "    c = []\n",
    "    for b in a.bindings:\n",
    "        rowvals=[]\n",
    "        for k in a.vars:\n",
    "            rowvals.append(b[k])\n",
    "        c.append(rowvals)\n",
    "\n",
    "    df = DataFrame(c)\n",
    "    df.columns = [str(v) for v in a.vars]\n",
    "    if cast_to_numeric:\n",
    "      df = df.apply(lambda x: pd.to_numeric(x, errors='ignore'))\n",
    "\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "# Overview\n",
    "\n",
    "We have two APIs, the original pseudo-RDF unit/node structure, plus also now RDFLib. \n",
    "It is better to use the latter as it gives access to SPARQL, parsers/serializers etc."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "sdocore = findGraph(\"http://schema.org/\")\n",
    "bibex = findGraph(\"http://bib.schema.org/\")\n",
    "auto = findGraph(\"http://auto.schema.org/\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'Found 583 types.'\n",
      "u'Direct subtypes of Article: NewsArticle, Report, ScholarlyArticle, SocialMediaPosting, TechArticle'\n",
      "u'Direct subtypes of CreativeWork: Article, Blog, Book, Clip, Code, Comment, Conversation, CreativeWorkSeason, CreativeWorkSeries, DataCatalog, Dataset, DigitalDocument, Episode, Game, Map, MediaObject, Message, Movie, MusicComposition, MusicPlaylist, MusicRecording, Painting, Photograph, PublicationIssue, PublicationVolume, Question, Recipe, Review, Sculpture, Season, Series, SoftwareApplication, SoftwareSourceCode, TVSeason, TVSeries, VisualArtwork, WebPage, WebPageElement, WebSite'\n",
      "u'Direct subtypes of Product: IndividualProduct, ProductModel, SomeProducts, Vehicle'\n",
      "u'Direct subtypes of MedicalEntity: '\n",
      "u'Direct subtypes of Event: BusinessEvent, ChildrensEvent, ComedyEvent, DanceEvent, DeliveryEvent, EducationEvent, ExhibitionEvent, Festival, FoodEvent, LiteraryEvent, MusicEvent, PublicationEvent, SaleEvent, ScreeningEvent, SocialEvent, SportsEvent, TheaterEvent, UserInteraction, VisualArtsEvent'\n"
     ]
    }
   ],
   "source": [
    "# Test OLD API (skip this, unless debugging; slow on first run.)\n",
    "\n",
    "pprint.pprint( \"Found %s types.\" % len( GetAllTypes() ) )\n",
    "for t in [\"Article\", \"CreativeWork\", \"Product\", \"MedicalEntity\", \"Event\"]: \n",
    "    someType = Unit.GetUnit(t)\n",
    "    p_subtypes = GetImmediateSubtypes(someType)\n",
    "    pprint.pprint( \"Direct subtypes of %s: %s\" % ( someType.id, ', '.join([str(x.id) for x in p_subtypes]) ) )\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "older: http://schema.org/merchant -> newer: http://schema.org/seller\n",
      "older: http://schema.org/attendees -> newer: http://schema.org/attendee\n",
      "older: http://schema.org/catalog -> newer: http://schema.org/includedInDataCatalog\n",
      "older: http://schema.org/area -> newer: http://schema.org/serviceArea\n",
      "older: http://schema.org/containedIn -> newer: http://schema.org/containedInPlace\n",
      "older: http://schema.org/sampleType -> newer: http://schema.org/codeSampleType\n",
      "older: http://schema.org/collection -> newer: http://schema.org/targetCollection\n",
      "older: http://schema.org/warrantyPromise -> newer: http://schema.org/warranty\n",
      "older: http://schema.org/Taxi -> newer: http://schema.org/TaxiService\n",
      "older: http://schema.org/application -> newer: http://schema.org/actionApplication\n",
      "older: http://schema.org/Code -> newer: http://schema.org/SoftwareSourceCode\n",
      "older: http://schema.org/UserPageVisits -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/DatedMoneySpecification -> newer: http://schema.org/MonetaryAmount\n",
      "older: http://schema.org/Season -> newer: http://schema.org/CreativeWorkSeason\n",
      "older: http://schema.org/awards -> newer: http://schema.org/award\n",
      "older: http://schema.org/ingredients -> newer: http://schema.org/recipeIngredient\n",
      "older: http://schema.org/datasetTimeInterval -> newer: http://schema.org/temporalCoverage\n",
      "older: http://schema.org/course -> newer: http://schema.org/exerciseCourse\n",
      "older: http://schema.org/UserPlays -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/episodes -> newer: http://schema.org/episode\n",
      "older: http://schema.org/paymentDue -> newer: http://schema.org/paymentDueDate\n",
      "older: http://schema.org/founders -> newer: http://schema.org/founder\n",
      "older: http://schema.org/temporal -> newer: http://schema.org/temporalCoverage\n",
      "older: http://schema.org/employees -> newer: http://schema.org/employee\n",
      "older: http://schema.org/UserInteraction -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/photos -> newer: http://schema.org/photo\n",
      "older: http://schema.org/option -> newer: http://schema.org/actionOption\n",
      "older: http://schema.org/siblings -> newer: http://schema.org/sibling\n",
      "older: http://schema.org/UserComments -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/map -> newer: http://schema.org/hasMap\n",
      "older: http://schema.org/events -> newer: http://schema.org/event\n",
      "older: http://schema.org/benefits -> newer: http://schema.org/jobBenefits\n",
      "older: http://schema.org/serviceArea -> newer: http://schema.org/areaServed\n",
      "older: http://schema.org/language -> newer: http://schema.org/inLanguage\n",
      "older: http://schema.org/partOfTVSeries -> newer: http://schema.org/partOfSeries\n",
      "older: http://schema.org/contactPoints -> newer: http://schema.org/contactPoint\n",
      "older: http://schema.org/colleagues -> newer: http://schema.org/colleague\n",
      "older: http://schema.org/produces -> newer: http://schema.org/serviceOutput\n",
      "older: http://schema.org/bookingAgent -> newer: http://schema.org/broker\n",
      "older: http://schema.org/musicGroupMember -> newer: http://schema.org/member\n",
      "older: http://schema.org/device -> newer: http://schema.org/availableOnDevice\n",
      "older: http://schema.org/serviceAudience -> newer: http://schema.org/audience\n",
      "older: http://schema.org/directors -> newer: http://schema.org/director\n",
      "older: http://schema.org/surface -> newer: http://schema.org/artworkSurface\n",
      "older: http://schema.org/isBasedOnUrl -> newer: http://schema.org/isBasedOn\n",
      "older: http://schema.org/spatial -> newer: http://schema.org/spatialCoverage\n",
      "older: http://schema.org/namedPosition -> newer: http://schema.org/roleName\n",
      "older: http://schema.org/seasons -> newer: http://schema.org/season\n",
      "older: http://schema.org/albums -> newer: http://schema.org/album\n",
      "older: http://schema.org/includedDataCatalog -> newer: http://schema.org/includedInDataCatalog\n",
      "older: http://schema.org/assembly -> newer: http://schema.org/executableLibraryName\n",
      "older: http://schema.org/significantLinks -> newer: http://schema.org/significantLink\n",
      "older: http://schema.org/maps -> newer: http://schema.org/hasMap\n",
      "older: http://schema.org/tracks -> newer: http://schema.org/track\n",
      "older: http://schema.org/carrier -> newer: http://schema.org/provider\n",
      "older: http://schema.org/performers -> newer: http://schema.org/performer\n",
      "older: http://schema.org/actors -> newer: http://schema.org/actor\n",
      "older: http://schema.org/UserPlusOnes -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/incentives -> newer: http://schema.org/incentiveCompensation\n",
      "older: http://schema.org/encodings -> newer: http://schema.org/encoding\n",
      "older: http://schema.org/requirements -> newer: http://schema.org/softwareRequirements\n",
      "older: http://schema.org/interactionCount -> newer: http://schema.org/interactionStatistic\n",
      "older: http://schema.org/free -> newer: http://schema.org/isAccessibleForFree\n",
      "older: http://schema.org/branchOf -> newer: http://schema.org/parentOrganization\n",
      "older: http://schema.org/UserLikes -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/subEvents -> newer: http://schema.org/subEvent\n",
      "older: http://schema.org/vendor -> newer: http://schema.org/seller\n",
      "older: http://schema.org/members -> newer: http://schema.org/member\n",
      "older: http://schema.org/UserCheckins -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/parents -> newer: http://schema.org/parent\n",
      "older: http://schema.org/blogPosts -> newer: http://schema.org/blogPost\n",
      "older: http://schema.org/reviews -> newer: http://schema.org/review\n",
      "older: http://schema.org/season -> newer: http://schema.org/containsSeason\n",
      "older: http://schema.org/UserBlocks -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/UserDownloads -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/UserTweets -> newer: http://schema.org/InteractionCounter\n",
      "older: http://schema.org/runtime -> newer: http://schema.org/runtimePlatform\n"
     ]
    }
   ],
   "source": [
    "renamed =  sdocore.query(\"select ?x ?y where { ?x <http://schema.org/supersededBy> ?y }\")\n",
    "\n",
    "for (old, new) in renamed:\n",
    "    print \"older: %s -> newer: %s\" % (old, new)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>x</th>\n",
       "      <th>p</th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/Chapter</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#label</td>\n",
       "      <td>Chapter</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>http://schema.org/Newspaper</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#label</td>\n",
       "      <td>Newspaper</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>http://schema.org/Collection</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#subClassOf</td>\n",
       "      <td>http://schema.org/CreativeWork</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              x  \\\n",
       "0     http://schema.org/Chapter   \n",
       "1   http://schema.org/Newspaper   \n",
       "2  http://schema.org/Collection   \n",
       "\n",
       "                                                 p  \\\n",
       "0       http://www.w3.org/2000/01/rdf-schema#label   \n",
       "1       http://www.w3.org/2000/01/rdf-schema#label   \n",
       "2  http://www.w3.org/2000/01/rdf-schema#subClassOf   \n",
       "\n",
       "                                y  \n",
       "0                         Chapter  \n",
       "1                       Newspaper  \n",
       "2  http://schema.org/CreativeWork  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = bibex.query(\"select ?x ?p ?y where { ?x ?p ?y } LIMIT 3\")\n",
    "sparql2df(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>item</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/associatedArticle</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>http://schema.org/awayTeam</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>http://schema.org/lastReviewed</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>http://schema.org/VideoGallery</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>http://schema.org/orderDate</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>http://schema.org/Church</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>http://schema.org/AssignAction</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>http://schema.org/pagination</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>http://schema.org/Rating</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>http://schema.org/supportingData</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>http://schema.org/InsertAction</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>http://schema.org/encodings</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>http://schema.org/ClothingStore</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>http://schema.org/founder</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>http://schema.org/PublicationIssue</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>http://schema.org/validUntil</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>http://schema.org/serviceOutput</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>http://schema.org/attendee</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>http://schema.org/TouristInformationCenter</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>http://schema.org/workFeatured</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>http://schema.org/AutoPartsStore</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>http://schema.org/CookAction</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>http://schema.org/OrganizationRole</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>http://schema.org/makesOffer</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>http://schema.org/Painting</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>http://schema.org/UseAction</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>http://schema.org/Blog</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>http://schema.org/Season</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>http://schema.org/CassetteFormat</td>\n",
       "      <td>http://schema.org/MusicReleaseFormatType</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>http://schema.org/targetPlatform</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1547</th>\n",
       "      <td>http://schema.org/LodgingReservation</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1548</th>\n",
       "      <td>http://schema.org/actionPlatform</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1549</th>\n",
       "      <td>http://schema.org/HousePainter</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1550</th>\n",
       "      <td>http://schema.org/season</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1551</th>\n",
       "      <td>http://schema.org/isicV4</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1552</th>\n",
       "      <td>http://schema.org/transFatContent</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1553</th>\n",
       "      <td>http://schema.org/EmergencyService</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1554</th>\n",
       "      <td>http://schema.org/characterAttribute</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1555</th>\n",
       "      <td>http://schema.org/TVClip</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1556</th>\n",
       "      <td>http://schema.org/publishedOn</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1557</th>\n",
       "      <td>http://schema.org/OutletStore</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1558</th>\n",
       "      <td>http://schema.org/ConsumeAction</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1559</th>\n",
       "      <td>http://schema.org/AudioObject</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1560</th>\n",
       "      <td>http://schema.org/FlightReservation</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1561</th>\n",
       "      <td>http://schema.org/MotorcycleDealer</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1562</th>\n",
       "      <td>http://schema.org/opponent</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1563</th>\n",
       "      <td>http://schema.org/athlete</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1564</th>\n",
       "      <td>http://schema.org/MusicEvent</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1565</th>\n",
       "      <td>http://schema.org/partOfSeason</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1566</th>\n",
       "      <td>http://schema.org/Resort</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1567</th>\n",
       "      <td>http://schema.org/sibling</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1568</th>\n",
       "      <td>http://schema.org/Car</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1569</th>\n",
       "      <td>http://schema.org/DepartmentStore</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1570</th>\n",
       "      <td>http://schema.org/salaryCurrency</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1571</th>\n",
       "      <td>http://schema.org/Demand</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1572</th>\n",
       "      <td>http://schema.org/EmploymentAgency</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1573</th>\n",
       "      <td>http://schema.org/benefits</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1574</th>\n",
       "      <td>http://schema.org/specialCommitments</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1575</th>\n",
       "      <td>http://schema.org/tickerSymbol</td>\n",
       "      <td>http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1576</th>\n",
       "      <td>http://schema.org/DryCleaningOrLaundry</td>\n",
       "      <td>http://www.w3.org/2000/01/rdf-schema#Class</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1577 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            item  \\\n",
       "0            http://schema.org/associatedArticle   \n",
       "1                     http://schema.org/awayTeam   \n",
       "2                 http://schema.org/lastReviewed   \n",
       "3                 http://schema.org/VideoGallery   \n",
       "4                    http://schema.org/orderDate   \n",
       "5                       http://schema.org/Church   \n",
       "6                 http://schema.org/AssignAction   \n",
       "7                   http://schema.org/pagination   \n",
       "8                       http://schema.org/Rating   \n",
       "9               http://schema.org/supportingData   \n",
       "10                http://schema.org/InsertAction   \n",
       "11                   http://schema.org/encodings   \n",
       "12               http://schema.org/ClothingStore   \n",
       "13                     http://schema.org/founder   \n",
       "14            http://schema.org/PublicationIssue   \n",
       "15                  http://schema.org/validUntil   \n",
       "16               http://schema.org/serviceOutput   \n",
       "17                    http://schema.org/attendee   \n",
       "18    http://schema.org/TouristInformationCenter   \n",
       "19                http://schema.org/workFeatured   \n",
       "20              http://schema.org/AutoPartsStore   \n",
       "21                  http://schema.org/CookAction   \n",
       "22            http://schema.org/OrganizationRole   \n",
       "23                  http://schema.org/makesOffer   \n",
       "24                    http://schema.org/Painting   \n",
       "25                   http://schema.org/UseAction   \n",
       "26                        http://schema.org/Blog   \n",
       "27                      http://schema.org/Season   \n",
       "28              http://schema.org/CassetteFormat   \n",
       "29              http://schema.org/targetPlatform   \n",
       "...                                          ...   \n",
       "1547        http://schema.org/LodgingReservation   \n",
       "1548            http://schema.org/actionPlatform   \n",
       "1549              http://schema.org/HousePainter   \n",
       "1550                    http://schema.org/season   \n",
       "1551                    http://schema.org/isicV4   \n",
       "1552           http://schema.org/transFatContent   \n",
       "1553          http://schema.org/EmergencyService   \n",
       "1554        http://schema.org/characterAttribute   \n",
       "1555                    http://schema.org/TVClip   \n",
       "1556               http://schema.org/publishedOn   \n",
       "1557               http://schema.org/OutletStore   \n",
       "1558             http://schema.org/ConsumeAction   \n",
       "1559               http://schema.org/AudioObject   \n",
       "1560         http://schema.org/FlightReservation   \n",
       "1561          http://schema.org/MotorcycleDealer   \n",
       "1562                  http://schema.org/opponent   \n",
       "1563                   http://schema.org/athlete   \n",
       "1564                http://schema.org/MusicEvent   \n",
       "1565              http://schema.org/partOfSeason   \n",
       "1566                    http://schema.org/Resort   \n",
       "1567                   http://schema.org/sibling   \n",
       "1568                       http://schema.org/Car   \n",
       "1569           http://schema.org/DepartmentStore   \n",
       "1570            http://schema.org/salaryCurrency   \n",
       "1571                    http://schema.org/Demand   \n",
       "1572          http://schema.org/EmploymentAgency   \n",
       "1573                  http://schema.org/benefits   \n",
       "1574        http://schema.org/specialCommitments   \n",
       "1575              http://schema.org/tickerSymbol   \n",
       "1576      http://schema.org/DryCleaningOrLaundry   \n",
       "\n",
       "                                                   type  \n",
       "0     http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1     http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "2     http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "3            http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "4     http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "5            http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "6            http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "7     http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "8            http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "9     http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "10           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "11    http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "12           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "13    http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "14           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "15    http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "16    http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "17    http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "18           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "19    http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "20           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "21           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "22           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "23    http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "24           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "25           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "26           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "27           http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "28             http://schema.org/MusicReleaseFormatType  \n",
       "29    http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "...                                                 ...  \n",
       "1547         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1548  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1549         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1550  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1551  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1552  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1553         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1554  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1555         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1556  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1557         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1558         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1559         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1560         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1561         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1562  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1563  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1564         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1565  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1566         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1567  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1568         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1569         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1570  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1571         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1572         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "1573  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1574  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1575  http://www.w3.org/1999/02/22-rdf-syntax-ns#Pro...  \n",
       "1576         http://www.w3.org/2000/01/rdf-schema#Class  \n",
       "\n",
       "[1577 rows x 2 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sparql2df( sdocore.query(\"select ?item ?type where { ?item a ?type }\") )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "s=\"\"\"SELECT ?child (count(?grandchild) as ?nGrandchildren) where {\n",
    "  ?child rdfs:subClassOf schema:Thing .\n",
    "  OPTIONAL { ?grandchild rdfs:subClassOf ?child }\n",
    "}\n",
    "GROUP BY ?child order by desc(count(?grandchild))\"\"\"\n",
    "ets = sparql2df(  sdocore.query(s)) # Count subtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            child  nGrandchildren\n",
      "0  http://schema.org/CreativeWork              39\n",
      "1    http://schema.org/Intangible              36\n",
      "2         http://schema.org/Event              19\n",
      "3        http://schema.org/Action              14\n",
      "4  http://schema.org/Organization               9\n",
      "5         http://schema.org/Place               8\n",
      "6       http://schema.org/Product               4\n",
      "7        http://schema.org/Person               1\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x117a3fc10>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW0AAAD8CAYAAAC8TPVwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAF1hJREFUeJzt3X+QVeWd5/H3p0H5YULTiNIo2M1iCLAV0YmwlZJsLrqx\n3TEZoxZEqU1aw7hJVVzFTKxENmprpaYmE39Uki3/SCEUJhOnxJBFJv4gUW4oZrMDKohRV6dUEAU6\nKgw/Rvllf/ePPrTdzW3u7b63uf00n1fVLc495znP870N/emHp8+9RxGBmZmloabaBZiZWekc2mZm\nCXFom5klxKFtZpYQh7aZWUIc2mZmCSk5tCXVSHpe0mPZ8zpJqyW9KukpSbX9V6aZmUHvZto3Ay93\nev594PcR8WngGeC2ShZmZmbHKim0JU0A/hJY3Gn3FcCybHsZ8JXKlmZmZt2VOtO+H7gV6Pz2yXER\n0QoQETuBMytcm5mZdTO0WANJlwOtEbFJUu44TQu+H16S3ydvZtYHEaHu+0qZaV8E/JWkN4CHgYsl\n/QLYKWkcgKR64M/HGbiijzvvvLPiffbHw3WeXDW6TtdZyUdPioZ2RCyKiHMi4j8A1wDPRMTXgFXA\ndVmzZmBlCT8AzMysDOVcp/13wBclvQpckj03M7N+VHRNu7OI+APwh2x7F/Bf+qOoYnK5XDWG7TXX\nWTkp1Aius9Jc57F0vLWTigwgRX+PYWY22EgiCvwislcz7f5UX99Ia+vWivY5blwDO3duqWifZr3R\n2NjI1q2V/Xdtg0tDQwNbtmwpuf2AmWlLooerBssZ/bi/hTXrb9lsqdpl2ADW07+Rnmba/sAoM7OE\nOLTNzBLi0DYzS4hD28wsIQ5tMxuwrr/+eu64446i7ebMmcOSJUsKHtu2bRujRo3q+GXf8dpu3bqV\nmpoa2tra+l50P3Nom51g9fWNSOq3R319Y0Xq3L9/P9/5zneYNGkSn/zkJ2lsbGTevHmsX7++Iv2f\nKBMnTmTv3r3ZFWrFldquWgbMddpmJ4v29yP032WAra3lh86hQ4eYM2cOY8aM4fHHH2fq1KkcOHCA\nJ554gieffJJZs2Ydc85HH33EkCFDyh57IIuIqoe6Z9pmJ7FJkyZx7733MmPGDOrq6rj22ms5dOgQ\nDz30ENu3b2flypVMmzYNSYwYMYKrrrqqy3JFTU0NDzzwAFOmTGHKlCkALFy4kHPOOYfa2lpmzpzJ\nunXrOtrfddddfPWrX6W5uZlRo0bxmc98hueff77j+MaNG/nsZz9LbW0t11xzDQcOHOhS78qVK7ng\ngguora3lU5/6FKtXr+44tmXLFmbPns2oUaO47LLL2LVrF3D8JY+2tja++93vcsYZZ3Duuefy29/+\ntsvxOXPm8IMf/IDZs2dz2mmn8eabb7J3714WLFjAWWedxcSJE7n99ts7ll6WLVvG5z//eW699VbG\njBnD5MmTefLJJ/v611OQQ9vsJLd8+XJWr17Nm2++yebNm1m6dClPP/00TU1NDB8+vOj5K1euZMOG\nDbz8cvvdCGfNmsXmzZvZvXs38+fPZ+7cuRw6dKij/apVq5g/fz579uzhy1/+Mt/+9rcBOHz4MFde\neSXNzc3s2rWLuXPn8utf/7rjvPXr19Pc3My9997Lnj17WLt2LY2NjR3HH374YZYtW8a7777LwYMH\nueeeezqO9TQ7/vnPf87jjz/OCy+8wLPPPsujjz56TJtf/vKXLF68mH379nHOOefQ3NzMsGHDeOON\nN9i4cSO/+93vWLz445t6rV+/nmnTpvH+++9z6623smDBgqJfw95waJud5G6++WbGjRvH6NGj+dKX\nvsSmTZt47733qK+v72jzwgsvUFdXR21tLdOmTety/qJFi6itrWXYsGEAzJ8/n9GjR1NTU8Mtt9zC\nwYMHefXVVzvaz549m6amJiTxta99jc2bNwPwxz/+kSNHjnDTTTcxZMgQrr76ambOnNlx3pIlS1iw\nYAEXX3wxAOPHj++Y3UP7Ly0nT57MsGHDmDdvHps2bSr62pcvX87ChQs566yzGD16NLfdduytbq+7\n7jqmTp1KTU0Nu3bt4oknnuD+++9n+PDhjB07loULF/Lwww93tG9oaOAb3/gGk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i8Ansu1G4FnagxtgY7Xr\n61TnS8AQYCSwFxiV7R8BvFDt+jrV+TzwSyAHfCH7c0e2/YVq19epzo2dtjcAZ2TbpwEvVru+TrW9\n0vlr2+3YpmrX1/nrSfuE4lLgQeBd4EmgGfhkf49fzptrToQ24Cyg+0djjc+ODRiSNvd0CBh3Ims5\njpqI2A8QEVsk5YBHJTXQXudAcSgiPgI+kPR6ROwFiIgPJQ2kv/cLgZuB/wncGhGbJH0YEX+ocl3d\n1Uiqoz1ohkQ2K4yIf5d0pLqldfGnTv8rfUHShRHxrKQpwOFqF9dJREQb7Zc7r5Z0CvBfaV8VuAc4\noz8HH+ihvRB4WtK/8vHnnJwDnAvcWLWqChtH+yce7u62X8D/OfHlFNQq6fyI2AQQEfslfQlYAnym\nuqV1cUjSyIj4APjs0Z3ZuuaAWc/LvnHvl7Q8+7OVgfk9VQs8R/u/xZA0PiJ2ZL/XGEg/rP8a+Imk\nHwDvAX+UtI327/2/rmplXXX5mkX7B+Y9BjwmaWS/D55N9wes7CNgZ/Hxh1G9A2zIZmIDhqQHgaUR\nsa7AsV9FxPwqlNW9jgnAkYjYWeDYRRHxz1Uo6xiShkXEwQL7xwLjI+LFKpRVlKTLgYsiYlG1aylF\nFjDjIuLNatfSWfbLyEm0/wB8OyJaq1xSF5KmRMRrVRt/oIe2mZl9bMBf8mdmZh9zaJuZJcShbWaW\nEIe2mVlC/j9Y/uzKaQIUZQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x118eca490>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print ets\n",
    "ets.plot(kind='bar')\n",
    "\n",
    "# ets['nGrandchildren']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>child</th>\n",
       "      <th>nGrandchildren</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/CreativeWork</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>http://schema.org/Intangible</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>http://schema.org/Event</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>http://schema.org/Action</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>http://schema.org/Organization</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>http://schema.org/Place</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>http://schema.org/Product</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>http://schema.org/Person</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            child  nGrandchildren\n",
       "0  http://schema.org/CreativeWork              39\n",
       "1    http://schema.org/Intangible              36\n",
       "2         http://schema.org/Event              19\n",
       "3        http://schema.org/Action              14\n",
       "4  http://schema.org/Organization               9\n",
       "5         http://schema.org/Place               8\n",
       "6       http://schema.org/Product               4\n",
       "7        http://schema.org/Person               1"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Property counts e.g. Movie\n",
    "<a id=\"moviecount\"></a>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>t</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/Movie</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         t   n\n",
       "0  http://schema.org/Movie  10"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Properties on each class (outgoing)\n",
    "\n",
    "# What's wrong with this query?\n",
    "#s = \"SELECT distinct ?t (count(?prop) as ?n)  WHERE { ?prop schema:domainIncludes ?t . } GROUP BY ?prop ORDER BY DESC(?n)\"\n",
    "\n",
    "\n",
    "s = \"\"\"SELECT ?t (count(?prop) as ?n)  WHERE { ?prop schema:domainIncludes ?t . \n",
    "FILTER (?t = <http://schema.org/Movie> ) . } GROUP BY ?t ORDER BY DESC(?n)\"\"\"\n",
    "sparql2df(  sdocore.query( s))\n",
    "\n",
    "# Something is wrong here. Movie should have 10 properties (2 of which are superseded: actors, directors).\n",
    "# Why are there multiple rows?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>t</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/StructuredValue</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>http://schema.org/Number</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>http://schema.org/AdministrativeArea</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>http://schema.org/ContactPoint</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>http://schema.org/URL</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>http://schema.org/Thing</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>http://schema.org/PriceSpecification</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>http://schema.org/Boolean</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>http://schema.org/Place</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>http://schema.org/QualitativeValue</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>http://schema.org/DataFeedItem</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>http://schema.org/PostalAddress</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>http://schema.org/Person</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>http://schema.org/Audience</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>http://schema.org/QualitativeValue</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>http://schema.org/URL</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>http://schema.org/URL</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>http://schema.org/CreativeWork</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>http://schema.org/PriceSpecification</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>http://schema.org/Product</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>http://schema.org/Place</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>http://schema.org/Organization</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>http://schema.org/QuantitativeValue</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>http://schema.org/Service</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>http://schema.org/MonetaryAmount</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>http://schema.org/ImageObject</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>http://schema.org/ProductModel</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>817</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>818</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>819</th>\n",
       "      <td>http://schema.org/CreativeWorkSeason</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>820</th>\n",
       "      <td>http://schema.org/DateTime</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>821</th>\n",
       "      <td>http://schema.org/Duration</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>822</th>\n",
       "      <td>http://schema.org/DeliveryMethod</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>823</th>\n",
       "      <td>http://schema.org/Date</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>824</th>\n",
       "      <td>http://schema.org/URL</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>825</th>\n",
       "      <td>http://schema.org/BroadcastService</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>826</th>\n",
       "      <td>http://schema.org/LocationFeatureSpecification</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>827</th>\n",
       "      <td>http://schema.org/QuantitativeValue</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>828</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>829</th>\n",
       "      <td>http://schema.org/Person</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>830</th>\n",
       "      <td>http://schema.org/VideoObject</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>831</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>832</th>\n",
       "      <td>http://schema.org/DateTime</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>833</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>834</th>\n",
       "      <td>http://schema.org/Organization</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>835</th>\n",
       "      <td>http://schema.org/Question</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>836</th>\n",
       "      <td>http://schema.org/Integer</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>837</th>\n",
       "      <td>http://schema.org/Action</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>838</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>839</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>840</th>\n",
       "      <td>http://schema.org/TrainStation</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>841</th>\n",
       "      <td>http://schema.org/Person</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>842</th>\n",
       "      <td>http://schema.org/PostalAddress</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>843</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>844</th>\n",
       "      <td>http://schema.org/Place</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>845</th>\n",
       "      <td>http://schema.org/Text</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>846</th>\n",
       "      <td>http://schema.org/CreativeWork</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>847 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  t  n\n",
       "0                 http://schema.org/StructuredValue  5\n",
       "1                          http://schema.org/Number  4\n",
       "2              http://schema.org/AdministrativeArea  4\n",
       "3                    http://schema.org/ContactPoint  4\n",
       "4                             http://schema.org/URL  3\n",
       "5                           http://schema.org/Thing  3\n",
       "6              http://schema.org/PriceSpecification  3\n",
       "7                         http://schema.org/Boolean  3\n",
       "8                           http://schema.org/Place  3\n",
       "9                http://schema.org/QualitativeValue  3\n",
       "10                   http://schema.org/DataFeedItem  3\n",
       "11                  http://schema.org/PostalAddress  3\n",
       "12                         http://schema.org/Person  3\n",
       "13                           http://schema.org/Text  3\n",
       "14                           http://schema.org/Text  3\n",
       "15                       http://schema.org/Audience  3\n",
       "16               http://schema.org/QualitativeValue  3\n",
       "17                            http://schema.org/URL  3\n",
       "18                            http://schema.org/URL  3\n",
       "19                   http://schema.org/CreativeWork  3\n",
       "20             http://schema.org/PriceSpecification  3\n",
       "21                           http://schema.org/Text  3\n",
       "22                        http://schema.org/Product  3\n",
       "23                          http://schema.org/Place  3\n",
       "24                   http://schema.org/Organization  2\n",
       "25              http://schema.org/QuantitativeValue  2\n",
       "26                        http://schema.org/Service  2\n",
       "27                 http://schema.org/MonetaryAmount  2\n",
       "28                    http://schema.org/ImageObject  2\n",
       "29                   http://schema.org/ProductModel  2\n",
       "..                                              ... ..\n",
       "817                          http://schema.org/Text  1\n",
       "818                          http://schema.org/Text  1\n",
       "819            http://schema.org/CreativeWorkSeason  1\n",
       "820                      http://schema.org/DateTime  1\n",
       "821                      http://schema.org/Duration  1\n",
       "822                http://schema.org/DeliveryMethod  1\n",
       "823                          http://schema.org/Date  1\n",
       "824                           http://schema.org/URL  1\n",
       "825              http://schema.org/BroadcastService  1\n",
       "826  http://schema.org/LocationFeatureSpecification  1\n",
       "827             http://schema.org/QuantitativeValue  1\n",
       "828                          http://schema.org/Text  1\n",
       "829                        http://schema.org/Person  1\n",
       "830                   http://schema.org/VideoObject  1\n",
       "831                          http://schema.org/Text  1\n",
       "832                      http://schema.org/DateTime  1\n",
       "833                          http://schema.org/Text  1\n",
       "834                  http://schema.org/Organization  1\n",
       "835                      http://schema.org/Question  1\n",
       "836                       http://schema.org/Integer  1\n",
       "837                        http://schema.org/Action  1\n",
       "838                          http://schema.org/Text  1\n",
       "839                          http://schema.org/Text  1\n",
       "840                  http://schema.org/TrainStation  1\n",
       "841                        http://schema.org/Person  1\n",
       "842                 http://schema.org/PostalAddress  1\n",
       "843                          http://schema.org/Text  1\n",
       "844                         http://schema.org/Place  1\n",
       "845                          http://schema.org/Text  1\n",
       "846                  http://schema.org/CreativeWork  1\n",
       "\n",
       "[847 rows x 2 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Properties on each class (*incoming*)\n",
    "s = \"SELECT  ?t (count(?prop) as ?n)  WHERE { ?prop schema:rangeIncludes ?t . } GROUP BY ?prop ORDER BY DESC(?n)\"\n",
    "sparql2df(  sdocore.query( s))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>x</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/Festival</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>http://schema.org/DanceEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>http://schema.org/BusinessEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>http://schema.org/SocialEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>http://schema.org/ExhibitionEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>http://schema.org/PublicationEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>http://schema.org/DeliveryEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>http://schema.org/EducationEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>http://schema.org/ComedyEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>http://schema.org/MusicEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>http://schema.org/UserInteraction</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>http://schema.org/ChildrensEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>http://schema.org/LiteraryEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>http://schema.org/SaleEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>http://schema.org/FoodEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>http://schema.org/TheaterEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>http://schema.org/ScreeningEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>http://schema.org/SportsEvent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>http://schema.org/VisualArtsEvent</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     x\n",
       "0           http://schema.org/Festival\n",
       "1         http://schema.org/DanceEvent\n",
       "2      http://schema.org/BusinessEvent\n",
       "3        http://schema.org/SocialEvent\n",
       "4    http://schema.org/ExhibitionEvent\n",
       "5   http://schema.org/PublicationEvent\n",
       "6      http://schema.org/DeliveryEvent\n",
       "7     http://schema.org/EducationEvent\n",
       "8        http://schema.org/ComedyEvent\n",
       "9         http://schema.org/MusicEvent\n",
       "10   http://schema.org/UserInteraction\n",
       "11    http://schema.org/ChildrensEvent\n",
       "12     http://schema.org/LiteraryEvent\n",
       "13         http://schema.org/SaleEvent\n",
       "14         http://schema.org/FoodEvent\n",
       "15      http://schema.org/TheaterEvent\n",
       "16    http://schema.org/ScreeningEvent\n",
       "17       http://schema.org/SportsEvent\n",
       "18   http://schema.org/VisualArtsEvent"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sparql2df( sdocore.query(\"select ?x where { ?x rdfs:subClassOf <http://schema.org/Event> } LIMIT 30 \") )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Graph identifier=http://schema.org/ (<class 'rdflib.graph.Graph'>)>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sdocore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>x</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/Blog</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>http://schema.org/TVSeries</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>http://schema.org/SoftwareSourceCode</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>http://schema.org/PublicationVolume</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>http://schema.org/Episode</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>http://schema.org/Clip</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>http://schema.org/DataCatalog</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>http://schema.org/Sculpture</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>http://schema.org/Review</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>http://schema.org/CreativeWorkSeries</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>http://schema.org/Message</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>http://schema.org/CreativeWorkSeason</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>http://schema.org/MusicComposition</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>http://schema.org/WebPageElement</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>http://schema.org/Photograph</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>http://schema.org/WebSite</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>http://schema.org/Conversation</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>http://schema.org/MusicPlaylist</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>http://schema.org/Map</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>http://schema.org/Book</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>http://schema.org/WebPage</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>http://schema.org/Article</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>http://schema.org/Painting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>http://schema.org/Game</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>http://schema.org/Dataset</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>http://schema.org/Season</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>http://schema.org/Code</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>http://schema.org/Series</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>http://schema.org/MusicRecording</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>http://schema.org/VisualArtwork</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>http://schema.org/SoftwareApplication</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>http://schema.org/Recipe</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>http://schema.org/MediaObject</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>http://schema.org/Movie</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>http://schema.org/DigitalDocument</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>http://schema.org/PublicationIssue</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>http://schema.org/Comment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>http://schema.org/TVSeason</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>http://schema.org/Question</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        x\n",
       "0                  http://schema.org/Blog\n",
       "1              http://schema.org/TVSeries\n",
       "2    http://schema.org/SoftwareSourceCode\n",
       "3     http://schema.org/PublicationVolume\n",
       "4               http://schema.org/Episode\n",
       "5                  http://schema.org/Clip\n",
       "6           http://schema.org/DataCatalog\n",
       "7             http://schema.org/Sculpture\n",
       "8                http://schema.org/Review\n",
       "9    http://schema.org/CreativeWorkSeries\n",
       "10              http://schema.org/Message\n",
       "11   http://schema.org/CreativeWorkSeason\n",
       "12     http://schema.org/MusicComposition\n",
       "13       http://schema.org/WebPageElement\n",
       "14           http://schema.org/Photograph\n",
       "15              http://schema.org/WebSite\n",
       "16         http://schema.org/Conversation\n",
       "17        http://schema.org/MusicPlaylist\n",
       "18                  http://schema.org/Map\n",
       "19                 http://schema.org/Book\n",
       "20              http://schema.org/WebPage\n",
       "21              http://schema.org/Article\n",
       "22             http://schema.org/Painting\n",
       "23                 http://schema.org/Game\n",
       "24              http://schema.org/Dataset\n",
       "25               http://schema.org/Season\n",
       "26                 http://schema.org/Code\n",
       "27               http://schema.org/Series\n",
       "28       http://schema.org/MusicRecording\n",
       "29        http://schema.org/VisualArtwork\n",
       "30  http://schema.org/SoftwareApplication\n",
       "31               http://schema.org/Recipe\n",
       "32          http://schema.org/MediaObject\n",
       "33                http://schema.org/Movie\n",
       "34      http://schema.org/DigitalDocument\n",
       "35     http://schema.org/PublicationIssue\n",
       "36              http://schema.org/Comment\n",
       "37             http://schema.org/TVSeason\n",
       "38             http://schema.org/Question"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"select ?x where { ?x rdfs:subClassOf <http://schema.org/CreativeWork> } LIMIT 60 \"\n",
    "a = sdocore.query(s)\n",
    "sparql2df( a )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Unit Tests\n",
    "# Seems we could run them here, https://amodernstory.com/2015/06/28/running-unittests-in-the-ipython-notebook/\n",
    "# unittest.TextTestRunner().run(suite)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>t</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/Movie</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         t  n\n",
       "0  http://schema.org/Movie  1"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s=\"\"\"\n",
    "PREFIX schema: <http://schema.org/> \n",
    "SELECT distinct ?t (count(?prop) as ?n) \n",
    "WHERE { \n",
    "?prop schema:domainIncludes ?t . FILTER (?t = <http://schema.org/Movie> ) .\n",
    "} \n",
    "GROUP BY ?prop ORDER BY DESC(?n)\"\"\"\n",
    "\n",
    "sparql2df( sdocore.query(s) )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "# Debugging. \n",
    "<a id=\"debugcounts\"></a>\n",
    "\n",
    "Something is wrong with the count queries above. \n",
    "\n",
    "* The count query thinks 11 property terms apply directly to Movie\n",
    "* Querying finds just 10\n",
    "* http://webschemas.org/Movie shows just 8, because 'actors' and 'directors' were suppressed. By why 11 not 10?\n",
    "* Trying in Dydra, see http://dydra.com/danbri/schema-org-3-1-sdo-makemake/@query#counting-props-on-types\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>t</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/Movie</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>http://schema.org/VideoGameSeries</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>http://schema.org/ReturnAction</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>http://schema.org/RadioSeries</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>http://schema.org/MovieSeries</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   t   n\n",
       "0            http://schema.org/Movie  11\n",
       "1  http://schema.org/VideoGameSeries  11\n",
       "2     http://schema.org/ReturnAction   9\n",
       "3      http://schema.org/RadioSeries   9\n",
       "4      http://schema.org/MovieSeries   9"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"SELECT distinct ?t (count(?prop) as ?n)  WHERE { ?prop schema:domainIncludes ?t . } GROUP BY ?prop ORDER BY DESC(?n) LIMIT 5\"\n",
    "sparql2df(  sdocore.query( s))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>prop</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/actors</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>http://schema.org/musicBy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>http://schema.org/actor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>http://schema.org/subtitleLanguage</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>http://schema.org/trailer</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>http://schema.org/directors</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>http://schema.org/duration</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>http://schema.org/productionCompany</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>http://schema.org/director</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>http://schema.org/countryOfOrigin</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  prop\n",
       "0             http://schema.org/actors\n",
       "1            http://schema.org/musicBy\n",
       "2              http://schema.org/actor\n",
       "3   http://schema.org/subtitleLanguage\n",
       "4            http://schema.org/trailer\n",
       "5          http://schema.org/directors\n",
       "6           http://schema.org/duration\n",
       "7  http://schema.org/productionCompany\n",
       "8           http://schema.org/director\n",
       "9    http://schema.org/countryOfOrigin"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"SELECT distinct *  WHERE { ?prop schema:domainIncludes <http://schema.org/Movie> . }\"\n",
    "sparql2df(  sdocore.query( s))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  debugging counts\n",
    "<a id=\"debug_counts2\"></a>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>prop</th>\n",
       "      <th>prop2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>http://schema.org/actor</td>\n",
       "      <td>http://schema.org/actors</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>http://schema.org/director</td>\n",
       "      <td>http://schema.org/directors</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         prop                        prop2\n",
       "0     http://schema.org/actor     http://schema.org/actors\n",
       "1  http://schema.org/director  http://schema.org/directors"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"\"\"SELECT distinct ?t (count(?prop) as ?n) ?prop2\n",
    "WHERE { \n",
    "OPTIONAL { ?prop schema:domainIncludes ?t . }  \n",
    "?prop2 schema:supersededBy ?prop .\n",
    "FILTER (?t = <http://schema.org/Movie>) .\n",
    "} \n",
    "GROUP BY ?prop ORDER BY DESC(?n)\n",
    "\"\"\"\n",
    "# sparql2df(  sdocore.query( s))\n",
    "\n",
    "\n",
    "s = \"\"\"SELECT distinct *  WHERE  {\n",
    " ?prop schema:domainIncludes <http://schema.org/Movie> . \n",
    " ?prop2 schema:supersededBy ?prop . \n",
    "}\"\"\"\n",
    "sparql2df(  sdocore.query( s))\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
back to top