Sending programs over the wire

Logic can be sent remotely to the server

In [1]:
from prologterms import TermGenerator, PrologRenderer, Program, Var, Term
from sparqlprog import SPARQLProg
from rdflib import Namespace
P = TermGenerator()
R = PrologRenderer()
In [2]:
dbont = Namespace("http://dbpedia.org/ontology/")
dbr = Namespace("http://dbpedia.org/resource/")
In [3]:
server = 'http://localhost:9083'

Creating a program

In [4]:
X = Var('X')
Y = Var('Y')
Z = Var('Z')
    
rules = [
    # in-band if bandMember OR formerBandMember
    P.in_band(X,Y) <= P.rdf(Y, dbont['bandMember'], X),
    P.in_band(X,Y) <= P.rdf(Y, dbont['formerBandMember'], X),
    
    # shared band members, at any point in time
    P.has_shared_band_member(X,Y,Z) <= (P.in_band(Z, X), P.in_band(Z,Y), Term('\=', X, Y))
]
In [5]:
S = SPARQLProg(server=server,
               rules=rules,
               endpoint='dbpedia')

setting up a query

In [7]:
query = P.has_shared_band_member(dbr['Deep_Purple'], X, Z)
#query = P.has_shared_band_member(Y, X, Z)
#query = P.in_band(X,Y)

running the querry

In [8]:
res = S.query(query)
In [9]:
for r in res:
    print(f"band: {r['X']} connecting member: {r['Z']}")
