Skip to content

Commit 6b0566b

Browse files
committed
Add inherence UUID functions
A follow-on patch will regenerate Make-managed files. References: * casework/CASE-Utilities-Python#112 Signed-off-by: Alex Nelson <[email protected]>
1 parent a09234e commit 6b0566b

File tree

2 files changed

+106
-24
lines changed

2 files changed

+106
-24
lines changed

case_exiftool/__init__.py

Lines changed: 105 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import os
2424
import typing
2525

26-
import case_utils
26+
import case_utils.inherent_uuid
2727
import rdflib.plugins.sparql
2828
import rdflib.util
2929
from case_utils.namespace import (
@@ -69,6 +69,11 @@
6969
help="A file recording the output of ExifTool run against some file. Expects exiftool was run with -binary, -duplicates, and -xmlFormat.",
7070
required=True,
7171
)
72+
argument_parser.add_argument(
73+
"--use-deterministic-uuids",
74+
action="store_true",
75+
help="Use UUIDs computed using the case_utils.inherent_uuid module.",
76+
)
7277
argument_parser.add_argument(
7378
"out_graph",
7479
help="A self-contained RDF graph file, in the format either requested by --output-format or guessed based on extension.",
@@ -145,13 +150,23 @@ class ExifToolRDFMapper(object):
145150
Those interested in extending this tool's mapping coverage of ExifTool IRIs are encouraged to update the method map_raw_and_printconv_iri.
146151
"""
147152

148-
def __init__(self, graph: rdflib.Graph, ns_base: rdflib.Namespace) -> None:
153+
def __init__(
154+
self,
155+
graph: rdflib.Graph,
156+
ns_base: rdflib.Namespace,
157+
*args: typing.Any,
158+
use_deterministic_uuids: bool = False,
159+
**kwargs: typing.Any,
160+
) -> None:
149161
assert isinstance(graph, rdflib.Graph)
150162

151163
self._exif_dictionary_dict: typing.Optional[
152164
typing.Dict[str, rdflib.Literal]
153165
] = None
154166
self._graph = graph
167+
168+
self._use_deterministic_uuids = use_deterministic_uuids
169+
155170
self._kv_dict_raw: typing.Dict[rdflib.URIRef, rdflib.term.Node] = dict()
156171
self._kv_dict_printconv: typing.Dict[rdflib.URIRef, rdflib.term.Node] = dict()
157172
self._mime_type: typing.Optional[str] = None
@@ -522,9 +537,18 @@ def n_camera_object_device_facet(self) -> rdflib.URIRef:
522537
Initialized on first access.
523538
"""
524539
if self._n_camera_object_device_facet is None:
525-
self._n_camera_object_device_facet = self.ns_base[
526-
"DeviceFacet-" + case_utils.local_uuid.local_uuid()
527-
]
540+
if self.use_deterministic_uuids:
541+
self._n_camera_object_device_facet = (
542+
case_utils.inherent_uuid.get_facet_uriref(
543+
self.n_camera_object,
544+
NS_UCO_OBSERVABLE.DeviceFacet,
545+
namespace=self.ns_base,
546+
)
547+
)
548+
else:
549+
self._n_camera_object_device_facet = self.ns_base[
550+
"DeviceFacet-" + case_utils.local_uuid.local_uuid()
551+
]
528552
self.graph.add(
529553
(
530554
self._n_camera_object_device_facet,
@@ -547,9 +571,16 @@ def n_content_data_facet(self) -> rdflib.URIRef:
547571
Initialized on first access.
548572
"""
549573
if self._n_content_data_facet is None:
550-
self._n_content_data_facet = self.ns_base[
551-
"ContentDataFacet-" + case_utils.local_uuid.local_uuid()
552-
]
574+
if self.use_deterministic_uuids:
575+
self._n_content_data_facet = case_utils.inherent_uuid.get_facet_uriref(
576+
self.n_observable_object,
577+
NS_UCO_OBSERVABLE.ContentDataFacet,
578+
namespace=self.ns_base,
579+
)
580+
else:
581+
self._n_content_data_facet = self.ns_base[
582+
"ContentDataFacet-" + case_utils.local_uuid.local_uuid()
583+
]
553584
self.graph.add(
554585
(
555586
self._n_content_data_facet,
@@ -590,9 +621,16 @@ def n_exif_facet(self) -> rdflib.URIRef:
590621
Initialized on first access.
591622
"""
592623
if self._n_exif_facet is None:
593-
self._n_exif_facet = self.ns_base[
594-
"EXIFFacet-" + case_utils.local_uuid.local_uuid()
595-
]
624+
if self.use_deterministic_uuids:
625+
self._n_exif_facet = case_utils.inherent_uuid.get_facet_uriref(
626+
self.n_observable_object,
627+
NS_UCO_OBSERVABLE.EXIFFacet,
628+
namespace=self.ns_base,
629+
)
630+
else:
631+
self._n_exif_facet = self.ns_base[
632+
"EXIFFacet-" + case_utils.local_uuid.local_uuid()
633+
]
596634
self.graph.add(
597635
(self._n_exif_facet, NS_RDF.type, NS_UCO_OBSERVABLE.EXIFFacet)
598636
)
@@ -607,9 +645,16 @@ def n_file_facet(self) -> rdflib.URIRef:
607645
Initialized on first access.
608646
"""
609647
if self._n_file_facet is None:
610-
self._n_file_facet = self.ns_base[
611-
"FileFacet-" + case_utils.local_uuid.local_uuid()
612-
]
648+
if self.use_deterministic_uuids:
649+
self._n_file_facet = case_utils.inherent_uuid.get_facet_uriref(
650+
self.n_observable_object,
651+
NS_UCO_OBSERVABLE.FileFacet,
652+
namespace=self.ns_base,
653+
)
654+
else:
655+
self._n_file_facet = self.ns_base[
656+
"FileFacet-" + case_utils.local_uuid.local_uuid()
657+
]
613658
self.graph.add(
614659
(self._n_file_facet, NS_RDF.type, NS_UCO_OBSERVABLE.FileFacet)
615660
)
@@ -638,9 +683,18 @@ def n_location_object_latlong_facet(self) -> rdflib.URIRef:
638683
Initialized on first access.
639684
"""
640685
if self._n_location_object_latlong_facet is None:
641-
self._n_location_object_latlong_facet = self.ns_base[
642-
"LatLongCoordinatesFacet-" + case_utils.local_uuid.local_uuid()
643-
]
686+
if self.use_deterministic_uuids:
687+
self._n_location_object_latlong_facet = (
688+
case_utils.inherent_uuid.get_facet_uriref(
689+
self.n_location_object,
690+
NS_UCO_LOCATION.LatLongCoordinatesFacet,
691+
namespace=self.ns_base,
692+
)
693+
)
694+
else:
695+
self._n_location_object_latlong_facet = self.ns_base[
696+
"LatLongCoordinatesFacet-" + case_utils.local_uuid.local_uuid()
697+
]
644698
self.graph.add(
645699
(
646700
self._n_location_object_latlong_facet,
@@ -683,9 +737,18 @@ def n_raster_picture_facet(self) -> rdflib.URIRef:
683737
Initialized on first access.
684738
"""
685739
if self._n_raster_picture_facet is None:
686-
self._n_raster_picture_facet = self.ns_base[
687-
"RasterPictureFacet-" + case_utils.local_uuid.local_uuid()
688-
]
740+
if self.use_deterministic_uuids:
741+
self._n_raster_picture_facet = (
742+
case_utils.inherent_uuid.get_facet_uriref(
743+
self.n_observable_object,
744+
NS_UCO_OBSERVABLE.RasterPictureFacet,
745+
namespace=self.ns_base,
746+
)
747+
)
748+
else:
749+
self._n_raster_picture_facet = self.ns_base[
750+
"RasterPictureFacet-" + case_utils.local_uuid.local_uuid()
751+
]
689752
self.graph.add(
690753
(
691754
self._n_raster_picture_facet,
@@ -754,9 +817,18 @@ def n_unix_file_permissions_facet(self) -> rdflib.URIRef:
754817
Initialized on first access.
755818
"""
756819
if self._n_unix_file_permissions_facet is None:
757-
self._n_unix_file_permissions_facet = self.ns_base[
758-
"UNIXFilePermissionsFacet-" + case_utils.local_uuid.local_uuid()
759-
]
820+
if self.use_deterministic_uuids:
821+
self._n_unix_file_permissions_facet = (
822+
case_utils.inherent_uuid.get_facet_uriref(
823+
self.n_observable_object,
824+
NS_UCO_OBSERVABLE.UNIXFilePermissionsFacet,
825+
namespace=self.ns_base,
826+
)
827+
)
828+
else:
829+
self._n_unix_file_permissions_facet = self.ns_base[
830+
"UNIXFilePermissionsFacet-" + case_utils.local_uuid.local_uuid()
831+
]
760832
self.graph.add(
761833
(
762834
self._n_unix_file_permissions_facet,
@@ -791,6 +863,13 @@ def oo_slug(self, value: str) -> None:
791863
assert isinstance(value, str)
792864
self._oo_slug = value
793865

866+
@property
867+
def use_deterministic_uuids(self) -> bool:
868+
"""
869+
No setter provided.
870+
"""
871+
return self._use_deterministic_uuids
872+
794873

795874
def main() -> None:
796875
case_utils.local_uuid.configure()
@@ -820,7 +899,9 @@ def main() -> None:
820899
out_graph.namespace_manager.bind("uco-observable", NS_UCO_OBSERVABLE)
821900
out_graph.namespace_manager.bind("uco-types", NS_UCO_TYPES)
822901

823-
exiftool_rdf_mapper = ExifToolRDFMapper(out_graph, NS_BASE)
902+
exiftool_rdf_mapper = ExifToolRDFMapper(
903+
out_graph, NS_BASE, use_deterministic_uuids=args.use_deterministic_uuids
904+
)
824905
exiftool_rdf_mapper.map_raw_and_printconv_rdf(args.raw_xml, args.print_conv_xml)
825906

826907
# _logger.debug("args.output_format = %r." % args.output_format)

tests/govdocs1/files/799/987/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ analysis.ttl: \
5555
--output-format turtle \
5656
--print-conv-xml 799987_printConv.xml \
5757
--raw-xml 799987_raw.xml \
58+
--use-deterministic-uuids \
5859
__$@
5960
source $(top_srcdir)/tests/venv/bin/activate \
6061
&& case_validate \

0 commit comments

Comments
 (0)