1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Prefix Register - A PostgreSQL-backed namespace prefix registry for CURIE expansion
This library provides bidirectional mapping between namespace prefixes
(like "foaf", "rdf", "schema") and their full URI bases, optimized for
use in RDF/semantic web applications.
Example:
>>> import asyncio
>>> from prefix_register import PrefixRegistry
>>>
>>> async def main():
... # Connect to PostgreSQL
... registry = await PrefixRegistry.new("postgres://localhost/mydb", 10)
...
... # Store a prefix (only if URI doesn't already have one)
... stored = await registry.store_prefix_if_new("foaf", "http://xmlns.com/foaf/0.1/")
... print(f"Prefix stored: {stored}")
...
... # Expand a CURIE
... uri = await registry.expand_curie("foaf", "Person")
... if uri:
... print(f"foaf:Person = {uri}")
...
... # Batch store prefixes
... prefixes = [
... ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"),
... ("rdfs", "http://www.w3.org/2000/01/rdf-schema#"),
... ]
... result = await registry.store_prefixes_if_new(prefixes)
... print(f"Stored {result['stored']}, skipped {result['skipped']}")
>>>
>>> asyncio.run(main())
"""
=
=