Trouble accessing data property (dash?)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble accessing data property (dash?)

Sam S

Hi all,

I'm new to RDF – I'm only diving into this stuff because I want to transform the MITRE D3FEND ontology. Their ontology has a number of data properties I need - but they include the - character in the name, which is not working with Python's dot notation.

Here's my simple code to demonstrate what I'm trying to do, and where it's falling over:


#!/usr/bin/env python

from owlready2 import *
onto = get_ontology("https://d3fend.mitre.org/ontologies/d3fend.owl")

onto.load()

for level1 in onto.DefensiveTechnique.subclasses():
   for level2 in level1.subclasses():
        print("%s: %s" % (level1.label[0], level2.label[0]))
        print("%s" % (level2.d3fend-id))

Obviously the "d3fend-id" property isn't working since Python parses it as a minus operator.

Tips and pointers warmly welcomed....

Reply | Threaded
Open this post in threaded view
|

Re: Trouble accessing data property (dash?)

Jiba
Administrator
Hi,

You can rename the property in Python, as follows:

onto["d3fend-id"].python_name = "d3fend_id"

And the use:

        print("%s" % (level2.d3fend_id))

Jiba