I'm trying to do a query with a cardinality restriction. The query looks like
ClassA and (roleA min 2 ClassB)
but this returns an empty set. On the other hand when I do the query
ClassA and (roleA some ClassB)
it returns some individuals of ClassA. Why does the cardinality query not work when I know there are definitely a least two roleAs on some ClassA individuals?
To be more specific, I have the classes Team, Player and Position, and object properties employs (which relates Teams and Players), and hasPosition (which relates Players and Positions). I'm trying to do the query
Team and employs min 2 (Player and hasPosition some { Striker**}**)
which should return the teams with two or more Strikers but obviously because OWL doesn't make the unique name assumption it returns an empty set. I have tried to declare that some of my individuals are distinct, but when I execute the query with the distinct individuals in place it causes Protégé to crash. Protégé does not crash when running the query without the distinct individuals.
Edit:
Error Message from Pellet in Protege
Striker shown in Ontology XML
There's not enough information in this question yet to determine why you're not getting the results that you're looking for, but we can reproduce the scenario well enough to show that this achievable. Consider an ontology with three classes and some individuals:
Player {p1, p2}
Team {team1}
Position {Striker}
and the axioms
p1 ≠ p2
team1 employs p1
team1 employs p2
p1 hasPosition Striker
p2 hasPosition Striker
Then the query
Team and employs min 2 (Player and hasPosition value Striker)
returns the individual team1. (This works with “hasPosition some {Striker}”, too, but for just one value, I think that the value keyword is a better fit.)
Here's the ontology:
#prefix : <http://stackoverflow.com/q/22688901/1281433/competitions#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://stackoverflow.com/q/22688901/1281433/competitions>
a owl:Ontology .
:Player a owl:Class .
:Position a owl:Class .
:Team a owl:Class .
:hasPosition a owl:ObjectProperty .
:Striker a owl:NamedIndividual , :Position .
:p1 a owl:NamedIndividual , :Player ;
:hasPosition :Striker .
:p2 a owl:NamedIndividual , :Player ;
:hasPosition :Striker .
[ a owl:AllDifferent ;
owl:distinctMembers ( :p1 :p2 )
] .
:team1 a owl:NamedIndividual , :Team ;
:employs :p1 , :p2 .
Related
I'm working on a project that tries to map DBpedia concepts to table data columns. Specifically I wanted to map literal(numerical values; float, int..). Therefore I need adequate number of data to build a background knowledge base. I extract some data from T2D-golden-dataset as the given format at the end of this description. Actually I should use them as a bench mark for testing and it only contains less than 20 columns from overall tables. Could anyone help me to find such a literal valued and dbpedia annotated dataset ?
Literal valued dbpedia ranges;
"http://www.w3.org/2001/XMLSchema#float"
"http://www.w3.org/2001/XMLSchema#integer"
"http://www.w3.org/2001/XMLSchema#positiveInteger"
"http://www.w3.org/2001/XMLSchema#integer"
Some properties having these ranges;
"http://dbpedia.org/ontology/speaker",
"http://dbpedia.org/ontology/ranking",
"http://dbpedia.org/ontology/humanDevelopmentIndex",
"http://dbpedia.org/ontology/numberOfPlatformLevels",
"http://dbpedia.org/ontology/enginePower",
"http://dbpedia.org/ontology/graySubject",
"http://dbpedia.org/ontology/shareOfAudience",
"http://dbpedia.org/ontology/percentageLiteracyWomen",.........
Sample examples I need to found or somehow generate is an array corresponding to concepts given above. For an example;
"http://dbpedia.org/ontology/enginePower" : ["220", "125", "1300",....],
"http://dbpedia.org/ontology/humanDevelopmentIndex" : ["0.34", "0.78", "0.98", ...]
I don't need that exact format. It would be great If I can find enough number of data tables given as T2D golden dataset for dbpedia.
This query starts you down the road, as it gets you 100 typed literal values for <http://dbpedia.org/ontology/populationTotal>, which are all typed as <http://www.w3.org/2001/XMLSchema#nonNegativeInteger> --
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?value
WHERE
{ ?subject dbo:populationTotal ?value }
LIMIT 100
This rather more complex (and expensive) query gets you something like the end result I think you want -- but you will need to run it a number of times, for a few predicates at a time, to get everything you're asking for from the public endpoint. If needed, you could spin up your own DBpedia mirror instance in the AWS cloud, and adjust Virtuoso's timeouts and other limits, in order to build and run one query that would deliver one giant result set.
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT # DISTINCT ?predicate ?value ?value_type ?value_str
?predicate ?value_type ( GROUP_CONCAT ( DISTINCT ?value_str ; separator=", " ) AS ?values )
WHERE
{ ?subject ?predicate ?value
VALUES ( ?predicate ) { ( dbo:numberOfPlatformLevels )
( dbo:shareOfAudience )
( dbo:populationTotal )
}
BIND ( DATATYPE ( ?value ) AS ?value_type )
BIND ( STR ( ?value ) AS ?value_str )
}
GROUP BY ?predicate ?value_type
ORDER BY ?predicate ?value_type
LIMIT 1000
I'm trying to run the following SPARQL query in Protege 4.3 (on Pizza.owl), but I get an empty result:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT ?pizzaInstance ?pizzaClass ?toppingInstance
WHERE {
?pizzaClass rdfs:subClassOf :NamedPizza .
?pizzaInstance rdf:type ?pizzaClass .
?pizzaInstance :hasTopping ?toppingInstance .
}
This only happens when I run queries involving properties.
With the same prefixes the following query works - and returns NamedPizza:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT ?pizzaInstance
WHERE {
?pizzaInstance rdfs:subClassOf :Pizza .
}
What is wrong with the first query?
I finally understood what I was doing wrong. This query returns individuals for pizzaInstance, and none of the individuals in my ontology had a topping. When I queried for hasCalorificContentValue instead of hasTopping I got the desired results:
PREFIX pz: <http://www.semanticweb.org/ontologies/2017/11/Ontology1512823737278.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?pizzaClass ?pizzaInstance ?calorificInstance
WHERE {
?pizzaClass rdfs:subClassOf pz:NamedPizza .
?pizzaInstance rdf:type ?pizzaClass.
?pizzaInstance pz:hasCalorificContentValue ?calorificInstance.
}
The query becomes meaningful when you check the raw owl file (Example-MargheritaPizza is of type MargheritaPizza and is involved in the datatype property hasCalorificValue):
<owl:NamedIndividual rdf:about="&Ontology1512823737278;Example-MargheritaPizza">
<rdf:type rdf:resource="&Ontology1512823737278;MargheritaPizza"/>
<hasCalorificContentValue rdf:datatype="&xsd;int">263</hasCalorificContentValue>
</owl:NamedIndividual>
Here is a good tutorial, hope this helps someone.
How to export data from ontology to an excel sheet using Protege.
For example, I want to get a table with 2 columns:
Class rdf:ID, Super Class rdf:ID.
solved!..
From the tap SPARQL Query
type the query:
SELECT ?subject ?object
WHERE { ?subject rdfs:subClassOf ?object }
then execute and copy the result directly into an excel sheet :)
I'm looking at a section of "A Guide to the SQL Standard" (C.J.Date/Hugh Darwen) concerning LEFT JOIN and it gives the following syntax:
table-reference [ NATURAL ] outer-join-type
JOIN table-reference
[ ON conditional-expression
| USING ( column-commalist ) ]
What is USING?
Is it useful?
Is it implemented in SQL-Server?
No, it's not supported by SQL Server, see FROM:
<joined_table> ::=
{
<table_source> <join_type> <table_source> ON <search_condition>
| <table_source> CROSS JOIN <table_source>
| left_table_source { CROSS | OUTER } APPLY right_table_source
| [ ( ] <joined_table> [ ) ]
}
As to what it is? It's a way of performing a join between two tables where the column names in both tables exactly match, and as a convenience, it allows you to name the columns only once. Compare that to using ON to achieve the same:
ON
table1.columnA = table2.columnA AND
table1.columnB = table2.columnB AND
table1.columnC = table2.columnC
with USING it's just:
USING (columnA,columnB,columnC)
No, the USING clause for joins isn't supported in SQL Server (or Sybase). You'll need to continue to use ON clauses.
There's a request on MSDN connect to have it implemented here - but as it was suggested in 2006 and not implemented yet, I wouldn't hold your breath!
I'm trying to use the HermiT reasoner to compute inferences for an ontology which contains a set of OWL axioms and a SWRL rule:
Ontology(
ClassAssertion( :Student :Bob )
ClassAssertion( :Professor :DrBoffin )
ClassAssertion( :University :UF )
ObjectPropertyAssertion( :supervises :DrBoffin :Bob )
ObjectPropertyAssertion( :worksAt :DrBoffin :UF )
EquivalentClasses( :Student ObjectHasSelf( :r1 ))
EquivalentClasses(
ObjectHasSelf( :r2 )
ObjectSomeValuesFrom( :worksAt :University ))
SubObjectPropertyOf(
ObjectPropertyChain( :r2 :supervises :r1 ) :professorOf )
DLSafeRule(Body(ObjectPropertyAtom( :professorOf Variable( ?x ) Variable( ?y )))
Head(ObjectPropertyAtom( :instructorOf Variable( ?x ) Variable( ?y ))))
)
Basically, the OWL part is trying to express such a rule:
worksAt(x, y), University(y), supervises(x, z), Student(z) -> professorOf(x, z)
using property chain and rolification techniques:
The SWRL part is:
professorOf(x, y) -> instructorOf(x, y)
The expected output should contain both ObjectPropertyAssertion( :professorOf :DrBoffin :Bob ) and ObjectPropertyAssertion( :instructorOf :DrBoffin :Bob ). However, the actual output is (showing only object properties)
ObjectPropertyAssertion( :r1 :Bob :Bob )
ObjectPropertyAssertion( :professorOf :DrBoffin :Bob )
ObjectPropertyAssertion( :r2 :DrBoffin :DrBoffin )
ObjectPropertyAssertion( :supervises :DrBoffin :Bob )
ObjectPropertyAssertion( :worksAt :DrBoffin :UF)
Why isn't the expected SWRL result showing up? Any suggestions?
After re-reading your question, I realized that the rule you are trying to represent is
worksAt(x, y), University(y), supervises(x, z), Student(z) → professorOf(x, z)
but that you are trying to represent it, essentially by
(worksAt some University)(x), supervises(x, z), Student(z) → professorOf(x, z)
which is actually a valid SWRL rule, even though it has a complex class expression. (See Can OWL Class Expressions be used in SWRL Rules? for more information. Even though they're valid, the Protégé editor didn't accept that input, though it would display rules correctly if they are already in the ontology.)
Although it can be expressed in SWRL, that will only cover cases where the individuals are named, so the rolification based solution will cover more cases. So, the idea is to create a role rWorksAtSomeUniversity (the rolification of worksAt some University) and a role rStudent (the rolification of Student, and then to assert that
rWorksAtSomeUniversity o supervises o rStudent SubPropertyOf professorOf
Then, to relate professorOf and instructorOf, you can either use a SWRL rule
professorOf(x,y) → instructorOf(x,y)
or a subproperty axiom
professorOf SubPropertyOf instructorOf
As with rolification-based rule, the non-SWRL rule will cover more cases, and does not require that the reasoner have SWRL support.
Here's an ontology that contains these classes and axioms, in the OWL functional syntax. It's not wonderfully human readable, but it's complete; you should be able to download it and test it out with your reasoner.
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(ex:=<http://www.example.com/university#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://www.example.com/university>
Declaration(Class(ex:Professor))
Declaration(Class(ex:Student))
EquivalentClasses(ex:Student ObjectHasSelf(ex:rStudent))
Declaration(Class(ex:University))
Declaration(ObjectProperty(ex:instructorOf))
Declaration(ObjectProperty(ex:professorOf))
SubObjectPropertyOf(ex:professorOf ex:instructorOf)
Declaration(ObjectProperty(ex:rStudent))
Declaration(ObjectProperty(ex:rWorksAtSomeUniversity))
Declaration(ObjectProperty(ex:supervises))
Declaration(ObjectProperty(ex:worksAt))
Declaration(NamedIndividual(ex:Bob))
ClassAssertion(ex:Student ex:Bob)
Declaration(NamedIndividual(ex:DrBoffin))
ClassAssertion(ex:Professor ex:DrBoffin)
ObjectPropertyAssertion(ex:supervises ex:DrBoffin ex:Bob)
ObjectPropertyAssertion(ex:worksAt ex:DrBoffin ex:UF)
Declaration(NamedIndividual(ex:UF))
ClassAssertion(ex:University ex:UF)
EquivalentClasses(ObjectHasSelf(ex:rWorksAtSomeUniversity) ObjectSomeValuesFrom(ex:worksAt ex:University))
SubObjectPropertyOf(ObjectPropertyChain(ex:rWorksAtSomeUniversity ex:supervises ex:rStudent) ex:professorOf)
)
Both Pellet and HermiT 1.3.7 can produce the inferences:
DrBoffin professorOf Bob
DrBoffin instructorOf Bob