How to use double values in Protégé / OWL / DL for class expressions (Syntax)? - double

I want to use double values for class expression syntax in Protégé but I can't find any examples. All are using integer values, not double. For instance: http://protegeproject.github.io/protege/class-expression-syntax/
For instance, I want to express the height of a person in meters:
hasHeight value 1.89
hasHeight min 1.70
How can I do this?
What currently works (according syntax): "hasHeight some xsd:double" infers that all instances that has a xsd:double value in the property hasHeight are instances. However, I want to restrict this to a particular value range. For example: between 1.80 and 1.70. How can I do this?
I thougt this is equivalent to queries from The DL Query tab where I can query relevant instances with "hasHeight some xsd:double[<=1.80]", but this is not allowed in the class expression editor in Protégé. Why?
Thanks in advance!

It doesn't work because Protégé is an editor for OWL 2, which in fact has some restrictions on the datatypes allowed in facets:
The OWL 2 datatype map provides the following datatypes for the
representation of real numbers, decimal numbers, and integers:
owl:real
owl:rational
xsd:decimal
xsd:integer
xsd:nonNegativeInteger
xsd:nonPositiveInteger
xsd:positiveInteger
xsd:negativeInteger
xsd:long
xsd:int
xsd:short
xsd:byte
xsd:unsignedLong
xsd:unsignedInt
xsd:unsignedShort
xsd:unsignedByte
Possible class expression:
hasHeight some xsd:decimal[>= 1.7, <= 1.8] (the parser in Protégé seems to need the spaces after <= symbol)

To define that individuals of type Person can have one or more hasHeight data properties you can state the following:
DataProperty: hasHeight
Class: Person
SubClassOf:
hasHeight some xsd:double
Note that this is different from cardinality restrictions, which limits how many times an individual of type Person can be associated via the hasHeight property. To specify that an individual of type Person has exactly 1 height you can specify it as follows:
DataProperty: hasHeight
Class: Person
SubClassOf:
hasHeight exactly 1 xsd:double
Thus the complete definition is as follows:
DataProperty: hasHeight
Class: Person
SubClassOf:
hasHeight some xsd:double,
hasHeight exactly 1 xsd:double

Related

Need clarification on Enumeration types in Swift

I am trying to understand Enumerations in Swift but I am confused about the assignment to a variable. Here is an example:
enum Planet {
case Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
}
var myPlanet = Planet.Mercury
I am confused about the last line. Is myPlanet variable being assigned a Planet object with case Mercury as its value?
It's not really a Planet "Object" because Swift prefers the term "Type". An "Object" implies that it's an instance of a "class." Classes, enums & structs in Swift sort of blur the lines a bit vs. other languages.
Planet is not a class, but an enumeration - a collection of related "member values". You're literally counting or "enumerating" all the various options within the group, and saying what name each one should go by. This provides a helpful alias to each value, allowing you to refer to the planets by name, instead of saying "Planet #1, #2, #3, #4, #5..."
Any situation where you have a finite collection of equal options may be a good candidate for an enum: "North, South, East, West" is another common example.
What you're doing here is declaring a new variable myPlanet, and assigning its initial value to the Planet enum's member value Mercury. The Planet Type is not explicitly declared, but is inferred from context - this new variable must be of Type Planet in order to hold the desired value of .Mercury.
An alternative declaration would be: var myPlanet: Planet = .Mercury
By explicitly declaring the Type of the var to be a Planet you can omit Planet from the righthand side.
Also, since it's a var & not let you could later change myPlanet to any of the "member values" of the Planet enum. Since myPlanet can only be 1 of the possible Planet options, you only need to refer to the member value:
myPlanet = .Earth
You could not, however, change myPlanet to a different Type (whether enum, struct, or class), because its type was already defined as Planet.
See the Enumerations chapter of the Swift Programming Language Guide for more examples/details (though this example is the same, so you're probably reading it).
EDIT BASED ON COMMENTS:
To me Planet.Mercury means an enumeration type called Planet with only case Mercury inside of it.
Your myPlanet variable is of Type Planet, with only the value .Mercury assigned to it. "Planet.Mercury" as a statement is like pointing to "Menu of Planets, Value: Mercury."
A basic enum is a list of possible options, like a menu:
List of Planets to Choose From
1. Mercury
2. Venus
3. Earth
4. etc...
The variable myPlanet is a container that can only have 1 value at a time.
Since you set it to 1 of the options listed within the Planet enum definition, Swift infers that it must be of Type Planet. From that point forward, this container is marked "Only For Planets" and its assigned value can only come from the enum list. The Planet enum itself is static - it's the restaurant menu and always contains the same options (unless you edit the enum definition itself).
If I were to write it in terms of a class called Planet, I see it as myPlanet = Planet(name: "Mercury"). Do you have an analogy that can help me grasp the enumeration concept? – Walter
With the class example, you'd be using a method to initialize a Planet instance with a property name that you set to the String "Mercury". This is different in a number of ways. For one, "name" in this case is a property of Type String, which has getter/setter methods, etc. You could presumably set name to whatever you want: Planet.name = "Walter" You also have to access the property by its name, and provide it with a value. This is not true of enums.
With an enum, all you have is the predefined list of possible options.
Mercury, Venus, Earth, Mars, etc. The enum's "member values" are simply nicknames, similar to an alias for "Entry #1, Entry #2, Entry #3". If "Planet.Walter" is not in the predefined list, you cannot assign a variable of Type Planet to that value. It knows it has to be a Planet but it won't find case Walter among the options.
Also, the reason I am still confused has to do with accessing computed properties inside the enumeration. For example, if I had a computed property called size that is based on self inside the enumeration based on, the way to access is myPlanet.size. This means that it is equivalent to Planet.Mercury.size. How am I accessing a computed property through the case >value Mercury?
Computed properties are one of the places where Swift blurs the lines of traditional Object-Oriented Programming, because they exist in classes, enums, and structs, so it can get confusing.
myPlanet.size doesn't necessarily equal Planet.Mercury.size - it could be Planet.size where size is a computed property returned from a function within the enum itself.
See this question for an example:
Swift Tour Card.createDeck() Returning [{(enum value), (enum value)}]
The following is an untested variation on the card deck example:
enum Planet {
case Mercury, Venus, Earth, Mars
func size() -> String {
switch self {
case .Mercury:
return "pretty darn small!"
case .Venus:
return "still small!"
case .Earth:
return "we think this is normal"
case .Mars:
return "slightly bigger than Earth"
}
}
}
var myPlanet: Planet = .Mercury
print(\myPlanet.size()) //"pretty darn small!"
myPlanet = .Mars
print(\myPlanet.size()) //"slightly bigger than Earth"
With this approach, the "size" function is a method of the Planet enum, similar to how an object can have instance methods, or a struct can have methods too. Calling myPlanet.size() after assigning a value is like saying "I'm a Type Planet, so if I look at myself, I know I'm a Mercury, so when I execute this method I have because I'm a Planet, I return the value for Mercury." Change the assigned value, and the method remains the same, but the returned value is now different, because myPlanet now has a different value.
I wouldn't say it is an object that you're assigning to myPlanet. You're assigning myPlanet with Mercury, which is a member of the enumeration Planet. Apple's documentation states:
If you are familiar with C, you will know that C enumerations assign related names to a set of integer values. Enumerations in Swift are much more flexible, and do not have to provide a value for each member of the enumeration. If a value (known as a “raw” value) is provided for each enumeration member, the value can be a string, a character, or a value of any integer or floating-point type.
They go on to elaborate on this further (answering your question, in my opinion):
The values defined in an enumeration (such as North, South, East, and West) are the member values (or members) of that enumeration. The case keyword indicates that a new line of member values is about to be defined.
NOTE
Unlike C and Objective-C, Swift enumeration members are not assigned a default integer value when they are created. In the CompassPoint example above, North, South, East and West do not implicitly equal 0, 1, 2 and 3. Instead, the different enumeration members are fully-fledged values in their own right, with an explicitly-defined type of CompassPoint.
You're not entirely wrong in thinking of the assigned value as an object, though – as the documentation continues with:
Enumerations in Swift are first-class types in their own right. They adopt many features traditionally supported only by classes, such as computed properties to provide additional information about the enumeration’s current value, and instance methods to provide functionality related to the values the enumeration represents. Enumerations can also define initializers to provide an initial member value; can be extended to expand their functionality beyond their original implementation; and can conform to protocols to provide standard functionality.
Swift enumerations do not work the same way as in Objective C.
The values which are stored inside of them cannot be used on their own (unless the type can be inferred). In the example below type can be inferred:
var myPlanet:Planet = .Mercury
First you are telling compiler that the variable is of type Planet and then you can use shorthand notation.
Apple's documentation is pretty good on enumerations and I strongly encourage you to read it:

how do I add a final variable to class diagram

I am designing a class diagram for scrabble game. In one of the classes, I have final variable declared. Can anybody tell me, how can I indicate a variable as final in the UML class diagram?
There are different notions of final that are all represented in different ways:
final definition, i.e. it cannot be overridden in sub-classes - this corresponds to the isLeaf property of the attribute:
The isLeaf property, when true for a particular RedefinableElement, specifies that it shall have no redefinitions. - UML 2.5 specifications, page 99
There is no official notation anymore for attributes with isLeaf=true; adding {leaf} was the former official notation (UML 1.x) and it is still common.
final value, i.e. its value cannot be changed - this corresponds to the isReadOnly property of the attribute:
If a StructuralFeature is marked with isReadOnly true, then it may not be updated once it has been assigned an initial value. Conversely, when isReadOnly is false (the default), the value may be modified. - UML 2.5 specifications, page 106
Notation for read-only attributes consists of appending {readOnly} to the attribute string.
constant usually refers to a non-changeable attribute of the class itself instead of an instance (static final attribute). In UML it would have both properties mentioned above and additionally be static, which corresponds to the isStatic property:
The isStatic property specifies whether the characteristic relates to the Classifier’s instances considered individually (isStatic=false), or to the Classifier itself (isStatic=true). - UML 2.5 specifications, page 105
Static attributes are indicated by underlining the attribute definition. Constants, as already mentioned are usually UPPERCASE, but that's just a convention.
So, to sum it up, a constant attribute FOO of type String with value "x" would look like this and be underlined in addition (which isn't supported here):
+ FOO : String = "x" {readOnly,leaf}
Constant (i.e. final) fields are indicated via naming convention:
constants should be in ALL_CAPS
Source
Declaring a variable/attribute final is implementation detail. So you don't need to specify it in your CLASS Diagram but you can follow the convention as suggested by eboix.
UML specification doesn't say anything specifically about it; so you can follow convention of showing it in ALL CAPS.

How to specify a List<MyCustomType> as a "Return Type" for a UML Interface Property

In my Visio 2007 UML document I am unable to figure out how I can add an operation to an Interface that returns a generic List<MyCustomType> type.
For example:
Say I have a class named "MyClass" and an Interface named "IFace". IFace has a signature of a method that returns a Generic List of MyClass.
For clarity, here's an example of the C# code:
namespace StackO
{
public interface IFace
{
List<MyClass> SomeMethod(string data);
}
public class MyClass
{
}
}
Here's a screenshot of where I'm stuck:
It seems as though the only way to specify a List<MyClass> as my Return Type is to create another user-defined datatype that is explicitly written as List<MyClass>. If this is the case, so be it. However, I'm posting this in hopes that there is a better/proper way to do this.
How can I define the Return Type of an Operation of a Visio Interface to be a Generic List of a User-Defined Datatype?
In the Class diagram properties > Go to operations > select the return type you are interested in changing and click properties.
In the next dialog you will have option for setting prefix List< and suffix >.
This way you can specify the return type as List<>.
I see this option in Visio 2010. But I am not sure if this option is available in Visio 2007.
There is no such a thing as T1<T2> in UML class diagrams.
If you want to specify that the method returns several values, the correct notation is:
SomeMethod(data: String) : MyClass [*]
This notation is much more powerful than the one used by C#. List<MyClass> SomeMethod(string data) gives no information about the contract of the method. With UML, you know that in:
SomeMethod(data: String) : MyClass [*]
SomethingElse() : String [1..*]
LastExample(number: UnlimitedNatural) : Integer [0..1]
SomeMethod returns a sequence containing zero or more elements. SomethingElse returns a sequence of one or several elements: this sequence is never empty. Finally, LastExample returns an optional value. This could be expressed in C# as int? LastExample(uint number) — see, no IEnumerable here.
Also note that:
SomeMethod(data: String) : MyClass [0..*]
shouldn't be used, since [*] means the same thing and is shorter. As for:
SomeMethod(data: String) : MyClass [0..n]
is incorrect, despite being used a lot on the internet.

How to handle subclasses in JasperReports?

I've two classes (A and B) that extend a base class BASE. I need to make a report that takes an array of such classes and the prints the fields of A or B. I tought of using conditional expressions, then casting to one or another (depending on a field value). But I can't cast, because I don't know how to refere to the current bean.
To do this I am using a JRBeanCollectionDataSource filled with a List<BASE>. How do I cast every bean to A or B in a report (or subreport)? I tried:
((A)this)
but it says basically that this contains the report instance, not the current bean and gives error.
use ((A) BASE) suppose BASE is your BASE class
now BASE point to the current record

constructor with parameters in UML class diagram

How would you create an uml class diagram for constructors with parameters?
For default constructors (no parameters) you do
policyholder() for the diagram and in the pseudo-code
For constructors with parameters would you do the same thing:
policyholder (policynumber, service class, and customer age) for class diagrams and pseudo-code.
It also asked to initialize each attribute to value where an object of this type can be instantiated. If a policy number is not between 1000 and 999 inclusive, then set the policy number to 0. (policy number is attribute)
The common way is to write constructors like methods and simply omit the return type.
If you want to be extra clear, you can add <<constructor>> in front.