pymantic.parsers
¶
-
class
pymantic.parsers.base.
BaseParser
(environment=None)[source]¶ Common base class for all parsers
Provides shared utilities for creating RDF objects, handling IRIs, and tracking parser state.
pymantic.parsers.jsonld
¶
Parse RDF serialized as jsonld
Usage:
from pymantic.parsers.jsonld import jsonld_parser
graph = jsonld_parser.parse_json(json.load(io.open('file.jsonld', mode='rt')))
lark parsers¶
pymantic.parsers.lark.base
¶
-
class
pymantic.parsers.lark.base.
LarkParser
(lark)[source]¶ Provide a consistent interface for parsing serialized RDF using one of the lark parsers.
pymantic.parsers.lark.ntriples
¶
Parse RDF serialized as ntriples files.
Usage:
from pymantic.parsers.lark import ntriples_parser
graph = ntriples_parser.parse(io.open('a_file.nt', mode='rt'))
graph2 = ntriples_parser.parse("<http://a.example/s> <http://a.example/p> <http://a.example/o> .")
If .parse()
is called with a file-like object implementing readline
,
it will efficiently parse line by line rather than parsing the entire file.
pymantic.parsers.lark.nquads
¶
Parse RDF serialized as nquads files.
Usage:
from pymantic.parsers.lark import nquads_parser
graph = nquads_parser.parse(io.open('a_file.nq', mode='rt'))
graph2 = nquads_parser.parse("<http://a.example/s> <http://a.example/p> <http://a.example/o> <http://a.example/g> .")
If .parse()
is called with a file-like object implementing readline
,
it will efficiently parse line by line rather than parsing the entire file.
pymantic.parsers.lark.turtle
¶
Parse RDF serialized as turtle files.
Usage:
from pymantic.parsers.lark import turtle_parser
graph = turtle_parser.parse(io.open('a_file.ttl', mode='rt'))
graph2 = turtle_parser.parse("""@prefix p: <http://a.example/s>.
p: <http://a.example/p> <http://a.example/o> .""")
Unlike pymantic.parsers.lark.ntriples
, this parser cannot efficiently
parse turtle line by line. If a file-like object is provided, the entire file
will be read into memory and parsed there.