Skip to content

(Python) Invoking rudof from Python

Jose Emilio Labra Gayo edited this page Nov 14, 2024 · 3 revisions

If you prefer, you can run this example Google colab: https://tinyurl.com/rudof-demo

Installation instructions

pip install pyrudof

Usage instructions

Loading data

from pyrudof import Rudof, RudofConfig
rudof = Rudof(RudofConfig())
with open('path/to/data.file') as fd_data:
    rudof.read_data_str(f_data.read())
    with open('path/to/shapes.file') as fd_shapes:
        rudof.read_data_str(f_shacl.read())

Querying using SPARQL

# assuming data is loaded
results = rudof.run_query_str("""
    SELECT * WHERE {
      ?x ?y ?z .
    }
""")
for result in iter(results):
    print(result.show())

Sample output:

?x -> <iri>
?y -> <iri>
?z -> <iri>

Validation

# assuming data and shape files/strings are loaded
result = rudof.validate_shacl()
print(result.conforms()) # returns boolean
print(result.show()) # returns string of issues separated by newline

Sample output:

False
False
18 errors found
Focus node <iri>, Component: sh:minCount, severity: sh:Violation
Focus node prefix:term, Component: sh:minCount, severity: sh:Violation
Clone this wiki locally