Lightweight RDF Stream Parser
Project description
Lightweight RDF Stream Parser for Python
A lightweight RDF parser which streams triples directly from disk or standard input without loading the entire graph into memory.
Support N-Triples and N-Quads format
Usage
Read and write to disk.
from rdf import NTriples
from rdf import Literal
with NTriples(path = "./pizzacats.nt", mode = 'r') as g:
with NTriples(path = "./out.nt", mode = 'w') as h:
for subject, predicate, object in g.parse():
if type(object) is Literal and object.language == "en":
# do stuff
h.write((subject, predicate, object))
Read / write from standard input / output.
from os import stdin
from rdf import NQuads
from rdf import IRIRef
g = NQuads(data=stdin.read(), mode = 'r')
h = NQuads(mode = 'w')
target = IRIRef("https://example.org/Pizzacat")
for triple in g.parse():
if triple[0] == target: # subject
# do stuff
h.write(triple)
g.close()
h.close()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyRDF-2.1.0.tar.gz
(17.8 kB
view details)
File details
Details for the file pyRDF-2.1.0.tar.gz
.
File metadata
- Download URL: pyRDF-2.1.0.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.3 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0f2b340eac86df8211ce85a9a1bc925c686b6c2c6fb5a445704f6f829937cdb |
|
MD5 | 900d78bcd1e2d062b0173cdf849b4b57 |
|
BLAKE2b-256 | 2870e86af7b73b095680f5a605bf93164028dc53a86c9bb8bc89a5acdc1c65b3 |