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}'

Ninjasoup
  • 173
  • 1
  • 12

0 Answers0