From 9a5cd8b86e41a3eae5267168a067fba478faa2f7 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Wed, 16 Oct 2024 23:30:51 +0100 Subject: [PATCH] Building document metadata --- trustgraph-base/trustgraph/schema/metadata.py | 12 +++-- trustgraph-cli/scripts/tg-load-pdf | 54 ++++++++++++++++++- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/trustgraph-base/trustgraph/schema/metadata.py b/trustgraph-base/trustgraph/schema/metadata.py index c7dbbae6..aac38f46 100644 --- a/trustgraph-base/trustgraph/schema/metadata.py +++ b/trustgraph-base/trustgraph/schema/metadata.py @@ -1,10 +1,16 @@ -from pulsar.schema import Record, String +from pulsar.schema import Record, String, Array +from . types import Triple class Metadata(Record): - source = String() + + # Source identifier id = String() - title = String() + + # Subgraph + source = Array(Triple()) + + # Collection management user = String() collection = String() diff --git a/trustgraph-cli/scripts/tg-load-pdf b/trustgraph-cli/scripts/tg-load-pdf index 460a2f06..e0904609 100755 --- a/trustgraph-cli/scripts/tg-load-pdf +++ b/trustgraph-cli/scripts/tg-load-pdf @@ -55,7 +55,11 @@ class Loader: path = file data = open(path, "rb").read() - id = hashlib.sha256(path.encode("utf-8")).hexdigest()[0:8] + # Create a SHA256 hash from the data + id = hashlib.sha256(data).hexdigest() + + # Convert into a UUID, 64-byte hash becomes 32-byte UUID + id = str(uuid.UUID(id[::2])) r = Document( metadata=Metadata( @@ -112,6 +116,54 @@ def main(): help=f'Collection ID (default: {default_collection})' ) + parser.add_argument( + '--name', help=f'Document name' + ) + + parser.add_argument( + '--description', help=f'Document description' + ) + + parser.add_argument( + '--copyright-notice', help=f'Copyright notice' + ) + + parser.add_argument( + '--copyright-holder', help=f'Copyright holder' + ) + + parser.add_argument( + '--copyright-year', help=f'Copyright year' + ) + + parser.add_argument( + '--licence', help=f'Copyright licence' + ) + + parser.add_argument( + '--publication-organization', help=f'Publication organization' + ) + + parser.add_argument( + '--publication-description', help=f'Publication description' + ) + + parser.add_argument( + '--publication-date', help=f'Publication date' + ) + + parser.add_argument( + '--url', help=f'Document URL' + ) + + parser.add_argument( + '--keyword', help=f'Keyword' + ) + + parser.add_argument( + '--title', help=f'Document title' + ) + parser.add_argument( '-l', '--log-level', type=LogLevel,