Skip to content

Instantly share code, notes, and snippets.

@jermnelson
Last active September 23, 2021 15:28
Show Gist options
  • Save jermnelson/c430eb37133170e84f3c22734c52702c to your computer and use it in GitHub Desktop.
Save jermnelson/c430eb37133170e84f3c22734c52702c to your computer and use it in GitHub Desktop.
PCC-BIBFRAME-Exchange-02021-September-9
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import rdflib\n",
"import pyshacl\n",
"import kglab"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PCC BIBFRAME Exchange\n",
"## Interchange Challenges\n",
"As a developer and a tech lead on the [Sinopia](https://sinopia.io) Linked Data Editor, we experience interchange challenges when trying to import external RDF. This notebook can be run by clicking on [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gist/jermnelson/c430eb37133170e84f3c22734c52702c/HEAD).\n",
"\n",
"The following are examples using the [BIBFRAME Title](https://id.loc.gov/ontologies/bibframe.html#c_Title) class (inspired by Nancy Lorimer's comments):"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ShareVDE\n",
"Searching the Stanford's ShareVDE Cache for Octavia Butler's *Parable of the Sower* from Questioning Authority API [query]('https://lookup.ld4l.org/authorities/fetch/linked_data/sharevde_stanford_ld4l_cache?format=n3&uri=http://share-vde.org/sharevde/rdfBibframe/Work/7985783') returns the following RDF related to the Work's title:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"sharevde_title_rdf = \"\"\"@prefix bf2: <http://id.loc.gov/ontologies/bibframe/> .\n",
"@prefix marcrelators: <http://id.loc.gov/vocabulary/relators/> .\n",
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n",
"\n",
"<http://share-vde.org/sharevde/rdfBibframe/Work/7985783-1> a bf2:Text,\n",
" bf2:Work ;\n",
" bf2:title <http://share-vde.org/sharevde/rdfBibframe/Title_996/0409b9ef-0416-3b57-8826-259ebc9fdb53> .\n",
" \n",
"<http://share-vde.org/sharevde/rdfBibframe/Title_996/0409b9ef-0416-3b57-8826-259ebc9fdb53> rdfs:label \" Parable of the sower\" .\n",
"\"\"\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Library of Congress\n",
"Searching [id.loc.gov](https://id.loc.gov/resources/works.html) BIBFRAME Work's endpont for *Parable of the Sower*, we'll use this [BIBFRAME Work](https://id.loc.gov/resources/works/21223749.html)'s RDF with the following related to the Work's title:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"loc_title_rdf = \"\"\"@prefix bf: <http://id.loc.gov/ontologies/bibframe/> .\n",
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n",
"\n",
"<http://id.loc.gov/resources/works/21223749> a bf:Text,\n",
" bf:Work ;\n",
" bf:title [ a bf:Title ;\n",
" rdfs:label \"Parable of the sower\" ;\n",
" bf:mainTitle \"Parable of the sower\" ] .\n",
"\"\"\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Sinopia\n",
"Finally, using the [pcc:bf2:Monograph:Work](https://api.stage.sinopia.io/resource/pcc:bf2:Monograph:Work) template, created the same title-related RDF as http://id.loc.gov/resources/works/21223749:\n",
"\n",
"![Sinopia Title Screenshot](sinopia-title-screenshot.png)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"sinopia_title_rdf = \"\"\"@prefix bf: <http://id.loc.gov/ontologies/bibframe/> .\n",
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n",
"\n",
"<https://api.stage.sinopia.io/resource/addeddfb-d87a-4e67-bcd3-c1e5a8df4e7c> a bf:Text,\n",
" bf:Work ;\n",
" bf:title [ a bf:Title ;\n",
" rdfs:label \"Parable of the Sower\"@eng;\n",
" bf:mainTitle \"Parable of the Sower\"@eng ] .\n",
"\"\"\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Comparing RDF\n",
"Creating three variables for the BIBFRAME Works and then parsing the RDF into three graphs; we get the following statistics:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"BF = rdflib.Namespace(\"http://id.loc.gov/ontologies/bibframe/\")\n",
"namespaces = { \"bf\": BF }\n",
"\n",
"sharevde_work_uri = rdflib.URIRef('http://share-vde.org/sharevde/rdfBibframe/Work/7985783-1')\n",
"loc_work_uri = rdflib.URIRef('http://id.loc.gov/resources/works/21223749')\n",
"sinopia_work_uri = rdflib.URIRef('https://api.stage.sinopia.io/resource/addeddfb-d87a-4e67-bcd3-c1e5a8df4e7c')\n",
"\n",
"\n",
"def build_graph(rdf: str) -> rdflib.Graph():\n",
" graph = rdflib.Graph()\n",
" for prefix, url in namespaces.items():\n",
" graph.namespace_manager.bind(prefix, url)\n",
" graph.parse(data=rdf, format='turtle')\n",
" return graph\n",
"\n",
"sharevde_graph = build_graph(sharevde_title_rdf)\n",
"loc_graph = build_graph(loc_title_rdf)\n",
"sinopia_graph = build_graph(sinopia_title_rdf)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Total Triples"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"sharevde_title: 4\n",
"loc_title: 6\n",
"sinopia_title: 6\n"
]
}
],
"source": [
"print(f\"\"\"sharevde_title: {len(sharevde_graph)}\n",
"loc_title: {len(loc_graph)}\n",
"sinopia_title: {len(sinopia_graph)}\"\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Work Classes (bf:Work, bf:Text)\n",
"Confirms that all three bf:Works share the same `rdf:type`"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[rdflib.term.URIRef('http://id.loc.gov/ontologies/bibframe/Text'),\n",
" rdflib.term.URIRef('http://id.loc.gov/ontologies/bibframe/Work')]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[obj for obj in sharevde_graph.objects(subject=sharevde_work_uri, predicate=rdflib.RDF.type)]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[obj for obj in sharevde_graph.objects(subject=sharevde_work_uri, predicate=rdflib.RDF.type)] == \\\n",
"[obj for obj in loc_graph.objects(subject=loc_work_uri, predicate=rdflib.RDF.type)] == \\\n",
"[obj for obj in sinopia_graph.objects(subject=sinopia_work_uri, predicate=rdflib.RDF.type)]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"sharevde_title = sharevde_graph.value(subject=sharevde_work_uri, predicate=BF.title)\n",
"loc_title = loc_graph.value(subject=loc_work_uri, predicate=BF.title)\n",
"sinopia_title = sinopia_graph.value(subject=sinopia_work_uri, predicate=BF.title)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'rdflib.term.URIRef'> <class 'rdflib.term.BNode'> <class 'rdflib.term.BNode'>\n"
]
}
],
"source": [
"print(type(sharevde_title), type(loc_title), type(sinopia_title))"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"sharevde_title_label = sharevde_graph.value(subject=sharevde_title, predicate=rdflib.RDFS.label)\n",
"loc_title_label = loc_graph.value(subject=loc_title, predicate=rdflib.RDFS.label)\n",
"sinopia_title_label = sinopia_graph.value(subject=sinopia_title, predicate=rdflib.RDFS.label)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Labels\n",
" Share VDE: Parable of the sower\n",
" Library of Congress: Parable of the sower\n",
" Sinopia: Parable of the Sower\n"
]
}
],
"source": [
"print(f\"\"\"Labels\n",
" Share VDE: {sharevde_title_label}\n",
" Library of Congress: {loc_title_label}\n",
" Sinopia: {sinopia_title_label}\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Compare:\n",
" ShareVDE vs LOC labels: False\n",
" LOC vs Sinopia labels: False\n",
" Sinopia vs ShareVDE: False\n"
]
}
],
"source": [
"print(f\"\"\"Compare:\n",
" ShareVDE vs LOC labels: {sharevde_title_label == loc_title_label}\n",
" LOC vs Sinopia labels: {loc_title_label == sinopia_title_label}\n",
" Sinopia vs ShareVDE: {sinopia_title_label == sharevde_title_label}\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"rdflib.term.Literal(' Parable of the sower')"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sharevde_title_label"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"rdflib.term.Literal('Parable of the sower')"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"loc_title_label"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"rdflib.term.Literal('Parable of the Sower', lang='eng')"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sinopia_title_label"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualizating the RDF"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <iframe\n",
" width=\"500px\"\n",
" height=\"500px\"\n",
" src=\"works_viz.html\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" ></iframe>\n",
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x7fc403b08eb0>"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf_works_graph = rdflib.Graph()\n",
"bf_works_graph.namespace_manager.bind(\"bf\", BF)\n",
"bf_works_graph.parse(data=sharevde_title_rdf, format='turtle')\n",
"bf_works_graph.parse(data=loc_title_rdf, format='turtle')\n",
"bf_works_graph.parse(data=sinopia_title_rdf, format='turtle')\n",
"\n",
"bf_works_kg = kglab.KnowledgeGraph(\n",
" import_graph=bf_works_graph,\n",
" namespaces=namespaces\n",
")\n",
"\n",
"bf_works_subgraph = kglab.SubgraphTensor(bf_works_kg)\n",
"pyvis_bf_works_graph = bf_works_subgraph.build_pyvis_graph(notebook=True)\n",
"pyvis_bf_works_graph.force_atlas_2based()\n",
"pyvis_bf_works_graph.show(\"works_viz.html\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Validating with SHACL\n",
"We will use this simple validation graph to check to see "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"bf_shacl = \"\"\"@prefix sh: <http://www.w3.org/ns/shacl#> .\n",
"@prefix bf: <http://id.loc.gov/ontologies/bibframe/> .\n",
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n",
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n",
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n",
"\n",
"bf:WorkShape ;\n",
" a sh:NodeShape ;\n",
" sh:targetClass bf:Work ;\n",
" sh:property [\n",
" sh:path bf:title ;\n",
" sh:class bf:Title ;\n",
" sh:node bf:TitleShape ;\n",
" ] .\n",
"\n",
"bf:TitleShape\n",
" a sh:NodeShape ;\n",
" sh:targetClass bf:Title ;\n",
" sh:nodeKind sh:BlankNodeOrIRI ;\n",
" sh:property [\n",
" sh:path rdfs:label ;\n",
" sh:datatype xsd:string ;\n",
" ] ;\n",
" sh:property [\n",
" sh:path bf:mainTitle ;\n",
" sh:datatype rdf:langString ; \n",
" ] .\n",
"\"\"\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ShareVDE"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):\n",
"\tSeverity: sh:Violation\n",
"\tSource Shape: [ sh:class bf:Title ; sh:node bf:TitleShape ; sh:path bf:title ]\n",
"\tFocus Node: <http://share-vde.org/sharevde/rdfBibframe/Work/7985783-1>\n",
"\tValue Node: <http://share-vde.org/sharevde/rdfBibframe/Title_996/0409b9ef-0416-3b57-8826-259ebc9fdb53>\n",
"\tResult Path: bf:title\n",
"\tMessage: Value does not have class bf:Title\n",
"\n"
]
}
],
"source": [
"sharevde_validation_results = pyshacl.validate(\n",
" sharevde_title_rdf,\n",
" shacl_graph=bf_shacl,\n",
" data_graph_format=\"ttl\",\n",
" shacl_graph_format=\"ttl\",\n",
" inference=\"rdfs\",\n",
" debug=True,\n",
" serialize_report_graph=\"ttl\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Library of Congress"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n",
"\tSeverity: sh:Violation\n",
"\tSource Shape: [ sh:datatype rdf:langString ; sh:path bf:mainTitle ]\n",
"\tFocus Node: [ bf:mainTitle Literal(\"Parable of the sower\") ; rdf:type bf:Title, rdfs:Resource ; rdfs:label Literal(\"Parable of the sower\") ]\n",
"\tValue Node: Literal(\"Parable of the sower\")\n",
"\tResult Path: bf:mainTitle\n",
"\tMessage: Value is not Literal with datatype rdf:langString\n",
"\n",
"Constraint Violation in NodeConstraintComponent (http://www.w3.org/ns/shacl#NodeConstraintComponent):\n",
"\tSeverity: sh:Violation\n",
"\tSource Shape: [ sh:class bf:Title ; sh:node bf:TitleShape ; sh:path bf:title ]\n",
"\tFocus Node: <http://id.loc.gov/resources/works/21223749>\n",
"\tValue Node: [ bf:mainTitle Literal(\"Parable of the sower\") ; rdf:type bf:Title, rdfs:Resource ; rdfs:label Literal(\"Parable of the sower\") ]\n",
"\tResult Path: bf:title\n",
"\tMessage: Value does not conform to Shape bf:TitleShape\n",
"\n",
"Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n",
"\tSeverity: sh:Violation\n",
"\tSource Shape: [ sh:datatype rdf:langString ; sh:path bf:mainTitle ]\n",
"\tFocus Node: [ bf:mainTitle Literal(\"Parable of the sower\") ; rdf:type bf:Title, rdfs:Resource ; rdfs:label Literal(\"Parable of the sower\") ]\n",
"\tValue Node: Literal(\"Parable of the sower\")\n",
"\tResult Path: bf:mainTitle\n",
"\tMessage: Value is not Literal with datatype rdf:langString\n",
"\n"
]
}
],
"source": [
"loc_validation_results = pyshacl.validate(\n",
" loc_title_rdf,\n",
" shacl_graph=bf_shacl,\n",
" data_graph_format=\"ttl\",\n",
" shacl_graph_format=\"ttl\",\n",
" inference=\"rdfs\",\n",
" debug=True,\n",
" serialize_report_graph=\"ttl\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Sinopia"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n",
"\tSeverity: sh:Violation\n",
"\tSource Shape: [ sh:datatype xsd:string ; sh:path rdfs:label ]\n",
"\tFocus Node: [ bf:mainTitle Literal(\"Parable of the Sower\", lang=eng) ; rdf:type bf:Title, rdfs:Resource ; rdfs:label Literal(\"Parable of the Sower\", lang=eng) ]\n",
"\tValue Node: Literal(\"Parable of the Sower\", lang=eng)\n",
"\tResult Path: rdfs:label\n",
"\tMessage: Value is not Literal with datatype xsd:string\n",
"\n",
"Constraint Violation in NodeConstraintComponent (http://www.w3.org/ns/shacl#NodeConstraintComponent):\n",
"\tSeverity: sh:Violation\n",
"\tSource Shape: [ sh:class bf:Title ; sh:node bf:TitleShape ; sh:path bf:title ]\n",
"\tFocus Node: <https://api.stage.sinopia.io/resource/addeddfb-d87a-4e67-bcd3-c1e5a8df4e7c>\n",
"\tValue Node: [ bf:mainTitle Literal(\"Parable of the Sower\", lang=eng) ; rdf:type bf:Title, rdfs:Resource ; rdfs:label Literal(\"Parable of the Sower\", lang=eng) ]\n",
"\tResult Path: bf:title\n",
"\tMessage: Value does not conform to Shape bf:TitleShape\n",
"\n",
"Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n",
"\tSeverity: sh:Violation\n",
"\tSource Shape: [ sh:datatype xsd:string ; sh:path rdfs:label ]\n",
"\tFocus Node: [ bf:mainTitle Literal(\"Parable of the Sower\", lang=eng) ; rdf:type bf:Title, rdfs:Resource ; rdfs:label Literal(\"Parable of the Sower\", lang=eng) ]\n",
"\tValue Node: Literal(\"Parable of the Sower\", lang=eng)\n",
"\tResult Path: rdfs:label\n",
"\tMessage: Value is not Literal with datatype xsd:string\n",
"\n"
]
}
],
"source": [
"sinopia_validation_results = pyshacl.validate(\n",
" sinopia_title_rdf,\n",
" shacl_graph=bf_shacl,\n",
" data_graph_format=\"ttl\",\n",
" shacl_graph_format=\"ttl\",\n",
" inference=\"rdfs\",\n",
" debug=True,\n",
" serialize_report_graph=\"ttl\"\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis.css" type="text/css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis-network.min.js"> </script>
<center>
<h1></h1>
</center>
<!-- <link rel="stylesheet" href="../node_modules/vis/dist/vis.min.css" type="text/css" />
<script type="text/javascript" src="../node_modules/vis/dist/vis.js"> </script>-->
<style type="text/css">
#mynetwork {
width: 500px;
height: 500px;
background-color: #ffffff;
border: 1px solid lightgray;
position: relative;
float: left;
}
</style>
</head>
<body>
<div id = "mynetwork"></div>
<script type="text/javascript">
// initialize global variables.
var edges;
var nodes;
var network;
var container;
var options, data;
// This method is responsible for drawing the graph, returns the drawn network
function drawGraph() {
var container = document.getElementById('mynetwork');
// parsing and collecting nodes and edges from the python
nodes = new vis.DataSet([{"id": 0, "label": "\u003chttp://id.loc.gov/resources/works/21223749\u003e", "shape": "dot", "title": "\u003chttp://id.loc.gov/resources/works/21223749\u003e"}, {"id": 1, "label": "bf:Text", "shape": "dot", "title": "bf:Text"}, {"id": 2, "label": "\u003chttp://share-vde.org/sharevde/rdfBibframe/Work/7985783-1\u003e", "shape": "dot", "title": "\u003chttp://share-vde.org/sharevde/rdfBibframe/Work/7985783-1\u003e"}, {"id": 3, "label": "_:ub5bL5C14", "shape": "dot", "title": "_:ub5bL5C14"}, {"id": 4, "label": "Parable of the sower", "shape": "dot", "title": "Parable of the sower"}, {"id": 5, "label": "\u003chttp://share-vde.org/sharevde/rdfBibframe/Title_996/0409b9ef-0416-3b57-8826-259ebc9fdb53\u003e", "shape": "dot", "title": "\u003chttp://share-vde.org/sharevde/rdfBibframe/Title_996/0409b9ef-0416-3b57-8826-259ebc9fdb53\u003e"}, {"id": 6, "label": " Parable of the sower", "shape": "dot", "title": " Parable of the sower"}, {"id": 7, "label": "\u003chttps://api.stage.sinopia.io/resource/addeddfb-d87a-4e67-bcd3-c1e5a8df4e7c\u003e", "shape": "dot", "title": "\u003chttps://api.stage.sinopia.io/resource/addeddfb-d87a-4e67-bcd3-c1e5a8df4e7c\u003e"}, {"id": 8, "label": "_:ub6bL5C14", "shape": "dot", "title": "_:ub6bL5C14"}, {"id": 9, "label": "Parable of the Sower", "shape": "dot", "title": "Parable of the Sower"}, {"id": 10, "label": "bf:Work", "shape": "dot", "title": "bf:Work"}, {"id": 11, "label": "bf:Title", "shape": "dot", "title": "bf:Title"}]);
edges = new vis.DataSet([{"from": 0, "label": "rdf:type", "to": 1}, {"from": 2, "label": "rdf:type", "to": 1}, {"from": 3, "label": "rdfs:label", "to": 4}, {"from": 2, "label": "bf:title", "to": 5}, {"from": 5, "label": "rdfs:label", "to": 6}, {"from": 7, "label": "rdf:type", "to": 1}, {"from": 8, "label": "rdfs:label", "to": 9}, {"from": 7, "label": "bf:title", "to": 8}, {"from": 2, "label": "rdf:type", "to": 10}, {"from": 8, "label": "rdf:type", "to": 11}, {"from": 3, "label": "rdf:type", "to": 11}, {"from": 0, "label": "rdf:type", "to": 10}, {"from": 7, "label": "rdf:type", "to": 10}, {"from": 0, "label": "bf:title", "to": 3}]);
// adding nodes and edges to the graph
data = {nodes: nodes, edges: edges};
var options = {
"configure": {
"enabled": false
},
"edges": {
"color": {
"inherit": true
},
"smooth": {
"enabled": false,
"type": "continuous"
}
},
"interaction": {
"dragNodes": true,
"hideEdgesOnDrag": false,
"hideNodesOnDrag": false
},
"physics": {
"enabled": true,
"forceAtlas2Based": {
"avoidOverlap": 0,
"centralGravity": 0.01,
"damping": 0.4,
"gravitationalConstant": -50,
"springConstant": 0.08,
"springLength": 100
},
"solver": "forceAtlas2Based",
"stabilization": {
"enabled": true,
"fit": true,
"iterations": 1000,
"onlyDynamicEdges": false,
"updateInterval": 50
}
}
};
network = new vis.Network(container, data, options);
return network;
}
drawGraph();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment