Shacl sh:qualifiedValueShape expression abbreviation - shacl

Let say that i am trying to express that a Binding must have exactly 1 partner that is a FunctionalClass and exactly 1 partner that is Protein.
I wonder if this is enough
resnet:Binding
rdf:type owl:Class ;
rdf:type sh:NodeShape ;
rdfs:label "Binding" ;
rdfs:subClassOf owl:Thing ;
sh:property [
sh:path resnet:partner ;
sh:NodeKind sh:IRI ;
sh:qualifiedMaxCount 1 ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class resnet:FunctionalClass ;
] ;
] ;
sh:property [
sh:path resnet:partner ;
sh:NodeKind sh:IRI ;
sh:qualifiedMaxCount 1 ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class resnet:Protein ;
] ;
] ;
.
Or do i need the full ceremony
resnet:Binding
rdf:type owl:Class ;
rdf:type sh:NodeShape ;
rdfs:label "Binding" ;
rdfs:subClassOf owl:Thing ;
sh:property [
sh:path resnet:partner ;
sh:minCount 2 ;
sh:maxCount 2 ;
] ;
sh:property [
sh:path resnet:partner ;
sh:qualifiedMaxCount 1 ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class resnet:FunctionalClass ;
] ;
] ;
sh:property [
sh:path resnet:partner ;
sh:qualifiedMaxCount 1 ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class resnet:Protein ;
] ;
] ;
.

I believe you need the second for the case where some partner is both FunctionalClass and a Protein, i.e. you may only have one value and still fulfill the first shape.
Alternatively, this looks like a case for sh:qualifiedValueShapesDisjoint

Related

How to validate rdf:type in engine.validateNodesAgainstShape

In TopQuadrant shacl 1.3.2, I'm trying to use
engine.validateNodesAgainstShape(focusNodes, shape.asNode());
with shape graph:
bds:PersonNameShape a sh:NodeShape ;
rdfs:label "Person Name Shape"#en ;
sh:property bds:PersonNameShape-personNameLabel ;
sh:targetClass bdo:PersonName .
bds:PersonNameShape-personNameLabel
a sh:PropertyShape ;
sh:datatype rdf:langString ;
sh:description "this Person has a name given by the label."#en ;
sh:maxCount 1 ;
sh:minCount 1 ;
sh:path rdfs:label .
and data graph:
bdr:P707 a bdo:Person ;
bdo:hasFather bdr:P705 ;
bdo:hasParent bdr:P705 ;
bdo:isRoot true ;
bdo:kinWith bdr:P705 ;
bdo:note bdr:NT08B650B715F414F1 ;
bdo:personEvent bdr:EVFD910DBE53BCE208 , bdr:EVD4758367CFC1276C ;
bdo:personGender bdr:GenderMale ;
bdo:personName bdr:NM0895CB6787E8AC6E , bdr:NM2463D933BA1F9A38 ,
bdr:NMEA2B380AF0BBFB1B , bdr:NMC2A097019ABA499F ;
bdo:personStudentOf bdr:P705 ;
skos:prefLabel "dri med 'od zer/"#bo-x-ewts ;
.
bdr:NMC2A097019ABA499F
a bdo:PersonPrimaryName ;
rdfs:label "dri med 'od zer/"#bo-x-ewts ;
.
bdr:NM0895CB6787E8AC6E
a bdo:PersonPrimaryTitle ;
rdfs:label "sprul sku dri med/"#bo-x-ewts ;
.
bdr:NM2463D933BA1F9A38
a bdo:PersonPrimaryTitle ;
rdfs:label "bdud 'joms gter sras dri med 'od zer/"#bo-x-ewts ;
.
bdr:NMEA2B380AF0BBFB1B
a bdo:PersonGterStonTitle ;
rdfs:label "pad+ma 'gro 'dul gsang sngags gling pa/"#bo-x-ewts ;
.
The focusNodes and shape are:
validating facets:
[http://purl.bdrc.io/resource/NM0895CB6787E8AC6E,
http://purl.bdrc.io/resource/NMEA2B380AF0BBFB1B,
http://purl.bdrc.io/resource/NMC2A097019ABA499F,
http://purl.bdrc.io/resource/NM2463D933BA1F9A38]
against shape:
http://purl.bdrc.io/ontology/shapes/core/PersonNameShape
I was expecting to get a validation report showing violations of PersonNameShape owing to there not being any statements in the data graph indicating that, for example:
bdo:PersonPrimaryTitle rdfs:subClassOf bdo:PersonName .
but, I get an empty report:
[ a sh:ValidationReport ] .
If I modify one of the PersonName resources to use skos:prefLabel instead of rdfs:label, then I get an expected violation result:
[ a sh:ValidationReport ;
sh:result [ a sh:ValidationResult ;
sh:focusNode bdr:NMC2A097019ABA499F ;
sh:resultMessage "Property needs to have at least 1 values, but found 0" ;
sh:resultPath rdfs:label ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape bds:PersonNameShape-personNameLabel
]
] .
I had thought that the sh:targetClass bdo:PersonName in the PersonNameShape declaration was part of validation but apparently Shacl spec 2.1.3:
Targets of a shape are ignored whenever a focus node is provided directly as input to the validation process for that shape.
is indicating part of why I'm not seeing the expected (hoped for) violations. So my question is how do I specify that part of validation should be to check that the rdf:type of each of the focusNodes is a (rdfs:subClassOf*) bdo:PersonName.
I tried adding sh:property bds:PersonNameShape-personNameType ; to PersonNameShape with:
bds:PersonNameShape-personNameType
a sh:PropertyShape ;
sh:class bdo:PersonPrimaryTitle ;
sh:description "type class."#en ;
sh:maxCount 1 ;
sh:minCount 1 ;
sh:path rdf:type .
I expected to see violations for bdr:NMC2A097019ABA499F and bdr:NMEA2B380AF0BBFB1B but the other two should validate I thought since they have rdf:type, bdo:PersonPrimaryTitle. However, I see violations that I don't understand:
[ a sh:ValidationReport ;
sh:result [ a sh:ValidationResult ;
sh:focusNode bdr:NM2463D933BA1F9A38 ;
sh:resultMessage "Value must be an instance of bdo:PersonName" ;
sh:resultPath rdf:type ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClassConstraintComponent ;
sh:sourceShape bds:PersonNameShape-personNameType ;
sh:value bdo:PersonPrimaryTitle
] ;
sh:result [ a sh:ValidationResult ;
sh:focusNode bdr:NMC2A097019ABA499F ;
sh:resultMessage "Value must be an instance of bdo:PersonName" ;
sh:resultPath rdf:type ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClassConstraintComponent ;
sh:sourceShape bds:PersonNameShape-personNameType ;
sh:value bdo:PersonPrimaryName
] ;
sh:result [ a sh:ValidationResult ;
sh:focusNode bdr:NMEA2B380AF0BBFB1B ;
sh:resultMessage "Value must be an instance of bdo:PersonName" ;
sh:resultPath rdf:type ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClassConstraintComponent ;
sh:sourceShape bds:PersonNameShape-personNameType ;
sh:value bdo:PersonGterStonTitle
] ;
sh:result [ a sh:ValidationResult ;
sh:focusNode bdr:NM0895CB6787E8AC6E ;
sh:resultMessage "Value must be an instance of bdo:PersonName" ;
sh:resultPath rdf:type ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClassConstraintComponent ;
sh:sourceShape bds:PersonNameShape-personNameType ;
sh:value bdo:PersonPrimaryTitle
]
] .
I imagine this is a simple lack of understanding on my part, but I'm not seeing it.
Thanks in advance.

How to extract rows from a json array using the mysql udf json_extract 0.4.0?

I have some sql that I want to pass into a mysql stored procedure. I'm using the json functions in mysql-json-udfs-0.4.0-labs-json-udfs-linux-glibc2.5-x86_64. We are running a mysql 5.5.4 server. Updating to 5.7.x is an option.
When I run
set #mapJSON = '[{"from":12,"to":0},{"from":11,"to":-1},{"from":1,"to":1}]' ;
select json_extract(#mapJSON,'from') `from`,json_extract(#mapJSON,'to') `to` ;
I am expecting
from to
12 0
11 -1
1 1
I am getting
from to
{"from":12,"to":0} {"from":12,"to":0}
The question is how to extract rows from a json array using the udf json_extract 0.4.0?
I solved this for the moment by using comma_schema with json as
{
"map": [
{
"from": 12,
"to": 0
},
{
"from": 1,
"to": 10
},
{
"from": 2,
"to": 20
},
{
"from": 3,
"to": 30
},
{
"from": 4,
"to": 40
},
{
"from": 5,
"to": 50
},
{
"from": 6,
"to": 60
},
{
"from": 7,
"to": 70
},
{
"from": 8,
"to": 80
},
{
"from": 9,
"to": 90
},
{
"from": 10,
"to": 100
}
]
}
which gives the result after running
select `common_schema`.`extract_json_value`(#mapJSON,'/map/from') `from`,`common_schema`.`extract_json_value`(#mapJSON,'/map/to') `to` ;
as space delimited strings
from to
12 1 2 3 4 5 6 7 8 9 10 0 10 20 30 40 50 60 70 80 90 100
which I then extract using where #recommendationMapJSON is the new json being passed into the stored procedure.
create temporary table temporary_recommendation_maps AS (
select `common_schema`.`extract_json_value`(#recommendationMapJSON,'/map/from') `from`,`common_schema`.`extract_json_value`(#recommendationMapJSON,'/map/to') `to`
) ;
create temporary table temporary_recommendation_map (
`from` int ,
`to` int
) ;
select length(`from`) - length(replace(`from`,' ','')) +1 into #mapCount from temporary_recommendation_maps ;
set #mapIndex = 0 ;
while #mapIndex < #mapCount do
select substring_index(`from`,' ',1) into #from from temporary_recommendation_maps ;
select substring_index(`to`,' ',1) into #to from temporary_recommendation_maps ;
insert into temporary_recommendation_map(`from`,`to`) values (#from,#to) ;
update temporary_recommendation_maps
set `from` = substring(`from`,instr(`from`,' ')+1)
, `to` = substring(`to`,instr(`to`,' ')+1) ;
set #mapIndex = #mapIndex + 1 ;
end while ;
update temporary_recommendation_maps
set `from` = ''
, `to` = '' ;
which gives the map that I wanted.
select * from temporary_recommendation_map ;
from to
12 0
1 10
2 20
3 30
4 40
5 50
6 60
7 70
8 80
9 90
10 100
Use index to get array value.
$[ index ]
sample:
SELECT JSON_EXTRACT(#mapJSON, "$[0].from") AS 'from',
JSON_EXTRACT(#mapJSON, "$[0].to") AS 'to' ;
Bit late to the party but here's how I did it.
Example:
select json_extract(#mapJSON,'$[*].from') `from`,json_extract(#mapJSON,'$[*].to') `to`
Your syntax inside json_extract() was a bit off. Try using this instead:
SET #mapJSON = '[{"from":12,"to":0},{"from":11,"to":-1},{"from":1,"to":1}]' ;
SELECT JSON_EXTRACT(#mapJSON, "$.from") AS `from`,
JSON_EXTRACT(#mapJSON, "$.to") AS `to`
This should give you a result set looking something like this:
from to
[12, 11, 1] [0, -1, 1]
try this code.
DROP TABLE IF EXISTS tmp;
DROP PROCEDURE IF EXISTS teste;
DELIMITER $$
CREATE PROCEDURE teste()
BEGIN
DECLARE i INT DEFAULT 0;
DECLARE jCount INT DEFAULT -1;
CREATE TEMPORARY TABLE tmp( ou_from INT, out_to INT );
SET #mapJSON = '[{"from":12,"to":0},{"from":11,"to":-1},{"from":1,"to":1},{"a":"teste"}]' ;
SET jCount = jCount + JSON_LENGTH( #mapJSON, '$' );
WHILE ( i <= jCount ) DO
INSERT INTO tmp( ou_from, out_to )
VALUES( JSON_EXTRACT(#mapJSON, CONCAT( '$[', i, '].from') )
, JSON_EXTRACT(#mapJSON, CONCAT( '$[', i, '].to' ) )
);
SET i = i + 1;
END WHILE;
SELECT ou_from AS 'from', out_to AS 'to' FROM tmp;
/*
SELECT JSON_EXTRACT(#mapJSON, "$[1].from") AS 'from',
JSON_EXTRACT(#mapJSON, "$[1].to") AS 'to' ;
*/
END $$
DELIMITER ;
CALL teste;

Reserved keywords after SELECT

Is there a way to know all the possible (acceptable) keywords, after a SELECT statement in SQL before the list of fields?
Edit
Reference DB is MySQL
PostgreSQL 9.4
http://www.postgresql.org/docs/9.4/static/sql-select.html
[ WITH [ RECURSIVE ] with_query [, ...] ]
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
[ * | expression [ [ AS ] output_name ] [, ...] ]
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY expression [, ...] ]
[ HAVING condition [, ...] ]
[ WINDOW window_name AS ( window_definition ) [, ...] ]
[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]
[ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ]
[ LIMIT { count | ALL } ]
[ OFFSET start [ ROW | ROWS ] ]
[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]
[ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT ] [...] ]
where from_item can be one of:
[ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
[ LATERAL ] ( select ) [ AS ] alias [ ( column_alias [, ...] ) ]
with_query_name [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
[ LATERAL ] function_name ( [ argument [, ...] ] )
[ WITH ORDINALITY ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
[ LATERAL ] function_name ( [ argument [, ...] ] ) [ AS ] alias ( column_definition [, ...] )
[ LATERAL ] function_name ( [ argument [, ...] ] ) AS ( column_definition [, ...] )
[ LATERAL ] ROWS FROM( function_name ( [ argument [, ...] ] ) [ AS ( column_definition [, ...] ) ] [, ...] )
[ WITH ORDINALITY ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
from_item [ NATURAL ] join_type from_item [ ON join_condition | USING ( join_column [, ...] ) ]
and with_query is:
with_query_name [ ( column_name [, ...] ) ] AS ( select | values | insert | update | delete )
TABLE [ ONLY ] table_name [ * ]
MySQL 5.6
https://dev.mysql.com/doc/refman/5.6/en/select.html
SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[PARTITION partition_list]
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
[ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
[ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name'
[CHARACTER SET charset_name]
export_options
| INTO DUMPFILE 'file_name'
| INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]
SQL Server 2014
https://msdn.microsoft.com/en-us/library/ms189499.aspx
<SELECT statement> ::=
[ WITH { [ XMLNAMESPACES ,] [ <common_table_expression> [,...n] ] } ]
<query_expression>
[ ORDER BY { order_by_expression | column_position [ ASC | DESC ] }
[ ,...n ] ]
[ <FOR Clause>]
[ OPTION ( <query_hint> [ ,...n ] ) ]
<query_expression> ::=
{ <query_specification> | ( <query_expression> ) }
[ { UNION [ ALL ] | EXCEPT | INTERSECT }
<query_specification> | ( <query_expression> ) [...n ] ]
<query_specification> ::=
SELECT [ ALL | DISTINCT ]
[TOP ( expression ) [PERCENT] [ WITH TIES ] ]
< select_list >
[ INTO new_table ]
[ FROM { <table_source> } [ ,...n ] ]
[ WHERE <search_condition> ]
[ <GROUP BY> ]
[ HAVING < search_condition > ]
See the documentation.
For example: mysql 5.0 documentation
Reserved Keywords in MySql
Keywords are words that have significance in SQL. Certain keywords, such as SELECT, DELETE, or BIGINT, are reserved and require special treatment for use as identifiers such as table and column names. This may also be true for the names of built-in functions.
Nonreserved keywords are permitted as identifiers without quoting. Reserved words are permitted as identifiers if you quote them
Reserved Keywords in MSSQL server :
Microsoft SQL Server uses reserved keywords for defining, manipulating, and accessing databases. Reserved keywords are part of the grammar of the Transact-SQL language that is used by SQL Server to parse and understand Transact-SQL statements and batches.
Although it is syntactically possible to use SQL Server reserved keywords as identifiers and object names in Transact-SQL scripts, you can do this only by using delimited identifiers.

Is it possible to have a WITH-clause inside a SELECT statement?

We have a cloud-based GUI at my work where I can choose some fields from different tables so it can print out the values afterwards. It is not possible for me to write a WITH clause before a SELECT statement as the program automatically write SELECT first. So I want to know If it is possible somehow.
Yes you can, according to MSDN documentation (https://msdn.microsoft.com/en-us/library/ms189499.aspx) :
<SELECT statement> ::=
[WITH <common_table_expression> [,...n]]
<query_expression>
[ ORDER BY { order_by_expression | column_position [ ASC | DESC ] }
[ ,...n ] ]
[ <FOR Clause>]
[ OPTION ( <query_hint> [ ,...n ] ) ]
<query_expression> ::=
{ <query_specification> | ( <query_expression> ) }
[ { UNION [ ALL ] | EXCEPT | INTERSECT }
<query_specification> | ( <query_expression> ) [...n ] ]
<query_specification> ::=
SELECT [ ALL | DISTINCT ]
[TOP ( expression ) [PERCENT] [ WITH TIES ] ]
< select_list >
[ INTO new_table ]
[ FROM { <table_source> } [ ,...n ] ]
[ WHERE <search_condition> ]
[ <GROUP BY> ]
[ HAVING < search_condition > ]
If you can't find any other way around it, this GUI might be persuaded to accept
SELECT * FROM (
-- write your entire select statement here
);

What's the name of this language that describes a language syntax?

for example:
<SELECT statement> ::=
[WITH <common_table_expression> [,...n]]
<query_expression>
[ ORDER BY { order_by_expression | column_position [ ASC | DESC ] }
[ ,...n ] ]
[ COMPUTE
{ { AVG | COUNT | MAX | MIN | SUM } ( expression ) } [ ,...n ]
[ BY expression [ ,...n ] ]
]
[ <FOR Clause>]
[ OPTION ( <query_hint> [ ,...n ] ) ]
<query_expression> ::=
{ <query_specification> | ( <query_expression> ) }
[ { UNION [ ALL ] | EXCEPT | INTERSECT }
<query_specification> | ( <query_expression> ) [...n ] ]
<query_specification> ::=
SELECT [ ALL | DISTINCT ]
[TOP expression [PERCENT] [ WITH TIES ] ]
< select_list >
[ INTO new_table ]
[ FROM { <table_source> } [ ,...n ] ]
[ WHERE <search_condition> ]
[ <GROUP BY> ]
[ HAVING < search_condition > ]
whats the language called?
It's the Backus-Naur Form, actually the Extended Backus-Naur Form.
This is not a language, but a formal description of syntax (in this case for SQL select statements) in BNF (Backus-Naur Form).
Since the example you provide uses "optional" brackets [...] it is actually Extended Backus Naur Form.
That looks a bit like a BNF definition of part of SQL.