Does anyone know an "official" name for a relation that is transitive and reflexive, but not necessarily anti-symmetric?
According to this, "a preorder is reflexive and transitive".
Related
Is it possible to get all fields that are defined explicitly and implicitly (inherited from parent classes) apart from iterating over a CXXRecordDecl's bases recursively and evaluating along the way, using C++'s inheritance and access rules, whether a given member of a base class is accessible in the class I started searching for members?
This procedure is really cumbersome and not straight-forward - it seems like there must be a more intuitive and simple solution using existing implementations of LLVM/clang to this problem.
Thank you in advance!
I'm trying to model the Modern dataset (http://www.tinkerpop.com/docs/3.0.0.M7/images/tinkerpop-modern.png) in Graql. Marko knows Vadas and Vadas knows Marko - for the purposes of this example, I'm assuming that they are friends.
So can I do this?
insert friendship isa relation-type;
insert friend isa role-type;
insert friendship has-role friend, has-role friend;
All the examples I've seen so far, have two different roles on a relationship (e.g. teacher/student).
Roles must be distinct, so you cannot have two friend roles in a single relation.
If the relation you are describing is symmetric, you should instead introduce two roles friend1 and friend2. If you want, these can both be ako friend.
Given the dataset you're using, it might be better to not describe this as a symmetric relationship and instead uses a knows relationship, where one role is the knower and the other role is known-about.
As Felix Chapman pointed out, role-types are unique, so a true symmetric relation is not possible.
There are a few ways around it; say you have defined your relation as
insert
friendship isa relation-type
has-role friend1
has-role friend2;
The first possibility is to use ako and abstract roles:
friend isa role-type is abstract;
friend1 ako friend;
friend2 ako friend;
person isa entity-type plays-role friend;
The second possibility is using inference rules:
SymmetricFriendship isa inference-rule,
lhs {match (friend1 $x, friend2 $y) isa friendship;
select $x, $y},
rhs {match (friend1 $y, friend2 $x} isa friendship;};
The second way makes the friendship relation a true symmetric relation from a mathematical point of view, but given Graql's match syntax and for performance reasons, there is rarely the need to explicitly make a relation symmetric, so I personally prefer the first way.
You can do something symmetric by adding an entity that models a group of friends:
friendship sub relation,
relates friend,
relates friend-group;
person sub entity,
plays friend;
group sub entity,
plays friend-group;
This does feel like a kludge. The friendship relation effectively just expresses the subset relationship. I have used group instead of pair because now friendship is not binary any more, as I do not know how to restrict the number of friends in a friend-group. Moreover, the same two friends can be part of multiple friendships.
Graql as a modeling language would be more powerful if it would allow specifying variadic relations, e.g. using ranges for the number of role-players for each role. This would cover this use case as well:
friendship sub relation,
relates 2 friend;
You can use the fact that any role can be repeated in a relationship instance:
friendship sub relation,
relates friend;
name sub attribute,
datatype string;
person sub entity,
has name,
plays friend;
Then you can say
insert $x isa Person, has name "X";
insert $y isa Person, has name "Y";
match
$x isa Person, has name "X";
$y isa Person, has name "Y";
insert $xy (friend: $x, friend: $y) isa friendship;
E.g. parent/child is an obvious one, where the parent is the key holder and the child has a reference to that key.
Another example would be as in Entity Framework, "End 1" and "End 2" but this doesn't specify which "end" is the owner of the key.
Perhaps another could be "owning entity" and "referencing entity".
I'm interested to know more examples of this, specifically examples which have a clear "owner" e.g. the entity which defines the start of the relationship, if that makes sense.
I think any combination of Root/Super and Leaf/Child/Offspring/Sub would probably work. I personally like Root/Sub, since it applies regardless of where on the tree you are and isn't Parent/Child.
I've found a question asking about the differences between class inclusion and class inheritance. What exactly does class inclusion mean? I don't think I've hear this term before ..
It's composition. Generally speaking, prefer composition over inheritance. Use inheritance to model only is-a-relationship (Liskov principle), not uses, dependencies or implemented-in-terms-of.
Think about your problem in terms of "is-a" and "has-a" (composition and inheritance). Please take a look at: Is-a and Has-a.
In short terms - if the class/object you're trying to implement "is" an instance of something more general, then it is an example of inheritance i.e.: Apple (derived class) is a Fruit (base class), Porsche is a Car etc.
If your object "has" or "is part of" something, then it is composition. Example: Car has an Engine (object of Engine is included in every Car object), House has Windows and Doors etc.
Whether you should use one or another is a topic for a different type of discussion. In general you want to prefer composition over inheritance as this allows for more flexible code.
Inclusion may have different treatments depending on the context:
InstanceOf/TypeOf relation describe the relationship between an instance and its class. In mathematics, it is membership relation (a member is included in its set). In the relational model, it is how tuples are members of relations.
General-specific relation among classes. In mathematics, it is subset relation which means that all members of a more specific set are also members of its more general set.
Object inclusion in prototype-based programming (like JavaScript). Here an object is included in its prototype object. Note however that it is not inclusion of classes and inheritance is implemented differently.
Concept inclusion in concept-oriented programming where concepts generalize classes and inclusion generalizes inheritance. In particularly, objects can share a super-object precisely as classes can share a super-class.
Composition. It is actually a different relation - not inclusion. Yet, it can be treated as inclusion under this assumption: composition object/class is a more specific element than an element it has. This assumption is one of the features of the concept-oriented model. It is a quite natural assumption which allows us to use composition for inheriting. One its advantage is that a super-object may have many extensions.
Containment relation. It is normally used to describe how instances are included in container objects (like Bad, Set etc.)
Inner classes.
One of the main conceptual differences of all forms of inclusion from inheritance is that inclusion assumes that many elements can be included in one (parent) element at the level of instances. In contrast, the classical inheritance (implicitly) assumes that an object may have only one extension. In other words, a super-object cannot be shared among many extensions.
Note again that it is probably not a complete list and there are significant overlaps between the above treatments as well as some incompatibilities.
I am curious as to why it is possible, with the CriteriaBuilder class of JPA 2, to create such queries. Suppose I have a User class with a persisted String called name as attribute. Why can I write this?
CriteriaBuilder builder = mgr.getCriteriaBuilder();
CriteriaQuery<User> crit = builder.createQuery(User.class);
Root<User> user = crit.from(User.class); // 1
crit.select(user)
.where(builder.equal(user.get(User_.name), 2.5)); // 2
First, at Marker 1: Why must I indicate User.class again? Isn't my CriteriaQuery supposed to know I'm interested in users anyway? Doesn't it break type safety to possibly inject another class here?
Second, at Marker 2: The name property is a String. Why can I compile nonsense like this, comparing a String with a double? In other words, why is the signature of the called equal method this:
public Predicate equal(Expression<?> x, Object y)
instead of a presumably more type safe version as follows?
public <T> Predicate equal(Expression<T> x, T y)
Would other query frameworks like Querydsl provide a better solution to this issue?
I believe the typesafe aspects of the JPA 2 Criteria API were added at a quite late point of the specification process. That's why it doesn't feel consistent.
Querydsl is more concise than the JPA 2 Criteria API and also more typesafe. Querydsl uses fluent builders instead of a factory class for predicate creation, so the equivalent method can be found here http://www.querydsl.com/static/querydsl/2.8.0/apidocs/com/mysema/query/types/expr/SimpleExpression.html#eq%28T%29
I am the maintainer of Querydsl, so this answer is biased.
specific on JPA you can use also Object Query or Torpedo Query(but this is specialized on HQL) that not needs compile time model generation. anyway QueryDsl is one of the first to implement typesafe query