virtuoso-t +foreground +configfile path/to/virtuoso.ini python from rdflib import Graph, Namespace, Literal from rdflib.namespace import RDF g = Graph() ex = Namespace("http://example.com/") g.add((ex.subject1, RDF.type, ex.object1)) g.add((ex.subject2, RDF.type, ex.object2)) g.add((ex.subject3, RDF.type, ex.object3)) g.serialize(destination='triples.rdf', format='xml') g.load('triples.rdf', format='xml') query = """ PREFIX ex: <http://example.com/> SELECT ?subject ?object WHERE { ?subject rdf:type ex:object1 . ?subject rdf:type ex:object2 . ?subject rdf:type ex:object3 . ?subject ?predicate ?object . } """ results = g.query(query) for row in results: print(f"{row['subject']} - {row['object']}")


上一篇:
下一篇:
切换中文