Package: lightrdf
LightRDFA fast and lightweight Python RDF parser which wraps bindings to Rust'sRiousingPyO3.ContentsFeaturesInstallBasic UsageIterate over all triplesSearch triples with a triple patternSearch triples with a triple pattern (Regex)Load file objects / textsBenchmark (WIP)AlternativesTodoLicenseFeaturesSupports N-Triples, Turtle, and RDF/XMLHandles large-size RDF documentsProvides HDT-like interfacesInstallpip install lightrdfBasic UsageIterate over all triplesWithParser:importlightrdfparser=lightrdf.Parser()fortripleinparser.parse("./go.owl",base_iri=None):print(triple)WithRDFDocument:importlightrdfdoc=lightrdf.RDFDocument("./go.owl")# `None` matches arbitrary termfortripleindoc.search_triples(None,None,None):print(triple)Search triples with a triple patternimportlightrdfdoc=lightrdf.RDFDocument("./go.owl")fortripleindoc.search_triples("http://purl.obolibrary.org/obo/GO_0005840",None,None):print(triple)# Output:# ('<http://purl.obolibrary.org/obo/GO_0005840>', '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', '<http://www.w3.org/2002/07/owl#Class>')# ('<http://purl.obolibrary.org/obo/GO_0005840>', '<http://www.w3.org/2000/01/rdf-schema#subClassOf>', '<http://purl.obolibrary.org/obo/GO_0043232>')# ...# ('<http://purl.obolibrary.org/obo/GO_0005840>', '<http://www.geneontology.org/formats/oboInOwl#inSubset>', '<http://purl.obolibrary.org/obo/go#goslim_yeast>')# ('<http://purl.obolibrary.org/obo/GO_0005840>', '<http://www.w3.org/2000/01/rdf-schema#label>', '"ribosome"^^<http://www.w3.org/2001/XMLSchema#string>')Search triples with a triple pattern (Regex)importlightrdffromlightrdfimportRegexdoc=lightrdf.RDFDocument("./go.owl")fortripleindoc.search_triples(Regex("^<http://purl.obolibrary.org/obo/.*>$"),None,Regex(".*amino[\w]+?transferase")):print(triple)# Output:# ('<http://purl.obolibrary.org/obo/GO_0003961>', '<http://www.w3.org/2000/01/rdf-schema#label>', '"O-acetylhomoserine aminocarboxypropyltransferase activity"^^<http://www.w3.org/2001/XMLSchema#string>')# ('<http://purl.obolibrary.org/obo/GO_0004047>', '<http://www.geneontology.org/formats/oboInOwl#hasExactSynonym>', '"S-aminomethyldihydrolipoylprotein:(6S)-tetrahydrofolate aminomethyltransferase (ammonia-forming) activity"^^<http://www.w3.org/2001/XMLSchema#string>')# ...# ('<http://purl.obolibrary.org/obo/GO_0050447>', '<http://www.w3.org/2000/01/rdf-schema#label>', '"zeatin 9-aminocarboxyethyltransferase activity"^^<http://www.w3.org/2001/XMLSchema#string>')# ('<http://purl.obolibrary.org/obo/GO_0050514>', '<http://www.geneontology.org/formats/oboInOwl#hasExactSynonym>', '"spermidine:putrescine 4-aminobutyltransferase (propane-1,3-diamine-forming)"^^<http://www.w3.org/2001/XMLSchema#string>')Load file objects / textsLoad file objects withParser:importlightrdfparser=lightrdf.Parser()withopen("./go.owl","rb")asf:fortripleinparser.parse(f,format="owl",base_iri=None):print(triple)Load file objects withRDFDocument:importlightrdfwithopen("./go.owl","rb")asf:doc=lightrdf.RDFDocument(f,parser=lightrdf.xml.PatternParser)fortripleindoc.search_triples("http://purl.obolibrary.org/obo/GO_0005840",None,None):print(triple)Load texts:importioimportlightrdfdata="""<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> ._:subject1 <http://an.example/predicate1> "object1" ._:subject2 <http://an.example/predicate2> "object2" ."""doc=lightrdf.RDFDocument(io.BytesIO(data.encode()),parser=lightrdf.turtle.PatternParser)fortripleindoc.search_triples("http://one.example/subject1",None,None):print(triple)Benchmark (WIP)On MacBook Air (13-inch, 2017), 1.8 GHz Intel Core i5, 8 GB 1600 MHz DDR3https://gist.github.com/ozekik/b2ae3be0fcaa59670d4dd4759cdffbed$wget-qhttp://purl.obolibrary.org/obo/go.owl
$gtimepython3count_triples_rdflib_graph.py./go.owl# RDFLib 4.2.21436427235.29user2.30system3:59.56elapsed99%CPU(0avgtext+0avgdata1055816maxresident)k
0inputs+0outputs(283major+347896minor)pagefaults0swaps
$gtimepython3count_triples_lightrdf_rdfdocument.py./go.owl# LightRDF 0.1.114364277.90user0.22system0:08.27elapsed98%CPU(0avgtext+0avgdata163760maxresident)k
0inputs+0outputs(106major+41389minor)pagefaults0swaps
$gtimepython3count_triples_lightrdf_parser.py./go.owl# LightRDF 0.1.114364278.00user0.24system0:08.47elapsed97%CPU(0avgtext+0avgdata163748maxresident)k
0inputs+0outputs(106major+41388minor)pagefaults0swapshttps://gist.github.com/ozekik/636a8fb521401070e02e010ce591fa92$wget-qhttp://downloads.dbpedia.org/2016-10/dbpedia_2016-10.nt
$gtimepython3count_triples_rdflib_ntparser.pydbpedia_2016-10.nt# RDFLib 4.2.2310501.63user0.23system0:02.47elapsed75%CPU(0avgtext+0avgdata26568maxresident)k
0inputs+0outputs(1140major+6118minor)pagefaults0swaps
$gtimepython3count_triples_lightrdf_ntparser.pydbpedia_2016-10.nt# LightRDF 0.1.1310500.21user0.04system0:00.36elapsed71%CPU(0avgtext+0avgdata7628maxresident)k
0inputs+0outputs(534major+1925minor)pagefaults0swapsAlternativesRDFLib– (Pros) pure-Python, matured, feature-rich / (Cons) takes some time to load triplespyHDT– (Pros) extremely fast and efficient / (Cons) requires pre-conversion into HDTTodoPush to PyPIAdopt CIHandle Base IRIAdd basic testsSwitch to maturin-action from cibuildwheelSupport NQuads and TriGAdd docsAdd tests forw3c/rdf-testsResume on errorAllow opening fpSupport and test on RDF-starLicenseRioandPyO3are licensed under the Apache-2.0 license.Copyright 2020 Kentaro Ozeki

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.