Skip to content

Commit 5c75d60

Browse files
committed
Centralize namespace constants in namespace.py
References: * #38 * [UCO OC-217] (CP-107) Revise ontology IRI to be slash-based and drop IRI base * [ONT-64] (CP-17) Define scheme for CASE and UCO importable versioned IRIs Signed-off-by: Alex Nelson <[email protected]>
1 parent f174764 commit 5c75d60

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
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://unifiedcyberontology.org/ontology/uco/core#")
34-
NS_UCO_OBSERVABLE = rdflib.Namespace(
35-
"https://unifiedcyberontology.org/ontology/uco/observable#"
36-
)
37-
NS_UCO_TYPES = rdflib.Namespace("https://unifiedcyberontology.org/ontology/uco/types#")
38-
NS_UCO_VOCABULARY = rdflib.Namespace(
39-
"https://unifiedcyberontology.org/ontology/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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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_UCO_ACTION = rdflib.Namespace("https://unifiedcyberontology.org/ontology/uco/action#")
30+
NS_UCO_CORE = rdflib.Namespace("https://unifiedcyberontology.org/ontology/uco/core#")
31+
NS_UCO_LOCATION = rdflib.Namespace("https://unifiedcyberontology.org/ontology/uco/location#")
32+
NS_UCO_OBSERVABLE = rdflib.Namespace(
33+
"https://unifiedcyberontology.org/ontology/uco/observable#"
34+
)
35+
NS_UCO_TYPES = rdflib.Namespace("https://unifiedcyberontology.org/ontology/uco/types#")
36+
NS_UCO_VOCABULARY = rdflib.Namespace(
37+
"https://unifiedcyberontology.org/ontology/uco/vocabulary#"
38+
)

tests/case_utils/case_file/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ sample.txt.json: \
127127
$(tests_srcdir)/src/isomorphic_diff.py \
128128
$(top_srcdir)/case_utils/case_file/__init__.py \
129129
$(top_srcdir)/case_utils/local_uuid.py \
130+
$(top_srcdir)/case_utils/namespace.py \
130131
sample.txt-nocompact.json
131132
rm -f $@ _$@ __$@
132133
export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \
@@ -158,6 +159,7 @@ sample.txt.ttl: \
158159
$(tests_srcdir)/.venv.done.log \
159160
$(top_srcdir)/case_utils/case_file/__init__.py \
160161
$(top_srcdir)/case_utils/local_uuid.py \
162+
$(top_srcdir)/case_utils/namespace.py \
161163
sample.txt.done.log
162164
rm -f _$@ __$@
163165
export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \
@@ -180,6 +182,7 @@ sample.txt-disable_hashes.ttl: \
180182
$(tests_srcdir)/.venv.done.log \
181183
$(top_srcdir)/case_utils/case_file/__init__.py \
182184
$(top_srcdir)/case_utils/local_uuid.py \
185+
$(top_srcdir)/case_utils/namespace.py \
183186
sample.txt.done.log
184187
rm -f _$@ __$@
185188
export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \
@@ -204,6 +207,7 @@ sample.txt-nocompact.json: \
204207
$(tests_srcdir)/src/isomorphic_diff.py \
205208
$(top_srcdir)/case_utils/case_file/__init__.py \
206209
$(top_srcdir)/case_utils/local_uuid.py \
210+
$(top_srcdir)/case_utils/namespace.py \
207211
sample.txt.done.log
208212
rm -f _$@
209213
export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \

tests/case_utils/case_file/test_case_file.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,14 @@
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-
IRI_UCO_CORE = "https://unifiedcyberontology.org/ontology/uco/core#"
26-
IRI_UCO_OBSERVABLE = "https://unifiedcyberontology.org/ontology/uco/observable#"
27-
IRI_UCO_TYPES = "https://unifiedcyberontology.org/ontology/uco/types#"
28-
29-
NS_RDF = rdflib.RDF
30-
NS_UCO_CORE = rdflib.Namespace(IRI_UCO_CORE)
31-
NS_UCO_OBSERVABLE = rdflib.Namespace(IRI_UCO_OBSERVABLE)
32-
NS_UCO_TYPES = rdflib.Namespace(IRI_UCO_TYPES)
33-
3426
NSDICT = {
35-
"uco-core": IRI_UCO_CORE,
36-
"uco-observable": IRI_UCO_OBSERVABLE,
37-
"uco-types": IRI_UCO_TYPES,
27+
"uco-core": NS_UCO_CORE,
28+
"uco-observable": NS_UCO_OBSERVABLE,
29+
"uco-types": NS_UCO_TYPES,
3830
}
3931

4032
SRCDIR = os.path.dirname(__file__)

0 commit comments

Comments
 (0)