Design of Experiment with RSPLib


In [4]:
import rsplib as rsp
import json

In [5]:
e = rsp.Experiment()

def jdefault(o):
        return o.__dict__()
    
def pretty_print(exp):
    print(json.dumps(exp, default=jdefault, indent=4, sort_keys=True))

Engine Selection


In [6]:
e.add_engine('http://csparql.westeurope.cloudapp.azure.com', 8182, rsp.Dialects.CSPARQL)
pretty_print(e)


{
    "engine": {
        "dialect": "CSPARQL",
        "host": "http://csparql.westeurope.cloudapp.azure.com",
        "port": 8182
    },
    "graphs": [],
    "metadata": {},
    "queries": [],
    "streams": []
}

Query Selection

Query 1


In [7]:
q = e.add_query("Q1", "query", rsp.Dialects.CSPARQL)
q.set_select_clause("?obId1 ?obId2 ?v1 ?v2")
q.set_where_clause("{?p1   a <http://www.insight-centre.org/citytraffic#CongestionLevel>.?p2   a <http://www.insight-centre.org/citytraffic#CongestionLevel>. {?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p1.?obId1 <http://purl.oclc.org/NET/sao/hasValue> ?v1.?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData182955>.}{?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p2.?obId2 <http://purl.oclc.org/NET/sao/hasValue> ?v2.?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData158505>.}}")

pretty_print(q)


{
    "body": "SELECT ?obId1 ?obId2 ?v1 ?v2\nWHERE {?p1   a <http://www.insight-centre.org/citytraffic#CongestionLevel>.?p2   a <http://www.insight-centre.org/citytraffic#CongestionLevel>. {?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p1.?obId1 <http://purl.oclc.org/NET/sao/hasValue> ?v1.?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData182955>.}{?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p2.?obId2 <http://purl.oclc.org/NET/sao/hasValue> ?v2.?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData158505>.}}",
    "dialect": "CSPARQL",
    "name": "Q1",
    "type": "query"
}

In [ ]:

Streams Selection


In [8]:
e.add_windowed_stream("Q1","AarhusTrafficData158505", "http://triplewave1.westeurope.cloudapp.azure.com:4000/sgraph", '3s','1s' )
print ("Stream Added")


Stream Added

In [9]:
#pretty_print(e)

Graphs Selection


In [10]:
e.add_graph("Q1", "SensorRepository", "https://rsplab.blob.core.windows.net/static/SensorRepository.rdf", serialization="RDF/XML", default='true')

print("Graphs Added")


Graphs Added

In [11]:
#pretty_print(e)

Query 2


In [12]:
q = e.add_query("Q2", "query", rsp.Dialects.CSPARQL)
q.set_select_clause("?obId1 ?obId2 ?v1 ?v2")
q.set_where_clause("{?p1   a <http://www.insight-centre.org/citytraffic#CongestionLevel>.?p2   a <http://www.insight-centre.org/citytraffic#CongestionLevel>. {?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p1.?obId1 <http://purl.oclc.org/NET/sao/hasValue> ?v1.?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData182955>.}{?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p2.?obId2 <http://purl.oclc.org/NET/sao/hasValue> ?v2.?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData158505>.}}")

e.add_windowed_stream("Q2","AarhusParkingDataKALKVAERKSVEJ", "http://triplewave1.westeurope.cloudapp.azure.com:4000/sgraph", '3s','3s' )

pretty_print(q)


{
    "body": "SELECT ?obId1 ?obId2 ?v1 ?v2 FROM STREAM <AarhusParkingDataKALKVAERKSVEJ> [RANGE 3s STEP 3s]\n\nWHERE {?p1   a <http://www.insight-centre.org/citytraffic#CongestionLevel>.?p2   a <http://www.insight-centre.org/citytraffic#CongestionLevel>. {?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p1.?obId1 <http://purl.oclc.org/NET/sao/hasValue> ?v1.?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData182955>.}{?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p2.?obId2 <http://purl.oclc.org/NET/sao/hasValue> ?v2.?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData158505>.}}",
    "dialect": "CSPARQL",
    "name": "Q2",
    "type": "query"
}

Query 3


In [13]:
q = e.add_query("Q3", "query", rsp.Dialects.CSPARQL)
q.set_select_clause("?obId1 ?obId2 ?v1 ?v2")
q.set_where_clause("{?p1   a <http://www.insight-centre.org/citytraffic#CongestionLevel>.?p2   a <http://www.insight-centre.org/citytraffic#CongestionLevel>. {?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p1.?obId1 <http://purl.oclc.org/NET/sao/hasValue> ?v1.?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData182955>.}{?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p2.?obId2 <http://purl.oclc.org/NET/sao/hasValue> ?v2.?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData158505>.}}")

e.add_windowed_stream("Q3","AarhusTrafficData158505", "http://triplewave1.westeurope.cloudapp.azure.com:4000/sgraph", '3s','1s' )

pretty_print(q)


{
    "body": "SELECT ?obId1 ?obId2 ?v1 ?v2 FROM STREAM <AarhusTrafficData158505> [RANGE 3s STEP 1s]\n\nWHERE {?p1   a <http://www.insight-centre.org/citytraffic#CongestionLevel>.?p2   a <http://www.insight-centre.org/citytraffic#CongestionLevel>. {?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p1.?obId1 <http://purl.oclc.org/NET/sao/hasValue> ?v1.?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData182955>.}{?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p2.?obId2 <http://purl.oclc.org/NET/sao/hasValue> ?v2.?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData158505>.}}",
    "dialect": "CSPARQL",
    "name": "Q3",
    "type": "query"
}

In [14]:
experiment_execution = rsp.execute(e)


{"name":"csparql","host":"csparql/","runUUID":"63509a9c-248a-11e7-8ce9-000d3a27a904","port":8182,"empty_results":false,"inference":false,"timestam_function":false,"backloop":true}
Registering static sources: SensorRepository
"Dataset SensorRepository succesfully registered with IRI https://rsplab.blob.core.windows.net/static/SensorRepository.rdf"
Registering stream: AarhusTrafficData158505
"AarhusTrafficData158505 already exists"
Registering stream: AarhusParkingDataKALKVAERKSVEJ
"AarhusParkingDataKALKVAERKSVEJ already exists"
Registering stream: AarhusTrafficData158505
"AarhusTrafficData158505 already exists"
Registering query Q1 
"Query with same name already exists"
Query with same name already exists
Registering observers for Q1
"http://csparql.westeurope.cloudapp.azure.com:8182/queries/Q1/observers/default"
{ "@context": {"sld":"http://streamreasoning.org/ontologies/SLD4TripleWave#","generatedAt": {"@id":"http://www.w3.org/ns/prov#generatedAtTime","@type":"http://www.w3.org/2001/XMLSchema#dateTime"}},"@id": "default","@type": "sld:sGraph","sld:streamLocation": "ws://csparql.westeurope.cloudapp.azure.com:9101/Q1/results"}
[{"id":"Q3","type":"QUERY","status":"RUNNING"},{"id":"Q2","type":"QUERY","status":"RUNNING"},{"id":"Q1","type":"QUERY","status":"RUNNING"}]
Registering query Q2 
"Query with same name already exists"
Query with same name already exists
Registering observers for Q2
"http://csparql.westeurope.cloudapp.azure.com:8182/queries/Q2/observers/default"
{ "@context": {"sld":"http://streamreasoning.org/ontologies/SLD4TripleWave#","generatedAt": {"@id":"http://www.w3.org/ns/prov#generatedAtTime","@type":"http://www.w3.org/2001/XMLSchema#dateTime"}},"@id": "default","@type": "sld:sGraph","sld:streamLocation": "ws://csparql.westeurope.cloudapp.azure.com:9101/Q2/results"}
[{"id":"Q3","type":"QUERY","status":"RUNNING"},{"id":"Q2","type":"QUERY","status":"RUNNING"},{"id":"Q1","type":"QUERY","status":"RUNNING"}]
Registering query Q3 
"Query with same name already exists"
Query with same name already exists
Registering observers for Q3
"http://csparql.westeurope.cloudapp.azure.com:8182/queries/Q3/observers/default"
{ "@context": {"sld":"http://streamreasoning.org/ontologies/SLD4TripleWave#","generatedAt": {"@id":"http://www.w3.org/ns/prov#generatedAtTime","@type":"http://www.w3.org/2001/XMLSchema#dateTime"}},"@id": "default","@type": "sld:sGraph","sld:streamLocation": "ws://csparql.westeurope.cloudapp.azure.com:9101/Q3/results"}
[{"id":"Q3","type":"QUERY","status":"RUNNING"},{"id":"Q2","type":"QUERY","status":"RUNNING"},{"id":"Q1","type":"QUERY","status":"RUNNING"}]

In [16]:
pretty_print(experiment_execution)


{
    "Execution": {
        "D": [
            "Dataset SensorRepository succesfully registered with IRI https://rsplab.blob.core.windows.net/static/SensorRepository.rdf"
        ],
        "E": {
            "backloop": true,
            "empty_results": false,
            "host": "csparql/",
            "inference": false,
            "name": "csparql",
            "port": 8182,
            "runUUID": "63509a9c-248a-11e7-8ce9-000d3a27a904",
            "timestam_function": false
        },
        "K": null,
        "O": [
            {
                "Q1": {
                    "@context": {
                        "generatedAt": {
                            "@id": "http://www.w3.org/ns/prov#generatedAtTime",
                            "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
                        },
                        "sld": "http://streamreasoning.org/ontologies/SLD4TripleWave#"
                    },
                    "@id": "default",
                    "@type": "sld:sGraph",
                    "sld:streamLocation": "ws://csparql.westeurope.cloudapp.azure.com:9101/Q1/results"
                }
            },
            {
                "Q2": {
                    "@context": {
                        "generatedAt": {
                            "@id": "http://www.w3.org/ns/prov#generatedAtTime",
                            "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
                        },
                        "sld": "http://streamreasoning.org/ontologies/SLD4TripleWave#"
                    },
                    "@id": "default",
                    "@type": "sld:sGraph",
                    "sld:streamLocation": "ws://csparql.westeurope.cloudapp.azure.com:9101/Q2/results"
                }
            },
            {
                "Q3": {
                    "@context": {
                        "generatedAt": {
                            "@id": "http://www.w3.org/ns/prov#generatedAtTime",
                            "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
                        },
                        "sld": "http://streamreasoning.org/ontologies/SLD4TripleWave#"
                    },
                    "@id": "default",
                    "@type": "sld:sGraph",
                    "sld:streamLocation": "ws://csparql.westeurope.cloudapp.azure.com:9101/Q3/results"
                }
            }
        ],
        "Q": [
            {
                "id": "Q3",
                "status": "RUNNING",
                "type": "QUERY"
            },
            {
                "id": "Q2",
                "status": "RUNNING",
                "type": "QUERY"
            },
            {
                "id": "Q1",
                "status": "RUNNING",
                "type": "QUERY"
            },
            {
                "id": "Q3",
                "status": "RUNNING",
                "type": "QUERY"
            },
            {
                "id": "Q2",
                "status": "RUNNING",
                "type": "QUERY"
            },
            {
                "id": "Q1",
                "status": "RUNNING",
                "type": "QUERY"
            },
            {
                "id": "Q3",
                "status": "RUNNING",
                "type": "QUERY"
            },
            {
                "id": "Q2",
                "status": "RUNNING",
                "type": "QUERY"
            },
            {
                "id": "Q1",
                "status": "RUNNING",
                "type": "QUERY"
            }
        ],
        "R": null,
        "S": [
            "AarhusTrafficData158505 already exists",
            "AarhusParkingDataKALKVAERKSVEJ already exists",
            "AarhusTrafficData158505 already exists"
        ]
    },
    "Experiment": {
        "engine": {
            "dialect": "CSPARQL",
            "host": "http://csparql.westeurope.cloudapp.azure.com",
            "port": 8182
        },
        "graphs": [
            {
                "default": "true",
                "location": "https://rsplab.blob.core.windows.net/static/SensorRepository.rdf",
                "name": "SensorRepository",
                "serialization": "RDF/XML"
            }
        ],
        "metadata": {},
        "queries": [
            {
                "body": "SELECT ?obId1 ?obId2 ?v1 ?v2 FROM STREAM <AarhusTrafficData158505> [RANGE 3s STEP 1s]\nFROM <https://rsplab.blob.core.windows.net/static/SensorRepository.rdf>\n\nWHERE {?p1   a <http://www.insight-centre.org/citytraffic#CongestionLevel>.?p2   a <http://www.insight-centre.org/citytraffic#CongestionLevel>. {?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p1.?obId1 <http://purl.oclc.org/NET/sao/hasValue> ?v1.?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData182955>.}{?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p2.?obId2 <http://purl.oclc.org/NET/sao/hasValue> ?v2.?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData158505>.}}",
                "dialect": "CSPARQL",
                "name": "Q1",
                "type": "query"
            },
            {
                "body": "SELECT ?obId1 ?obId2 ?v1 ?v2 FROM STREAM <AarhusParkingDataKALKVAERKSVEJ> [RANGE 3s STEP 3s]\n\nWHERE {?p1   a <http://www.insight-centre.org/citytraffic#CongestionLevel>.?p2   a <http://www.insight-centre.org/citytraffic#CongestionLevel>. {?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p1.?obId1 <http://purl.oclc.org/NET/sao/hasValue> ?v1.?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData182955>.}{?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p2.?obId2 <http://purl.oclc.org/NET/sao/hasValue> ?v2.?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData158505>.}}",
                "dialect": "CSPARQL",
                "name": "Q2",
                "type": "query"
            },
            {
                "body": "SELECT ?obId1 ?obId2 ?v1 ?v2 FROM STREAM <AarhusTrafficData158505> [RANGE 3s STEP 1s]\n\nWHERE {?p1   a <http://www.insight-centre.org/citytraffic#CongestionLevel>.?p2   a <http://www.insight-centre.org/citytraffic#CongestionLevel>. {?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p1.?obId1 <http://purl.oclc.org/NET/sao/hasValue> ?v1.?obId1 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData182955>.}{?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedProperty> ?p2.?obId2 <http://purl.oclc.org/NET/sao/hasValue> ?v2.?obId2 <http://purl.oclc.org/NET/ssnx/ssn#observedBy> <http://www.insight-centre.org/dataset/SampleEventService#AarhusTrafficData158505>.}}",
                "dialect": "CSPARQL",
                "name": "Q3",
                "type": "query"
            }
        ],
        "streams": [
            {
                "location": "http://triplewave1.westeurope.cloudapp.azure.com:4000/sgraph",
                "name": "AarhusTrafficData158505",
                "scale_factor": 1,
                "window": {
                    "range": "3s",
                    "step": "1s"
                }
            },
            {
                "location": "http://triplewave1.westeurope.cloudapp.azure.com:4000/sgraph",
                "name": "AarhusParkingDataKALKVAERKSVEJ",
                "scale_factor": 1,
                "window": {
                    "range": "3s",
                    "step": "3s"
                }
            },
            {
                "location": "http://triplewave1.westeurope.cloudapp.azure.com:4000/sgraph",
                "name": "AarhusTrafficData158505",
                "scale_factor": 1,
                "window": {
                    "range": "3s",
                    "step": "1s"
                }
            }
        ]
    }
}

In [ ]:
engine = rsp.RSPClient('http://csparql.westeurope.cloudapp.azure.com', 8182);

In [ ]:
engine.queries()

In [ ]: