Skip to content

Commit d78453d

Browse files
authored
Merge pull request #64 from casework/use_urirefs_for_facets
Use URIRefs for Facets
2 parents faeafe2 + 33ebd89 commit d78453d

File tree

7 files changed

+304
-288
lines changed

7 files changed

+304
-288
lines changed

case_utils/case_file/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,19 @@ def create_file_node(
8282
:returns: The File Observable Object's node.
8383
:rtype: rdflib.URIRef
8484
"""
85+
node_namespace = rdflib.Namespace(node_prefix)
86+
8587
if node_iri is None:
8688
node_slug = "file-" + case_utils.local_uuid.local_uuid()
87-
node_iri = rdflib.Namespace(node_prefix)[node_slug]
89+
node_iri = node_namespace[node_slug]
8890
n_file = rdflib.URIRef(node_iri)
8991
graph.add((n_file, NS_RDF.type, NS_UCO_OBSERVABLE.File))
9092

9193
basename = os.path.basename(filepath)
9294
literal_basename = rdflib.Literal(basename)
9395

9496
file_stat = os.stat(filepath)
95-
n_file_facet = rdflib.BNode()
97+
n_file_facet = node_namespace["file-facet-" + case_utils.local_uuid.local_uuid()]
9698
graph.add(
9799
(
98100
n_file_facet,
@@ -119,7 +121,9 @@ def create_file_node(
119121
graph.add((n_file_facet, NS_UCO_OBSERVABLE.modifiedTime, literal_mtime))
120122

121123
if not disable_hashes:
122-
n_contentdata_facet = rdflib.BNode()
124+
n_contentdata_facet = node_namespace[
125+
"content-data-facet-" + case_utils.local_uuid.local_uuid()
126+
]
123127
graph.add((n_file, NS_UCO_CORE.hasFacet, n_contentdata_facet))
124128
graph.add(
125129
(n_contentdata_facet, NS_RDF.type, NS_UCO_OBSERVABLE.ContentDataFacet)
@@ -191,7 +195,7 @@ def create_file_node(
191195
for key in successful_hashdict._fields:
192196
if key not in ("md5", "sha1", "sha256", "sha512"):
193197
continue
194-
n_hash = rdflib.BNode()
198+
n_hash = node_namespace["hash-" + case_utils.local_uuid.local_uuid()]
195199
graph.add((n_contentdata_facet, NS_UCO_OBSERVABLE.hash, n_hash))
196200
graph.add((n_hash, NS_RDF.type, NS_UCO_TYPES.Hash))
197201
graph.add(

tests/case_utils/case_file/kb.json

Lines changed: 99 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,92 +8,120 @@
88
"xsd": "http://www.w3.org/2001/XMLSchema#"
99
},
1010
"@graph": [
11+
{
12+
"@id": "kb:content-data-facet-1833f979-1f19-5543-9d82-6cefd144b169",
13+
"@type": "uco-observable:ContentDataFacet",
14+
"uco-observable:hash": [
15+
{
16+
"@id": "kb:hash-24644904-83ea-5911-aea8-be687a9f3caf"
17+
},
18+
{
19+
"@id": "kb:hash-295bdeb5-7f23-5a3f-8b7f-4bb1191b7c21"
20+
},
21+
{
22+
"@id": "kb:hash-39127f5c-598b-51d4-a720-2e949f18f85f"
23+
},
24+
{
25+
"@id": "kb:hash-49e81fee-c6b3-5f5f-af8b-0746d32e4932"
26+
}
27+
],
28+
"uco-observable:sizeInBytes": {
29+
"@type": "xsd:integer",
30+
"@value": "4"
31+
}
32+
},
1133
{
1234
"@id": "kb:file-800784de-5c9e-5eb2-b843-0ac51a1bd4b9",
1335
"@type": "uco-observable:File",
1436
"uco-core:hasFacet": {
15-
"@type": "uco-observable:FileFacet",
16-
"uco-observable:fileName": "sample.txt",
17-
"uco-observable:modifiedTime": {
18-
"@type": "xsd:dateTime",
19-
"@value": "2010-01-02T03:04:56+00:00"
20-
},
21-
"uco-observable:sizeInBytes": {
22-
"@type": "xsd:integer",
23-
"@value": "4"
24-
}
37+
"@id": "kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d"
2538
}
2639
},
2740
{
2841
"@id": "kb:file-ace6460a-92a9-58b9-83ea-a18ae87f6e04",
2942
"@type": "uco-observable:File",
3043
"uco-core:hasFacet": [
3144
{
32-
"@type": "uco-observable:ContentDataFacet",
33-
"uco-observable:hash": [
34-
{
35-
"@type": "uco-types:Hash",
36-
"uco-types:hashMethod": {
37-
"@type": "uco-vocabulary:HashNameVocab",
38-
"@value": "MD5"
39-
},
40-
"uco-types:hashValue": {
41-
"@type": "xsd:hexBinary",
42-
"@value": "098f6bcd4621d373cade4e832627b4f6"
43-
}
44-
},
45-
{
46-
"@type": "uco-types:Hash",
47-
"uco-types:hashMethod": {
48-
"@type": "uco-vocabulary:HashNameVocab",
49-
"@value": "SHA1"
50-
},
51-
"uco-types:hashValue": {
52-
"@type": "xsd:hexBinary",
53-
"@value": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
54-
}
55-
},
56-
{
57-
"@type": "uco-types:Hash",
58-
"uco-types:hashMethod": {
59-
"@type": "uco-vocabulary:HashNameVocab",
60-
"@value": "SHA256"
61-
},
62-
"uco-types:hashValue": {
63-
"@type": "xsd:hexBinary",
64-
"@value": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
65-
}
66-
},
67-
{
68-
"@type": "uco-types:Hash",
69-
"uco-types:hashMethod": {
70-
"@type": "uco-vocabulary:HashNameVocab",
71-
"@value": "SHA512"
72-
},
73-
"uco-types:hashValue": {
74-
"@type": "xsd:hexBinary",
75-
"@value": "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"
76-
}
77-
}
78-
],
79-
"uco-observable:sizeInBytes": {
80-
"@type": "xsd:integer",
81-
"@value": "4"
82-
}
45+
"@id": "kb:content-data-facet-1833f979-1f19-5543-9d82-6cefd144b169"
8346
},
8447
{
85-
"@type": "uco-observable:FileFacet",
86-
"uco-observable:fileName": "sample.txt",
87-
"uco-observable:modifiedTime": {
88-
"@type": "xsd:dateTime",
89-
"@value": "2010-01-02T03:04:56+00:00"
90-
},
91-
"uco-observable:sizeInBytes": {
92-
"@type": "xsd:integer",
93-
"@value": "4"
94-
}
48+
"@id": "kb:file-facet-1297a4bd-563b-54c3-ad8a-f67f01ba9b10"
9549
}
9650
]
51+
},
52+
{
53+
"@id": "kb:file-facet-1297a4bd-563b-54c3-ad8a-f67f01ba9b10",
54+
"@type": "uco-observable:FileFacet",
55+
"uco-observable:fileName": "sample.txt",
56+
"uco-observable:modifiedTime": {
57+
"@type": "xsd:dateTime",
58+
"@value": "2010-01-02T03:04:56+00:00"
59+
},
60+
"uco-observable:sizeInBytes": {
61+
"@type": "xsd:integer",
62+
"@value": "4"
63+
}
64+
},
65+
{
66+
"@id": "kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d",
67+
"@type": "uco-observable:FileFacet",
68+
"uco-observable:fileName": "sample.txt",
69+
"uco-observable:modifiedTime": {
70+
"@type": "xsd:dateTime",
71+
"@value": "2010-01-02T03:04:56+00:00"
72+
},
73+
"uco-observable:sizeInBytes": {
74+
"@type": "xsd:integer",
75+
"@value": "4"
76+
}
77+
},
78+
{
79+
"@id": "kb:hash-24644904-83ea-5911-aea8-be687a9f3caf",
80+
"@type": "uco-types:Hash",
81+
"uco-types:hashMethod": {
82+
"@type": "uco-vocabulary:HashNameVocab",
83+
"@value": "MD5"
84+
},
85+
"uco-types:hashValue": {
86+
"@type": "xsd:hexBinary",
87+
"@value": "098f6bcd4621d373cade4e832627b4f6"
88+
}
89+
},
90+
{
91+
"@id": "kb:hash-295bdeb5-7f23-5a3f-8b7f-4bb1191b7c21",
92+
"@type": "uco-types:Hash",
93+
"uco-types:hashMethod": {
94+
"@type": "uco-vocabulary:HashNameVocab",
95+
"@value": "SHA1"
96+
},
97+
"uco-types:hashValue": {
98+
"@type": "xsd:hexBinary",
99+
"@value": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
100+
}
101+
},
102+
{
103+
"@id": "kb:hash-39127f5c-598b-51d4-a720-2e949f18f85f",
104+
"@type": "uco-types:Hash",
105+
"uco-types:hashMethod": {
106+
"@type": "uco-vocabulary:HashNameVocab",
107+
"@value": "SHA256"
108+
},
109+
"uco-types:hashValue": {
110+
"@type": "xsd:hexBinary",
111+
"@value": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
112+
}
113+
},
114+
{
115+
"@id": "kb:hash-49e81fee-c6b3-5f5f-af8b-0746d32e4932",
116+
"@type": "uco-types:Hash",
117+
"uco-types:hashMethod": {
118+
"@type": "uco-vocabulary:HashNameVocab",
119+
"@value": "SHA512"
120+
},
121+
"uco-types:hashValue": {
122+
"@type": "xsd:hexBinary",
123+
"@value": "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"
124+
}
97125
}
98126
]
99127
}

tests/case_utils/case_file/kb.ttl

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,65 @@
88
@prefix uco-vocabulary: <https://ontology.unifiedcyberontology.org/uco/vocabulary/> .
99
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
1010

11+
kb:content-data-facet-1833f979-1f19-5543-9d82-6cefd144b169
12+
a uco-observable:ContentDataFacet ;
13+
uco-observable:hash
14+
kb:hash-24644904-83ea-5911-aea8-be687a9f3caf ,
15+
kb:hash-295bdeb5-7f23-5a3f-8b7f-4bb1191b7c21 ,
16+
kb:hash-39127f5c-598b-51d4-a720-2e949f18f85f ,
17+
kb:hash-49e81fee-c6b3-5f5f-af8b-0746d32e4932
18+
;
19+
uco-observable:sizeInBytes "4"^^xsd:integer ;
20+
.
21+
1122
kb:file-800784de-5c9e-5eb2-b843-0ac51a1bd4b9
1223
a uco-observable:File ;
13-
uco-core:hasFacet [
14-
a uco-observable:FileFacet ;
15-
uco-observable:fileName "sample.txt" ;
16-
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
17-
uco-observable:sizeInBytes "4"^^xsd:integer ;
18-
] ;
24+
uco-core:hasFacet kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d ;
1925
.
2026

2127
kb:file-ace6460a-92a9-58b9-83ea-a18ae87f6e04
2228
a uco-observable:File ;
2329
uco-core:hasFacet
24-
[
25-
a uco-observable:ContentDataFacet ;
26-
uco-observable:hash
27-
[
28-
a uco-types:Hash ;
29-
uco-types:hashMethod "MD5"^^uco-vocabulary:HashNameVocab ;
30-
uco-types:hashValue "098f6bcd4621d373cade4e832627b4f6"^^xsd:hexBinary ;
31-
] ,
32-
[
33-
a uco-types:Hash ;
34-
uco-types:hashMethod "SHA1"^^uco-vocabulary:HashNameVocab ;
35-
uco-types:hashValue "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"^^xsd:hexBinary ;
36-
] ,
37-
[
38-
a uco-types:Hash ;
39-
uco-types:hashMethod "SHA256"^^uco-vocabulary:HashNameVocab ;
40-
uco-types:hashValue "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"^^xsd:hexBinary ;
41-
] ,
42-
[
43-
a uco-types:Hash ;
44-
uco-types:hashMethod "SHA512"^^uco-vocabulary:HashNameVocab ;
45-
uco-types:hashValue "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"^^xsd:hexBinary ;
46-
]
47-
;
48-
uco-observable:sizeInBytes "4"^^xsd:integer ;
49-
] ,
50-
[
51-
a uco-observable:FileFacet ;
52-
uco-observable:fileName "sample.txt" ;
53-
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
54-
uco-observable:sizeInBytes "4"^^xsd:integer ;
55-
]
30+
kb:content-data-facet-1833f979-1f19-5543-9d82-6cefd144b169 ,
31+
kb:file-facet-1297a4bd-563b-54c3-ad8a-f67f01ba9b10
5632
;
5733
.
5834

35+
kb:file-facet-1297a4bd-563b-54c3-ad8a-f67f01ba9b10
36+
a uco-observable:FileFacet ;
37+
uco-observable:fileName "sample.txt" ;
38+
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
39+
uco-observable:sizeInBytes "4"^^xsd:integer ;
40+
.
41+
42+
kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d
43+
a uco-observable:FileFacet ;
44+
uco-observable:fileName "sample.txt" ;
45+
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
46+
uco-observable:sizeInBytes "4"^^xsd:integer ;
47+
.
48+
49+
kb:hash-24644904-83ea-5911-aea8-be687a9f3caf
50+
a uco-types:Hash ;
51+
uco-types:hashMethod "MD5"^^uco-vocabulary:HashNameVocab ;
52+
uco-types:hashValue "098f6bcd4621d373cade4e832627b4f6"^^xsd:hexBinary ;
53+
.
54+
55+
kb:hash-295bdeb5-7f23-5a3f-8b7f-4bb1191b7c21
56+
a uco-types:Hash ;
57+
uco-types:hashMethod "SHA1"^^uco-vocabulary:HashNameVocab ;
58+
uco-types:hashValue "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"^^xsd:hexBinary ;
59+
.
60+
61+
kb:hash-39127f5c-598b-51d4-a720-2e949f18f85f
62+
a uco-types:Hash ;
63+
uco-types:hashMethod "SHA256"^^uco-vocabulary:HashNameVocab ;
64+
uco-types:hashValue "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"^^xsd:hexBinary ;
65+
.
66+
67+
kb:hash-49e81fee-c6b3-5f5f-af8b-0746d32e4932
68+
a uco-types:Hash ;
69+
uco-types:hashMethod "SHA512"^^uco-vocabulary:HashNameVocab ;
70+
uco-types:hashValue "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"^^xsd:hexBinary ;
71+
.
72+

tests/case_utils/case_file/sample.txt-disable_hashes.ttl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
kb:file-800784de-5c9e-5eb2-b843-0ac51a1bd4b9
1010
a uco-observable:File ;
11-
uco-core:hasFacet [
12-
a uco-observable:FileFacet ;
13-
uco-observable:fileName "sample.txt" ;
14-
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
15-
uco-observable:sizeInBytes "4"^^xsd:integer ;
16-
] ;
11+
uco-core:hasFacet kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d ;
12+
.
13+
14+
kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d
15+
a uco-observable:FileFacet ;
16+
uco-observable:fileName "sample.txt" ;
17+
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
18+
uco-observable:sizeInBytes "4"^^xsd:integer ;
1719
.
1820

0 commit comments

Comments
 (0)