comparison graphconvert.py @ 42:7d9609edcf9c

track calendar feed summary/description text and emit them in graphs
author drewp@bigasterisk.com
date Sun, 18 Feb 2024 12:34:53 -0800
parents e2209226b001
children b5d3d9a8c83d
comparison
equal deleted inserted replaced
41:ab54c9f65f76 42:7d9609edcf9c
1 from rdflib import RDF, ConjunctiveGraph, Literal, Namespace, URIRef 1 from localtypes import Conf, feedFromCalId
2 from rdflib import RDF, RDFS, ConjunctiveGraph, Literal, Namespace, URIRef
2 3
3 EV = Namespace("http://bigasterisk.com/event#") 4 EV = Namespace("http://bigasterisk.com/event#")
4 5
5 6
6 def asGraph(events, extraClasses=[], ctx=EV['gcalendar']): 7 def asGraph(conf: Conf, cals, events, extraClasses=[], ctxUri:URIRef=EV['gcalendar']):
8 ctx = ConjunctiveGraph(identifier=ctxUri)
7 graph = ConjunctiveGraph() 9 graph = ConjunctiveGraph()
8 graph.namespace_manager.bind('ev', EV) 10 graph.namespace_manager.bind('ev', EV)
11
12 for doc in cals:
13 feed = URIRef(feedFromCalId(conf, doc['_id']))
14 graph.add((feed, RDF.type, EV['CalendarFeed'], ctx))
15 if doc['summary']:
16 graph.add((feed, RDFS.label, Literal(doc['summary'].strip()), ctx))
17 if doc['description']:
18 graph.add((feed, EV['description'], Literal(doc['description'].strip()), ctx))
19
9 for ev in events: 20 for ev in events:
10 uri = URIRef(ev['uri']) 21 uri = URIRef(ev['uri'])
11 22
12 def add(p, o): 23 def add(p: URIRef, o: URIRef|Literal):
13 return graph.add((uri, p, o, ctx)) 24 return graph.add((uri, p, o, ctx))
14 25
15 add(RDF.type, EV['Event']) 26 add(RDF.type, EV['Event'])
16 for cls in extraClasses: 27 for cls in extraClasses:
17 add(RDF.type, cls) 28 add(RDF.type, cls)