0

I'm struggling to understand how sparkle query's work. I have a following xml file:

xmlns:rdf="http://www.xx.org/xxxx/xx/22-rdf-syntax-ns#"
xmlns:md="http://xxx.xx/xxxx/xxxxx-xxx/ModelDescription/1#"
xmlns:cim="http://xxx.xx/xxxx/xxxx/CIM-schema-cim16#"
xmlns:entsoe="http://xxxxx.xx/xxx/SchemaExtension/3/1#">
<md:FullModel rdf:about = "urn:uuid:'id_number">
    <md:Model.scenarioTime>2018-04-23T00:30:00Z</md:Model.scenarioTime>
    <md:Model.created>2018-05-18T11:35:36Z</md:Model.created>
    <md:Model.description>YYYY</md:Model.description>
    <md:Model.version>001</md:Model.version>
    <md:Model.profile>http://xxxx.xx/xxx/EquipmentC/3/1</md:Model.profile>
    <md:Model.profile>http://xxxx.xx/xxx/EquipmentO/3/1</md:Model.profile>
    <md:Model.DependentOn rdf:resource="urn:uuid:other_id_number" />
    <md:Model.modelingAuthoritySet>http://xxxx.xxx/xxxx/2.4.15</md:Model.modelingAuthoritySet>
</md:FullModel>
<cim:ItemA rdf:ID="_itemA_number">
    <cim:IdentifiedObject.description></cim:IdentifiedObject.description>
    <entsoe:IdentifiedObject.energyIdentCodeEic>                                                                                         </entsoe:IdentifiedObject.energyIdentCodeEic>
    <cim:IdentifiedObject.name>V</cim:IdentifiedObject.name>
    <cim:BaseVoltage.nominalVoltage>17</cim:BaseVoltage.nominalVoltage>
    <entsoe:IdentifiedObject.shortName> </entsoe:IdentifiedObject.shortName>
</cim:ItemA>
<cim:ItemB rdf:ID="_itemB_number">
    <cim:IdentifiedObject.description></cim:IdentifiedObject.description>
    <entsoe:IdentifiedObject.energyIdentCodeEic> </entsoe:IdentifiedObject.energyIdentCodeEic>
    <cim:IdentifiedObject.name>1</cim:IdentifiedObject.name>
    <cim:BaseVoltage.nominalVoltage>110</cim:BaseVoltage.nominalVoltage>
    <entsoe:IdentifiedObject.shortName></entsoe:IdentifiedObject.shortName>
</cim:ItemB>

So what I'm trying to do is get cim:IdentifiedObject.name values for ItemA only (There are hundreds of ItemA and ItemB)

I was trying the following:

import rdflib

rawData = r'C:\path\my.xml'

graph = rdflib.Graph()
result = graph.parse(rawData)

#print("graph has %s statements." % len(graph))


qres = result.query(
 """
PREFIX cim:<http://xxx.xx/xxxx/xxxx/CIM-schema-cim16#>
SELECT  ?subject ?predicate 
    WHERE {
       ?subject ItemA
       ?predicate cim:IdentifiedObject.name

    }""")

for r in qres.result:
    print (r)

But this doesn't work, I read quite a few web pages on sparkle but I don't really understand how the querying works.

Any help would be great.

Edit: I'm now getting a 'ParseException: Expected {SelectQuery | ConstructQuery | DescribeQuery | AskQuery}'

6
  • what is "sparkle"? Jul 13, 2018 at 19:35
  • And SPARQL is a query language for RDF, I don"t get why you think loading a web page or any XML file should work here? Jul 13, 2018 at 19:35
  • your SPARQL query is missing the prefix declaration for cim: Jul 13, 2018 at 19:37
  • and last but not least, your're querying for a predicate which does not exist in the sample data shown by you - where is cim:VoltageLevel? And the whole query doesn't reflect what your planning to do - are sure how to use SPARQL? any tutorial done so far? I mean, ItemA is the subject of the triples, cim:IdentifiedObject.name the predicate. what's so difficult now with creating the triple pattern? Jul 13, 2018 at 19:41
  • VoltageLevel should be ItemA
    – Ninjasoup
    Jul 13, 2018 at 19:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.