How to reuse a list in OWL? - owl

Let's say I'm defining a class Alcohol:
:Alcohol rdf:type owl:Class ;
owl:equivalentClass [
rdf:type owl:Class ;
owl:oneOf ( :Vodka :Champagne :Bourbon :Tequila :Whiskey ) ] .
But I want members to be distinct:
[ rdf:type owl:AllDifferent ;
owl:distinctMembers ( :Bourbon :Vodka :Champagne :Whiskey :Tequila ) ] .
How can I write those two statements without repeating the list?
Thanks.

As mentioned in the comment, use blank node reference:
:Alcohol a owl:Class ;
owl:equivalentClass [ a owl:Class ;
owl:oneOf _:b0 ] .
[ a owl:AllDifferent ;
owl:distinctMembers _:b0 ] .
_:b0 rdf:first :Vodka ;
rdf:rest ( :Champagne :Bourbon :Tequila :Whiskey ) .

Related

Creating New Classes and Individuals with SWRL in Protege

I've been trying to write SWRL rules that automate creation of new entities and their assignment to classes and predicates in a Protege ontology. The code here didn't result in creation of even one individual, neither did the example in the readme work.
For clarity, here is the rule I'm trying to make work:
Person(?person) ^ hasSSN(?person, ?ssn) ^ swrlx:makeOWLThing(?patient, ?person) -> Patient(?patient) ^ hasPID(?patient, ?ssn)
In this ontology:
#prefix : <http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix xml: <http://www.w3.org/XML/1998/namespace> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#base <http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48> .
<http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48> rdf:type owl:Ontology .
#################################################################
# Annotation properties
#################################################################
### http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled
<http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> rdf:type owl:AnnotationProperty .
#################################################################
# Data properties
#################################################################
### http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#hasPID
:hasPID rdf:type owl:DatatypeProperty .
### http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#hasSSN
:hasSSN rdf:type owl:DatatypeProperty .
#################################################################
# Classes
#################################################################
### http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#Patient
:Patient rdf:type owl:Class .
### http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#Person
:Person rdf:type owl:Class .
#################################################################
# Individuals
#################################################################
### http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#person1
:person1 rdf:type owl:NamedIndividual ,
:Person ;
:hasSSN 1001 .
### http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#person2
:person2 rdf:type owl:NamedIndividual ,
:Person ;
:hasSSN 1002 .
### http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#person3
:person3 rdf:type owl:NamedIndividual ,
:Person ;
:hasSSN 1003 .
#################################################################
# Rules
#################################################################
:person rdf:type <http://www.w3.org/2003/11/swrl#Variable> .
:ssn rdf:type <http://www.w3.org/2003/11/swrl#Variable> .
:patient rdf:type <http://www.w3.org/2003/11/swrl#Variable> .
[ <http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> "true"^^xsd:boolean ;
rdfs:comment "Patient For Every Person With PID Equal To SSN"^^xsd:string ;
rdfs:label "PatientForEveryPersonWithPIDEqualToSSN"^^xsd:string ;
rdf:type <http://www.w3.org/2003/11/swrl#Imp> ;
<http://www.w3.org/2003/11/swrl#body> [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#ClassAtom> ;
<http://www.w3.org/2003/11/swrl#classPredicate> :Person ;
<http://www.w3.org/2003/11/swrl#argument1> :person
] ;
rdf:rest [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#DatavaluedPropertyAtom> ;
<http://www.w3.org/2003/11/swrl#propertyPredicate> :hasSSN ;
<http://www.w3.org/2003/11/swrl#argument1> :person ;
<http://www.w3.org/2003/11/swrl#argument2> :ssn
] ;
rdf:rest [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#BuiltinAtom> ;
<http://www.w3.org/2003/11/swrl#builtin> <http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl#makeOWLThing> ;
<http://www.w3.org/2003/11/swrl#arguments> ( :patient
:person
)
] ;
rdf:rest rdf:nil
]
]
] ;
<http://www.w3.org/2003/11/swrl#head> [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#ClassAtom> ;
<http://www.w3.org/2003/11/swrl#classPredicate> :Patient ;
<http://www.w3.org/2003/11/swrl#argument1> :patient
] ;
rdf:rest [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#DatavaluedPropertyAtom> ;
<http://www.w3.org/2003/11/swrl#propertyPredicate> :hasPID ;
<http://www.w3.org/2003/11/swrl#argument1> :patient ;
<http://www.w3.org/2003/11/swrl#argument2> :ssn
] ;
rdf:rest rdf:nil
]
]
] .
### Generated by the OWL API (version 4.2.8.20170104-2310) https://github.com/owlcs/owlapi
Pellet doesn't support SWRLX:
WARNING: Ignoring rule Rule([Person(?person), hasSSN(?person,?ssn), makeOWLThing([?patient, ?person])] => [Patient(?patient), hasPID(?patient,?ssn)]):
No builtin for http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl#makeOWLThing
However, you can use Drools translation. On the SWRLTab, press:
OWL+SWRL -> Drools
Run Drools
Drools -> OWL
This is what was generated (in the Turtle syntax):
#prefix p1: <http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#> .
#prefix p2: <http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48##> .
# ...
p2:d5d68a85_03f9_4a69_8c07_9f1a57ffe7aa rdf:type owl:NamedIndividual, p1:Patient ;
p1:hasPID 1003 .
p2:c8c3_3ad6_4c49_b9f6_940f711e8d5f rdf:type owl:NamedIndividual, p1:Patient ;
p1:hasPID 1002 .
p2:c2038_2adb_4d12_b3ee_326cc45ffa2b rdf:type owl:NamedIndividual, p1:Patient ;
p1:hasPID 1001 .
Please note double ## in the generated URIs.

