commit c96aa1eac19ac96406feb1147884763bb50f0042
parent 95d4bfdf7eb422f079bac9784e425d11c19b0fd0
Author: lash <dev@holbrook.no>
Date: Wed, 24 Sep 2025 06:07:14 +0100
Rename modules, add base
Diffstat:
10 files changed, 87 insertions(+), 71 deletions(-)
diff --git a/adesse/__init__.py b/adesse/__init__.py
@@ -2,8 +2,8 @@ from .base import Serializer
from .entity import Entity
from .org import Org
from .cert import Cert
+from .action import Action
from .event import Event
-from .bundle import Bundle
from .testimony import Testimony
from .attachment import Attachment
from .person import Person
diff --git a/adesse/action.py b/adesse/action.py
@@ -0,0 +1,36 @@
+import datetime
+
+from rdflib import Literal, RDF
+from rdflib.namespace import PROV, XSD, RDF
+from rdflib.term import URIRef
+
+from adesse import Entity
+from adesse.ns import DF
+from adesse.uri import to_uuid_uri
+
+
+class Action(Entity):
+
+ def __init__(self, title, start: datetime.datetime, end: datetime.datetime, uu=None):
+ super().__init__(title, uu=uu)
+ self.dtstart = start
+ self.dtstart = self.dtstart.astimezone(datetime.timezone.utc)
+ self.dtend = end
+ self.dtend = self.dtend.astimezone(datetime.timezone.utc)
+ self.topic = []
+
+
+ def add_topic(self, v):
+ if not isinstance(v, URIRef):
+ if not instance(v, str):
+ raise TypeError("topic must be URIRef or string")
+ v = URIRef(v)
+ self.cat.append(v)
+
+
+ def apply(self, g):
+ uu = to_uuid_uri(self.uu)
+ g.add((uu, PROV.startedAtTime, Literal(self.dtstart.isoformat(timespec='seconds'), datatype=XSD.dateTime)))
+ g.add((uu, PROV.endedAtTime, Literal(self.dtend.isoformat(timespec='seconds'), datatype=XSD.dateTime)))
+ g.add((uu, RDF.type, DF.Action))
+ super().apply(g)
diff --git a/adesse/base.py b/adesse/base.py
@@ -3,12 +3,13 @@ from rdflib.namespace import NamespaceManager
from rdflib.namespace import FOAF, XSD, PROV, DC, DCTERMS
from .ns import DF, COUNTRY, PSS, UU
+from .config import serialize_format, base
class Serializer:
def __init__(self):
- self.g = Graph()
+ self.g = Graph(base=base)
self.ns = NamespaceManager(self.g)
self.ns.bind('uuid', UU)
self.ns.bind('dc', DC)
@@ -24,4 +25,4 @@ class Serializer:
def __str__(self):
- return self.g.serialize(format='turtle')
+ return self.g.serialize(format=serialize_format)
diff --git a/adesse/bundle.py b/adesse/bundle.py
@@ -1,21 +0,0 @@
-from adesse import Entity
-from .uri import to_uuid_uri
-
-
-class Bundle(Entity):
-
- def __init__(self, label, crt, uu=None):
- super().__init__(label, uu=uu)
- self.cert = crt
- self.testimony = []
-
-
- def add_testimony(self, v):
- self.testimony.append(v)
-
-
- def apply(self, g):
- uu = to_uuid_uri(self.uu)
- self.cert.apply(g)
- for v in self.testimony:
- v.apply(g)
diff --git a/adesse/cert.py b/adesse/cert.py
@@ -1,26 +1,25 @@
+from rdflib import Literal, RDF
+
from adesse import Entity
-from .uri import to_uuid_uri
-from .ns import DF
+from adesse.ns import DF
+from adesse.uri import to_uuid_uri
class Cert(Entity):
- def __init__(self, subj, obj, agent, uu=None, title=None):
- super().__init__(str(uu), uu=uu)
- self.subject = subj
- self.object = obj
- self.agent = agent
+ def __init__(self, label, crt, uu=None):
+ super().__init__(label, uu=uu)
+ self.cert = crt
+ self.testimony = []
+
+
+ def add_testimony(self, v):
+ self.testimony.append(v)
def apply(self, g):
uu = to_uuid_uri(self.uu)
- o = self.subject.to_ref()
- g.add((uu, DF.subject, o))
- o = self.object.to_ref()
- g.add((uu, DF.object, o))
- o = self.agent.to_ref()
- g.add((uu, DF.agent, o))
-
- self.subject.apply(g)
- self.object.apply(g)
- self.agent.apply(g)
+ #g.add((uu, RDF.type, DF.Certificate))
+ self.cert.apply(g)
+ for v in self.testimony:
+ v.apply(g)
diff --git a/adesse/config.py b/adesse/config.py
@@ -1,3 +1,5 @@
+import os
+
namespace_sources = {
'DF': 'http://defalsify.org/rdf/0.1/core/',
'COUNTRY': 'http://www.iso.org/obp/ui/#iso:code:3166:',
@@ -5,3 +7,7 @@ namespace_sources = {
'PSS': 'http://standards.internetofproduction.org/pub/r7g0n9fo/release/4#',
'WOT': 'http://xmlns.com/wot/0.1/#',
}
+
+serialize_format = os.environ.get('ADESSE_FORMAT', 'xml')
+
+base = 'URN:uuid:'
diff --git a/adesse/event.py b/adesse/event.py
@@ -1,36 +1,29 @@
-import datetime
-
-from rdflib import Literal
-from rdflib.namespace import PROV, XSD, RDF
-from rdflib.term import URIRef
+from rdflib import RDF
from adesse import Entity
-from adesse.ns import DF
-from adesse.uri import to_uuid_uri
+from .uri import to_uuid_uri
+from .ns import DF
class Event(Entity):
- def __init__(self, title, start: datetime.datetime, end: datetime.datetime, uu=None):
- super().__init__(title, uu=uu)
- self.dtstart = start
- self.dtstart = self.dtstart.astimezone(datetime.timezone.utc)
- self.dtend = end
- self.dtend = self.dtend.astimezone(datetime.timezone.utc)
- self.topic = []
+ def __init__(self, subj, obj, agent, uu=None, title=None):
+ super().__init__(str(uu), uu=uu)
+ self.subject = subj
+ self.object = obj
+ self.agent = agent
-
- def add_topic(self, v):
- if not isinstance(v, URIRef):
- if not instance(v, str):
- raise TypeError("topic must be URIRef or string")
- v = URIRef(v)
- self.cat.append(v)
-
def apply(self, g):
uu = to_uuid_uri(self.uu)
- g.add((uu, PROV.startedAtTime, Literal(self.dtstart.isoformat(timespec='seconds'), datatype=XSD.dateTime)))
- g.add((uu, PROV.endedAtTime, Literal(self.dtend.isoformat(timespec='seconds'), datatype=XSD.dateTime)))
g.add((uu, RDF.type, DF.Event))
- super().apply(g)
+ o = self.subject.to_ref()
+ g.add((uu, DF.subject, o))
+ o = self.object.to_ref()
+ g.add((uu, DF.object, o))
+ o = self.agent.to_ref()
+ g.add((uu, DF.agent, o))
+
+ self.subject.apply(g)
+ self.object.apply(g)
+ self.agent.apply(g)
diff --git a/adesse/ns.py b/adesse/ns.py
@@ -27,6 +27,8 @@ class DF(DefinedNamespace):
Event: URIRef
AttachmentData: URIRef
Testimony: URIRef
+ Certificate: URIRef
+ Action: URIRef
# perceptionmedium
video: URIRef
diff --git a/adesse/testimony.py b/adesse/testimony.py
@@ -13,7 +13,7 @@ class Testimony(Entity):
self.medium = []
self.dt = date
self.target = target
- self.identity = identity
+ self.identity = identity # may be PSS.Person or did (can be refed by uuid and sha256)
self.claim = []
self.behalf = []
self.verdict = DF.certified
diff --git a/test/test_serialize.py b/test/test_serialize.py
@@ -4,7 +4,7 @@ import hashlib
from rdflib.term import URIRef
-from adesse import Serializer, Entity, Person, Org, Cert, Event, Bundle, Testimony, Attachment
+from adesse import Serializer, Entity, Person, Org, Action, Cert, Event, Testimony, Attachment
from adesse.ns import DF
@@ -19,11 +19,11 @@ class TestSerialize(unittest.TestCase):
z = Serializer()
subj = Person("Melvin", "Ferd", "SV", common_name="Melvin B. Ferd")
subj.set_url('http://rotten.com')
- obj = Event('foo', datetime.datetime.fromtimestamp(1758673250), datetime.datetime.fromtimestamp(1758679250))
+ obj = Action('foo', datetime.datetime.fromtimestamp(1758673250), datetime.datetime.fromtimestamp(1758679250))
agent = Org("Toxic Mopping Inc.")
agent.set_url('http://foo.xyz')
- crt = Cert(subj, obj, agent)
- o = Bundle('bundle in the jungle', crt)
+ crt = Event(subj, obj, agent)
+ o = Cert('bundle in the jungle', crt)
v = Testimony('testify', datetime.datetime.now(), crt, URIRef('did:deadbeef'))
d = Attachment('some medium', 'foo baz bar', datetime.datetime.now(), 'image/png')
h = hashlib.sha256()