schemarama
schemarama copied to clipboard
Compare schemarama representation with Google draft shape export
@ericprud @rrlevering
Here is the current draft of an export in ShEx format. SHACL is also below. For contrast see also the last version of something close to the schemarama codebase (albeit not guaranteed to run right now):
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <http://schema.org/> .
@prefix sx: <http://www.w3.org/ns/shex#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
[] a sx:Schema ;
sx:shapes [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max 1 ;
sx:min 1 ;
sx:predicate schema:url ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:semActs ( [ a sx:SemAct ;
sx:code "console.log('some url checking code here')" ;
sx:name <https://google.com/search/validation/valid-url> ] ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max 1 ;
sx:min 1 ;
sx:predicate schema:claimReviewed ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:itemReviewed ;
sx:valueExpr [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:CreativeWork ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Claim ) ] ] ] ) ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:CreativeWork ) ] ] ] ] [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:author ;
sx:valueExpr [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Organization ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Person ) ] ] ] ) ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Organization ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Person ) ] ] ] ) ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max 1 ;
sx:min 0 ;
sx:predicate schema:name ] ] ) ] ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:datePublished ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:semActs ( [ a sx:SemAct ;
sx:code "console.log('some datetime checking code here')" ;
sx:name <https://google.com/search/validation/valid-date-time> ] ) ] ] ] ) ] ) ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Claim ) ] ] ] ] [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:appearance ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:firstAppearance ] ] ) ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:appearance ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:firstAppearance ] ] ) ] ) ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:appearance ;
sx:valueExpr [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:NodeConstraint ;
sx:pattern "https?://.*" ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:CreativeWork ) ] ] ] ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:firstAppearance ;
sx:valueExpr [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:NodeConstraint ;
sx:pattern "https?://.*" ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:CreativeWork ) ] ] ] ) ] ] ] [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:author ;
sx:valueExpr [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Organization ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Person ) ] ] ] ) ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Organization ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Person ) ] ] ] ) ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max 1 ;
sx:min 0 ;
sx:predicate schema:name ] ] ) ] ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:datePublished ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:semActs ( [ a sx:SemAct ;
sx:code "console.log('some datetime checking code here')" ;
sx:name <https://google.com/search/validation/valid-date-time> ] ) ] ] ] ) ] ) ] ) ] ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:author ;
sx:valueExpr [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Organization ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Person ) ] ] ] ) ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Organization ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Person ) ] ] ] ) ] ] [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:name ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:url ] ] ) ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:name ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:url ] ] ) ] ) ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:url ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:semActs ( [ a sx:SemAct ;
sx:code "console.log('some url checking code here')" ;
sx:name <https://google.com/search/validation/valid-url> ] ) ] ] ] ) ] ) ] ) ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:reviewRating ;
sx:valueExpr [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Rating ) ] ] ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:predicate rdf:type ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:values ( schema:Rating ) ] ] ] ] [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max 1 ;
sx:min 0 ;
sx:predicate schema:alternateName ] ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:name ] ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:alternateName ] ] ) ] [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:alternateName ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:name ] ] ) ] ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:ratingValue ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:bestRating ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:worstRating ] ] ) ] [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:ratingValue ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:pattern "-1" ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:bestRating ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:pattern "-1" ] ] ] [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:worstRating ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:pattern "-1" ] ] ] ) ] ] ) ] ] [ a sx:ShapeAnd ;
sx:shapeExprs ( [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 0 ;
sx:predicate schema:ratingValue ;
sx:valueExpr [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:NodeConstraint ;
sx:pattern "(\\d+[\\.,]?\\d*)/(\\d+[\\.,]?\\d*)" ] [ a sx:NodeConstraint ;
sx:pattern "(\\d+[\\.,]?\\d*)%" ] [ a sx:NodeConstraint ;
sx:pattern "(\\d+[\\.,]?\\d*)" ] ) ] ] ] [ a sx:ShapeOr ;
sx:shapeExprs ( [ a sx:ShapeNot ;
sx:shapeExpr [ a sx:Shape ;
sx:expression [ a sx:TripleConstraint ;
sx:max -1 ;
sx:min 1 ;
sx:predicate schema:ratingValue ;
sx:valueExpr [ a sx:NodeConstraint ;
sx:pattern "(\\d+[\\.,]?\\d*)" ] ] ] ] [ a sx:Shape ;
sx:expression [ a sx:SemAct ;
sx:name <https://google.com/search/validation/valid-rating> ] ] ) ] ) ] ) ] ) ] ) ] ) ] ] ] ) ] .
Here is the corresponding SHACL. The internal representation is very similar and has a few other constructs:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
[] a sh:NodeShape ;
schema:identifier "ValidSoClaimReview" ;
sh:property [ sh:maxCount 1 ;
sh:message "VALID_URL" ;
sh:minCount 1 ;
sh:path schema:url ],
[ sh:maxCount 1 ;
sh:minCount 1 ;
sh:path schema:claimReviewed ],
[ sh:and ( [ sh:or ( [ sh:class schema:CreativeWork ] [ sh:class schema:Claim ] ) ] [ sh:or ( [ sh:not [ sh:class schema:CreativeWork ] ] [ a sh:NodeShape ;
sh:property [ sh:and ( [ sh:or ( [ sh:class schema:Organization ] [ sh:class schema:Person ] ) ] [ sh:or ( [ sh:not [ sh:or ( [ sh:class schema:Organization ] [ sh:class schema:Person ] ) ] ] [ a sh:NodeShape ;
sh:property [ sh:maxCount 1 ;
sh:minCount 1 ;
sh:path schema:name ;
sh:severity sh:Warning ] ] ) ] ) ;
sh:minCount 1 ;
sh:path schema:author ;
sh:severity sh:Warning ],
[ sh:message "VALID_DATE_TIME" ;
sh:minCount 1 ;
sh:path schema:datePublished ;
sh:severity sh:Warning ] ] ) ] [ sh:or ( [ sh:not [ sh:class schema:Claim ] ] [ a sh:NodeShape ;
sh:and ( [ sh:or ( [ sh:property [ sh:minCount 1 ;
sh:path schema:appearance ] ] [ sh:property [ sh:minCount 1 ;
sh:path schema:firstAppearance ] ] ) ;
sh:severity sh:Warning ] [ sh:or ( [ sh:property [ sh:minCount 1 ;
sh:path schema:appearance ] ] [ sh:property [ sh:minCount 1 ;
sh:path schema:firstAppearance ] ] ) ;
sh:severity sh:Warning ] ),
( [ sh:property [ sh:and ( [ sh:or ( [ sh:class schema:Organization ] [ sh:class schema:Person ] ) ] [ sh:or ( [ sh:not [ sh:or ( [ sh:class schema:Organization ] [ sh:class schema:Person ] ) ] ] [ a sh:NodeShape ;
sh:property [ sh:maxCount 1 ;
sh:minCount 1 ;
sh:path schema:name ;
sh:severity sh:Warning ] ] ) ] ) ;
sh:minCount 1 ;
sh:path schema:author ;
sh:severity sh:Warning ] ] [ sh:property [ sh:message "VALID_DATE_TIME" ;
sh:minCount 1 ;
sh:path schema:datePublished ;
sh:severity sh:Warning ] ] ) ;
sh:property [ sh:or ( [ sh:datatype xsd:anyURI ] [ sh:class schema:CreativeWork ] ) ;
sh:path schema:appearance ],
[ sh:or ( [ sh:datatype xsd:anyURI ] [ sh:class schema:CreativeWork ] ) ;
sh:path schema:firstAppearance ] ] ) ] ) ;
sh:minCount 1 ;
sh:path schema:itemReviewed ;
sh:severity sh:Warning ],
[ sh:and ( [ sh:or ( [ sh:class schema:Organization ] [ sh:class schema:Person ] ) ] [ sh:or ( [ sh:not [ sh:or ( [ sh:class schema:Organization ] [ sh:class schema:Person ] ) ] ] [ a sh:NodeShape ;
sh:and ( [ sh:or ( [ sh:property [ sh:minCount 1 ;
sh:path schema:name ] ] [ sh:property [ sh:minCount 1 ;
sh:path schema:url ] ] ) ;
sh:severity sh:Warning ] [ sh:or ( [ sh:property [ sh:minCount 1 ;
sh:path schema:name ] ] [ sh:property [ sh:minCount 1 ;
sh:path schema:url ] ] ) ;
sh:severity sh:Warning ] ) ;
sh:property [ sh:message "VALID_URL" ;
sh:path schema:url ] ] ) ] ) ;
sh:minCount 1 ;
sh:path schema:author ;
sh:severity sh:Warning ],
[ sh:and ( [ a sh:NodeShape ;
sh:property [ sh:hasValue schema:Rating ;
sh:path rdf:type ] ] [ sh:or ( [ sh:not [ a sh:NodeShape ;
sh:property [ sh:hasValue schema:Rating ;
sh:path rdf:type ] ] ] [ a sh:NodeShape ;
sh:not [ sh:and ( [ sh:property [ sh:minCount 1 ;
sh:path schema:alternateName ] ] [ sh:property [ sh:minCount 1 ;
sh:path schema:name ] ] ) ] ;
sh:or ( [ sh:not [ sh:not [ sh:property [ sh:minCount 1 ;
sh:path schema:name ] ] ] ] [ sh:property [ sh:minCount 1 ;
sh:path schema:alternateName ] ] ),
( [ sh:not [ sh:and ( [ sh:or ( [ sh:property [ sh:minCount 1 ;
sh:path schema:ratingValue ] ] [ sh:property [ sh:minCount 1 ;
sh:path schema:bestRating ] ] [ sh:property [ sh:minCount 1 ;
sh:path schema:worstRating ] ] ) ] [ sh:not [ sh:and ( [ sh:property [ sh:path schema:ratingValue ;
sh:pattern "-1" ] ] [ sh:property [ sh:path schema:bestRating ;
sh:pattern "-1" ] ] [ sh:property [ sh:path schema:worstRating ;
sh:pattern "-1" ] ] ) ] ] ) ] ] [ sh:and ( [ sh:property [ sh:or ( [ sh:pattern "(\\d+[\\.,]?\\d*)/(\\d+[\\.,]?\\d*)" ] [ sh:pattern "(\\d+[\\.,]?\\d*)%" ] [ sh:pattern "(\\d+[\\.,]?\\d*)" ] ) ;
sh:path schema:ratingValue ] ] [ sh:or ( [ sh:not [ sh:property [ sh:minCount 1 ;
sh:path schema:ratingValue ;
sh:pattern "(\\d+[\\.,]?\\d*)" ] ] ] [ sh:message "VALID_RATING" ] ) ] ) ] ) ;
sh:property [ sh:maxCount 1 ;
sh:path schema:alternateName ] ;
sh:severity sh:Warning ] ) ] ) ;
sh:minCount 1 ;
sh:path schema:reviewRating ] .