How to Infer such "indirect" assertion with OWL or SWRL?

Knowledge
lawn is wet today if it rained last night
Fact
we found lawn was wet this morning
Infer
it rained last night
is this belong to SWRL?
what should i read or check to easily understand these ?
I've figured it out, i paste a turtle syntax file.
To do this we have to make some Object (Predict) Properties.
hasFact
previousDay
nextDay (inverseOf previousDay)
Then add some Individuals like :
URIs:
wet, rain, today, yesterday
assert today previousDay yesterday and today hasFact wet, next go to swrl tab add this rule.
hasFact(?today, wet) ^ previousDay(?today, ?yesterday) -> hasFact(?yesterday, rain)
Start REASONING it will work.
#prefix : <http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix xml: <http://www.w3.org/XML/1998/namespace> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#base <http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31> .
<http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31> rdf:type owl:Ontology .
#################################################################
# Annotation properties
#################################################################
### http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled
<http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> rdf:type owl:AnnotationProperty .
#################################################################
# Object Properties
#################################################################
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#hasFact
:hasFact rdf:type owl:ObjectProperty .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#nextDay
:nextDay rdf:type owl:ObjectProperty ;
owl:inverseOf :previousDay .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#previousDay
:previousDay rdf:type owl:ObjectProperty .
#################################################################
# Data properties
#################################################################
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#hasValue
:hasValue rdf:type owl:DatatypeProperty ;
rdfs:range [ rdf:type rdfs:Datatype ;
owl:oneOf [ rdf:type rdf:List ;
rdf:first "rain" ;
rdf:rest [ rdf:type rdf:List ;
rdf:first "wet" ;
rdf:rest rdf:nil
]
]
] .
#################################################################
# Classes
#################################################################
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#Day
:Day rdf:type owl:Class .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#ItRainsLastNight
:ItRainsLastNight rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Restriction ;
owl:onProperty :previousDay ;
owl:someValuesFrom [ rdf:type owl:Restriction ;
owl:onProperty :hasFact ;
owl:hasValue :rain
]
] ;
rdfs:subClassOf :Phenomenon .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#Phenomenon
:Phenomenon rdf:type owl:Class .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#Today
:Today rdf:type owl:Class ;
rdfs:subClassOf :Day .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#Weather
:Weather rdf:type owl:Class .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#Yesterday
:Yesterday rdf:type owl:Class ;
rdfs:subClassOf :Day .
#################################################################
# Individuals
#################################################################
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#rain
:rain rdf:type owl:NamedIndividual ,
:Weather ;
:hasValue "rain"^^xsd:string .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#today2018614
:today2018614 rdf:type owl:NamedIndividual ,
:Today ;
:hasFact :wet ;
:previousDay :yesterday2018613 .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#wet
:wet rdf:type owl:NamedIndividual ,
:Phenomenon ;
:hasValue "wet"^^xsd:string .
### http://www.semanticweb.org/monsterstep/ontologies/2018/5/untitled-ontology-31#yesterday2018613
:yesterday2018613 rdf:type owl:NamedIndividual ,
:Yesterday .
#################################################################
# Rules
#################################################################
<today> rdf:type <http://www.w3.org/2003/11/swrl#Variable> .
<yesterday> rdf:type <http://www.w3.org/2003/11/swrl#Variable> .
[ <http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> "true"^^xsd:boolean ;
rdfs:comment ""^^xsd:string ;
rdfs:label "ItRainsLastNight"^^xsd:string ;
rdf:type <http://www.w3.org/2003/11/swrl#Imp> ;
<http://www.w3.org/2003/11/swrl#body> [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#IndividualPropertyAtom> ;
<http://www.w3.org/2003/11/swrl#propertyPredicate> :hasFact ;
<http://www.w3.org/2003/11/swrl#argument1> <today> ;
<http://www.w3.org/2003/11/swrl#argument2> :wet
] ;
rdf:rest [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#IndividualPropertyAtom> ;
<http://www.w3.org/2003/11/swrl#propertyPredicate> :previousDay ;
<http://www.w3.org/2003/11/swrl#argument1> <today> ;
<http://www.w3.org/2003/11/swrl#argument2> <yesterday>
] ;
rdf:rest rdf:nil
]
] ;
<http://www.w3.org/2003/11/swrl#head> [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#IndividualPropertyAtom> ;
<http://www.w3.org/2003/11/swrl#propertyPredicate> :hasFact ;
<http://www.w3.org/2003/11/swrl#argument1> <yesterday> ;
<http://www.w3.org/2003/11/swrl#argument2> :rain
] ;
rdf:rest rdf:nil
]
] .
### Generated by the OWL API (version 4.2.8.20170104-2310) https://github.com/owlcs/owlapi

owl closing the world with OneOf

In the following Ontology I'm trying to make Boy the complement of Girl by using OneOf however using Fact++ or Hermit I'm unable to get any instances by querying for Boy (Protege 5.2 DL query), any suggestions?
:Bob rdf:type owl:NamedIndividual ,
:Person .
:Mike rdf:type owl:NamedIndividual ,
owl:Thing .
:Sarah rdf:type owl:NamedIndividual ,
:Girl.
:Person rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:oneOf ( :Bob
:Mike
:Sarah
)
] .
:Girl rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:oneOf ( :Sarah
)
] ;
rdfs:subClassOf :Person .
:Boy rdf:type owl:Class ;
owl:equivalentClass [ owl:intersectionOf ( :Person
[ rdf:type owl:Class ;
owl:complementOf :Girl
]
) ;
rdf:type owl:Class
] ;
rdfs:subClassOf :Person ;
owl:disjointWith :Girl .
Adding an axiom to make all individuals as different solves the problem as suggested by Stanislav:
[ rdf:type owl:AllDifferent ;
owl:distinctMembers ( :Bob
:Mike
:Sarah
)
] .
See https://en.wikipedia.org/wiki/Unique_name_assumption

Update Data into table from another table using SSIS package

How to update data from one table to another table where A common column value matched (both tables are on different server) , Can we design a SSIS package for such case ?
You can link the server using
exec sp_addlinkedserver [ #server= ] 'server' [ , [ #srvproduct= ] 'product_name' ]
[ , [ #provider= ] 'provider_name' ]
[ , [ #datasrc= ] 'data_source' ]
[ , [ #location= ] 'location' ]
[ , [ #provstr= ] 'provider_string' ]
[ , [ #catalog= ] 'catalog' ]
http://msdn.microsoft.com/en-us/library/ms190479.aspx
and then
select * from [server].[database].[schema].[table]

Add sp parameter sql server without modifying the stored procedure request

I have a sample stored procedure named SPExample .
I want to add a parameter named TestParam to this stored procedure without using this syntax
Alter PROCEDURE SPExample
#TestParamint
AS
BEGIN
...
END
Is there a syntax like: Alter PROCEDURE SPExample Add parameter ... or any other alternative?
Short answer:
NO you can not
Detailed answer:
Alter procedure has 3 different syntax as below:
SQL Server Syntax:
ALTER { PROC | PROCEDURE } [schema_name.] procedure_name [ ; number ]
[ { #parameter [ type_schema_name. ] data_type }
[ VARYING ] [ = default ] [ OUT | OUTPUT ] [READONLY]
] [ ,...n ]
[ WITH <procedure_option> [ ,...n ] ]
[ FOR REPLICATION ]
AS { [ BEGIN ] sql_statement [;] [ ...n ] [ END ] }
[;]
<procedure_option> ::=
[ ENCRYPTION ]
[ RECOMPILE ]
[ EXECUTE AS Clause ]
SQL Server CLR Stored Procedure Syntax:
ALTER { PROC | PROCEDURE } [schema_name.] procedure_name [ ; number ]
[ { #parameter [ type_schema_name. ] data_type }
[ = default ] [ OUT | OUTPUT ] [READONLY]
] [ ,...n ]
[ WITH EXECUTE AS Clause ]
AS { EXTERNAL NAME assembly_name.class_name.method_name }
[;]
Azure SQL Database Syntax:
ALTER { PROC | PROCEDURE } [schema_name.] procedure_name
[ { #parameter [type_schema_name. ] data_type }
[ VARYING ] [= default ] [ [ OUT [ PUT ]
] [,...n ]
[ WITH <procedure_option> [ , ...n ] ]
[ FOR REPLICATION ]
AS
{ <sql_statement> [...n ] }
[;]
<procedure_option> ::=
[ ENCRYPTION ]
[ RECOMPILE ]
[ EXECUTE_AS_Clause ]
<sql_statement> ::=
{ [ BEGIN ] statements [ END ] }
Note that in all 3 syntaxes above, sql_statement is one of the mandatory parts of the syntax. Parts inside [ and ] are optional, Read more about Transact-SQL Syntax Conventions here: https://msdn.microsoft.com/en-us/library/ms177563.aspx
As you see in the above syntaxes there is not any syntax like one you requested.
Read more here: https://msdn.microsoft.com/en-us/library/ms189762.aspx
You cant add parameter with out altering stored proc. A closer option would be to use Default Parameters in case if you dont want to edit your stored procedure when you want to add new Parameter..
this goes something like this..
create proc usp_test
(
#param1 int=4,
#param2 int =null,
#param3 int =null
)
as
Begin
END
Those parameters with null wont be having any impact

Resources