Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

I am trying to query my Ontology which I created on Protege by SPARQL (I am 2 weeks old Python user) and I didnt take any error or result either

This is What I wrote after importing rdflib and my owl data. I wrote 3 query part, and I couldnt take any answer from all. *

PREFIX : "<http://xmlns.com/foaf/0.1/>"
    g = Graph()
    g.bind("foaf", FOAF)

First one:

 qres = g.query(
            """SELECT DISTINCT ?Name ?Microsoft
               WHERE {
                  ?a foaf:subclassof ?Microsoft .
                  ?a foaf:Name ?Name .
                  ?b foaf:Microsoft ?Microsoft .
               }""")
        for row in qres:
            print("%s subclassof %s" % row)
       
     from rdflib.namespace import FOAF

Second One:

 qres = g.query('SELECT * WHERE { ?p a foaf:Engineers}', initNs={ 'foaf': FOAF })
    for row in qres:
        print("%s" % row)
 Third One:


qres = g.query(
        """SELECT DISTINCT ?aName ?bOracle
       WHERE {
          ?a foaf:individual_of ?b .
          ?a foaf:Name ?aName.
          ?b foaf:Oracle ?bOracle .
       }""")
for row in qres:
    print("%s individual_of %s" % row)
question from:https://stackoverflow.com/questions/65874749/i-am-trying-to-query-my-ontology-which-i-created-on-protege-by-sparql-i-am-2-we

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...