Last active
August 2, 2022 18:59
-
-
Save datadavev/f806944ed20686d6036205f5aafb0a12 to your computer and use it in GitHub Desktop.
Basic setup for solr nested docs / graph searching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"This notebook explores a couple of graph search options in solr. It assumes SOLR is available using this `docker-compose.yml`:\n", | |
"\n", | |
"```yaml\n", | |
"version: '3'\n", | |
"services:\n", | |
" solr:\n", | |
" image: solr\n", | |
" ports:\n", | |
" - \"18983:8983\"\n", | |
" volumes:\n", | |
" - \"solrdata:/var/solr\"\n", | |
" command: solr -f -cloud\n", | |
"volumes:\n", | |
" solrdata:\n", | |
"```\n", | |
"\n", | |
"Start it up like `docker-compose up -d`\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Some data documents to mess with\n", | |
"docs = [\n", | |
" {\n", | |
" \"id\":\"a\",\n", | |
" \"name_t\":\"parent a\"\n", | |
" },\n", | |
" {\n", | |
" \"id\":\"b\",\n", | |
" \"name_t\":\"parent b\"\n", | |
" },\n", | |
" {\n", | |
" \"id\":\"aa\",\n", | |
" \"name_t\":\"sub aa\",\n", | |
" \"related\":[\n", | |
" {\n", | |
" \"id\":\"111\",\n", | |
" \"relation_type_s\":\"subsample-of\",\n", | |
" \"target_s\":\"a\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
" {\n", | |
" \"id\":\"ab\",\n", | |
" \"name_t\":\"sub ab\",\n", | |
" \"related\":[\n", | |
" {\n", | |
" \"id\":\"112\",\n", | |
" \"relation_type_s\":\"subsample-of\",\n", | |
" \"target_s\":\"a\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
" {\n", | |
" \"id\":\"aaa\",\n", | |
" \"name_t\":\"sub aaa\",\n", | |
" \"related\":[\n", | |
" {\n", | |
" \"id\":\"113\",\n", | |
" \"relation_type_s\":\"analysis-of\",\n", | |
" \"target_s\":\"aa\"\n", | |
" },\n", | |
" {\n", | |
" \"id\":\"114\",\n", | |
" \"relation_type_s\":\"subsample-of\",\n", | |
" \"target_s\":\"aa\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
" {\n", | |
" \"id\":\"aab\",\n", | |
" \"name_t\":\"sub aab\",\n", | |
" \"related\":[\n", | |
" {\n", | |
" \"id\":\"120\",\n", | |
" \"relation_type_s\":\"subsample-of\",\n", | |
" \"target_s\":\"ab\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
" {\n", | |
" \"id\":\"ba\",\n", | |
" \"name_t\":\"sub ba\",\n", | |
" \"related\":[\n", | |
" {\n", | |
" \"id\":\"114\",\n", | |
" \"relation_type_s\":\"subsample-of\",\n", | |
" \"target_s\":\"b\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
" {\n", | |
" \"id\":\"baa\",\n", | |
" \"name_t\":\"sub baa\",\n", | |
" \"related\":[\n", | |
" {\n", | |
" \"id\":\"115\",\n", | |
" \"relation_type_s\":\"analysis-of\",\n", | |
" \"target_s\":\"ba\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
" {\n", | |
" \"id\":\"bb\",\n", | |
" \"name_t\":\"sub bb\",\n", | |
" \"related\":[\n", | |
" {\n", | |
" \"id\":\"121\",\n", | |
" \"relation_type_s\":\"subsample-of\",\n", | |
" \"target_s\":\"b\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10e106b60>" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Visualize the data as a graph\n", | |
"# Nodes with id in id_ighlight will be outlined in red\n", | |
"import graphviz\n", | |
"\n", | |
"def generateViz(recs, id_highlight=[]):\n", | |
" colors = {\n", | |
" 'subsample-of':'green',\n", | |
" 'analysis-of':'blue'\n", | |
" }\n", | |
" g = graphviz.Digraph()\n", | |
" g.attr('graph', rankdir='BT')\n", | |
" for rec in recs:\n", | |
" _label = f\"{rec.get('id')}\\n{rec.get('name_t')}\"\n", | |
" _color = \"black\"\n", | |
" if rec.get('id') in id_highlight:\n", | |
" _color='red'\n", | |
" g.node(rec.get('id'), label=_label, color=_color)\n", | |
" for rel in rec.get('related', {}):\n", | |
" g.edge(\n", | |
" rec.get('id'), \n", | |
" rel.get('target_s'), \n", | |
" label=rel.get('relation_type_s'),\n", | |
" color=colors.get(rel.get('relation_type_s'),'black')\n", | |
" )\n", | |
" return g\n", | |
"\n", | |
"generateViz(docs) " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# some basic operations for creating the collection and running queries\n", | |
"import json\n", | |
"import requests\n", | |
"COLLECTION=\"reltest\"\n", | |
"SERVER = \"http://localhost:18983\"\n", | |
"SOLR = f\"{SERVER}/solr\"\n", | |
"SERVICE = f\"{SOLR}/{COLLECTION}\"\n", | |
"\n", | |
"def addField(collection_name, name, ftype=\"string\", indexed=\"true\", stored=\"true\"):\n", | |
" url = f\"{SOLR}/{collection_name}/schema\"\n", | |
" data = {\n", | |
" \"add-field\":{\n", | |
" \"name\": name,\n", | |
" \"type\": ftype,\n", | |
" \"indexed\": indexed,\n", | |
" \"stored\": stored\n", | |
" }\n", | |
" }\n", | |
" headers = {\"Content-Type\":\"application/json\"}\n", | |
" res = requests.post(url, headers=headers, data=json.dumps(data))\n", | |
" print(res.text)\n", | |
"\n", | |
"\n", | |
"def createCollection(collection_name):\n", | |
" url = f\"{SOLR}/admin/collections\"\n", | |
" params = {\n", | |
" \"action\":\"CREATE\",\n", | |
" \"name\":collection_name,\n", | |
" \"numShards\":1,\n", | |
" \"collection.configName\":\"_default\",\n", | |
" }\n", | |
" res = requests.get(url, params=params)\n", | |
" print(res.text)\n", | |
"\n", | |
"\n", | |
"def deleteCollection(collection_name):\n", | |
" url = f'{SERVER}/api/c/{collection_name}'\n", | |
" res = requests.delete(url)\n", | |
" print(res.text)\n", | |
"\n", | |
"\n", | |
"def addDocument(doc):\n", | |
" url = f\"{SERVICE}/update\"\n", | |
" headers = {\n", | |
" \"Content-type\":\"application/json\"\n", | |
" }\n", | |
" add_doc = {\n", | |
" \"add\":{\n", | |
" \"doc\": doc\n", | |
" }\n", | |
" }\n", | |
" data = json.dumps(add_doc, indent=2)\n", | |
" params = {\"commit\":\"true\"}\n", | |
" res = requests.post(url, headers=headers, data=data, params=params)\n", | |
" if res.status_code != 200:\n", | |
" print(res.status_code)\n", | |
" print(res.text)\n", | |
" return 0\n", | |
" return 1\n", | |
" \n", | |
"\n", | |
"def query(q=\"*:*\", fl=\"*\", rows=100):\n", | |
" url = f\"{SERVICE}/select\"\n", | |
" params = {\n", | |
" \"wt\":\"json\",\n", | |
" \"omitHeader\": \"true\",\n", | |
" \"q\":q,\n", | |
" \"fl\":fl,\n", | |
" \"rows\":rows\n", | |
" }\n", | |
" headers = {\n", | |
" \"Accept\": \"application/json\"\n", | |
" }\n", | |
" res = requests.get(url, params=params, headers=headers)\n", | |
" return res.json()\n", | |
"\n", | |
"def sendExpr(expr):\n", | |
" url = f'{SERVICE}/stream'\n", | |
" headers = {\n", | |
" \"Accept\": \"application/json\"\n", | |
" }\n", | |
" res = requests.post(url,data={\"expr\":expr}, headers=headers)\n", | |
" return res.json()\n", | |
"\n", | |
"def squery(q=\"*:*\", fl=\"*\", sort=\"id ASC\", rows=100):\n", | |
" selection_method = \"search\"\n", | |
" params = [\n", | |
" f'q=\"{q}\"',\n", | |
" f'fl=\"{fl}\"',\n", | |
" f'rows={rows}',\n", | |
" ]\n", | |
" expr = f'{selection_method}({COLLECTION},{\",\".join(params)},qt=\"/select\")'\n", | |
" return sendExpr(expr)\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"responseHeader\":{\n", | |
" \"status\":0,\n", | |
" \"QTime\":251},\n", | |
" \"success\":{\n", | |
" \"172.29.0.2:8983_solr\":{\n", | |
" \"responseHeader\":{\n", | |
" \"status\":0,\n", | |
" \"QTime\":71}}}}\n", | |
"\n", | |
"{\n", | |
" \"responseHeader\":{\n", | |
" \"status\":0,\n", | |
" \"QTime\":894},\n", | |
" \"success\":{\n", | |
" \"172.29.0.2:8983_solr\":{\n", | |
" \"responseHeader\":{\n", | |
" \"status\":0,\n", | |
" \"QTime\":421},\n", | |
" \"core\":\"reltest_shard1_replica_n1\"}},\n", | |
" \"warning\":\"Using _default configset. Data driven schema functionality is enabled by default, which is NOT RECOMMENDED for production use. To turn it off: curl http://{host:port}/solr/reltest/config -d '{\\\"set-user-property\\\": {\\\"update.autoCreateFields\\\":\\\"false\\\"}}'\"}\n", | |
"\n", | |
"{\n", | |
" \"responseHeader\":{\n", | |
" \"status\":400,\n", | |
" \"QTime\":122},\n", | |
" \"error\":{\n", | |
" \"metadata\":[\n", | |
" \"error-class\",\"org.apache.solr.api.ApiBag$ExceptionWithErrObject\",\n", | |
" \"root-error-class\",\"org.apache.solr.api.ApiBag$ExceptionWithErrObject\"],\n", | |
" \"details\":[{\n", | |
" \"add-field\":{\n", | |
" \"name\":\"_nest_parent_\",\n", | |
" \"type\":\"string\",\n", | |
" \"indexed\":\"true\",\n", | |
" \"stored\":\"true\"},\n", | |
" \"errorMessages\":[\"Field '_nest_parent_' already exists.\\n\"]}],\n", | |
" \"msg\":\"error processing commands, errors: [{add-field={name=_nest_parent_, type=string, indexed=true, stored=true}, errorMessages=[Field '_nest_parent_' already exists.\\n]}], \",\n", | |
" \"code\":400}}\n", | |
"\n", | |
"Added 9 documents\n" | |
] | |
} | |
], | |
"source": [ | |
"\n", | |
"# Create the collection and add some docs\n", | |
"# dispose of existing collection if present\n", | |
"deleteCollection(COLLECTION)\n", | |
"# Create the collection\n", | |
"createCollection(COLLECTION)\n", | |
"# Add the _nest_parent_ field so child records have their parent id available\n", | |
"addField(COLLECTION, \"_nest_parent_\")\n", | |
"\n", | |
"# Add some documents\n", | |
"ndocs = 0\n", | |
"for doc in docs:\n", | |
" ndocs += addDocument(doc)\n", | |
"print(f\"Added {ndocs} documents\")\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x1054ef250>" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Null query - list all documents\n", | |
"res = squery()\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('id'))\n", | |
"generateViz(docs, id_highlight=ids)\n", | |
"#print(json.dumps(squery(), indent=2))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"node\": \"aa\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"a\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 1\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 10\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x1054ef520>" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Ancestors of aaa\n", | |
"# Query to match the parent records, i.e. the document with id = 'aaa'\n", | |
"ex1 = 'search(reltest, q=\"{!child of=\\\"*:* -_nest_path_:*\\\"}id:aaa\", fl=\"target_s,_nest_parent_\")'\n", | |
"expr = f'''nodes(\n", | |
" reltest,\n", | |
" {ex1},\n", | |
" walk=\"target_s->_nest_parent_\",\n", | |
" gather=\"target_s\",\n", | |
" scatter=\"branches,leaves\"\n", | |
" )\n", | |
"'''\n", | |
"res = sendExpr(expr)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('node'))\n", | |
"generateViz(docs, id_highlight=ids)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"node\": \"aa\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"aa\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0,\n", | |
" \"name_t\": \"sub aa\"\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"ba\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"ba\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0,\n", | |
" \"name_t\": \"sub ba\"\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"a\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"a\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 1,\n", | |
" \"name_t\": \"parent a\"\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"b\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"b\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 1,\n", | |
" \"name_t\": \"parent b\"\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 18\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10db35270>" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Ancestors of documents that are analyses (i.e. relations contains analysis-of), \n", | |
"# and include some record properties with the fetch() operation\n", | |
"# The root query\n", | |
"ex1 = 'search(reltest, q=\"relation_type_s:analysis-of\", fl=\"*,target_s,_nest_parent_\")'\n", | |
"\n", | |
"# Walking the graph\n", | |
"ex2 = f'''nodes(reltest, \n", | |
" {ex1}, \n", | |
" walk=\"target_s->_nest_parent_\",\n", | |
" gather=\"target_s\",\n", | |
" scatter=\"branches,leaves\"\n", | |
")'''\n", | |
"\n", | |
"# Using the fetch operation to retrieve fields from documents found in the graph walk\n", | |
"expr = f'''fetch(reltest,\n", | |
" {ex2},\n", | |
" fl=\"id,name_t,[child]\",\n", | |
" on=\"node=id\")\n", | |
"'''\n", | |
"res = sendExpr(expr)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('id'))\n", | |
"generateViz(docs, id_highlight=ids)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 70, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"node\": \"bb\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"bb\",\n", | |
" \"field\": \"_nest_parent_\",\n", | |
" \"level\": 0,\n", | |
" \"name_t\": \"sub bb\"\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"ba\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"ba\",\n", | |
" \"field\": \"_nest_parent_\",\n", | |
" \"level\": 0,\n", | |
" \"name_t\": \"sub ba\"\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"baa\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"baa\",\n", | |
" \"field\": \"_nest_parent_\",\n", | |
" \"level\": 1,\n", | |
" \"name_t\": \"sub baa\"\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 17\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10db36b60>" | |
] | |
}, | |
"execution_count": 70, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Descendants of b\n", | |
"ex1 = 'search(reltest, q=\"target_s:b\", fl=\"*,relation_type_s,target_s,_nest_parent_\")'\n", | |
"# Walking the descendant graph (opposite of previous)\n", | |
"ex2 = f'''nodes(reltest, \n", | |
" {ex1}, \n", | |
" walk=\"_nest_parent_->target_s\",\n", | |
" gather=\"_nest_parent_\",\n", | |
" scatter=\"branches,leaves\",\n", | |
")'''\n", | |
"# Using the fetch operation to retrieve fields from documents found in the graph walk\n", | |
"expr = f'''fetch(reltest,\n", | |
" {ex2},\n", | |
" fl=\"id,name_t,[child]\",\n", | |
" on=\"node=id\")\n", | |
"'''\n", | |
"res = sendExpr(expr)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('id'))\n", | |
"generateViz(docs, id_highlight=ids)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 114, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"node\": \"baa\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"baa\",\n", | |
" \"field\": \"_nest_parent_\",\n", | |
" \"related\": {\n", | |
" \"id\": \"115\",\n", | |
" \"relation_type_s\": \"analysis-of\",\n", | |
" \"_version_\": 1740059794685820928,\n", | |
" \"_nest_path_\": \"/related#\"\n", | |
" },\n", | |
" \"level\": 1\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 26\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10d9d5750>" | |
] | |
}, | |
"execution_count": 114, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Documents that are some analysis-of \"b\".\n", | |
"#\n", | |
"# Since there are no direct analyses of b, we\n", | |
"# walk the descendants graph and intersect with the stream of\n", | |
"# records that have a sub-document that are analysis-of\n", | |
"#\n", | |
"# The root query\n", | |
"ex1 = 'search(reltest, q=\"target_s:b\", fl=\"id,relation_type_s,target_s,_nest_parent_\")'\n", | |
"\n", | |
"# Walking the descendant graph (opposite of previous)\n", | |
"ex2 = f'''nodes(reltest, \n", | |
" {ex1}, \n", | |
" walk=\"_nest_parent_->target_s\",\n", | |
" gather=\"_nest_parent_\",\n", | |
" scatter=\"branches,leaves\",\n", | |
" fq=\"relation_type_s:analysis-of\",\n", | |
")'''\n", | |
"\n", | |
"# Using the fetch operation to retrieve fields from documents in the graph walk\n", | |
"# Note - accidental discovery on how to include child fields. Doesn't seem to\n", | |
"# be documented anywhere.\n", | |
"# Sorting is needed by the intersect() op\n", | |
"ex3 = f'''sort(fetch(\n", | |
" reltest,\n", | |
" {ex2},\n", | |
" fl=\"id,label_s,related,[child],_nest_path_,relation_type_s\",\n", | |
" on=\"node=id\"\n", | |
"), by=\"id asc\")\n", | |
"'''\n", | |
"\n", | |
"# Stream to intersect, the nodes that are analysis-of, sorted for intersect op\n", | |
"ex3b = 'search(reltest, q=\"{!parent which=\\\"*:* -_nest_path_:*\\\"}relation_type_s:analysis\\-of\", sort=\"id asc\")'\n", | |
"ex4 = f'''intersect(\n", | |
" {ex3},\n", | |
" {ex3b},\n", | |
" on=\"id\"\n", | |
")\n", | |
"'''\n", | |
"res = sendExpr(ex4)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('id'))\n", | |
"generateViz(docs, id_highlight=ids)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 106, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"relation\": \"subsample-of\",\n", | |
" \"id\": \"a\"\n", | |
" },\n", | |
" {\n", | |
" \"relation\": \"subsample-of\",\n", | |
" \"id\": \"a\"\n", | |
" },\n", | |
" {\n", | |
" \"relation\": \"analysis-of\",\n", | |
" \"id\": \"aa\"\n", | |
" },\n", | |
" {\n", | |
" \"relation\": \"subsample-of\",\n", | |
" \"id\": \"aa\"\n", | |
" },\n", | |
" {\n", | |
" \"relation\": \"subsample-of\",\n", | |
" \"id\": \"ab\"\n", | |
" },\n", | |
" {\n", | |
" \"relation\": \"subsample-of\",\n", | |
" \"id\": \"b\"\n", | |
" },\n", | |
" {\n", | |
" \"relation\": \"analysis-of\",\n", | |
" \"id\": \"ba\"\n", | |
" },\n", | |
" {\n", | |
" \"relation\": \"subsample-of\",\n", | |
" \"id\": \"b\"\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 4\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10d9d7130>" | |
] | |
}, | |
"execution_count": 106, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# documents that are the target of any relation\n", | |
"# subject --relation--> target\n", | |
"\n", | |
"q = \"relation_type_s:*\"\n", | |
"fl = \"id:target_s,relation:relation_type_s\"\n", | |
"res = squery(q=q, fl=fl)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('id'))\n", | |
"generateViz(docs, id_highlight=ids)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 107, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"_version_\": 1740059794381733888,\n", | |
" \"id\": \"aa\",\n", | |
" \"name_t\": \"sub aa\"\n", | |
" },\n", | |
" {\n", | |
" \"_version_\": 1740059794434162688,\n", | |
" \"id\": \"ab\",\n", | |
" \"name_t\": \"sub ab\"\n", | |
" },\n", | |
" {\n", | |
" \"_version_\": 1740059794492882944,\n", | |
" \"id\": \"aaa\",\n", | |
" \"name_t\": \"sub aaa\"\n", | |
" },\n", | |
" {\n", | |
" \"_version_\": 1740059794553700352,\n", | |
" \"id\": \"aab\",\n", | |
" \"name_t\": \"sub aab\"\n", | |
" },\n", | |
" {\n", | |
" \"_version_\": 1740059794616614912,\n", | |
" \"id\": \"ba\",\n", | |
" \"name_t\": \"sub ba\"\n", | |
" },\n", | |
" {\n", | |
" \"_version_\": 1740059794685820928,\n", | |
" \"id\": \"baa\",\n", | |
" \"name_t\": \"sub baa\"\n", | |
" },\n", | |
" {\n", | |
" \"_version_\": 1740059794753978368,\n", | |
" \"id\": \"bb\",\n", | |
" \"name_t\": \"sub bb\"\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 4\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10d9d6f80>" | |
] | |
}, | |
"execution_count": 107, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Documents that are the subsample-of or analysis-of something\n", | |
"q = '{!parent which=\"*:* -_nest_path_:*\"}(relation_type_s:subsample\\-of OR relation_type_s:analysis\\-of)'\n", | |
"res = squery(q=q)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('id'))\n", | |
"generateViz(docs, id_highlight=ids)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 108, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"relation_type_s:subsample-of\n", | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"relation_type_s\": \"subsample-of\",\n", | |
" \"_nest_parent_\": \"aa\",\n", | |
" \"id\": \"111\",\n", | |
" \"target_s\": \"a\",\n", | |
" \"_version_\": 1740059794381733888\n", | |
" },\n", | |
" {\n", | |
" \"relation_type_s\": \"subsample-of\",\n", | |
" \"_nest_parent_\": \"ab\",\n", | |
" \"id\": \"112\",\n", | |
" \"target_s\": \"a\",\n", | |
" \"_version_\": 1740059794434162688\n", | |
" },\n", | |
" {\n", | |
" \"relation_type_s\": \"subsample-of\",\n", | |
" \"_nest_parent_\": \"aaa\",\n", | |
" \"id\": \"114\",\n", | |
" \"target_s\": \"aa\",\n", | |
" \"_version_\": 1740059794492882944\n", | |
" },\n", | |
" {\n", | |
" \"relation_type_s\": \"subsample-of\",\n", | |
" \"_nest_parent_\": \"aab\",\n", | |
" \"id\": \"120\",\n", | |
" \"target_s\": \"ab\",\n", | |
" \"_version_\": 1740059794553700352\n", | |
" },\n", | |
" {\n", | |
" \"relation_type_s\": \"subsample-of\",\n", | |
" \"_nest_parent_\": \"ba\",\n", | |
" \"id\": \"114\",\n", | |
" \"target_s\": \"b\",\n", | |
" \"_version_\": 1740059794616614912\n", | |
" },\n", | |
" {\n", | |
" \"relation_type_s\": \"subsample-of\",\n", | |
" \"_nest_parent_\": \"bb\",\n", | |
" \"id\": \"121\",\n", | |
" \"target_s\": \"b\",\n", | |
" \"_version_\": 1740059794753978368\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 2\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10d9d59f0>" | |
] | |
}, | |
"execution_count": 108, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Relations that point to the origin of a subsample\n", | |
"# {!child of=\"*:* -_nest_path_:\\\\/related\\\\/*\"}(\n", | |
"#q = '{!child of=\"*:* _nest_path_:\\\\/related\\\\/*\"}relation_type_s:subsample\\-of'\n", | |
"q = \"relation_type_s:subsample-of\"\n", | |
"print(q)\n", | |
"res = squery(q=q)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('target_s'))\n", | |
"generateViz(docs, id_highlight=ids)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 109, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"id\": \"a\"\n", | |
" },\n", | |
" {\n", | |
" \"id\": \"a\"\n", | |
" },\n", | |
" {\n", | |
" \"id\": \"aa\"\n", | |
" },\n", | |
" {\n", | |
" \"id\": \"ab\"\n", | |
" },\n", | |
" {\n", | |
" \"id\": \"b\"\n", | |
" },\n", | |
" {\n", | |
" \"id\": \"b\"\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 3\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10d9d5b70>" | |
] | |
}, | |
"execution_count": 109, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Documents that have been subsampled\n", | |
"q = \"relation_type_s:subsample\\-of\"\n", | |
"fl = \"id:target_s\"\n", | |
"res = squery(q=q, fl=fl)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('id'))\n", | |
"generateViz(docs, id_highlight=ids)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 110, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"node\": \"a\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"b\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"aa\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"ab\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 8\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10d9d7a30>" | |
] | |
}, | |
"execution_count": 110, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Same as previous but using the nodes operation\n", | |
"expr = f\"\"\"\n", | |
"nodes({COLLECTION},\n", | |
" search({COLLECTION}, q=\"relation_type_s:subsample\\-of\"),\n", | |
" walk=\"target_s->target_s\",\n", | |
" gather=\"target_s\",\n", | |
" scatter=\"branches, leaves\"\n", | |
")\n", | |
"\"\"\"\n", | |
"res = sendExpr(expr)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('node'))\n", | |
"generateViz(docs, id_highlight=ids)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 111, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"result-set\": {\n", | |
" \"docs\": [\n", | |
" {\n", | |
" \"node\": \"a\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"a\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0,\n", | |
" \"name_t\": \"parent a\"\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"b\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"b\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0,\n", | |
" \"name_t\": \"parent b\"\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"aa\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"aa\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0,\n", | |
" \"name_t\": \"sub aa\"\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"ba\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"ba\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0,\n", | |
" \"name_t\": \"sub ba\"\n", | |
" },\n", | |
" {\n", | |
" \"node\": \"ab\",\n", | |
" \"collection\": \"reltest\",\n", | |
" \"id\": \"ab\",\n", | |
" \"field\": \"target_s\",\n", | |
" \"level\": 0,\n", | |
" \"name_t\": \"sub ab\"\n", | |
" },\n", | |
" {\n", | |
" \"EOF\": true,\n", | |
" \"RESPONSE_TIME\": 12\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 5.0.0 (20220707.1540)\n -->\n<!-- Pages: 1 -->\n<svg width=\"449pt\" height=\"271pt\"\n viewBox=\"0.00 0.00 448.98 271.22\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 267.22)\">\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-267.22 444.98,-267.22 444.98,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"156.98\" cy=\"-236.35\" rx=\"42.35\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<text text-anchor=\"middle\" x=\"156.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"307.98\" cy=\"-236.35\" rx=\"43.27\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-240.15\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<text text-anchor=\"middle\" x=\"307.98\" y=\"-225.15\" font-family=\"Times,serif\" font-size=\"14.00\">parent b</text>\n</g>\n<!-- aa -->\n<g id=\"node3\" class=\"node\">\n<title>aa</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"84.98\" cy=\"-131.61\" rx=\"36.12\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">aa</text>\n<text text-anchor=\"middle\" x=\"84.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub aa</text>\n</g>\n<!-- aa->a -->\n<g id=\"edge1\" class=\"edge\">\n<title>aa->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M82.9,-158.48C83.18,-169.35 85.09,-181.72 90.98,-191.48 96.58,-200.76 104.99,-208.49 113.94,-214.74\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"112.31,-217.85 122.62,-220.28 116.08,-211.95 112.31,-217.85\"/>\n<text text-anchor=\"middle\" x=\"127.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ab -->\n<g id=\"node4\" class=\"node\">\n<title>ab</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"181.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ab</text>\n</g>\n<!-- ab->a -->\n<g id=\"edge2\" class=\"edge\">\n<title>ab->a</title>\n<path fill=\"none\" stroke=\"green\" d=\"M175.74,-158.27C172.69,-170.77 168.98,-186.02 165.67,-199.63\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"162.19,-199.12 163.23,-209.66 169,-200.77 162.19,-199.12\"/>\n<text text-anchor=\"middle\" x=\"207.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aaa -->\n<g id=\"node5\" class=\"node\">\n<title>aaa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"42.98\" cy=\"-26.87\" rx=\"40.11\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aaa</text>\n<text text-anchor=\"middle\" x=\"42.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aaa</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge3\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M16.6,-47.4C4.7,-58.68 -5.09,-73.28 2.98,-86.74 11.56,-101.06 26.57,-110.96 41.43,-117.69\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"40.53,-121.1 51.11,-121.66 43.19,-114.62 40.53,-121.1\"/>\n<text text-anchor=\"middle\" x=\"32.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- aaa->aa -->\n<g id=\"edge4\" class=\"edge\">\n<title>aaa->aa</title>\n<path fill=\"none\" stroke=\"green\" d=\"M54.71,-52.79C57.5,-58.95 60.42,-65.55 62.98,-71.74 66.21,-79.55 69.51,-88.03 72.53,-96.05\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"69.29,-97.38 76.05,-105.54 75.85,-94.95 69.29,-97.38\"/>\n<text text-anchor=\"middle\" x=\"105.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- aab -->\n<g id=\"node6\" class=\"node\">\n<title>aab</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"181.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">aab</text>\n<text text-anchor=\"middle\" x=\"181.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub aab</text>\n</g>\n<!-- aab->ab -->\n<g id=\"edge5\" class=\"edge\">\n<title>aab->ab</title>\n<path fill=\"none\" stroke=\"green\" d=\"M181.98,-53.8C181.98,-66.09 181.98,-80.97 181.98,-94.36\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"178.48,-94.69 181.98,-104.69 185.48,-94.69 178.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"218.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- ba -->\n<g id=\"node7\" class=\"node\">\n<title>ba</title>\n<ellipse fill=\"none\" stroke=\"red\" cx=\"283.98\" cy=\"-131.61\" rx=\"36.54\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">ba</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub ba</text>\n</g>\n<!-- ba->b -->\n<g id=\"edge6\" class=\"edge\">\n<title>ba->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M281.85,-158.45C281.66,-168.86 282.27,-180.88 284.98,-191.48 285.86,-194.92 287.05,-198.39 288.43,-201.79\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"285.36,-203.49 292.73,-211.11 291.72,-200.56 285.36,-203.49\"/>\n<text text-anchor=\"middle\" x=\"321.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n<!-- baa -->\n<g id=\"node8\" class=\"node\">\n<title>baa</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"283.98\" cy=\"-26.87\" rx=\"41.02\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-30.67\" font-family=\"Times,serif\" font-size=\"14.00\">baa</text>\n<text text-anchor=\"middle\" x=\"283.98\" y=\"-15.67\" font-family=\"Times,serif\" font-size=\"14.00\">sub baa</text>\n</g>\n<!-- baa->ba -->\n<g id=\"edge7\" class=\"edge\">\n<title>baa->ba</title>\n<path fill=\"none\" stroke=\"blue\" d=\"M283.98,-53.8C283.98,-66.09 283.98,-80.97 283.98,-94.36\"/>\n<polygon fill=\"blue\" stroke=\"blue\" points=\"280.48,-94.69 283.98,-104.69 287.48,-94.69 280.48,-94.69\"/>\n<text text-anchor=\"middle\" x=\"313.98\" y=\"-75.54\" font-family=\"Times,serif\" font-size=\"14.00\">analysis-of</text>\n</g>\n<!-- bb -->\n<g id=\"node9\" class=\"node\">\n<title>bb</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"380.98\" cy=\"-131.61\" rx=\"37.45\" ry=\"26.74\"/>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-135.41\" font-family=\"Times,serif\" font-size=\"14.00\">bb</text>\n<text text-anchor=\"middle\" x=\"380.98\" y=\"-120.41\" font-family=\"Times,serif\" font-size=\"14.00\">sub bb</text>\n</g>\n<!-- bb->b -->\n<g id=\"edge8\" class=\"edge\">\n<title>bb->b</title>\n<path fill=\"none\" stroke=\"green\" d=\"M374.47,-158.31C370.96,-169.16 365.91,-181.55 358.98,-191.48 354.66,-197.67 349.27,-203.53 343.63,-208.83\"/>\n<polygon fill=\"green\" stroke=\"green\" points=\"341.04,-206.46 335.86,-215.7 345.67,-211.7 341.04,-206.46\"/>\n<text text-anchor=\"middle\" x=\"403.98\" y=\"-180.28\" font-family=\"Times,serif\" font-size=\"14.00\">subsample-of</text>\n</g>\n</g>\n</svg>\n", | |
"text/plain": [ | |
"<graphviz.graphs.Digraph at 0x10d9d7370>" | |
] | |
}, | |
"execution_count": 111, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Same as previous but using the nodes operation and fetching properties of the final nodes\n", | |
"expr = f\"\"\"fetch({COLLECTION}, \n", | |
"nodes({COLLECTION},\n", | |
" search({COLLECTION}, q=\"relation_type_s:subsample\\-of OR relation_type_s:analysis\\-of\"),\n", | |
" walk=\"target_s->target_s\",\n", | |
" gather=\"target_s\",\n", | |
" scatter=\"branches,leaves\"\n", | |
"),\n", | |
"fl=\"id,name_t\",\n", | |
"on=\"node=id\"\n", | |
")\"\"\"\n", | |
"res = sendExpr(expr)\n", | |
"print(json.dumps(res, indent=2))\n", | |
"ids = []\n", | |
"for _rec in res.get('result-set',{}).get('docs',[]):\n", | |
" ids.append(_rec.get('node'))\n", | |
"generateViz(docs, id_highlight=ids)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3.10.5 ('solr-test')", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.10.5" | |
}, | |
"orig_nbformat": 4, | |
"vscode": { | |
"interpreter": { | |
"hash": "a1b12c3b28230d429dd5cb2accd3ae0fcf113d807ef6cb564b517c65dcfce2a0" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment