Question

Good day! I apply rdflib for python. I have a question. How can I put variable into SPARQL's query ? Instead of 'OSPF' in course:OSPF!

qres = g.query(
    """SELECT ?x ?z ?y
        WHERE {
           course:OSPF course:termName ?x.
           course:OSPF ?s ?t.
           ?s ?d ?z.
           ?t course:termName ?y.
           FILTER (regex(?z,"[^a-z]","i") && isLiteral(?z) )
        }"""
        ,initNs=dict(course=Namespace.....

@msalvadores I want enter my Variable by console. --->python parse.py OSPF A value of variable(OSPF) may be another one. How can I initialize it into query(WHERE)? I have resolved my question by interpolation of variable several days ago. Like this:

    qtest = "OSPF","OSPF"
    q =( """SELECT ?x ?z ?y\
            WHERE {\
               course:%s course:termName ?x.\
               course:%s ?s ?t.\
               ?s ?d ?z.\
               ?t course:termName ?y.\
               FILTER (regex(?z,'[^a-z0-9]','i') && isLiteral(?z) )\
            }ORDER BY ASC(?s)\
            """)% qtest
   qres = g.query(q, initNs=dict(course=Namespace

But I suppose it could be done another way. Because on my opinion the solution is not quite right presented by me.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top