diff --git a/examples/notebooks/use-cases/LocalValidation.ipynb b/examples/notebooks/use-cases/LocalValidation.ipynb index 0bb3e2ea..092a3687 100644 --- a/examples/notebooks/use-cases/LocalValidation.ipynb +++ b/examples/notebooks/use-cases/LocalValidation.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:20.068658Z", @@ -29,17 +29,17 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "import getpass\n", - "TOKEN = getpass.getpass()" + "# import getpass\n", + "# TOKEN = getpass.getpass()" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -48,14 +48,14 @@ "forge = KnowledgeGraphForge(\"../use-cases/prod-forge-nexus.yml\",\n", " endpoint=endpoint, \n", " bucket=BUCKET,\n", - " token=TOKEN,\n", + "# token=TOKEN,\n", " debug=True\n", " )" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -173,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -189,276 +189,203 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [ { - "name": "stderr", + "name": "stdout", "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:decimal ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:decimal\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:unsignedInt ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:unsignedInt\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:double ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:double\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:long ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:long\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:int ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:int\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:unsignedLong ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:unsignedLong\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:float ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:float\n", - "\n", - "Constraint Violation in NodeKindConstraintComponent (http://www.w3.org/ns/shacl#NodeKindConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: this11:LabeledOntologyEntityShape\n", - "\tFocus Node: Literal(\"bytes\")\n", - "\tValue Node: Literal(\"bytes\")\n", - "\tMessage: Value is not of Node Kind sh:IRI\n", - "\n", - "Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:string ; sh:description Literal(\"Human readable label.\") ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:name Literal(\"Label\") ; sh:path rdfs:label ]\n", - "\tFocus Node: Literal(\"bytes\")\n", - "\tResult Path: rdfs:label\n", - "\tMessage: Less than 1 values on Literal(\"bytes\")->rdfs:label\n", - "\n", - "Constraint Violation in NodeConstraintComponent (http://www.w3.org/ns/shacl#NodeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:node this11:LabeledOntologyEntityShape ]\n", - "\tFocus Node: Literal(\"bytes\")\n", - "\tValue Node: Literal(\"bytes\")\n", - "\tMessage: Value does not conform to Shape this11:LabeledOntologyEntityShape\n", - "\n", - "Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:description Literal(\"When followed this link leads to a resource providing further description on how to download the attached data.\") ; sh:maxCount Literal(\"1\", datatype=xsd:integer) ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:nodeKind sh:IRI ; sh:path schema:url ]\n", - "\tFocus Node: [ [ Literal(\"bytes\") ; Literal(\"2347304\", datatype=xsd:integer) ] ; ; Literal(\"application/nwb\") ; Literal(\"dNAD_ltb.nwb\") ; [ Literal(\"file:///gpfs/bbp.cscs.ch/data/project/proj94/nexus/bbp/uniprot/9/9/e/f/6/1/f/e/dNAD_ltb.nwb\") ; ; rdf:type ] ; [ Literal(\"SHA-256\") ; Literal(\"630f7455b9be5b212566a8dcc76d6a9b2303257ed9199a5c9262fc25aaa5749f\") ] ; rdf:type ]\n", - "\tResult Path: schema:url\n", - "\tMessage: Less than 1 values on [ [ Literal(\"bytes\") ; Literal(\"2347304\", datatype=xsd:integer) ] ; ; Literal(\"application/nwb\") ; Literal(\"dNAD_ltb.nwb\") ; [ Literal(\"file:///gpfs/bbp.cscs.ch/data/project/proj94/nexus/bbp/uniprot/9/9/e/f/6/1/f/e/dNAD_ltb.nwb\") ; ; rdf:type ] ; [ Literal(\"SHA-256\") ; Literal(\"630f7455b9be5b212566a8dcc76d6a9b2303257ed9199a5c9262fc25aaa5749f\") ] ; rdf:type ]->schema:url\n", - "\n", - "Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:string ; sh:description Literal(\"The entity name.\") ; sh:maxCount Literal(\"1\", datatype=xsd:integer) ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:name Literal(\"Name\") ; sh:path schema:name ]\n", - "\tFocus Node: \n", - "\tResult Path: schema:name\n", - "\tMessage: Less than 1 values on ->schema:name\n", - "\n", - "Constraint Violation in NodeConstraintComponent (http://www.w3.org/ns/shacl#NodeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:node this3:EntityShape ]\n", - "\tFocus Node: \n", - "\tValue Node: \n", - "\tMessage: Value does not conform to Shape this3:EntityShape\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:decimal ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:decimal\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:unsignedInt ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:unsignedInt\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:double ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:double\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:long ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:long\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:int ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:int\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:unsignedLong ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:unsignedLong\n", - "\n", - "Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:float ]\n", - "\tFocus Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tValue Node: Literal(\"2347304\", datatype=xsd:integer)\n", - "\tMessage: Value is not Literal with datatype xsd:float\n", - "\n", - "Constraint Violation in NodeKindConstraintComponent (http://www.w3.org/ns/shacl#NodeKindConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: this11:LabeledOntologyEntityShape\n", - "\tFocus Node: Literal(\"bytes\")\n", - "\tValue Node: Literal(\"bytes\")\n", - "\tMessage: Value is not of Node Kind sh:IRI\n", - "\n", - "Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:datatype xsd:string ; sh:description Literal(\"Human readable label.\") ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:name Literal(\"Label\") ; sh:path rdfs:label ]\n", - "\tFocus Node: Literal(\"bytes\")\n", - "\tResult Path: rdfs:label\n", - "\tMessage: Less than 1 values on Literal(\"bytes\")->rdfs:label\n", - "\n", - "Constraint Violation in NodeConstraintComponent (http://www.w3.org/ns/shacl#NodeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:node this11:LabeledOntologyEntityShape ]\n", - "\tFocus Node: Literal(\"bytes\")\n", - "\tValue Node: Literal(\"bytes\")\n", - "\tMessage: Value does not conform to Shape this11:LabeledOntologyEntityShape\n", - "\n", - "Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: [ sh:description Literal(\"When followed this link leads to a resource providing further description on how to download the attached data.\") ; sh:maxCount Literal(\"1\", datatype=xsd:integer) ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:nodeKind sh:IRI ; sh:path schema:url ]\n", - "\tFocus Node: [ [ Literal(\"bytes\") ; Literal(\"2347304\", datatype=xsd:integer) ] ; ; Literal(\"application/nwb\") ; Literal(\"dNAD_ltb.nwb\") ; [ Literal(\"file:///gpfs/bbp.cscs.ch/data/project/proj94/nexus/bbp/uniprot/9/9/e/f/6/1/f/e/dNAD_ltb.nwb\") ; ; rdf:type ] ; [ Literal(\"SHA-256\") ; Literal(\"630f7455b9be5b212566a8dcc76d6a9b2303257ed9199a5c9262fc25aaa5749f\") ] ; rdf:type ]\n", - "\tResult Path: schema:url\n", - "\tMessage: Less than 1 values on [ [ Literal(\"bytes\") ; Literal(\"2347304\", datatype=xsd:integer) ] ; ; Literal(\"application/nwb\") ; Literal(\"dNAD_ltb.nwb\") ; [ Literal(\"file:///gpfs/bbp.cscs.ch/data/project/proj94/nexus/bbp/uniprot/9/9/e/f/6/1/f/e/dNAD_ltb.nwb\") ; ; rdf:type ] ; [ Literal(\"SHA-256\") ; Literal(\"630f7455b9be5b212566a8dcc76d6a9b2303257ed9199a5c9262fc25aaa5749f\") ] ; rdf:type ]->schema:url\n", - "\n", - "Constraint Violation in AndConstraintComponent (http://www.w3.org/ns/shacl#AndConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: this1:MINDSShape\n", - "\tFocus Node: \n", - "\tValue Node: \n", - "\tMessage: Node does not conform to all shapes in [ sh:node this3:EntityShape ] , [ sh:property [ rdfs:seeAlso ; sh:class nsg:Contribution ; sh:description Literal(\"Information about the contribution of an agent during the generation of this dataset.\") ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:name Literal(\"Qualified Contribution\") ; sh:nodeKind sh:BlankNodeOrIRI ; sh:path nsg:contribution ], [ rdfs:seeAlso this2:SubjectShape ; sh:class nsg:Subject ; sh:description Literal(\"The subject of the study. This data represent an observation of this subject.\") ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:name Literal(\"Subject\") ; sh:path nsg:subject ; skos:editorialNote Literal(\"Asserted subject entity. It may differ from the subject from the provenance.\", datatype=xsd:string) ], [ sh:class nsg:Annotation ; sh:description Literal(\"Annotations of the dataset.\") ; sh:name Literal(\"Annotation\") ; sh:node this18:AnnotationShape ; sh:path nsg:annotation ], [ sh:class nsg:BrainAtlasSpatialReferenceSystem ; sh:maxCount Literal(\"1\", datatype=xsd:integer) ; sh:path nsg:isRegisteredIn ], [ sh:class nsg:BrainLocation ; sh:description Literal(\"The Brain location object.\") ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:name Literal(\"Brain Location\") ; sh:node this16:BrainLocationShape ; sh:path nsg:brainLocation ], [ sh:class nsg:ObjectOfStudy ; sh:description Literal(\"Object of Study\") ; sh:name Literal(\"Object of Study\") ; sh:node this15:ObjectOfStudyOntologyTermShape ; sh:path nsg:objectOfStudy ; skos:editorialNote Literal(\"The object of study \", datatype=xsd:string) ], [ sh:class schema:DataDownload ; sh:description Literal(\"A dataset in downloadable form. The downloadable form has a specific format and is located at a specific location.\") ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:name Literal(\"Distribution\") ; sh:node this9:DistributionShape ; sh:path schema:distribution ], [ sh:description Literal(\"The dataset release date.\") ; sh:maxCount Literal(\"1\", datatype=xsd:integer) ; sh:name Literal(\"Release date\") ; sh:path schema:releaseDate ], [ sh:description Literal(\"The dataset type.\") ; sh:minCount Literal(\"1\", datatype=xsd:integer) ; sh:name Literal(\"Type\") ; sh:nodeKind sh:IRI ; sh:path rdf:type ], [ sh:maxCount Literal(\"1\", datatype=xsd:integer) ; sh:nodeKind sh:IRI ; sh:path nsg:atlasRelease ] ]\n", - "\n", - "Constraint Violation in NodeConstraintComponent (http://www.w3.org/ns/shacl#NodeConstraintComponent):\n", - "\tSeverity: sh:Violation\n", - "\tSource Shape: this:DatasetShape\n", - "\tFocus Node: \n", - "\tValue Node: \n", - "\tMessage: Value does not conform to Shape this1:MINDSShape\n", - "\n" + " _validate_one\n", + " True\n" ] - }, + } + ], + "source": [ + "forge.validate(resource, type_=\"Entity\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ { - "ename": "ValidationError", - "evalue": "\nValidation Report\nConforms: False\nResults (1):\nConstraint Violation in NodeConstraintComponent (http://www.w3.org/ns/shacl#NodeConstraintComponent):\n\tSeverity: sh:Violation\n\tSource Shape: this:DatasetShape\n\tFocus Node: \n\tValue Node: \n\tMessage: Value does not conform to Shape this1:MINDSShape\n", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/var/folders/6p/k45nvhcs7v1_n9bd5g67wc3ctt8hpq/T/ipykernel_79079/2691144165.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mforge\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresource\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtype_\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"Dataset\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/core/forge.py\u001b[0m in \u001b[0;36mvalidate\u001b[0;34m(self, data, execute_actions_before, type_)\u001b[0m\n\u001b[1;32m 299\u001b[0m \"\"\"\n\u001b[1;32m 300\u001b[0m \u001b[0mdebug\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_debug\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 301\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_model\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexecute_actions_before\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtype_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdebug\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 302\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 303\u001b[0m \u001b[0;31m# Resolving User Interface.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/specializations/models/rdf_model.py\u001b[0m in \u001b[0;36mvalidate\u001b[0;34m(self, data, execute_actions_before, type_, debug)\u001b[0m\n\u001b[1;32m 113\u001b[0m run(self._validate_one, self._validate_many, data, execute_actions=execute_actions_before,\n\u001b[1;32m 114\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mValidationError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmonitored_status\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"_validated\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcatch_exceptions\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcatch_exceptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 115\u001b[0;31m type_=type_, debug=debug)\n\u001b[0m\u001b[1;32m 116\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 117\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_validate_many\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresources\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mResource\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtype_\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdebug\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbool\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/core/commons/execution.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(fun_one, fun_many, data, exception, id_required, required_synchronized, execute_actions, monitored_status, catch_exceptions, **kwargs)\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mResource\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 114\u001b[0m _run_one(fun_one, data, exception, id_required, required_synchronized, execute_actions,\n\u001b[0;32m--> 115\u001b[0;31m monitored_status, catch_exceptions, **kwargs)\n\u001b[0m\u001b[1;32m 116\u001b[0m \u001b[0maction\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_last_action\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 117\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maction\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/core/commons/execution.py\u001b[0m in \u001b[0;36m_run_one\u001b[0;34m(fun, resource, exception, id_required, required_synchronized, execute_actions, monitored_status, catch_exceptions, **kwargs)\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 160\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mcatch_exceptions\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 161\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/core/commons/execution.py\u001b[0m in \u001b[0;36m_run_one\u001b[0;34m(fun, resource, exception, id_required, required_synchronized, execute_actions, monitored_status, catch_exceptions, **kwargs)\u001b[0m\n\u001b[1;32m 143\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"resource has lazy actions which need to be executed before\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 144\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 145\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresource\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 146\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 147\u001b[0m \u001b[0mstatus\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/specializations/models/rdf_model.py\u001b[0m in \u001b[0;36m_validate_one\u001b[0;34m(self, resource, type_, debug)\u001b[0m\n\u001b[1;32m 132\u001b[0m \u001b[0mconforms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreport\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mservice\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresource\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtype_\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtype_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdebug\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 133\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mconforms\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 134\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValidationError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"\\n\"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mreport\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 135\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[0;31m# Utils.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mValidationError\u001b[0m: \nValidation Report\nConforms: False\nResults (1):\nConstraint Violation in NodeConstraintComponent (http://www.w3.org/ns/shacl#NodeConstraintComponent):\n\tSeverity: sh:Violation\n\tSource Shape: this:DatasetShape\n\tFocus Node: \n\tValue Node: \n\tMessage: Value does not conform to Shape this1:MINDSShape\n" + "name": "stdout", + "output_type": "stream", + "text": [ + " _register_one\n", + " False\n", + " RegistrationError: Resource 'https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210' failed to validate against the constraints defined in schema 'https://neuroshapes.org/dash/dataset'. Reason: Value does not have all the shapes in the sh:and enumeration for the shape: https://neuroshapes.org/commons/minds/shapes/MINDSShape\n" ] } ], "source": [ - "forge.validate(resource, type_=\"Dataset\")" + "forge.register(resource, schema_id=\"datashapes:dataset\")" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "jonis = \"\"\"\n", + "{\n", + " \"atlasRelease\": {\n", + " \"id\": \"https://bbp.epfl.ch/nexus/v1/resources/nse/test2/_/197d151d-4ed2-4549-85fd-6c51bd471262\",\n", + " \"type\": [\"AtlasRelease\", \"BrainAtlasRelease\"]\n", + " },\n", + " \"brainLocation\": {\n", + " \"brainRegion\": {\n", + " \"id\": \"http://api.brain-map.org/api/v2/data/Structure/549\",\n", + " \"label\": \"Thalamus\"\n", + " },\n", + " \"type\": \"BrainLocation\"\n", + " },\n", + " \"circuitConfigPath\": {\n", + " \"type\": \"DataDownload\",\n", + " \"url\": \"file:///will/this/path/exist\"\n", + " },\n", + " \"circuitType\": \"Test registration\",\n", + " \"description\": \"Test registration, to be deprecated\",\n", + " \"name\": \"Test Circuit registration\",\n", + " \"type\": \"DetailedCircuit\",\n", + " \"wasGeneratedBy\": [{\"id\": \"https://bbp.epfl.ch/nexus/v1/resources/nse/test2/_/9be40e75-8744-415b-b0b4-e4074ff54a8f\"},\n", + " {\"id\": \"https://bbp.epfl.ch/nexus/v1/resources/nse/test2/_/2b5819a1-c5e9-42c4-8da7-864d5e1e0a7e\"}],\n", + " \"nodeCollection\" : {\n", + " \"type\": \"NodeCollection\",\n", + " \"name\": \"My node collection\",\n", + " \"circuitCellProperties\": {\n", + " \"type\" : \"CircuitCellProperties\",\n", + " \"name\": \"My cell properties\"\n", + " },\n", + " \"memodelRelease\": {\n", + " \"type\" : \"MEModelRelease\",\n", + " \"name\": \"Some model release\"\n", + " }\n", + " }\n", + "}\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "joni_resource = forge.from_json(json.loads(jonis))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"@context\": \"https://bbp.neuroshapes.org\",\n", + " \"atlasRelease\": {\n", + " \"@id\": \"https://bbp.epfl.ch/nexus/v1/resources/nse/test2/_/197d151d-4ed2-4549-85fd-6c51bd471262\",\n", + " \"@type\": [\n", + " \"AtlasRelease\",\n", + " \"BrainAtlasRelease\"\n", + " ]\n", + " },\n", + " \"brainLocation\": {\n", + " \"brainRegion\": {\n", + " \"@id\": \"http://api.brain-map.org/api/v2/data/Structure/549\",\n", + " \"label\": \"Thalamus\"\n", + " },\n", + " \"@type\": \"BrainLocation\"\n", + " },\n", + " \"circuitConfigPath\": {\n", + " \"@type\": \"DataDownload\",\n", + " \"url\": \"file:///will/this/path/exist\"\n", + " },\n", + " \"circuitType\": \"Test registration\",\n", + " \"description\": \"Test registration, to be deprecated\",\n", + " \"name\": \"Test Circuit registration\",\n", + " \"@type\": \"DetailedCircuit\",\n", + " \"nodeCollection\": {\n", + " \"@type\": \"NodeCollection\",\n", + " \"name\": \"My node collection\",\n", + " \"circuitCellProperties\": {\n", + " \"@type\": \"CircuitCellProperties\",\n", + " \"name\": \"My cell properties\"\n", + " },\n", + " \"memodelRelease\": {\n", + " \"@type\": \"MEModelRelease\",\n", + " \"name\": \"Some model release\"\n", + " }\n", + " }\n", + "}\n" + ] + } + ], + "source": [ + "print(json.dumps(forge.as_jsonld(joni_resource), indent=4))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " _register_one\n", + " False\n", + " RegistrationError: Schema 'https://neuroshapes.org/DetailedCircuit' could not be resolved in 'dke/kgforge'\n" + ] + } + ], + "source": [ + "forge.register(joni_resource, schema_id=\"https://neuroshapes.org/DetailedCircuit\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "True" + "'Test Circuit registration'" ] }, - "execution_count": 7, + "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "forge._debug" + "joni_resource.name" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "catch_exceptions False\n" - ] - }, - { - "ename": "RegistrationError", - "evalue": "Resource 'https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210' failed to validate against the constraints defined in schema 'https://neuroshapes.org/dash/dataset'. {\"@type\": \"sh:ValidationReport\", \"conforms\": false, \"result\": {\"@type\": \"sh:ValidationResult\", \"detail\": [{\"@type\": \"sh:ValidationResult\", \"focusNode\": \"https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210\", \"resultMessage\": \"Value does not have all the shapes in the sh:and enumeration\", \"resultSeverity\": \"sh:Violation\", \"sourceConstraintComponent\": \"sh:AndConstraintComponent\", \"sourceShape\": \"https://neuroshapes.org/commons/minds/shapes/MINDSShape\", \"value\": \"https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210\"}], \"focusNode\": \"https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210\", \"resultMessage\": \"Value does not have shape \", \"resultSeverity\": \"sh:Violation\", \"sourceConstraintComponent\": \"sh:NodeConstraintComponent\", \"sourceShape\": \"https://neuroshapes.org/dash/dataset/shapes/DatasetShape\", \"value\": \"https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210\"}, \"targetedNodes\": 2}", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mHTTPError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/specializations/stores/bluebrain_nexus.py\u001b[0m in \u001b[0;36m_register_one\u001b[0;34m(self, resource, schema_id)\u001b[0m\n\u001b[1;32m 226\u001b[0m )\n\u001b[0;32m--> 227\u001b[0;31m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mraise_for_status\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 228\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.local/lib/python3.7/site-packages/requests/models.py\u001b[0m in \u001b[0;36mraise_for_status\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 942\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhttp_error_msg\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 943\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mHTTPError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhttp_error_msg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 944\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mHTTPError\u001b[0m: 400 Client Error: Bad Request for url: https://staging.nise.bbp.epfl.ch/nexus/v1/resources/dke/kgforge/datashapes%3Adataset", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[0;31mRegistrationError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/var/folders/6p/k45nvhcs7v1_n9bd5g67wc3ctt8hpq/T/ipykernel_79079/2755330261.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mforge\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mregister\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresource\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mschema_id\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"datashapes:dataset\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/core/forge.py\u001b[0m in \u001b[0;36mregister\u001b[0;34m(self, data, schema_id)\u001b[0m\n\u001b[1;32m 643\u001b[0m \u001b[0;34m:\u001b[0m\u001b[0mparam\u001b[0m \u001b[0mschema_id\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0man\u001b[0m \u001b[0midentifier\u001b[0m \u001b[0mof\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mschema\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mregistered\u001b[0m \u001b[0mresources\u001b[0m \u001b[0mshould\u001b[0m \u001b[0mconform\u001b[0m \u001b[0mto\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 644\u001b[0m \"\"\"\n\u001b[0;32m--> 645\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_store\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mregister\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mschema_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdebug\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_debug\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 646\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 647\u001b[0m \u001b[0;31m# No @catch because the error handling is done by execution.run().\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/specializations/stores/bluebrain_nexus.py\u001b[0m in \u001b[0;36mregister\u001b[0;34m(self, data, schema_id, debug)\u001b[0m\n\u001b[1;32m 150\u001b[0m \u001b[0mcatch_exceptions\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcatch_exceptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 151\u001b[0m \u001b[0mmonitored_status\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"_synchronized\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 152\u001b[0;31m \u001b[0mschema_id\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mschema_id\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 153\u001b[0m )\n\u001b[1;32m 154\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/core/commons/execution.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(fun_one, fun_many, data, exception, id_required, required_synchronized, execute_actions, monitored_status, catch_exceptions, **kwargs)\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mResource\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 114\u001b[0m _run_one(fun_one, data, exception, id_required, required_synchronized, execute_actions,\n\u001b[0;32m--> 115\u001b[0;31m monitored_status, catch_exceptions, **kwargs)\n\u001b[0m\u001b[1;32m 116\u001b[0m \u001b[0maction\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_last_action\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 117\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maction\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/core/commons/execution.py\u001b[0m in \u001b[0;36m_run_one\u001b[0;34m(fun, resource, exception, id_required, required_synchronized, execute_actions, monitored_status, catch_exceptions, **kwargs)\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 160\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mcatch_exceptions\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 161\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/core/commons/execution.py\u001b[0m in \u001b[0;36m_run_one\u001b[0;34m(fun, resource, exception, id_required, required_synchronized, execute_actions, monitored_status, catch_exceptions, **kwargs)\u001b[0m\n\u001b[1;32m 143\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mexception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"resource has lazy actions which need to be executed before\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 144\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 145\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresource\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 146\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 147\u001b[0m \u001b[0mstatus\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/code/nexus-forge/kgforge/specializations/stores/bluebrain_nexus.py\u001b[0m in \u001b[0;36m_register_one\u001b[0;34m(self, resource, schema_id)\u001b[0m\n\u001b[1;32m 228\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 229\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mnexus\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mHTTPError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 230\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mRegistrationError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_error_message\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 231\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 232\u001b[0m \u001b[0mresponse_json\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mRegistrationError\u001b[0m: Resource 'https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210' failed to validate against the constraints defined in schema 'https://neuroshapes.org/dash/dataset'. {\"@type\": \"sh:ValidationReport\", \"conforms\": false, \"result\": {\"@type\": \"sh:ValidationResult\", \"detail\": [{\"@type\": \"sh:ValidationResult\", \"focusNode\": \"https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210\", \"resultMessage\": \"Value does not have all the shapes in the sh:and enumeration\", \"resultSeverity\": \"sh:Violation\", \"sourceConstraintComponent\": \"sh:AndConstraintComponent\", \"sourceShape\": \"https://neuroshapes.org/commons/minds/shapes/MINDSShape\", \"value\": \"https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210\"}], \"focusNode\": \"https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210\", \"resultMessage\": \"Value does not have shape \", \"resultSeverity\": \"sh:Violation\", \"sourceConstraintComponent\": \"sh:NodeConstraintComponent\", \"sourceShape\": \"https://neuroshapes.org/dash/dataset/shapes/DatasetShape\", \"value\": \"https://bbp.epfl.ch/neurosciencegraph/data/traces/17b443b3-07fc-41c7-80c8-ea5e54662210\"}, \"targetedNodes\": 2}" + " _validate_one\n", + " True\n" ] } ], "source": [ - "forge.register(resource, schema_id=\"datashapes:dataset\")" + "forge.validate(joni_resource, type_='DetailedCircuit')" ] }, { diff --git a/kgforge/specializations/stores/bluebrain_nexus.py b/kgforge/specializations/stores/bluebrain_nexus.py index 3ab80e8a..3b69ce99 100644 --- a/kgforge/specializations/stores/bluebrain_nexus.py +++ b/kgforge/specializations/stores/bluebrain_nexus.py @@ -999,6 +999,12 @@ def _error_message(error: HTTPError) -> str: return format_message(str(error)) def _error_from_response(response: Response) -> str: + def details_string(details: dict) -> str: + string = f"\nReason: {detail.pop('resultMessage')} "\ + f"for the shape: {detail.pop('sourceShape')}.\nError details:\n" + for key, value in details.items(): + string += f"{key}:\t{value}\n" + return string messages = [] error_json = response.json() reason = error_json.get("reason", None) @@ -1012,11 +1018,9 @@ def _error_from_response(response: Response) -> str: if the_details: if isinstance(the_details, list): for detail in the_details: - messages.append(f"Reason: {detail['resultMessage']} "\ - f"for the shape: {detail['sourceShape']}") + messages.append(details_string(detail)) elif isinstance(the_details, dict): - messages.append(f"Reason: {detail['resultMessage']} "\ - f"for the shape: {detail['sourceShape']}") + messages.append(details_string(detail)) else: messages.append(str(the_details)) else: