Hi,
I have serached along the forum for the answer, but cannot find it. My question is obvious: how do I get information about domain and range of Object Property. In Object Property of onto there are two private members: _range and _domain, however thay are empty whilst example owl file (dummy.owl) I am reading has set these properties. Here is my code: #load the file pth = "file:///dummy.owl" onto = get_ontology(pth) onto.load(only_local=True) #try to access range and domain of specyfic object property print(onto.r1._range) The questions are: 1. how do I get range and domain of Object Property? 2. How do I easily find all Object Properties of a given class (e.g. onto.r1) for particular object class (e.g. onto.t1)? dummy.owl |
Hi,
This seems like a basic question. does nobody know the answer for it? Or maybe I don't understand how it should work. Please help. |
Ok,
I have discovered some strange behaviour: if I load this simple owl example (dummy.owl from posts above) it has only 1 singe object property called r1 i.e. onto.r1. 1. At first onto.r1._domain is None 2. I call onto.r1.domain (without underscore) and not onto.r1._domain is not empty anymore. how is it possible if onto.r1 does not have a method called "domain"? the same situation is with range. Can anyone explain that? |
Administrator
|
Hello,
You can get ranges and domains with the "range" and "domain" attribute (without _) of ObjectProperties. The "_range" and "_domain" are attributes used for caching the value of range and domain. Owlready do not load ranges and domains until they are asked for, hence the need for a cache. "_range" and "_domain" shoul dnot be used directly. Regarding your second question, you may use .get_class_properties() to get the properties of a class, but it returns only properties that are necessarily present (i.e. with a "some" constraint). If you want to obtain all possible properties (but not necessarily present), you can simply test all properties, as follows: def get_possible_class_properties(Class): for prop in default_world.properties(): if not prop.domain: yield prop else: for domain in prop.domain: if not issubclass(Class, domain): break else: yield prop print(list(get_possible_class_properties(onto.t1))) Jiba |
Hi Jiba, this doesn't seem to catch all properties. I have tried to handle multi-class domains (e.g. Or'd) and lists (Class.domain.Classes, Class.domain[0].Classes), but these are not catching the domains I am looking for.
What am I missing? Thanks
|
Free forum by Nabble | Edit this page |