23
23
import os
24
24
import typing
25
25
26
- import case_utils
26
+ import case_utils . inherent_uuid
27
27
import rdflib .plugins .sparql
28
28
import rdflib .util
29
29
from case_utils .namespace import (
69
69
help = "A file recording the output of ExifTool run against some file. Expects exiftool was run with -binary, -duplicates, and -xmlFormat." ,
70
70
required = True ,
71
71
)
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
+ )
72
77
argument_parser .add_argument (
73
78
"out_graph" ,
74
79
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):
145
150
Those interested in extending this tool's mapping coverage of ExifTool IRIs are encouraged to update the method map_raw_and_printconv_iri.
146
151
"""
147
152
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 :
149
161
assert isinstance (graph , rdflib .Graph )
150
162
151
163
self ._exif_dictionary_dict : typing .Optional [
152
164
typing .Dict [str , rdflib .Literal ]
153
165
] = None
154
166
self ._graph = graph
167
+
168
+ self ._use_deterministic_uuids = use_deterministic_uuids
169
+
155
170
self ._kv_dict_raw : typing .Dict [rdflib .URIRef , rdflib .term .Node ] = dict ()
156
171
self ._kv_dict_printconv : typing .Dict [rdflib .URIRef , rdflib .term .Node ] = dict ()
157
172
self ._mime_type : typing .Optional [str ] = None
@@ -522,9 +537,18 @@ def n_camera_object_device_facet(self) -> rdflib.URIRef:
522
537
Initialized on first access.
523
538
"""
524
539
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
+ ]
528
552
self .graph .add (
529
553
(
530
554
self ._n_camera_object_device_facet ,
@@ -547,9 +571,16 @@ def n_content_data_facet(self) -> rdflib.URIRef:
547
571
Initialized on first access.
548
572
"""
549
573
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
+ ]
553
584
self .graph .add (
554
585
(
555
586
self ._n_content_data_facet ,
@@ -590,9 +621,16 @@ def n_exif_facet(self) -> rdflib.URIRef:
590
621
Initialized on first access.
591
622
"""
592
623
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
+ ]
596
634
self .graph .add (
597
635
(self ._n_exif_facet , NS_RDF .type , NS_UCO_OBSERVABLE .EXIFFacet )
598
636
)
@@ -607,9 +645,16 @@ def n_file_facet(self) -> rdflib.URIRef:
607
645
Initialized on first access.
608
646
"""
609
647
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
+ ]
613
658
self .graph .add (
614
659
(self ._n_file_facet , NS_RDF .type , NS_UCO_OBSERVABLE .FileFacet )
615
660
)
@@ -638,9 +683,18 @@ def n_location_object_latlong_facet(self) -> rdflib.URIRef:
638
683
Initialized on first access.
639
684
"""
640
685
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
+ ]
644
698
self .graph .add (
645
699
(
646
700
self ._n_location_object_latlong_facet ,
@@ -683,9 +737,18 @@ def n_raster_picture_facet(self) -> rdflib.URIRef:
683
737
Initialized on first access.
684
738
"""
685
739
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
+ ]
689
752
self .graph .add (
690
753
(
691
754
self ._n_raster_picture_facet ,
@@ -754,9 +817,18 @@ def n_unix_file_permissions_facet(self) -> rdflib.URIRef:
754
817
Initialized on first access.
755
818
"""
756
819
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
+ ]
760
832
self .graph .add (
761
833
(
762
834
self ._n_unix_file_permissions_facet ,
@@ -791,6 +863,13 @@ def oo_slug(self, value: str) -> None:
791
863
assert isinstance (value , str )
792
864
self ._oo_slug = value
793
865
866
+ @property
867
+ def use_deterministic_uuids (self ) -> bool :
868
+ """
869
+ No setter provided.
870
+ """
871
+ return self ._use_deterministic_uuids
872
+
794
873
795
874
def main () -> None :
796
875
case_utils .local_uuid .configure ()
@@ -820,7 +899,9 @@ def main() -> None:
820
899
out_graph .namespace_manager .bind ("uco-observable" , NS_UCO_OBSERVABLE )
821
900
out_graph .namespace_manager .bind ("uco-types" , NS_UCO_TYPES )
822
901
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
+ )
824
905
exiftool_rdf_mapper .map_raw_and_printconv_rdf (args .raw_xml , args .print_conv_xml )
825
906
826
907
# _logger.debug("args.output_format = %r." % args.output_format)
0 commit comments