diff --git a/case_utils/case_file/__init__.py b/case_utils/case_file/__init__.py index 63dfef4..316ed3f 100644 --- a/case_utils/case_file/__init__.py +++ b/case_utils/case_file/__init__.py @@ -26,20 +26,10 @@ import rdflib # type: ignore import case_utils +from case_utils.namespace import * DEFAULT_PREFIX = "http://example.org/kb/" -NS_RDF = rdflib.RDF -NS_UCO_CORE = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/core/") -NS_UCO_OBSERVABLE = rdflib.Namespace( - "https://ontology.unifiedcyberontology.org/uco/observable/" -) -NS_UCO_TYPES = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/types/") -NS_UCO_VOCABULARY = rdflib.Namespace( - "https://ontology.unifiedcyberontology.org/uco/vocabulary/" -) -NS_XSD = rdflib.XSD - # Shortcut syntax for defining an immutable named tuple is noted here: # https://docs.python.org/3/library/typing.html#typing.NamedTuple # via the "See also" box here: https://docs.python.org/3/library/collections.html#collections.namedtuple diff --git a/case_utils/namespace.py b/case_utils/namespace.py new file mode 100644 index 0000000..f64b7a4 --- /dev/null +++ b/case_utils/namespace.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +# This software was developed at the National Institute of Standards +# and Technology by employees of the Federal Government in the course +# of their official duties. Pursuant to title 17 Section 105 of the +# United States Code this software is not subject to copyright +# protection and is in the public domain. NIST assumes no +# responsibility whatsoever for its use by other parties, and makes +# no guarantees, expressed or implied, about its quality, +# reliability, or any other characteristic. +# +# We would appreciate acknowledgement if the software is used. + +""" +This module provides importable constants for namespaces. + +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. +""" + +import rdflib # type: ignore + +NS_SH = rdflib.SH +NS_RDF = rdflib.RDF +NS_XSD = rdflib.XSD + +NS_CASE_INVESTIGATION = rdflib.Namespace( + "https://ontology.caseontology.org/case/investigation/" +) +NS_CASE_VOCABULARY = rdflib.Namespace( + "https://ontology.caseontology.org/case/vocabulary/" +) +NS_UCO_ACTION = rdflib.Namespace( + "https://ontology.unifiedcyberontology.org/uco/action/" +) +NS_UCO_CORE = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/core/") +NS_UCO_IDENTITY = rdflib.Namespace( + "https://ontology.unifiedcyberontology.org/uco/identity/" +) +NS_UCO_LOCATION = rdflib.Namespace( + "https://ontology.unifiedcyberontology.org/uco/location/" +) +NS_UCO_MARKING = rdflib.Namespace( + "https://ontology.unifiedcyberontology.org/uco/marking/" +) +NS_UCO_OBSERVABLE = rdflib.Namespace( + "https://ontology.unifiedcyberontology.org/uco/observable/" +) +NS_UCO_PATTERN = rdflib.Namespace( + "https://ontology.unifiedcyberontology.org/uco/pattern/" +) +NS_UCO_ROLE = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/role/") +NS_UCO_TIME = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/time/") +NS_UCO_TOOL = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/tool/") +NS_UCO_TYPES = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/types/") +NS_UCO_VICTIM = rdflib.Namespace( + "https://ontology.unifiedcyberontology.org/uco/victim/" +) +NS_UCO_VOCABULARY = rdflib.Namespace( + "https://ontology.unifiedcyberontology.org/uco/vocabulary/" +) diff --git a/tests/case_utils/case_file/Makefile b/tests/case_utils/case_file/Makefile index c3edca4..28d7e62 100644 --- a/tests/case_utils/case_file/Makefile +++ b/tests/case_utils/case_file/Makefile @@ -111,6 +111,7 @@ sample.txt.json: \ $(tests_srcdir)/src/isomorphic_diff.py \ $(top_srcdir)/case_utils/case_file/__init__.py \ $(top_srcdir)/case_utils/local_uuid.py \ + $(top_srcdir)/case_utils/namespace.py \ sample.txt-nocompact.json rm -f $@ _$@ __$@ export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \ @@ -142,6 +143,7 @@ sample.txt.ttl: \ $(tests_srcdir)/.venv.done.log \ $(top_srcdir)/case_utils/case_file/__init__.py \ $(top_srcdir)/case_utils/local_uuid.py \ + $(top_srcdir)/case_utils/namespace.py \ sample.txt.done.log rm -f _$@ __$@ export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \ @@ -164,6 +166,7 @@ sample.txt-disable_hashes.ttl: \ $(tests_srcdir)/.venv.done.log \ $(top_srcdir)/case_utils/case_file/__init__.py \ $(top_srcdir)/case_utils/local_uuid.py \ + $(top_srcdir)/case_utils/namespace.py \ sample.txt.done.log rm -f _$@ __$@ export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \ @@ -188,6 +191,7 @@ sample.txt-nocompact.json: \ $(tests_srcdir)/src/isomorphic_diff.py \ $(top_srcdir)/case_utils/case_file/__init__.py \ $(top_srcdir)/case_utils/local_uuid.py \ + $(top_srcdir)/case_utils/namespace.py \ sample.txt.done.log rm -f _$@ export DEMO_UUID_REQUESTING_NONRANDOM=NONRANDOM_REQUESTED \ diff --git a/tests/case_utils/case_file/test_case_file.py b/tests/case_utils/case_file/test_case_file.py index 6aff03a..013f68d 100644 --- a/tests/case_utils/case_file/test_case_file.py +++ b/tests/case_utils/case_file/test_case_file.py @@ -19,18 +19,10 @@ import rdflib.plugins.sparql # type: ignore import case_utils.ontology +from case_utils.namespace import * _logger = logging.getLogger(os.path.basename(__file__)) -NS_RDF = rdflib.RDF - -NS_UCO_CORE = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/core/") -NS_UCO_OBSERVABLE = rdflib.Namespace( - "https://ontology.unifiedcyberontology.org/uco/observable/" -) -NS_UCO_TYPES = rdflib.Namespace("https://ontology.unifiedcyberontology.org/uco/types/") - - NSDICT = { "uco-core": NS_UCO_CORE, "uco-observable": NS_UCO_OBSERVABLE,