OWL: How to refer to property holder's properties? - owl

This is a question about OWL (Web Ontology Language). There might be some mistakes of terms as I am a very beginner.
I want to represent a painting activity as a Painting class.
Painting has a property TargetSurface whose range is a Surface class:
Surface has properties SurfaceColor (range: Color), etc.
Painting has a property TargetColor whose range is a Color class.
Now I want to represent the objective of painting as a property of Painting. It would be something like: a property Painting.Objective has a range that is an instance of Change class (let's say, Change1), which involves properties Change1.What = TargetSurface.SurfaceColor and Change1.ToWhat = TargetColor.
My question is that Objective is referring to properties of Painting (Painting is a holder of Objective; referred properties are Painting.TargetSurface.SurfaceColor and Painting.TargetColor). How can we represent this in OWL? An ugly solution would be representing the properties of Change1 as xsd:string; Change1.What = "parent.TargetSurface.SurfaceColor" and Change1.ToWhat = "parent.TargetColor". Are there better solutions?
Note that Painting.TargetSurface and Painting.TargetColor will be referred to in other properties of Painting. So making an instance Change2 which directly refers to Painting.TargetSurface.SurfaceColor and Painting.TargetColor would not be a good idea.
Many thanks!

You can do this with "punning" in OWL2. Punning takes advantage of the fact that properties are objects too. We do something similar when modeling property attributes. We can use the property in the subject position of a triple when specifying the domain attribute, e.g. TargetSurface rdfs:range Surface. You can similarly specify rdf:Property in the object position of the rdfs:range assertion for your What property. An example assertion could be Change1 What TargetColor where Change1 is your individual change of the painting, What is the property and TargetColor is the property that is changed (which is used here as the object of the triple).

From the answer of #Jess, a solution came up to my mind.
We prepare two general classes. Holder class (properties Context, HeldVia) refers to a class that holds a class Context as a property HeldVia. Ref class (properties A, B) refers to a class that is held by A as a property B (i.e. like an A.B operator).
Then we can represent Painting.Objective as follows. An informative representation would be:
Painting.Objective = Change1
Change1.What = Ref(Ref(Holder(Change1,Objective),TargetSurface),SurfaceColor)
Change1.ToWhat = Ref(Holder(Change1,Objective),TargetColor)
Note that Holder(Change1,Objective) refers to Painting since Painting is holding Change1 as an Objective property.
More formally, the above would be represented as:
Painting.Objective = Change1
Holder1.Context = Change1
Holder1.HeldVia = Objective
Ref1.A = Holder1
Ref1.B = TargetSurface
Ref2.A = Ref1
Ref2.B = SurfaceColor
Ref3.A = Holder1
Ref3.B = TargetColor
Change1.What = Ref2
Change1.ToWhat = Ref3

Related

Check OWL Class

Suppose the range of an object property is defined through a class expression. I want to know whether a particular instance of the class can be used in the range of the object property. Is it possible to use the OWL API and check if a particular class is subsumed by this class expression ?
OWLAPI cannot provide a complete answer for this - an OWLReasoner implementation is necessary for complete results.
Given an implementation of OWLReasoner, to check entailment you can either list all the subclasses of a class expression and check if the class you're interested in appears in the response, or ask the reasoner if your class of interest is a subclass, i.e.,
OWLDataFactory df = ...
OWLClassExpression ce = ...
OWLClass c = ...
OWLReasoner r = ...
OWLAxiom ax = df.getOWLObjectSubClassOf(c, ce);
boolean cIsSubclassOfCE = r.isEntailed(ax);

Matlab: Creating arrays of objects that inherit from a parent class [duplicate]

As an example, suppose I have created an abstract class called Shape and two subclasses called Circle and Rectangle that both implement an (abstract) method called Draw. I would like to be able to create a number of Circle and Rectangle objects, store them in an array and call Draw on each array object by iterating through the array.
I have tried something like the following:
Shape.m:
classdef (Abstract) Shape < handle
methods (Abstract)
Draw(obj);
end
end
Circle.m:
classdef Circle < Shape
methods
function obj = Draw(obj)
disp('This is a circle');
end
end
end
Rectangle.m:
classdef Rectangle < Shape
methods
function obj = Draw(obj)
disp('This is a rectangle');
end
end
end
test.m:
shapes = Shape.empty();
myrect = Rectangle();
mycirc = Circle();
shapes(end + 1) = myrect;
shapes(end + 1) = mycirc;
for i = 1:size(shapes,1)
shapes(i).Draw();
end
When I try to run test.m, I get the following error message:
Error using Shape.empty
Abstract classes cannot be instantiated.
Class 'Shape' defines abstract methods
and/or properties.
Error in test (line 1)
shapes = Shape.empty();
As is clear from the error, you cannot instantiate an abstract class (see sebastian's answer for details). However, there is a special superclass called matlab.mixin.Heterogeneous from which you can derive to allow creation of an array of different classes.
First, derive from matlab.mixin.Heterogeneous in Shape.m:
classdef (Abstract) Shape < handle & matlab.mixin.Heterogeneous
Then in your test script, initialize shapes from either Circle or Rectangle:
shapes = Circle.empty();
When you run the loop, the array will change class:
>> shapes
shapes =
1x2 heterogeneous Shape (Rectangle, Circle) array with no properties.
>> shapes(1)
ans =
Rectangle with no properties.
>> shapes(2)
ans =
Circle with no properties.
That should be all you need, but for additional control over a heterogeneous array, you can override the getDefaultScalarElement method of matlab.mixin.Heterogeneous to specify the default object. This should be overridden for abstract base classes:
Override this method if the Root Class is abstract or is not an appropriate default object for the classes in the heterogeneous hierarchy. getDefaultScalarElement must return an instance of another member of the heterogeneous hierarchy.
Say you want the default object to be Circle for an array of objects deriving from Shape:
methods (Static, Sealed, Access = protected)
function default_object = getDefaultScalarElement
default_object = Circle;
end
end
Now missing elements in an array of objects derived from Shape will be filled with Circle objects:
>> clear r
>> r(2) = Rectangle
r =
1x2 heterogeneous Shape (Circle, Rectangle) array with no properties.
>> r(1)
ans =
Circle with no properties.
>> r(2)
ans =
Rectangle with no properties.
From the docs:
abstract class — A class that cannot be instantiated, but that defines class components used by subclasses.
See: Mathworks-Docs
Which is, afaik, the definition of abstract classes in other programming languages as well (someone correct me if I'm wrong).
So to construct an array that holds various kinds of Shape elements, I'd guess you'll either have to make Shape non-abstract or implement another non-abstract class, that all your real implementations inherit from.
EDIT: For completeness:
I tried what you're trying achieve and at first sight, object-arrays with mixed elements that have a common superclass don't exist:
>> objects(1) = Foo();
>> objects(2) = FooBar();
The following error occurred converting from FooBar to Foo:
Error using Foo
Too many input arguments.
>> FooBar
ans =
FooBar handle with no properties.
Methods, Events, Superclasses
Superclasses for class FooBar:
Foo
handle
EDIT 2:
See chappjc's solution for this issue ;)

db.expando + App Engine + Change an integer property value to float value

I've following model set up initially
class Obj (db.Model):
name = db.StringProperty(required=True)
rating = db.IntegerProperty(default=0, required=False)
There are entities already created with above, such as:
name="test1", rating="3"
So, I need to change the rating type to float. I was trying to achieve this with db.Expando
class Obj (db.Expando):
name = db.StringProperty(required=True)
rating = db.FloatProperty(default=0, required=False)
Before I'm able to retrieve the instance of the Obj model to update it to float value, I've already got the following error:
Property rating must be a float
At first, I got this error, because I wasn't using db.Expando. However, after using db.Expando, I assumed this error shouldn't come into place ? Since it can dynamically change value, type etc as I read the articles.
Being new to db.Expando, I need help. Does anyone have clue to what happened ?
EDIT
for o in Obj.all():
a = []
if o.rating:
o.rating = float(str(restaurant.rating))
else:
o.rating = float(0)
a.append(restaurant)
db.put(a)
After having above code, the same error pops up
Property rating must be a float
SOLUTION
Temporarily removed the rating from model definition and updated the values to float first and then add the new rating definition with db.FloatProperty
A db.Expando model allows you to add properties that aren't defined in the class itself; however, any properties that are explicitly defined in the class do need to be the correct type.
Simply removing rating from the model definition may work for you.

Find owlSubClasses of a class using the ROWLEX API?

I have a given ontology, on which I like to reason. I use the ROWLEX API for .NET.
How can I find all owlSubClasses of a class?
ROWLEX is not a reasoner. It has some functionality of a reasoner implemented - it is very necessary for the C# class generation - but its API is not designed for that. However, there is still hope, just not the most elegant solution.
I assume, that you have an ontology and you generated .NET classes from that using OwlGrinder.exe. Therefore by default, you have two associated .NET classes generated for each corresponding OWL class in the ontology: one light class and one full class. We are going to use the light classes only. We simply iterate through ALL .NET classes and filter out if is a subclass. That is it.
string baseClassUri = "http://myontology/2012/10#mybaseclass";
Assembly asm = GetMyAssemblyGeneratedByOwlGrinder();
Type[] subClasses = (from type in asm.GetTypes()
where type.IsSubclassOf(typeof(NC3A.SI.Rowlex.OwlThing))
// selecting subclasses only
let attributes = type.GetCustomAttributes(typeof(NC3A.SI.Rowlex.SubClassOfAttribute), false)
from attr in attributes
let subClassAttr = attr as NC3A.SI.Rowlex.SubClassOfAttribute
where subClassAttr.TypeUri == baseClassUri
// selecting light classes only
let lightAttributes = type.GetCustomAttributes(typeof(NC3A.SI.Rowlex.LightVersionAttribute), false)
from lightAttr in lightAttributes
let lightAttr_ = lightAttr as NC3A.SI.Rowlex.LightVersionAttribute
where lightAttr_.LightVersion == true
select type).ToArray();
I did not try the code, it may be buggy. But it does show the idea. Each generated class have a bunch of attributes added. These include their base classes in the SubClassOfAttribute and whether they are light classes or full classes using the LightVersionAttribute. You can filter out the classes you are interested in based on these attributes.

Is there a simple way to set a large number of WPF Form objects?

This is just basic example:
if (a == b)
{
textBox1.Text = "a == b";
textBox1.IsEnabled = true;
textBox2.Text = "EXAMPLE2";
textBox2.IsEnabled = false;
textBox3.Text = "EXAMPLE3";
textBox3.IsEnabled = false;
textBox4.Text = "EXAMPLE4";
textBox4.IsEnabled = false;
textBox5.Text = "EXAMPLE5";
textBox5.IsEnabled = false;
}
else
{
textBox1.Text = "a != b";
textBox1.IsEnabled = false;
textBox2.Text = "EXAMPLE2";
textBox2.IsEnabled = true;
textBox3.Text = "EXAMPLE3";
textBox3.IsEnabled = true;
textBox4.Text = "EXAMPLE4";
textBox4.IsEnabled = true;
textBox5.Text = "EXAMPLE5";
textBox5.IsEnabled = true;
}
This seems pretty tedious. I was wondering if there's a better way to handle situations like that? I just have this feeling that all the Pros out there don't do things using this 1x1x1x.... method.
There are lots of ways to refactor this sort of code to give something more succinct. It really does become a matter of experience and preference to choose the method that is appropriate for each case.
To that end, I've listed below several options that I find serve me well:
Binding
Binding particularly within WPF gives a very powerful way of easily updating form objects. In your Xaml you apply a datacontext (generally for the form/window) and bound property for each object which then allows you to then update properties in your c# code and have them automatically reflected in the form objects.
One big advantage of this is getting all that tedious object.Text = "xyz" code out of the way.
In your given example, you could introduce a boolean property TextBoxesEnabled which is bound to the enabled property of your text boxes, and reflects whether a == b.
Domain objects
This follows on from the binding approach—in your example above it looks like all your properties are dependant of only two external pieces of data ("a" and "b"). In this situation your are often limited to doing something just like you have, where you need to set your UI properties within lots of procedural code.
However, more often you can introduce expressive domain objects that have properties that map directly to UI properties. For example, perhaps you have a User object, with a Name property, and then a user window, with a name textbox.
Now your domain object will be provided by calls into your service layer and data access infrastructure, and due to binding automatically displayed in your UI.
Code refactoring
Even where you are needing to set lots of properties directly without the ability to use more expressive objects and binding, there will often be some simple refactorings that can help.
In the code example you gave, two easy refactorings leap out to me:
a == b is a Boolean evaluation so you could have something like:
bool enableTextBoxes = a == b;
TextBox1.Enabled = enableTextBoxes;
TextBox2.Enabled = enableTextBoxes;
// etc...
You are setting the text to the same thing in the branches of the if, so take that out of the if and just have it once (though I'm guessing this is just because you were giving trivial example code).
You can loop over collections of controls, so if you need to set large numbers of control values to the same thing you can just do iterate over them and assign to each.
Assuming:
1. your controls have a pattern myControl1, myControl2, etc. (e.g textBox1, textBox2, etc)
2. your controls are all children of same FrameworkElement parent (e.g. all of them are within a Grid)
you can try something like:
bool shouldEnable = (a == b); //or whatever logic you want to have to decide the enable/disable value
for(i=0; i<10; i++)
{
string myControlName = "textBox" + i.ToString(); //assuming your pattern to be textBox1, textBox2, etc.
object myControl = myGrid.FindName(myControlName); //assuming your textboxes present in a Grid named "myGrid"
if(myControl is TextBox) //assuming your controls to be TextBoxes
{
TextBox myTextBox = (TextBox)myControl;
myTextBox.IsEnabled = shouldEnable;
myTextBox.Text = "whatever you want based on your logic";
}
}
Do remember:
1. to refer to FindName on MSDN: FrameworkElement.FindName
2. in case all of your controls are not under one parent, you might want to have a look at: How can I find WPF controls by name or type?
3. to be aware of performance implications (you may want to check it).
Also see: Find Controls by Name in WPF

Resources