Skip to content
/ clisn Public

A collection of RDFLib namespaces for the CLSInfra project.

License

Notifications You must be signed in to change notification settings

lu-pl/clisn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLiSN <:books:>:sparkles:

License: GPL v3 PyPI version

A collection of RDFLib namespaces for the Computational Literary Studies Infrastructure project.

Requirements

  • Python >=3.11

Installation

pip install clisn

Usage

Namespaces

CLiSN provides rdflib.Namespaces for the CLSInfra project.

from rdflib import Graph
from rdflib.namespace import RDF

from clisn import crm, crmcls, corpus_base

base_ns = corpus_base("SweDraCor")
attrassign_uri = base_ns["attrassign/1"]

triples = [
    (
        attrassign_uri,
        RDF.type,
        crm["E13_Attribute_Assignment"]
    ),
    (
        attrassign_uri,
        crm["P140_assigned_attribute_to"],
        base_ns["corpus"]
    ),
    (
        attrassign_uri,
        crm["P177_assigned_property_of_type"],
        crmcls["Z8_corpus_has_corpus_type"]
    )
]

graph = Graph()

for triple in triples:
    graph.add(triple)

print(graph.serialize())

Output:

@prefix ns1: <http://www.cidoc-crm.org/cidoc-crm/> .

<https://swedracor.clscor.io/entity/attrassign/1> a ns1:E13_Attribute_Assignment ;
    ns1:P140_assigned_attribute_to <https://swedracor.clscor.io/entity/corpus> ;
    ns1:P177_assigned_property_of_type <https://clscor.io/ontologies/CRMcls/Z8_corpus_has_corpus_type> .

NamespaceManager

clisn features a custom NamespaceManager for CLSInfra namespaces. This e.g. allows to easily generate a namespaced rdflib.Graph like so:

from rdflib import Graph, URIRef, Literal
from clisn import CLSInfraNamespaceManager, crm

graph = Graph()
CLSInfraNamespaceManager(graph)

graph.add(
    (
        URIRef("https://subject.xyz/example/"),
        crm["p90_has_value"],
        Literal("some value")
    )
)

print(graph.serialize())

Output:

@prefix crm: <http://www.cidoc-crm.org/cidoc-crm/> .

<https://subject.xyz/example/> crm:p90_has_value "some value" .

About

A collection of RDFLib namespaces for the CLSInfra project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages