Protege issue: Object property assertion for a class in ontology - ontology

if I have the same object property value "val1" for all instances of "class1" in ontology, how can I infer that object property value for that "class1" is "val1"

Just to make this more clear to talk about, say you have Class1 and the object property property1. We further assume for Class1 the only explicitly specified instances are c1, c2 and c3. Further we have that:
property1(c1, val1)
property1(c2, val1)
property1(c3, val1)
Now due to your known c1...c3 instances being linked via property1 to val1, you want to infer that when property1(x,y) where x is of type Class1, it must follow that y = val1.
Due to the open world assumption, the possibility exist that another instance, say c4, can exist that is of type Class1 that is related via property1 to val2. Hence a reasoner will not be able to do this inference.
You could use rules though to do this. With SWRL you can state Class1(?x) => property1(?x, ?val1). This states whenever you have an instance of Class1 it is linked to val1 via property1.

Related

Designing the domain modal class

I have one domain class design issue regarding validation for the following domain classes:
Class Course {
String name // computers,maths,economics,zoology etc...
}
class Component{
String name //ex: C1,C2,C3
boolean type // 0 means internal , 1 means external
}
Class CourseComponent{
Course course
Component component
Integer MaxMarks
...
}
There client requirement is when creating CourseComponents for the particular Course .. total maxMarks should be equals to hundred. So
for instance: for Maths Course,component distribution like
1.Maths C1 15
2.Maths C2 15
3.Maths C3 70
The total marks should be equals 100.
How would I go about writing a constraint that examines multiple records or how do I need to change my domain classes?
If I correctly understood the requirement then CourseComponent should hold a collection of Component.
In this case I would not add a maxMarks attribute to the CourseComponent class since it may be computed easily and available through an accessor method. Therefore I would move this attribute to the Component class for storing the number of an individual Component for a given Course (or CourseComponent).
Next I would add a validation on the total maxMarks when adding Component instances to the CourseComponent.
But another question is do you really need a CourseComponent class?
You might have a Course class that holds related Component instances as a collection attribute.

Declare multiple objects in one definition

I am new to Xtext and I would like to be able to have declarations like
class A, B, C{
Some common features
}
and be able to refer to A, B and C.
I tried to do it like 'class' name +=ID (',' name += ID)* but this wont work since no object are apparently created. I assume I have to use actions but I don't understand how. Can anyone help me?

Filter by defining concrete entity as the operand, i.e. not using a primitive value

In the examples I've checked, the operand is always a primitive value, like:
http://host/service/Products?$filter=MainIngredient eq 'Milk'
what if the MainIngredient property is an entity, and I want to reference exactly this entity? Abstracting other cases, that would be something like
http://host/service/Products?$filter=MainIngredient eq Ingredient('770d5720-9ae8-11e3-a5e2-0800200c9a66)
...or isn't the filter not the correct instrument to use, at all?
I think you mean that MainIngredient is the name of a navigation property that points to a single entity of type Ingredient, such as:
http://host/service/Products(1234)/MainIngredient
If this is the case, and assuming that the key of Ingredient is called "ID" then I think the correct form of URL for what you want to do is:
http://host/service/Products?$filter=MainIngredient/ID eq guid'770d5720-9ae8-11e3-a5e2-0800200c9a66'
That would return only products that are linked, via MainIngredient, to the Ingredient with the ID you gave in the question.

Entity Framework: Sort on Field of Derived Type

I'm pretty sure I can't do what I want to do in EF4.3, but before I abandon the attempt I thought I'd run it by some more experienced programmers.
I have a schema where two entity types, 'person' and 'org', each derive from a root entity I call 'named'. This structure allows me to associate an instance of 'named' with instances of another entity called 'address' via a many-to-many relationship, 'entity_address', without having to distinguish between whether the 'named' entity is an organization or a person.
When I query entity_address I'd like to be able to sort the results by different properties depending upon whether the entity_address instance is a 'person' or an 'org'. In the case of a person the "input" to the sorting algorithm might be the value of the property "last_name", while for an org it might be the property "org_name".
If I try the obvious:
IQueryable<named> sorted = entities.OrderBy(x => ( x is person ) ? ( (person) x ).last_name : ( (org) x ).org_name);
when I access "sorted" EF throws an exception about only being able to cast primitive types. I presume it can't apply the cast operator to the "x" instance.
I've tried a lot of less obvious approaches, with no success :).
Is there a way to do this in LINQ to Entities?
I know I can solve the problem by denormalizing the database and sticking a "sort_field" in the entity 'named', and then just sort on that (I'd have to include logic for keeping the sort_field value consistent with changes to values in instances of person and org, but that's certainly feasible).
One way to achieve what you want is projecting both entities to the same (anonymous) type:
entities.OfType<Person>()
.Select(p => new { p.Prop1, p.Prop2, ..., SortProp = p.last_name })
.Union(
entities.OfType<Organization>()
.Select(o => new { o.Prop1, o.Prop2, ..., SortProp = o.org_name }))
.OrderBy(x => x.SortProp)
The projections should have exactly the same properties in the same order.
Of course, you can also do the sorting in memory the way you already did, i.e. on entities.ToList(). But that defeats the purpose of doing it with IQueryable: letting the database do the work.
does this work? I'm assuming that entities is a collection of named...
entities.OrderBy(x => x as person == null ? x.org_name : x.last_name)

F# -> Seq to Map

I'm trying to load all my Categories from the database and then map them to a Map (dictionary?), however when I use the following code:
[<StructuralComparison>]
type Category = {
mutable Id: string;
Name: string;
SavePath: string;
Tags: ResizeArray<Tag> }
let categories = session.Query<Category>()
|> Seq.map(fun z -> (z,0))
|> Map.ofSeq
it simply throws an error that says:
The struct, record or union type
'Category' has the
'StructuralComparison' attribute but
the component type 'ResizeArray'
does not satisfy the 'comparison'
constraint
I have absolutely no clue about what to do, so any help is appreciated!
F# is rightly complaining that ResizeArray<_> doesn't support structural comparison. ResizeArray<_> instances are mutable and don't support structural comparison, and you therefore can't use them as fields of records which are used as keys to Map<_,_>s (which are sorted by key). You have a few options:
Have Tags use a collection type that does support structural comparison (such as an immutable Tag list).
Use [<CustomComparison>] instead of [<StructuralComparison>], which requires implementing IComparable.
Use a mutable dictionary (or another relevant collection type) instead of a Map. Try using the dict function instead of Map.ofSeq, for instance.
The problem here is that by adding StructuralComparison attribute to the type Category you've asked F# to use structural comparison when comparing instances of Category. In short it will compare every member individually to see if they are equal to determine if two instances of Category are equal.
This puts an implicit constraint on every member of Category to themselves be comparable. The type ResizeArray<Tag> is generating an error because it's not comparable. This is true for most collection types.
In order to get rid of this error you'll need to make the ResizeArray<T> type comparable or choose a different key for the Map. Don has a great blog post that goes into this topic in depth and provides a number of different ways to achieve this. It's very much worth the read
http://blogs.msdn.com/b/dsyme/archive/2009/11/08/equality-and-comparison-constraints-in-f-1-9-7.aspx

Resources