|
30 | 30 | "outputs": [], |
31 | 31 | "source": [ |
32 | 32 | "import kglab\n", |
33 | | - "import rdflib" |
| 33 | + "import rdflib\n", |
| 34 | + "import numpy as np" |
34 | 35 | ] |
35 | 36 | }, |
36 | 37 | { |
|
55 | 56 | "name": "stdout", |
56 | 57 | "output_type": "stream", |
57 | 58 | "text": [ |
58 | | - "{\n", |
59 | | - " \"@context\": {\n", |
60 | | - " \"foaf\": \"http://xmlns.com/foaf/0.1/\",\n", |
61 | | - " \"hdf\": \"http://purl.allotrope.org/ontologies/hdf5/1.8#\",\n", |
62 | | - " \"prov\": \"http://www.w3.org/ns/prov#\",\n", |
63 | | - " \"rdf\": \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n", |
64 | | - " },\n", |
65 | | - " \"@graph\": [\n", |
66 | | - " {\n", |
67 | | - " \"@id\": \"_:69ad64a678055ecde7601c70b432cdd3\",\n", |
68 | | - " \"@type\": \"hdf:File\"\n", |
69 | | - " },\n", |
70 | | - " {\n", |
71 | | - " \"@id\": \"hdf:scalarDataspace\",\n", |
72 | | - " \"@type\": \"hdf:scalarDataspace\"\n", |
73 | | - " },\n", |
74 | | - " {\n", |
75 | | - " \"@id\": \"hdf:H5T_IEEE_F64LE\",\n", |
76 | | - " \"@type\": \"hdf:Datatype\"\n", |
77 | | - " },\n", |
78 | | - " {\n", |
79 | | - " \"@id\": \"_:03e43b66f42e2e7f00f2288985db2abf\",\n", |
80 | | - " \"@type\": \"prov:Person\",\n", |
81 | | - " \"foaf:firstName\": \"Matthias\",\n", |
82 | | - " \"foaf:lastName\": \"Probst\"\n", |
83 | | - " },\n", |
84 | | - " {\n", |
85 | | - " \"@id\": \"https://orcid.org/0000-0001-8729-0482\",\n", |
86 | | - " \"@type\": \"prov:Person\"\n", |
87 | | - " }\n", |
88 | | - " ]\n", |
89 | | - "}\n" |
| 59 | + "@prefix dcterms: <http://purl.org/dc/terms/> .\n", |
| 60 | + "@prefix ex: <https://example.org#> .\n", |
| 61 | + "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n", |
| 62 | + "@prefix hdf: <http://purl.allotrope.org/ontologies/hdf5/1.8#> .\n", |
| 63 | + "@prefix prov: <http://www.w3.org/ns/prov#> .\n", |
| 64 | + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n", |
| 65 | + "\n", |
| 66 | + "ex:tmp0.hdf a hdf:File ;\n", |
| 67 | + " hdf:rootGroup <https://example.org#tmp0.hdf/> .\n", |
| 68 | + "\n", |
| 69 | + "<https://example.org#tmp0.hdf/> a hdf:Group ;\n", |
| 70 | + " hdf:member <https://example.org#tmp0.hdf/contact>,\n", |
| 71 | + " <https://example.org#tmp0.hdf/nd-array>,\n", |
| 72 | + " <https://example.org#tmp0.hdf/test> ;\n", |
| 73 | + " hdf:name \"/\"^^xsd:string .\n", |
| 74 | + "\n", |
| 75 | + "<https://example.org#tmp0.hdf/contact> a hdf:Group ;\n", |
| 76 | + " hdf:attribute <https://example.org#tmp0.hdf/contact@fname>,\n", |
| 77 | + " <https://example.org#tmp0.hdf/contact@hint>,\n", |
| 78 | + " <https://example.org#tmp0.hdf/contact@lname> ;\n", |
| 79 | + " hdf:name \"/contact\"^^xsd:string ;\n", |
| 80 | + " dcterms:relation <https://orcid.org/0000-0001-8729-0482> .\n", |
| 81 | + "\n", |
| 82 | + "<https://example.org#tmp0.hdf/contact@fname> a hdf:StringAttribute ;\n", |
| 83 | + " hdf:data \"Matthias\"^^xsd:string ;\n", |
| 84 | + " hdf:name \"fname\" .\n", |
| 85 | + "\n", |
| 86 | + "<https://example.org#tmp0.hdf/contact@hint> a hdf:StringAttribute ;\n", |
| 87 | + " hdf:data \"This group could be representing a person.\"^^xsd:string ;\n", |
| 88 | + " hdf:name \"hint\" .\n", |
| 89 | + "\n", |
| 90 | + "<https://example.org#tmp0.hdf/contact@lname> a hdf:StringAttribute ;\n", |
| 91 | + " hdf:data \"Probst\"^^xsd:string ;\n", |
| 92 | + " hdf:name \"lname\" .\n", |
| 93 | + "\n", |
| 94 | + "<https://example.org#tmp0.hdf/nd-array> a hdf:Dataset ;\n", |
| 95 | + " hdf:chunk <https://example.org#tmp0.hdf/nd-array__chunk_dimensions> ;\n", |
| 96 | + " hdf:dataspace <https://example.org#tmp0.hdf/nd-array__dataspace> ;\n", |
| 97 | + " hdf:datatype hdf:H5T_IEEE_F64LE,\n", |
| 98 | + " \"H5T_FLOAT\" ;\n", |
| 99 | + " hdf:layout hdf:H5D_CHUNKED ;\n", |
| 100 | + " hdf:maximumSize 6 ;\n", |
| 101 | + " hdf:name \"/nd-array\" ;\n", |
| 102 | + " hdf:rank 2 ;\n", |
| 103 | + " hdf:size 6 .\n", |
| 104 | + "\n", |
| 105 | + "<https://example.org#tmp0.hdf/nd-array__chunk_dimension_0> a hdf:DataspaceDimension ;\n", |
| 106 | + " hdf:dimensionIndex 0 ;\n", |
| 107 | + " hdf:size 1 .\n", |
| 108 | + "\n", |
| 109 | + "<https://example.org#tmp0.hdf/nd-array__chunk_dimension_1> a hdf:DataspaceDimension ;\n", |
| 110 | + " hdf:dimensionIndex 1 ;\n", |
| 111 | + " hdf:size 3 .\n", |
| 112 | + "\n", |
| 113 | + "<https://example.org#tmp0.hdf/nd-array__chunk_dimensions> a hdf:ChunkDimension ;\n", |
| 114 | + " hdf:dimension <https://example.org#tmp0.hdf/nd-array__chunk_dimension_0>,\n", |
| 115 | + " <https://example.org#tmp0.hdf/nd-array__chunk_dimension_1> .\n", |
| 116 | + "\n", |
| 117 | + "<https://example.org#tmp0.hdf/nd-array__dataspace> a hdf:SimpleDataspace ;\n", |
| 118 | + " hdf:dimension <https://example.org#tmp0.hdf/nd-array__dataspace_dimension_0>,\n", |
| 119 | + " <https://example.org#tmp0.hdf/nd-array__dataspace_dimension_1> .\n", |
| 120 | + "\n", |
| 121 | + "<https://example.org#tmp0.hdf/nd-array__dataspace_dimension_0> a hdf:DataspaceDimension ;\n", |
| 122 | + " hdf:dimensionIndex 0 ;\n", |
| 123 | + " hdf:size 2 .\n", |
| 124 | + "\n", |
| 125 | + "<https://example.org#tmp0.hdf/nd-array__dataspace_dimension_1> a hdf:DataspaceDimension ;\n", |
| 126 | + " hdf:dimensionIndex 1 ;\n", |
| 127 | + " hdf:size 3 .\n", |
| 128 | + "\n", |
| 129 | + "<https://example.org#tmp0.hdf/test> a hdf:Dataset ;\n", |
| 130 | + " hdf:dataspace <https://example.org#tmp0.hdf/test__dataspace> ;\n", |
| 131 | + " hdf:datatype hdf:H5T_IEEE_F64LE,\n", |
| 132 | + " \"H5T_FLOAT\" ;\n", |
| 133 | + " hdf:layout hdf:H5D_CONTIGUOUS ;\n", |
| 134 | + " hdf:maximumSize -1 ;\n", |
| 135 | + " hdf:name \"/test\" ;\n", |
| 136 | + " hdf:rank 0 ;\n", |
| 137 | + " hdf:size 1 ;\n", |
| 138 | + " hdf:value 4.3e+00 .\n", |
| 139 | + "\n", |
| 140 | + "<https://example.org#tmp0.hdf/test__dataspace> a hdf:ScalarDataspace .\n", |
| 141 | + "\n", |
| 142 | + "<https://orcid.org/0000-0001-8729-0482> a prov:Person ;\n", |
| 143 | + " foaf:firstName \"Matthias\"^^xsd:string ;\n", |
| 144 | + " foaf:lastName \"Probst\"^^xsd:string .\n", |
| 145 | + "\n", |
| 146 | + "hdf:H5T_IEEE_F64LE a hdf:Datatype .\n", |
| 147 | + "\n", |
| 148 | + "\n" |
90 | 149 | ] |
91 | 150 | } |
92 | 151 | ], |
93 | 152 | "source": [ |
94 | 153 | "with h5tbx.File() as h5:\n", |
95 | 154 | " h5.create_dataset(name='test', data=4.3)\n", |
| 155 | + " h5.create_dataset(name='nd-array', data=np.random.rand(2, 3), chunks=(1,3))\n", |
96 | 156 | " grp = h5.create_group(name='contact')\n", |
97 | 157 | " grp.attrs['fname', rdflib.FOAF.firstName] = 'Matthias'\n", |
98 | 158 | " grp.attrs['lname', rdflib.FOAF.lastName] = 'Probst'\n", |
99 | 159 | " grp.attrs['hint'] = 'This group could be representing a person.'\n", |
100 | 160 | " grp.rdf['hint'].definition = 'A hint gives helpful information on something.'\n", |
101 | 161 | " grp.rdf.type = rdflib.PROV.Person # --> rdf.type = Person\n", |
102 | 162 | " grp.rdf.subject = 'https://orcid.org/0000-0001-8729-0482' # -> @id='https://orcid.org/0000-0001-8729-0482'\n", |
103 | | - "\n", |
104 | | - " print(h5.dump_jsonld(indent=2, structural=True, resolve_keys=True))\n", |
105 | 163 | " \n", |
106 | | - "graph = h5tbx.get_ld(h5.hdf_filename)" |
| 164 | + "graph = h5tbx.get_ld(h5.hdf_filename, structural=True, file_uri=\"https://example.org#\", context={\"ex\": \"https://example.org#\"})\n", |
| 165 | + "print(graph.serialize())" |
107 | 166 | ] |
108 | 167 | }, |
109 | 168 | { |
|
113 | 172 | "metadata": {}, |
114 | 173 | "outputs": [], |
115 | 174 | "source": [ |
| 175 | + "namespaces = {k: str(v) for k, v in dict(graph.namespaces()).items()}\n", |
116 | 176 | "kg = kglab.KnowledgeGraph(\n", |
117 | 177 | " import_graph=graph,\n", |
118 | | - " namespaces={k: str(v) for k, v in dict(graph.namespaces()).items()})" |
| 178 | + " namespaces=namespaces)" |
119 | 179 | ] |
120 | 180 | }, |
121 | 181 | { |
|
182 | 242 | "text": [ |
183 | 243 | "{\n", |
184 | 244 | " \"@context\": {\n", |
| 245 | + " \"dcterms\": \"http://purl.org/dc/terms/\",\n", |
185 | 246 | " \"foaf\": \"http://xmlns.com/foaf/0.1/\",\n", |
186 | | - " \"hdf\": \"http://purl.allotrope.org/ontologies/hdf5/1.8#\",\n", |
187 | | - " \"rdf\": \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n", |
| 247 | + " \"prov\": \"http://www.w3.org/ns/prov#\"\n", |
188 | 248 | " },\n", |
189 | 249 | " \"@graph\": [\n", |
190 | 250 | " {\n", |
191 | | - " \"@id\": \"_:af3b30750dbfd021eb8843274633ba46\",\n", |
192 | | - " \"@type\": \"hdf:File\"\n", |
193 | | - " },\n", |
194 | | - " {\n", |
195 | | - " \"@id\": \"_:33501378e9a891ca7b7655ee472f25b4\",\n", |
| 251 | + " \"@id\": \"prov:Person\",\n", |
196 | 252 | " \"foaf:firstName\": \"Matthias\",\n", |
197 | 253 | " \"foaf:lastName\": \"Probst\"\n", |
| 254 | + " },\n", |
| 255 | + " {\n", |
| 256 | + " \"@id\": \"https://example.org#tmp1.hdf/contact\",\n", |
| 257 | + " \"dcterms:relation\": {\n", |
| 258 | + " \"@id\": \"prov:Person\"\n", |
| 259 | + " }\n", |
198 | 260 | " }\n", |
199 | 261 | " ]\n", |
200 | 262 | "}\n" |
|
211 | 273 | " grp.rdf['hint'].definition = 'A hint'\n", |
212 | 274 | " grp.rdf.subject = rdflib.PROV.Person\n", |
213 | 275 | " grp.attrs['@id'] = 'https://orcid.org/0000-0001-8729-0482'\n", |
214 | | - " print(h5.dump_jsonld(indent=2, structural=False))\n", |
| 276 | + " print(h5.dump_jsonld(indent=2, structural=False, file_uri=\"https://example.org#\"))\n", |
215 | 277 | "\n", |
216 | | - "graph = h5tbx.get_ld(h5.hdf_filename, structural=False, use_simple_bnode_value=True)" |
| 278 | + "graph = h5tbx.get_ld(h5.hdf_filename, structural=False, file_uri=\"https://example.org#\")" |
217 | 279 | ] |
218 | 280 | }, |
219 | 281 | { |
|
291 | 353 | "name": "python", |
292 | 354 | "nbconvert_exporter": "python", |
293 | 355 | "pygments_lexer": "ipython3", |
294 | | - "version": "3.10.12" |
| 356 | + "version": "3.10.18" |
295 | 357 | } |
296 | 358 | }, |
297 | 359 | "nbformat": 4, |
|
0 commit comments