Skip to content

Commit b80e33b

Browse files
authored
Merge pull request #39 from casework/Issue_38
Centralize namespace constants in namespace.py
2 parents 5df4a05 + 285c61c commit b80e33b

File tree

4 files changed

+66
-20
lines changed

4 files changed

+66
-20
lines changed

case_utils/case_file/__init__.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,10 @@
2626
import rdflib # type: ignore
2727

2828
import case_utils
29+
from case_utils.namespace import *
2930

3031
DEFAULT_PREFIX = "http://example.org/kb/"
3132

32-
NS_RDF = rdflib.RDF
33-
NS_UCO_CORE = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/core/")
34-
NS_UCO_OBSERVABLE = rdflib.Namespace(
35-
"https://ontology.unifiedcyberontology.org/uco/observable/"
36-
)
37-
NS_UCO_TYPES = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/types/")
38-
NS_UCO_VOCABULARY = rdflib.Namespace(
39-
"https://ontology.unifiedcyberontology.org/uco/vocabulary/"
40-
)
41-
NS_XSD = rdflib.XSD
42-
4333
# Shortcut syntax for defining an immutable named tuple is noted here:
4434
# https://docs.python.org/3/library/typing.html#typing.NamedTuple
4535
# via the "See also" box here: https://docs.python.org/3/library/collections.html#collections.namedtuple

case_utils/namespace.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
3+
# This software was developed at the National Institute of Standards
4+
# and Technology by employees of the Federal Government in the course
5+
# of their official duties. Pursuant to title 17 Section 105 of the
6+
# United States Code this software is not subject to copyright
7+
# protection and is in the public domain. NIST assumes no
8+
# responsibility whatsoever for its use by other parties, and makes
9+
# no guarantees, expressed or implied, about its quality,
10+
# reliability, or any other characteristic.
11+
#
12+
# We would appreciate acknowledgement if the software is used.
13+
14+
"""
15+
This module provides importable constants for namespaces.
16+
17+
To use, add "from case_utils.namespace import *". Namespace variables starting with "NS_" are imported. As needs are demonstrated in CASE tooling (both in case_utils and from downstream requests), namespaces will also be imported from rdflib for a consistent "NS_*" spelling.
18+
"""
19+
20+
import rdflib # type: ignore
21+
22+
NS_SH = rdflib.SH
23+
NS_RDF = rdflib.RDF
24+
NS_XSD = rdflib.XSD
25+
26+
NS_CASE_INVESTIGATION = rdflib.Namespace(
27+
"https://ontology.caseontology.org/case/investigation/"
28+
)
29+
NS_CASE_VOCABULARY = rdflib.Namespace(
30+
"https://ontology.caseontology.org/case/vocabulary/"
31+
)
32+
NS_UCO_ACTION = rdflib.Namespace(
33+
"https://ontology.unifiedcyberontology.org/uco/action/"
34+
)
35+
NS_UCO_CORE = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/core/")
36+
NS_UCO_IDENTITY = rdflib.Namespace(
37+
"https://ontology.unifiedcyberontology.org/uco/identity/"
38+
)
39+
NS_UCO_LOCATION = rdflib.Namespace(
40+
"https://ontology.unifiedcyberontology.org/uco/location/"
41+
)
42+
NS_UCO_MARKING = rdflib.Namespace(
43+
"https://ontology.unifiedcyberontology.org/uco/marking/"
44+
)
45+
NS_UCO_OBSERVABLE = rdflib.Namespace(
46+
"https://ontology.unifiedcyberontology.org/uco/observable/"
47+
)
48+
NS_UCO_PATTERN = rdflib.Namespace(
49+
"https://ontology.unifiedcyberontology.org/uco/pattern/"
50+
)
51+
NS_UCO_ROLE = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/role/")
52+
NS_UCO_TIME = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/time/")
53+
NS_UCO_TOOL = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/tool/")
54+
NS_UCO_TYPES = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/types/")
55+
NS_UCO_VICTIM = rdflib.Namespace(
56+
"https://ontology.unifiedcyberontology.org/uco/victim/"
57+
)
58+
NS_UCO_VOCABULARY = rdflib.Namespace(
59+
"https://ontology.unifiedcyberontology.org/uco/vocabulary/"
60+
)

tests/case_utils/case_file/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ sample.txt.json: \
111111
$(tests_srcdir)/src/isomorphic_diff.py \
112112
$(top_srcdir)/case_utils/case_file/__init__.py \
113113
$(top_srcdir)/case_utils/local_uuid.py \
114+
$(top_srcdir)/case_utils/namespace.py \
114115
sample.txt-nocompact.json
115116
rm -f $@ _$@ __$@
116117
export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \
@@ -142,6 +143,7 @@ sample.txt.ttl: \
142143
$(tests_srcdir)/.venv.done.log \
143144
$(top_srcdir)/case_utils/case_file/__init__.py \
144145
$(top_srcdir)/case_utils/local_uuid.py \
146+
$(top_srcdir)/case_utils/namespace.py \
145147
sample.txt.done.log
146148
rm -f _$@ __$@
147149
export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \
@@ -164,6 +166,7 @@ sample.txt-disable_hashes.ttl: \
164166
$(tests_srcdir)/.venv.done.log \
165167
$(top_srcdir)/case_utils/case_file/__init__.py \
166168
$(top_srcdir)/case_utils/local_uuid.py \
169+
$(top_srcdir)/case_utils/namespace.py \
167170
sample.txt.done.log
168171
rm -f _$@ __$@
169172
export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \
@@ -188,6 +191,7 @@ sample.txt-nocompact.json: \
188191
$(tests_srcdir)/src/isomorphic_diff.py \
189192
$(top_srcdir)/case_utils/case_file/__init__.py \
190193
$(top_srcdir)/case_utils/local_uuid.py \
194+
$(top_srcdir)/case_utils/namespace.py \
191195
sample.txt.done.log
192196
rm -f _$@
193197
export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \

tests/case_utils/case_file/test_case_file.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,10 @@
1919
import rdflib.plugins.sparql # type: ignore
2020

2121
import case_utils.ontology
22+
from case_utils.namespace import *
2223

2324
_logger = logging.getLogger(os.path.basename(__file__))
2425

25-
NS_RDF = rdflib.RDF
26-
27-
NS_UCO_CORE = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/core/")
28-
NS_UCO_OBSERVABLE = rdflib.Namespace(
29-
"https://ontology.unifiedcyberontology.org/uco/observable/"
30-
)
31-
NS_UCO_TYPES = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/types/")
32-
33-
3426
NSDICT = {
3527
"uco-core": NS_UCO_CORE,
3628
"uco-observable": NS_UCO_OBSERVABLE,

0 commit comments

Comments
 (0)