how to model a transitive relation through two properties? - owl

My question is similar to the question
https://stackoverflow.com/questions/69979542/how-can-i-model-a-transitive-relationship-spanning-multiple-classes-in-protégé ,
but I think different and interesting enough to warrant its own question.
The common example of a transitive property relation:
P(x,y) and P(y,z) => P(x,z)
Mom hasAncestor Grandma and Magda hasAncestor Mom => Magda hasAncestor Grandma
Our model has many relations like this:
P1(x,y) and P2(y,z) => P2(x,z)
Magda hasWorkRole Program Manager and Program Manager hasTask T0220 => Magda hasTask T0220
Is there already a known term for this type of relation? (seems pretty common)
Is there a way to model this in OWL?

Related

How can I query Object Properties in an OWL ontology

I am working with the FoodOn ontology and need to figure out if a certain class is somehow related to another class. Typical use case: Can a vegan person eat honey? No, because honey is a subsub class of "invertebrate animal food product"!
I am using the python owlready2 library which allows me to run SPARQL queries and query subclass relations like this:
SELECT ?class
WHERE
{
# honey
<http://purl.obolibrary.org/obo/UBERON_0036016> rdfs:subClassOf* ?class .
# animal food product
?class rdfs:subClassOf* <http://purl.obolibrary.org/obo/FOODON_00001176>
}
This code gives me the full subclass path between honey and animal food product - great.
My problem is, that the relationship is not always that of a subclass. Let's look at "vegetarian food product" using the Protege editor:
We can see that "vegetarian food product" is a subclass of "food product by organism" but at the same time it is also equivalent to 'food product'
and (not ('derives from' some
('invertebrate animal' or 'vertebrate animal'))).
If I look at all triples using SPARQL I get the subclass relationship but the equivalentClass is just a bnode:
(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#subClassOf'),
rdflib.term.URIRef('http://purl.obolibrary.org/obo/FOODON_00002381')),
(rdflib.term.URIRef('http://www.w3.org/2002/07/owl#equivalentClass'),
rdflib.term.BNode('5846'))
[stripped some output]
Why does SPARQL not return all relationships?
How can I query for all classes that are either a subclass of 'vegetarian food product' or related to it by some other object property?
Also, how can I query for the 'AND' and 'OR' component in the example above?
I do accept non-python solutions as long as it can be automated. Protege has a DL Query tab but I think that I cannot export the results using the UI...
Thank you!

Abp One to many Relationship

I have Book and Author Entity.
I tried to establish a relationship between Book and Author, but the AuthorId key did not appear. I wonder how it is done.
enter image description here
First of all, I think you are looking at the tutorials part of the ABP framework document. If you haven't looked, I think you should look at this.
As explained in the document, you can do this as follows:
Open the BookStoreDbContextModelCreatingExtensions class under the EntityFrameworkCore folder of the Acme.BookStore.EntityFrameworkCore project and change the builder.Entity part as shown below
builder.Entity<Book>(b =>
{
b.ToTable(BookStoreConsts.DbTablePrefix + "Books", BookStoreConsts.DbSchema);
b.ConfigureByConvention(); //auto configure for the base class props
b.Property(x => x.Name).IsRequired().HasMaxLength(128);
// ADD THE MAPPING FOR THE RELATION
b.HasOne<Author>().WithMany().HasForeignKey(x => x.AuthorId).IsRequired();
});

CakePHP3 associated entities not coming through from find() (or get) even with contain clause

[edit] solved, see: https://stackoverflow.com/a/32638610/221650
Some associated data is not coming through, although it's in the contain clause.
I can get $project->Participants if I set a belongsToMany relationship in the Projects table, relating to Participants through ProjectParticipants, but that way I still can't reach other tables associated with ProjectParticipants even with $project->participants->_joinData->other_related_table
How would I do to get ProjectParticipants and Participants with the same query?
Code:
// Database: Projects <--1:N-- ProjectParticipants --M:1--> Participants
// ProjectController:
$project = $this->Projects->get($id, ['contain'=>[
'ProjectParticipants.Participants']);
// ProjectsTable:
$this->hasMany('ProjectParticipants', [
'foreignKey' => 'project_id']);
// ProjectParticipantsTable:
$this->belongsTo('Participants', [
'foreignKey' => 'participant_id']);
It's a very complicated many to many relationship.
//projectTable
$this->belongsToMany('Participants');
//praticipantsTable
$this->belongsToMany('Projects');
It's well explained in the Bookmark Tutorial.
Sorry, it's working fine, I hadn't noticed there was a custom Entity\Project::_getParticipants() that was returning a Collection.
A simple debug on that object showed everything alright, but then when running it through a foreach, the associations disappeared.

Joining 3 tables in Cakephp

Using Cakephp 2.5.3 ... I have the following tables:
transactions (belongs to methods and deliveries)
id
delivery_id
method_id
methods (has many transactions)
id
name
deliveries (has many transactions)
id
date
In my delivery view I would like to see the method name for each delivery.
foreach ($deliveries as $delivery) {
echo $method['name'];
}
( a similar unanswered question is
here:)
I am (obv.) very new to Cakephp, What approach should I take to go about this? Thanks!
=========UPDATE==============
I ended up adding methods to the deliveries controller
$this->set('methods', $this->Method->find('all', array('recursive' => -1)));
And looped through the methods in my (read only) view :
//filtered method array for
$method['id'] == $delivery['Transaction']['0']['method_id'])
// got method name
$button_text = $method['name'];
It works fine but can anyone tell me if this may cause problems for me down the line?
use has many assotiations in Transaction model as -
public $hasMny = array('Method', 'Delivery');
then fetch them -
$this->set(
'methods',
$this->Method->find('all', array('contain' => array('Method', 'Delivery')))
);
you will get all the related result together.

Cakephp Multiple Relations to the Same Model

I'm working on a real estate application, where one Home can be listed by either one or two Realtors. As such, I'm trying to follow the example given in section 3.7.6.7 of the Cake Cookbook. Here's what's going on in my Realtors model:
class Realtor extends AppModel {
var $primaryKey = $num;
var $name = 'Realtor';
var $hasMany = array('Homes' =>
array('className' => 'Home',
'foreignKey' => 'realtor_num',
...),
'CoListedHomes' =>
array('className' => 'Home',
'foreignKey' => 'realtor2_num',
...)
);
This completely breaks the application, with the error message "Database table co_listed_homes for model CoListedHomes was not found."
Referring back to the Cookbook 3.7.6.7, second example, it seems clear that they shouldn't have or need separate "messages_received" and "messages_sent" tables in their database, so what is it that I'm doing wrong?
ETA: Weirdly (to me) I think I got the relationships to work by swapping around the order of the arrays: the first array, on foreignKey = realtor2_num, is called 'ListedHomes', the second array, on foreignKey = realtor_num is called 'Home'. I suppose my question then is, why should the order matter, and why should Cake started talking about unfound database tables in some circumstances?
Just in case, I'd have built this as a categories setup. Then created a join table between Category and Home.
Then you can have a hasAndBelongsToMany beween both categories and homes
"Database table co_listed_homes for model CoListedHomes was not found" probably refers to you not having a model defined for CoListedHomes that points to the homes table.
I would, however, code this as a n:m otherwise known as hasAndBelongsToMany, as stated by DavidYell.

Resources