Skip to main content

DRB Metadata Extractor

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drb_metadata-1.4.2.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drb_metadata-1.4.2-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file drb_metadata-1.4.2.tar.gz.

File metadata

  • Download URL: drb_metadata-1.4.2.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for drb_metadata-1.4.2.tar.gz
Algorithm Hash digest
SHA256 f8f5ea1fffca781c47ee18cd3a53ea3fdd558b1a6ed1aaf4d0dc0ce0b4f420e1
MD5 c1c30e9ebf82b05ce65e851de2fe551b
BLAKE2b-256 b543f3a9e36f0bc1aec1f172271262f3272a8289ca96af87c688165748d2e3a1

See more details on using hashes here.

File details

Details for the file drb_metadata-1.4.2-py3-none-any.whl.

File metadata

  • Download URL: drb_metadata-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for drb_metadata-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1598057fdb26dffc758a853ce2858120c5b4545a014ff70b607c11b0ec455f58
MD5 756e3b438af44dead19bca9d5f6c8940
BLAKE2b-256 37c1d1473b9381900e57ea3deb01ed3bacfa5b2a83f0103534daf0a2c4ec8d03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page