site_graphlogo
- Terms of Use and Privacy
Source Code
rss
site_graphlogo
- Terms of Use and Privacy
Source Code
rss

Source Code | Triple SEND

This code will send compressed triples. See Triple Pub.

#!/usr/bin/python3
# coding=utf-8
import zstandard as zstd
import base64
import paho.mqtt.publish as publish
import sys
from datetime import datetime
from datetime import date
lines=[]
fl=open('dictionary',"rb")
data=fl.read()
dd = zstd.ZstdCompressionDict(data)
cctx = zstd.ZstdCompressor(dict_data=dd,level=22,write_checksum=False,write_dict_id=False,threads=2)
for l in sys.stdin:
   # The standard form for one piece of information is a triple on one line using this spec: https://www.w3.org/TR/n-triples/
   # The form here is to facilitate real-time collaboration by adding timestamps and the ability to remove a triple.
   # The resultant graph does not need either of these.    20210218T132421.516Z add|sub
   # It is assumed that this is a single graph.  Different channels could be used to work on different graphs.
   # The collaborative portion is meant to be minimal as far as the interface and grammar, but is extensible to full RDF and beyond.  
   ts=datetime.utcnow().isoformat(sep='T', timespec='milliseconds').replace(':','').replace('-','').replace(' ','')+'Z'
   m=base64.b64encode(cctx.compress(bytearray(ts+' '+l.strip(),"utf8")))[5:].decode()
   publish.single("allorg/dfd/full",m,hostname="localhost")