band: http://dbpedia.org/resource/Angelfire_(band) connecting member: http://dbpedia.org/resource/Steve_Morse
band: http://dbpedia.org/resource/Dixie_Dregs connecting member: http://dbpedia.org/resource/Steve_Morse
band: http://dbpedia.org/resource/Flying_Colors_(band) connecting member: http://dbpedia.org/resource/Steve_Morse
band: http://dbpedia.org/resource/Hollywood_Monsters_(band) connecting member: http://dbpedia.org/resource/Don_Airey
band: http://dbpedia.org/resource/Paice_Ashton_Lord connecting member: http://dbpedia.org/resource/Ian_Paice
band: http://dbpedia.org/resource/Episode_Six connecting member: http://dbpedia.org/resource/Ian_Gillan
band: http://dbpedia.org/resource/WhoCares connecting member: http://dbpedia.org/resource/Ian_Gillan
band: http://dbpedia.org/resource/Ian_Gillan_Band connecting member: http://dbpedia.org/resource/Ian_Gillan
band: http://dbpedia.org/resource/Gillan_(band) connecting member: http://dbpedia.org/resource/Ian_Gillan
band: http://dbpedia.org/resource/Episode_Six connecting member: http://dbpedia.org/resource/Roger_Glover
band: http://dbpedia.org/resource/Kansas_(band) connecting member: http://dbpedia.org/resource/Steve_Morse
band: http://dbpedia.org/resource/Living_Loud connecting member: http://dbpedia.org/resource/Steve_Morse
band: http://dbpedia.org/resource/Empire_(band) connecting member: http://dbpedia.org/resource/Don_Airey
band: http://dbpedia.org/resource/Quatermass_(band) connecting member: http://dbpedia.org/resource/Don_Airey
band: http://dbpedia.org/resource/Ten_(band) connecting member: http://dbpedia.org/resource/Don_Airey
band: http://dbpedia.org/resource/Anthem_(band) connecting member: http://dbpedia.org/resource/Don_Airey
band: http://dbpedia.org/resource/Earthshaker_(band) connecting member: http://dbpedia.org/resource/Don_Airey
band: http://dbpedia.org/resource/The_Company_of_Snakes connecting member: http://dbpedia.org/resource/Don_Airey
band: http://dbpedia.org/resource/Hughes/Thrall connecting member: http://dbpedia.org/resource/Glenn_Hughes
band: http://dbpedia.org/resource/Hughes_Turner_Project connecting member: http://dbpedia.org/resource/Glenn_Hughes
band: http://dbpedia.org/resource/Black_Country_Communion connecting member: http://dbpedia.org/resource/Glenn_Hughes
band: http://dbpedia.org/resource/Finders_Keepers_(band) connecting member: http://dbpedia.org/resource/Glenn_Hughes
band: http://dbpedia.org/resource/Mikhail_Men__Michael_Men_Project__1 connecting member: http://dbpedia.org/resource/Glenn_Hughes
band: http://dbpedia.org/resource/Whitesnake connecting member: http://dbpedia.org/resource/David_Coverdale
band: http://dbpedia.org/resource/Paice_Ashton_Lord connecting member: http://dbpedia.org/resource/Jon_Lord
band: http://dbpedia.org/resource/Over_the_Rainbow_(band) connecting member: http://dbpedia.org/resource/Joe_Lynn_Turner
band: http://dbpedia.org/resource/Hughes_Turner_Project connecting member: http://dbpedia.org/resource/Joe_Lynn_Turner
band: http://dbpedia.org/resource/Brazen_Abbot connecting member: http://dbpedia.org/resource/Joe_Lynn_Turner
band: http://dbpedia.org/resource/Mikhail_Men__Michael_Men_Project__1 connecting member: http://dbpedia.org/resource/Joe_Lynn_Turner
band: http://dbpedia.org/resource/Rainbow_(rock_band) connecting member: http://dbpedia.org/resource/Ritchie_Blackmore
band: http://dbpedia.org/resource/Blackmore's_Night connecting member: http://dbpedia.org/resource/Ritchie_Blackmore
band: http://dbpedia.org/resource/Trapeze_(band) connecting member: http://dbpedia.org/resource/Glenn_Hughes
band: http://dbpedia.org/resource/Brazen_Abbot connecting member: http://dbpedia.org/resource/Glenn_Hughes
band: http://dbpedia.org/resource/California_Breed connecting member: http://dbpedia.org/resource/Glenn_Hughes
band: http://dbpedia.org/resource/Kings_of_Chaos_(band) connecting member: http://dbpedia.org/resource/Glenn_Hughes
band: http://dbpedia.org/resource/The_Greg_Kihn_Band connecting member: http://dbpedia.org/resource/Joe_Satriani
band: http://dbpedia.org/resource/Coverdaleā€¢Page connecting member: http://dbpedia.org/resource/David_Coverdale
band: http://dbpedia.org/resource/WhoCares connecting member: http://dbpedia.org/resource/Jon_Lord
band: http://dbpedia.org/resource/The_Artwoods connecting member: http://dbpedia.org/resource/Jon_Lord
band: http://dbpedia.org/resource/Santa_Barbera_Machine_Head connecting member: http://dbpedia.org/resource/Jon_Lord
band: http://dbpedia.org/resource/Quatermass_(band) connecting member: http://dbpedia.org/resource/Nick_Simper
band: http://dbpedia.org/resource/Johnny_Kidd_&_the_Pirates connecting member: http://dbpedia.org/resource/Nick_Simper
band: http://dbpedia.org/resource/Warhorse_(British_band) connecting member: http://dbpedia.org/resource/Nick_Simper
band: http://dbpedia.org/resource/Zephyr_(band) connecting member: http://dbpedia.org/resource/Tommy_Bolin
band: http://dbpedia.org/resource/James_Gang connecting member: http://dbpedia.org/resource/Tommy_Bolin
band: http://dbpedia.org/resource/Fandango_(US_band) connecting member: http://dbpedia.org/resource/Joe_Lynn_Turner
band: http://dbpedia.org/resource/The_Outlaws_(band) connecting member: http://dbpedia.org/resource/Ritchie_Blackmore
band: http://dbpedia.org/resource/Captain_Beyond connecting member: http://dbpedia.org/resource/Rod_Evans
band: http://dbpedia.org/resource/Bogus_Deep_Purple connecting member: http://dbpedia.org/resource/Rod_Evans
In [ ]: