Пример #1
0
def get_all_obs():
	query= "SELECT distinct ?a ?c where {\
		 ?a <http://www.w3.org/1999/02/22-rdf-syntax-ns%23type> <http://purl.oclc.org/NET/ssnx/ssn%23Sensor> . \
		 ?b <http://purl.oclc.org/NET/ssnx/ssn%23observedBy> ?a . \
		 ?b <http://purl.oclc.org/NET/ssnx/ssn%23observedProperty> ?c . }"

	url = ENDPOINT_URL + query + "&output=json"

	print "Resolving URL..."
	json = simplejson.load(urllib.urlopen(url))
	print "Done!"
	#f = open("allprop.n3", 'a')
	store = IOMemory()
	gpr = Graph(store=store)

	#Add data to the graph


	for st in json['results']['bindings']:
		#f.write('<' + st['a']['value'] + '> <http://purl.oclc.org/NET/ssnx/ssn#observes> "' + st['c']['value'] + '" . \n')
		gpr.add((st['a']['value'], 'http://purl.oclc.org/NET/ssnx/ssn#observes', st['c']['value']))
		suprint st['a']['value']

	print "Inserting graph in SPARQL endpoint..."
	insertGraph(g=gpr, sparql=VIRTUOSO_URL, resourceuri=RESOURCE_URI)
	print "Done!"
	print "Finish!"
Пример #2
0
def properties_rdf_generator():
    for prop in properties:
        observedprop, obsunit, typeofuri, xsdclass, uriprefix = prop.values(
        )[0]

        if observedprop:
            #.../station/ZORRO2/NO2/15022011/10
            uri = RESOURCE_URI + 'prop/' + uriprefix

            #Initialization of graph
            ssn = Namespace("http://purl.oclc.org/NET/ssnx/ssn#")
            dc = Namespace("http://purl.org/dc/elements/1.1/")
            owl = Namespace("http://www.w3.org/2002/07/owl#")

            store = IOMemory()

            g = ConjunctiveGraph(store=store)
            g.bind("ssn", ssn)
            g.bind("dc", dc)
            g.bind("owl", owl)

            cpr = URIRef(uri)
            gpr = Graph(store=store, identifier=cpr)

            #Add data to the graph
            gpr.add((cpr, dc['description'], prop.keys()[0]))
            if typeofuri == 'Class':
                gpr.add((cpr, RDF.type, URIRef(observedprop)))
            else:
                gpr.add((cpr, owl["sameAs"], URIRef(observedprop)))

            gpr.add((cpr, RDF.type, ssn['Property']))

            #print g.serialize(format="pretty-xml")
            insertGraph(g=gpr, sparql=VIRTUOSO_URL, resourceuri=RESOURCE_URI)
def properties_rdf_generator():
	for prop in properties:
		observedprop, obsunit, typeofuri, xsdclass, uriprefix = prop.values()[0]

		if observedprop:
			#.../station/ZORRO2/NO2/15022011/10
			uri = RESOURCE_URI + 'prop/' + uriprefix
			
			#Initialization of graph
			ssn = Namespace("http://purl.oclc.org/NET/ssnx/ssn#")
			dc = Namespace("http://purl.org/dc/elements/1.1/")
			owl = Namespace("http://www.w3.org/2002/07/owl#")

			store = IOMemory()
			
			g = ConjunctiveGraph(store=store)
			g.bind("ssn", ssn)
			g.bind("dc", dc)
			g.bind("owl", owl)
			
			cpr = URIRef(uri)
			gpr = Graph(store=store, identifier=cpr)
			
			#Add data to the graph
			gpr.add((cpr, dc['description'], prop.keys()[0]))
			if typeofuri == 'Class':
				gpr.add((cpr, RDF.type, URIRef(observedprop)))
			else:
				gpr.add((cpr, owl["sameAs"], URIRef(observedprop)))

			gpr.add((cpr, RDF.type, ssn['Property']))

			#print g.serialize(format="pretty-xml")
			insertGraph(g=gpr, sparql=VIRTUOSO_URL, resourceuri=RESOURCE_URI)
Пример #4
0
def updateObservationProps(stationcod, typeslist):
    for obstype in typeslist:
        uri = RESOURCE_URI + 'station/' + stationcod

        #Initialization of the graph
        ssn = Namespace("http://purl.oclc.org/NET/ssnx/ssn#")

        store = IOMemory()

        g = ConjunctiveGraph(store=store)
        g.bind("ssn", ssn)

        cpr = URIRef(uri)
        gpr = Graph(store=store, identifier=cpr)

        #Add data to the graph
        gpr.add((cpr, RDF.type, ssn['Sensor']))
        gpr.add((cpr, ssn['observes'], RESOURCE_URI + 'prop/' + obstype))

        #Update RDF
        print uri + ' | ' + obstype
        insertGraph(g=gpr, sparql=VIRTUOSO_URL, resourceuri=RESOURCE_URI)
Пример #5
0
def updateObservationProps(stationcod, typeslist):
    for obstype in typeslist:
        uri = RESOURCE_URI + "station/" + stationcod

        # Initialization of the graph
        ssn = Namespace("http://purl.oclc.org/NET/ssnx/ssn#")

        store = IOMemory()

        g = ConjunctiveGraph(store=store)
        g.bind("ssn", ssn)

        cpr = URIRef(uri)
        gpr = Graph(store=store, identifier=cpr)

        # Add data to the graph
        gpr.add((cpr, RDF.type, ssn["Sensor"]))
        gpr.add((cpr, ssn["observes"], RESOURCE_URI + "prop/" + obstype))

        # Update RDF
        print uri + " | " + obstype
        insertGraph(g=gpr, sparql=VIRTUOSO_URL, resourceuri=RESOURCE_URI)
Пример #6
0
def generateMeditionRDF(medition, typeofobs, typeofuri, obsunit, stationcod,
                        dateday, uriprefix):
    '''  
		<?xml version="1.0"?>
			<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
			  xmlns:ssn="http://purl.oclc.org/NET/ssnx/ssn#"
			  xmlns:dc="http://purl.org/dc/elements/1.1/"
			  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
			  xmlns:obs="http://www.bidei.com/resource/station/ZORRO2/1510211/02/N02#"
			  xmlns:dul="http://www.loa.istc.cnr.it/ontologies/DUL.owl#"
			  xmlns:owl="http://www.w3.org/2002/07/owl#"
			>

			  <ssn:Observation rdf:about="http://www.bidei.com/resource/station/ZORRO2/1510211/02/N02">
				<ssn:observedProperty rdf:resource="obs:property"/>
				<ssn:observationResult rdf:resource="obs:sensoroutput"/>
				<ssn:observedBy rdf:resource="http://www.bidei.com/resource/station/ZORRO2"/>
				<dc:date>1997-07-16T19:20+01:00</dc:date>
			  </ssn:Observation>

			  <ssn:Property rdf:about="obs:property>
				<owl:sameAs rdf:resource=" URI  a NASA Instance " />
			      OR
			    <rdf:type rdf:resource=" URI a NASA Class " />
			  </ssn:Property>
			  
			  <ssn:SensorOutput rdf:about="obs:sensoroutput">
				<ssn:hasValue rdf:resource="obs:outputvalue"/>
			  </ssn:SensorOutput>
			  
			  <ssn:ObservationValue rdf:about="obs:outputvalue">
		      	<dul:isClassifiedBy rdf:resource=" URI a Celsius, Farenheit, Microgramo/metro..."/>
				<ssn:hasQuantityValue rdf:datatype="xsd:float">0.98</ssn:hasQuantityValue>
			  </ssn:ObservationValue>
		</rdf:RDF>
	'''

    #.../station/ZORRO2/NO2/15022011/10
    uri = RESOURCE_URI + 'station/' + stationcod + "/" + uriprefix + dateday.strftime(
        '/%d%m%Y/%H')

    #Initialization of graph
    ssn = Namespace("http://purl.oclc.org/NET/ssnx/ssn#")
    dc = Namespace("http://purl.org/dc/elements/1.1/")
    xsd = Namespace("http://www.w3.org/2001/XMLSchema")
    dul = Namespace("http://www.loa.istc.cnr.it/ontologies/DUL.owl#")
    owl = Namespace("http://www.w3.org/2002/07/owl#")
    obs = Namespace(uri + "#")

    store = IOMemory()

    g = ConjunctiveGraph(store=store)
    g.bind("ssn", ssn)
    g.bind("dc", dc)
    g.bind("xsd", xsd)
    g.bind("dul", dul)
    g.bind("owl", owl)
    g.bind("obs", obs)

    cpr = URIRef(uri)
    gpr = Graph(store=store, identifier=cpr)

    #Add data to the graph
    gpr.add((cpr, RDF.type, ssn['Observation']))

    gpr.add((cpr, ssn['observationResult'], obs["sensoroutput"]))

    gpr.add((cpr, ssn['observedProperty'],
             URIRef(RESOURCE_URI + 'prop/' + uriprefix)))

    gpr.add((cpr, ssn['observedBy'],
             URIRef(RESOURCE_URI + 'station/' + stationcod)))

    gpr.add((cpr, dc['date'], Literal(dateday.isoformat())))

    #SUBGRAPH1 (sensoroutput)
    cpr1 = obs["sensoroutput"]
    gpr.add((cpr1, RDF.type, ssn['SensorOutput']))
    gpr.add((cpr1, ssn['hasValue'], obs["outputvalue"]))

    #SUBGRAPH2 (outputvalue)
    cpr2 = obs["outputvalue"]
    gpr.add((cpr2, RDF.type, ssn['ObservationValue']))
    gpr.add((cpr2, dul['isClassifiedBy'], URIRef(obsunit)))
    gpr.add((cpr2, ssn['hasQuantityValue'], Literal(medition)))

    #Create RDF file
    if OBS_PATH:
        print gpr.serialize(format='pretty-xml')
        filename = "Med_" + dateday.strftime('%d_%m_%Y') + '.nt'
        f = open(OBS_PATH + filename, 'a')
        f.write(gpr.serialize(format='nt'))  #'pretty-xml'))
        f.close()
    else:
        print "Inserting " + uri + "..."
        insertGraph(g=gpr, sparql=VIRTUOSO_URL, resourceuri=RESOURCE_URI)
        print "OK"
Пример #7
0
def generateMeditionRDF(medition, typeofobs, typeofuri, obsunit, stationcod, dateday, uriprefix):
    """  
		<?xml version="1.0"?>
			<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
			  xmlns:ssn="http://purl.oclc.org/NET/ssnx/ssn#"
			  xmlns:dc="http://purl.org/dc/elements/1.1/"
			  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
			  xmlns:obs="http://www.bidei.com/resource/station/ZORRO2/1510211/02/N02#"
			  xmlns:dul="http://www.loa.istc.cnr.it/ontologies/DUL.owl#"
			  xmlns:owl="http://www.w3.org/2002/07/owl#"
			>

			  <ssn:Observation rdf:about="http://www.bidei.com/resource/station/ZORRO2/1510211/02/N02">
				<ssn:observedProperty rdf:resource="obs:property"/>
				<ssn:observationResult rdf:resource="obs:sensoroutput"/>
				<ssn:observedBy rdf:resource="http://www.bidei.com/resource/station/ZORRO2"/>
				<dc:date>1997-07-16T19:20+01:00</dc:date>
			  </ssn:Observation>

			  <ssn:Property rdf:about="obs:property>
				<owl:sameAs rdf:resource=" URI  a NASA Instance " />
			      OR
			    <rdf:type rdf:resource=" URI a NASA Class " />
			  </ssn:Property>
			  
			  <ssn:SensorOutput rdf:about="obs:sensoroutput">
				<ssn:hasValue rdf:resource="obs:outputvalue"/>
			  </ssn:SensorOutput>
			  
			  <ssn:ObservationValue rdf:about="obs:outputvalue">
		      	<dul:isClassifiedBy rdf:resource=" URI a Celsius, Farenheit, Microgramo/metro..."/>
				<ssn:hasQuantityValue rdf:datatype="xsd:float">0.98</ssn:hasQuantityValue>
			  </ssn:ObservationValue>
		</rdf:RDF>
	"""

    # .../station/ZORRO2/NO2/15022011/10
    uri = RESOURCE_URI + "station/" + stationcod + "/" + uriprefix + dateday.strftime("/%d%m%Y/%H")

    # Initialization of graph
    ssn = Namespace("http://purl.oclc.org/NET/ssnx/ssn#")
    dc = Namespace("http://purl.org/dc/elements/1.1/")
    xsd = Namespace("http://www.w3.org/2001/XMLSchema")
    dul = Namespace("http://www.loa.istc.cnr.it/ontologies/DUL.owl#")
    owl = Namespace("http://www.w3.org/2002/07/owl#")
    obs = Namespace(uri + "#")

    store = IOMemory()

    g = ConjunctiveGraph(store=store)
    g.bind("ssn", ssn)
    g.bind("dc", dc)
    g.bind("xsd", xsd)
    g.bind("dul", dul)
    g.bind("owl", owl)
    g.bind("obs", obs)

    cpr = URIRef(uri)
    gpr = Graph(store=store, identifier=cpr)

    # Add data to the graph
    gpr.add((cpr, RDF.type, ssn["Observation"]))

    gpr.add((cpr, ssn["observationResult"], obs["sensoroutput"]))

    gpr.add((cpr, ssn["observedProperty"], URIRef(RESOURCE_URI + "prop/" + uriprefix)))

    gpr.add((cpr, ssn["observedBy"], URIRef(RESOURCE_URI + "station/" + stationcod)))

    gpr.add((cpr, dc["date"], Literal(dateday.isoformat())))

    # SUBGRAPH1 (sensoroutput)
    cpr1 = obs["sensoroutput"]
    gpr.add((cpr1, RDF.type, ssn["SensorOutput"]))
    gpr.add((cpr1, ssn["hasValue"], obs["outputvalue"]))

    # SUBGRAPH2 (outputvalue)
    cpr2 = obs["outputvalue"]
    gpr.add((cpr2, RDF.type, ssn["ObservationValue"]))
    gpr.add((cpr2, dul["isClassifiedBy"], URIRef(obsunit)))
    gpr.add((cpr2, ssn["hasQuantityValue"], Literal(medition)))

    # Create RDF file
    if OBS_PATH:
        print gpr.serialize(format="pretty-xml")
        filename = "Med_" + dateday.strftime("%d_%m_%Y") + ".nt"
        f = open(OBS_PATH + filename, "a")
        f.write(gpr.serialize(format="nt"))  #'pretty-xml'))
        f.close()
    else:
        print "Inserting " + uri + "..."
        insertGraph(g=gpr, sparql=VIRTUOSO_URL, resourceuri=RESOURCE_URI)
        print "OK"
Пример #8
0
	def generateRDF(self, resourceuri, sparql=None, path=None):
		#print sparql
		'''  
			<?xml version="1.0"?>
				<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
				  xmlns:ssn="http://purl.oclc.org/NET/ssnx/ssn#"
				  xmlns:dc="http://purl.org/dc/elements/1.1/"
				  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
				  xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
				  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
				  xmlns:dul="http://www.loa.istc.cnr.it/ontologies/DUL.owl#"
				  xmlns:st="http://dev.morelab.deusto.es/bizkaisense/ZORRO2#"
				>

				<ssn:Sensor rdf:about="http://dev.morelab.deusto.es/bizkaisense/ZORRO2">
					<dc:identifier>EASO</rdfs:label>
					<dc:title>Easo</dc:title>
					<dc:description>Easo (EASO) @ Donostia (GUIPUZKOA)</rdfs:comment>
					<rdfs:seeAlso rdf:resource="http://www.ingurumena.ejgv.euskadi.net/r49-n82/es/vima_ai_vigilancia/estaciones.apl?CodZona=@DONOS&CodEst=EASO&lenguaje=c"/>
					<dul:hasLocation rdf:resource="st:point"/>
					<dul:nearTo rdf:resource="http://www.geonames.org/4654365"/>
				</ssn:Sensor>

				<geo:Point rdf:about="st:point">
					<geo:lat>43.3142945841</geo:lat>
					<geo:long>-1.97927578309</geo:long>	
				</geo:Point>
			</rdf:RDF>
		'''
	
		#.../station/ZORRO2/NO2/15022011/10
		uri = resourceuri + 'station/' + self.cod
	
		#Initialization of the graph
		ssn = Namespace("http://purl.oclc.org/NET/ssnx/ssn#")
		dc = Namespace("http://purl.org/dc/elements/1.1/")
		xsd = Namespace("http://www.w3.org/2001/XMLSchema")
		geo = Namespace("http://www.w3.org/2003/01/geo/wgs84_pos#")
		rdfs = Namespace("http://www.w3.org/2000/01/rdf-schema#")
		foaf = Namespace("http://xmlns.com/foaf/0.1/")
		dul = Namespace("http://www.loa.istc.cnr.it/ontologies/DUL.owl#")
		st = Namespace(uri + "#")

		store = IOMemory()
	
		g = ConjunctiveGraph(store=store)
		g.bind("ssn", ssn)
		g.bind("dc", dc)
		g.bind("xsd", xsd)
		g.bind("geo", geo)
		g.bind("rdfs", rdfs)
		g.bind("foaf", foaf)
		g.bind("dul", dul)
		g.bind("st", st)
	
		cpr = URIRef(uri)
		gpr = Graph(store=store, identifier=cpr)
	
		#Add data to the graph
		gpr.add((cpr, RDF.type, ssn['Sensor']))

		gpr.add((cpr, dc['identifier'], Literal(str(self.cod))))

		gpr.add((cpr, dc['title'], Literal(str(self.name))))

		desc = str(self.name) + " (" + str(self.cod) + ") @ " + str(self.location) + " (" + str(self.zonedesc) + " (" + str(self.codzone) + ") - " + str(self.province) + ")"

		gpr.add((cpr, dc['description'], Literal(desc)))

		gpr.add((cpr, rdfs['seeAlso'], URIRef(self.url)))

		gpr.add((cpr, dul['hasLocation'], st["point"]))

		if self.geonames:
			gpr.add((cpr, dul['nearTo'], URIRef(self.geonames)))
	
		#SUBGRAPH1 (point)
		cpr1 = st["point"]
		gpr.add((cpr1, RDF.type, geo['Point']))
		if self.address:
			gpr.add((cpr1, dc['description'], Literal(str(self.address) + ", " + str(self.location))))
		gpr.add((cpr1, geo['lat'], Literal(self.lat)))
		gpr.add((cpr1, geo['long'], Literal(self.lng)))

		#img = self.__getStationImage()
		img = None
		if img:
			gpr.add((cpr, foaf['img'], URIRef(img)))
	
		#Create RDF file
		if not sparql:
			f = open(path, 'w')
			f.write(gpr.serialize(format='pretty-xml'))
			f.close()
		else:
			insertGraph(g=gpr, sparql=sparql, resourceuri=resourceuri)
Пример #9
0
    def generateRDF(self, resourceuri, sparql=None, path=None):
        #print sparql
        '''  
			<?xml version="1.0"?>
				<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
				  xmlns:ssn="http://purl.oclc.org/NET/ssnx/ssn#"
				  xmlns:dc="http://purl.org/dc/elements/1.1/"
				  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
				  xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
				  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
				  xmlns:dul="http://www.loa.istc.cnr.it/ontologies/DUL.owl#"
				  xmlns:st="http://dev.morelab.deusto.es/bizkaisense/ZORRO2#"
				>

				<ssn:Sensor rdf:about="http://dev.morelab.deusto.es/bizkaisense/ZORRO2">
					<dc:identifier>EASO</rdfs:label>
					<dc:title>Easo</dc:title>
					<dc:description>Easo (EASO) @ Donostia (GUIPUZKOA)</rdfs:comment>
					<rdfs:seeAlso rdf:resource="http://www.ingurumena.ejgv.euskadi.net/r49-n82/es/vima_ai_vigilancia/estaciones.apl?CodZona=@DONOS&CodEst=EASO&lenguaje=c"/>
					<dul:hasLocation rdf:resource="st:point"/>
					<dul:nearTo rdf:resource="http://www.geonames.org/4654365"/>
				</ssn:Sensor>

				<geo:Point rdf:about="st:point">
					<geo:lat>43.3142945841</geo:lat>
					<geo:long>-1.97927578309</geo:long>	
				</geo:Point>
			</rdf:RDF>
		'''

        #.../station/ZORRO2/NO2/15022011/10
        uri = resourceuri + 'station/' + self.cod

        #Initialization of the graph
        ssn = Namespace("http://purl.oclc.org/NET/ssnx/ssn#")
        dc = Namespace("http://purl.org/dc/elements/1.1/")
        xsd = Namespace("http://www.w3.org/2001/XMLSchema")
        geo = Namespace("http://www.w3.org/2003/01/geo/wgs84_pos#")
        rdfs = Namespace("http://www.w3.org/2000/01/rdf-schema#")
        foaf = Namespace("http://xmlns.com/foaf/0.1/")
        dul = Namespace("http://www.loa.istc.cnr.it/ontologies/DUL.owl#")
        st = Namespace(uri + "#")

        store = IOMemory()

        g = ConjunctiveGraph(store=store)
        g.bind("ssn", ssn)
        g.bind("dc", dc)
        g.bind("xsd", xsd)
        g.bind("geo", geo)
        g.bind("rdfs", rdfs)
        g.bind("foaf", foaf)
        g.bind("dul", dul)
        g.bind("st", st)

        cpr = URIRef(uri)
        gpr = Graph(store=store, identifier=cpr)

        #Add data to the graph
        gpr.add((cpr, RDF.type, ssn['Sensor']))

        gpr.add((cpr, dc['identifier'], Literal(str(self.cod))))

        gpr.add((cpr, dc['title'], Literal(str(self.name))))

        desc = str(self.name) + " (" + str(self.cod) + ") @ " + str(
            self.location) + " (" + str(self.zonedesc) + " (" + str(
                self.codzone) + ") - " + str(self.province) + ")"

        gpr.add((cpr, dc['description'], Literal(desc)))

        gpr.add((cpr, rdfs['seeAlso'], URIRef(self.url)))

        gpr.add((cpr, dul['hasLocation'], st["point"]))

        if self.geonames:
            gpr.add((cpr, dul['nearTo'], URIRef(self.geonames)))

        #SUBGRAPH1 (point)
        cpr1 = st["point"]
        gpr.add((cpr1, RDF.type, geo['Point']))
        if self.address:
            gpr.add((cpr1, dc['description'],
                     Literal(str(self.address) + ", " + str(self.location))))
        gpr.add((cpr1, geo['lat'], Literal(self.lat)))
        gpr.add((cpr1, geo['long'], Literal(self.lng)))

        #img = self.__getStationImage()
        img = None
        if img:
            gpr.add((cpr, foaf['img'], URIRef(img)))

        #Create RDF file
        if not sparql:
            f = open(path, 'w')
            f.write(gpr.serialize(format='pretty-xml'))
            f.close()
        else:
            insertGraph(g=gpr, sparql=sparql, resourceuri=resourceuri)