Skip to main content

drb-metadata

drb-metadata is a DRB Addon (MetadataAddon) that extracts a product's metadata according to its topic. It sits on top of the drb core (topic resolution) and drb-extractor (XQuery evaluation primitives).

Extracting metadata

from drb.metadata import MetadataAddon
import drb.topics.resolver as resolver

topic, node = resolver.resolve('<my_resource_url>')
metadata = MetadataAddon().apply(node, topic=topic)  # topic optional
for name, md in metadata.items():
    print(name, '--', md.extract())

MetadataAddon().apply(node, topic=…) returns a dict[str, DrbMetadata]. The topic keyword argument is optional; if omitted, the topic is resolved automatically from node.

Call .extract() on any DrbMetadata value to run its XQuery against the product and return the result.

Declaring metadata — the RDF model

Metadata are declared as RDF triples in the topic's descriptor graph using the metadataset: vocabulary:

namespace: http://knowledge-base.gael.fr/drb/addons/metadataset/
triple:    <topic-uri>  metadataset:<name>  """<xquery>"""

The XQuery string is evaluated against the product node at extraction time.

Inheritance and override. Topics inherit all metadataset: triples from their rdfs:subClassOf parents. A child topic can override any inherited metadata by redeclaring a triple with the same <name>.

Example (Turtle)

@prefix metadataset: <http://knowledge-base.gael.fr/drb/addons/metadataset/> .

<http://knowledge-base.gael.fr/drb/test/product>
    metadataset:platform_name """'SENTINEL-6'""" ;
    metadataset:filename      """name()""" .

Full TTL workflow

  1. Write or extend a TTL file with metadataset: triples for your topic.

  2. Expose the TTL to drb — two options:

    • Packaged descriptor (recommended for libraries): ship the file as cortex.ttl inside your Python package and declare a drb.topic entry point pointing to that package. drb loads it automatically on import.

    • Runtime registration (useful for dynamic or remote graphs): register the graph with ManagerDao before resolving:

      from drb.topics.dao import ManagerDao
      from drb.topics.dao.rdf_dao import RDFDao
      
      # From a local or remote TTL URL:
      ManagerDao().add_dao('<ttl-url>')
      
      # From a Fuseki / Graph Store endpoint (with optional auth):
      ManagerDao().add_dao_instance(RDFDao(['<sparql-endpoint-url>'],
                                           auth=('user', 'password')))
      

      See the core Resolution documentation for details on ManagerDao.

  3. Resolve and apply:

    topic, node = resolver.resolve('<my_resource_url>')
    metadata = MetadataAddon().apply(node, topic=topic)
    

Out of scope. Server-side ingestion of TTL files into a Fuseki instance (e.g. ingest-kb-addons.sh) is handled by the drb-fuseki project and is not covered here.

extract_for_class(class_uri, graph)

When the class is not a resolvable DRB topic (e.g. a derived-table row class used by the Iceberg add-on), use extract_for_class to read metadataset: triples directly from a graph by URI:

from drb.metadata.core import extract_for_class
import rdflib

graph = rdflib.Graph().parse('<my-descriptor.ttl>')
md = extract_for_class('http://example.org/my-class', graph)
# md is a dict[str, DrbMetadata]; bind a node before calling .extract():
md['my_field'].node = some_node
print(md['my_field'].extract())

Migration note

The cortex.yaml format and the drb.metadata Python entry point have been removed. Metadata are now declared exclusively as metadataset: triples in the topic's RDF descriptor (TTL file). Remove any cortex.yaml files and drb.metadata entry points from your packages and replace them with metadataset: triples in a cortex.ttl (or equivalent TTL) exposed via a drb.topic entry point.

Release files for drb-metadata 1.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drb-metadata 1.4.2
File Size Uploaded
drb_metadata-1.4.2.tar.gz 27.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drb-metadata 1.4.2
File Interpreter ABI Platform
drb_metadata-1.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 36.8 kB

Release files / drb_metadata-1.4.2.tar.gz

Download URL drb_metadata-1.4.2.tar.gz
Size 27.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f8f5ea1fffca781c47ee18cd3a53ea3fdd558b1a6ed1aaf4d0dc0ce0b4f420e1
BLAKE2b-256 checksum
How to use checksums
b543f3a9e36f0bc1aec1f172271262f3272a8289ca96af87c688165748d2e3a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / drb_metadata-1.4.2-py3-none-any.whl

Download URL drb_metadata-1.4.2-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1598057fdb26dffc758a853ce2858120c5b4545a014ff70b607c11b0ec455f58
BLAKE2b-256 checksum
How to use checksums
37c1d1473b9381900e57ea3deb01ed3bacfa5b2a83f0103534daf0a2c4ec8d03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

1.4.2 This release

2 release files

1.4.1

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page