owl:functionalProperty & owl:differentFrom - owl

I'd be grateful for some help on what I'd assumed was a very simple scenario; but being a relative newcomer to OWL and GraphDB I may have made some basic error.
I have a very simple Turtle-specified OWL example as follows:
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix demo: <urn:demo> .
demo:Gender a owl:Class .
demo:Male a demo:Gender .
demo:Female a demo:Gender .
demo:Male owl:differentFrom demo:Female .
demo:Person a owl:Class .
demo:hasGender a owl:ObjectProperty, owl:FunctionalProperty;
rdfs:domain demo:Person;
rdfs:range demo:Gender .
demo:Per1 a demo:Person;
demo:hasGender demo:Male;
demo:hasGender demo:Female .
In essence, I have a class called Gender and assert that there are 2 distinct members Male and Female.
Then I define another class Person with a functional property hasGender whose range is Gender.
Finally I assert an instance of Person, and also two separate assertions that it is both Male and Female.
Now as I understand it this is something of a contradiction; I've asserted that the hasGender property is functional so that, for a given Person, there should be only one gender. I've also asserted that Male and Female are different, so when I import this into GraphDB I was expecting it to fail because of this.
But GraphDB is happy to load both assertions. Have I missed something?

When creating a repository:
select the Check for inconsistencies checkbox;
select the ruleset called OWL2-RL.
If you try to import your data, GraphDB will have to say:
Could not import data; com.ontotext.trree.consistency.ConsistencyException:
Consistency check eq_diff1_1 failed:
urn:demoMale owl:differentFrom urn:demoMale
urn:demoMale owl:sameAs urn:demoMale
Alternatively, unselect the checkbox, import your data and then execute:
PREFIX sys: <http://www.ontotext.com/owlim/system#>
INSERT DATA { [] sys:consistencyCheckAgainstRuleset "owl2-rl" }
Another modelling approach is to create Male and Female as disjoint subclasses of Person.
Unlike owl:FunctionalProperty, owl:AllDisjointClasses is covered by OWL 2 QL.

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!

How assert data property for classes in Protege?

I want to model Person class which takes data property givenName of type xsd:string. How to specify length restriction of this property (say maxLength=50) that is applicable only for Person class? For example, I want to allow other classes to use the same property and choose different value for restriction.
First of all, OWL is not a constraint language. It is intended rather to define classes based on restrictions, than to set up restrictions for classes.
However, one can define anonymous “restriction-based” class and declare another class to be a subclass of this anonymous class.
In the Manchester syntax, you can write something like this:
Class: Person
SubClassOf: givenName only xsd:string[maxLength 5]
In the Functional syntax:
SubClassOf(
:Person
DataAllValuesFrom(
:givenName
DatatypeRestriction(
xsd:string
xsd:maxLength "5"^^xsd:string
)
)
)
In the Turtle syntax:
:Person rdfs:subClassOf
[ rdf:type owl:Restriction ;
owl:onProperty :givenName ;
owl:allValuesFrom
[ rdf:type rdfs:Datatype ;
owl:onDatatype xsd:string ;
owl:withRestrictions ( [ xsd:maxLength "5"^^xsd:string ] )
]
] .
The image below is the "Class description" view in Protégé:
Now suppose you declare that
Individual: He
Types: Person
Facts: givenName "Alexander"^^xsd:string
Then reasoner (e.g. HermiT) have to say that your ontology is inconsistent:

Minimal example for an Inferred Class Hierarchy in OWL

In the ontology editor Protegé there is a tab called Class hierarchy (inferred). I am looking for a minimal example to create such an inferred class, e.g. is it mainly that :RedCar rdfs:subClassOf :Car, and that's all?
:RedCar a owl:Class ;
owl:equivalentClass [ a owl:Class ;
owl:intersectionOf
(
:Car
[ a owl:Restriction ;
owl:onProperty :hasColor ;
owl:hasValue :Red
]
)
] .
There are some possibilies that may produce this behavior. One example is due to general class axioms (see last line of example below).
Human rdf:type owl:Class
Man rdf:type owl:Class
[rdf:type owl:Class ; owl:complementOf Man ; rdfs:subClassOf Human]
You will notice, that in this ontology thing is equivalent to human, if you switch to the inference view.
Other reasons are found in the pizza ontology. If you take a look at VegetableTopping and VegetarianTopping, you will notice that the first one is subsumed by the second one in the inference view, because of the equivalentTo relation on VegetarianTopping. Hope this helps.

cakephp get realpath of view and layout

How can i retrieve absolute path of view and layout file in cakephp action.
I cant find useful method or property in
// in action
var_dump($this);
Thank
desire out put is
/home/sweb/www/cakeapp/app/View/Layout/mylayout.ctp
/home/sweb/www/cakeapp/app/View/Mycntl/myaction.ctp
I would use this to create a full path.
APP . 'View' . DS . 'Layout' . DS . $this->layout
Which will output something like this for you,
string '/Users/david/Sites/ExampleSite/app/View/Layout/default' (length=56)
In order to get the view, I'd use
APP . 'View' . DS . $this->modelClass . DS . $this->view

Computing table name from model name

In my CakePHP application, I have a model like this:
class Duck extends AppModel {
var $name = 'Duck';
function get_table_name() {
$tbl_name = //compute default table name for this model
}
}
I would like to write the function get_table_name() that outputs the default table name for the model. For the example above, it should output ducks.
EDIT:
Several people have pointed out the use of $this->table.
I did small testing and found out the following:
In the question as I have put above, $this->table indeed contains the table name.
However, actually, my code looked more like this:
class Duck extends Bird {
var $name = 'Duck';
function get_table_name(){
$tbl_name = //comput default table name for this model
}
}
class Bird extends AppModel {
}
In this case $this->table is empty string.
I went with this approach because I wanted to share some code between two of my models. Looks like this is not a good way to share code between models which need some common functionality.
You're looking for the Inflector class.
Inflector::tableize($this->name)
(tableize calls two Inflector methods to generate the table name: underscore() and pluralize())
Edit:
According to the source code, $this->table should contain the name of the table that CakePHP will use for the model, but in my experience this isn't always set. I'm not sure why.
To get the name of the table that the model is currently using, you can use: $this->table. If you don't manually change the model's table conventions, this may be the most useful in the case of CakePHP ever changing its conventions to use table names using something other than Inflector.
CakePHP's Inflector
function get_table_name() {
$tbl_name = Inflector::pluralize($this->name);
}
OR the tableize method
function get_table_name() {
$tbl_name = Inflector::tableize($this->name);
}
Edit
This also addresses the apparent "ghost" issue with $this->table in the Model.
Digging around in the __construct for Model I discovered two things:
Cake uses Inflector::tableize() to get the table name. This alone is enough to warrant using tableize over pluralize. You'll get consistent results.
$this->table is not set by the Model::__construct() unless $this->useTable === false AND $this->table === false.
It appears that if you know you haven't set $this->useTable to false you should be able to use this over $this->table. Admittedly though I only briefly scanned the source and I haven't really dug deep enough to say why $this->table isn't working sometimes.
To get the full table name for a model you have to take the table prefix into account.
$table = empty($this->table) ? Inflector::tableize($this->name) : $this->table;
$fullTableName = $this->tablePrefix . $table;
I used to use inflector to get the table name from model's name
$tableName = Inflector::pluralize(Inflector::underscore($model));
but this is not really universal, using useTable looks better, by default it will contain table's name by convention, and if you have a table that does not match the conventions, then you should manually specify it by useTable. So, in both cases the result will be correct
$this->User->useTable

Resources