Dynamic Descriptive Logic Insertion

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

Dynamic Descriptive Logic Insertion

Sree
I want to write Descriptive Logic dynamically for several classes. I'm using intersection in the DL. I find some examples in owlapi but not in owlready. Can anyone help with this??
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Descriptive Logic Insertion

Jiba
Administrator
Hello,

You can create an ontology dynamically with Owlready.

You can create classes dynamically, from a class name and a list of superclasses (see doc here: http://owlready2.readthedocs.io/en/latest/class.html#creating-classes-dynamically ).

Then, you can add some class construct to the class, for example:

        Class.is_a.append(property.some(Other_Class))

For intersection, you can use the & operator,  or the And([...]) construct:

        Class.is_a.append(property.some(Other_Class) & property2.some(Other_Class2))
        Class.is_a.append(And([property.some(Other_Class), property2.some(Other_Class2)]))

Both lines are equivalent, however the And([...]) version is possibly easier to use when creating classes dynamically.

Best regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13

> I want to write Descriptive Logic dynamically for several classes. I'm using
> intersection in the DL. I find some examples in owlapi but not in owlready.
> Can anyone help with this??
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://owlready.8326.n8.nabble.com/Dynamic-Descriptive-Logic-Insertion-tp236.html
> To start a new topic under Owlready, email [hidden email]
> To unsubscribe from Owlready, visit
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Descriptive Logic Insertion

Sree
Thank you for the response!! Please have a look into my code once:

dict1 is my dictionary, k is subject and v is of form "verb|object".

for k,v in dict1.items():
        y= v.split("|")
        a = y[0]
        b = y[1]
        with onto:
            NewClass = types.new_class(b, (Thing,)) #creating objects
            NewClass = types.new_class(a, (ObjectProperty,)) #creating obj properties

This works fine until here. Now I want to assign this dynamically created verb - objects to their respective subjects.

k.is_a.append(a.some(b)) -> is not working. Please let me know if there's a way.
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Descriptive Logic Insertion

Jiba
Administrator
Hi,

I think you messed up in your script, between NewClass and a and b.
Here is a small script that works as expected:


from owlready2 import *

onto_path.append("/tmp")

onto = get_ontology("http://www.test.org/o.owl")

with onto:
  klass1 = types.new_class("k", (Thing,)) #creating subject
  klass2 = types.new_class("b", (Thing,)) #creating object
  prop   = types.new_class("a", (ObjectProperty,)) #creating property
 
  klass1.is_a.append(prop.some(klass2))

print(klass1.is_a)
default_world.graph.dump()


Hope this help,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Descriptive Logic Insertion

Sree
Thank you very much Jean!! Appreciate your help. This is working fine now.

Just to learn more - is it possible to write many restrictions(say around 100 - using "and" operator) dynamically on one class?
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Descriptive Logic Insertion

Jiba
Administrator
Yes, I think you can start with an empty list, fill it with 100 restrictions, and finally create the And() and use .is_a.append().

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Descriptive Logic Insertion

Sree
Hi Jean,

I have made a list L1 containing 100 properties(p1,p2...p100) and list L2 containing 100 objects(o1,o2...o100). Now I want to write the expression for a given subject(S); S = And([(p1,01), (
p2,o2)...(p100,o100)]). I've tried for a while and I couldn't find a way to do the same. I'm seeing "Error1", "Error2"... in the place of objects in the ontology. Can you show the script if it works for you?

Thanks,
Sree
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Descriptive Logic Insertion

Jiba
Administrator
Hi,

The value inside And() should not be pair, but restriction, e.g. : And([p1.some(01), p2.some(02),...]).

Best regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13