Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Pierre-Antoine Champin

    Hi, you might be interested in a small tool I just started hacking. It allows you to explore an RDF store in your filesystem, using FUSE.


    For the moment, it is read-only, but my plan is to support mutations as well (through creating, modifying and deleting files).

    Benjamin Riesenberg
    Hi all:
    Question from a relative newcomer to Python, and rdflib.
    I'm planning to write a XSLT script to convert RDF/XML data into an HTML document.
    As part of this workflow I'm planning on using Python + rdflib to retrieve some triples and serialize as RDF/XML. This will be run on a regular basis going forward, so I thought I should ask:
    Is the output from rdflib's RDF/XML serializer stable?
    That is to say, can it be reasonably expected to stay mostly the same going forward? Or is this functionality still under development and likely to change?
    Thank you!
    Carlos Vega
    Hello, I have an issue with blank nodes that I've posted on Stack Overflow

    is there any way to avoid the creation of that extra rdf:description tag and provide parseType="Resource" to dcterms:modified?

    import rdflib
    from rdflib.namespace import Namespace, DCTERMS, RDF, XSD
    from datetime import datetime
    graph = rdflib.Graph()
    graph.bind('dcterms', DCTERMS)
    graph.bind('xsd', XSD)
    description = rdflib.URIRef(f'#TNFalpha_944')
    w3cdtf_node = rdflib.BNode()
    date = rdflib.Literal(datetime.now(), datatype=XSD.dateTime)
    graph.add((description, DCTERMS.modified, w3cdtf_node))
    graph.add((w3cdtf_node, DCTERMS.W3CDTF, date))
    ann = graph.serialize(format="pretty-xml").decode('utf-8')

    this is the code I used to generate that output.

    Carlos Vega
    Hi, all, Will RDFLib support RDF*( also RDF star)?
    Iwan Aucamp
    @joylix if someone adds support for it
    I am sure there is no opposition in principle
    but resources are finite
    Daniele Nicolodi

    Hello, to make a long story short, I am have some data for which I think could be nicely modeled as an RDF graph and for which SPARQL could be an effective query language. I don't know much about RDF or SPARQL or RDFlib, thus I started with a tiny example to familiarize myself with the concepts:

    import rdflib
    from rdflib import FOAF
    graph = rdflib.Graph()
    for n in range(0, 1000):
        node = rdflib.term.BNode()
        graph.add((node, FOAF.age, rdflib.term.Literal(n)))
        graph.add((node, FOAF.name, rdflib.term.Literal(f'Name{n:}')))
    rows = graph.query("""SELECT
                            ?name ?age
                          WHERE {                 
                            ?x :age ?age . FILTER(?age > 998) 
                            ?x :name ?name . }
                          ORDER BY ?age""",
                       initNs={'': FOAF})
    for name, age, in rows:
        print(name, age)

    This simple test runs in about two seconds on my laptop. Unfortunately this kind of performance would not be sufficient to work with my real data. Am I doing something wrong, or is the processing in RDFlib the bottleneck? Is there a way to speed this up?

    Thank you!

    Thomas Tanon
    Hi Daniele! Rdflib is written in plain python. It is designed to be feature complete, easy to use and extend but is not much optimized for performance.
    Anyway, your code takes 0.95s on the first run in my laptop and only 0.2s if I restart it while keeping the "imports" loaded using a REPL. If I drop the printing and replace range(0,1000) by range(0, 100000) it takes 18s.
    Tory Clasen
    @dnicolodi , without profiling the code you I can make a guess, if you create you build your list of triples as an iterator such as a list-comprehension, you can do a bulk insert into the graph using addN: https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.html#rdflib.graph.Graph.addN
    Iwan Aucamp
    hi, not sure if this is the best forum to ask, are you open to PR for adding linting ?
    Ashley Sommer
    Hi @aucampia
    What kind of linting are you suggesting? We already require PEP8 compliant pull-requests, and we also strongly suggest all contributors use black on their code before creating a PR (though we don't enforce that).
    We've had the discussion about linting many times in the past. The crux of the matter is we want to keep the barrier to contribution as low as possible for users of RDFLib. And the kinds of people who use RDFLib are not necessarily software engineers. We want researchers, academics, scientists, semantic extereprts, ontology experts, etc to be able to contribute to RDFLib. I don't like to stereotype or put people into categories, but in my experience a lot of experts do not want to deal with jumping through hoops to make their code compliant.
    Iwan Aucamp
    @ashleysommer thanks for the reply, and valid points. I was thinking PEP8, specifically autopep8, I guess I read right past it, but when I ran autopep8 on the codebase there were many warnings, so I guess I just assumed it was not being used, but I guess it makes sense to only apply it to pull requests.
    Iwan Aucamp
    so I am looking at this, to add tests for transitive_objects and transitive_subjects: https://github.com/RDFLib/rdflib/blob/master/examples/transitive.py
    nvm, I get it I think
    Iwan Aucamp
    are there some standard graphs that you run tests on?
    Iwan Aucamp
    I made a PR here: RDFLib/rdflib#1307 - suggestions for tests welcome
    Iwan Aucamp
    This issue can be closed: RDFLib/rdflib#1279
    Any suggestions on tests here would be appreciated: RDFLib/rdflib#1291
    Iwan Aucamp
    Are there any plans to make further 5.x releases?
    And if not can I look at it?