Skip to content

Commit

Permalink
check for Literal values (also schema.org #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimkont committed Aug 27, 2014
1 parent e8f7093 commit 4c46ac9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ rutg:RDFSRANGEC a rut:TestGenerator ;
?P1 (rdfs:range|schema:rangeIncludes) ?T .
# don't check for datatypes / literals here
FILTER NOT EXISTS {?T rdf:type/rdfs:subclassOf* rdfs:Literal }
FILTER NOT EXISTS {?T rdf:type/rdfs:subclassOf* rdfs:Datatype }
FILTER NOT EXISTS {?T rdf:type/rdfs:subclassOf* schema:DataType }
FILTER NOT EXISTS {?T rdf:type/rdfs:subClassOf* rdfs:Literal }
FILTER NOT EXISTS {?T rdf:type/rdfs:subClassOf* rdfs:Datatype }
FILTER NOT EXISTS {?T rdf:type/rdfs:subClassOf* schema:DataType }
# it must be defined that the range is a class
?T rdf:type/rdfs:subclassOf* ?class .
FILTER ( ?class IN (owl:Class, rdfs:Class) )
?T rdf:type/rdfs:subClassOf* ?class .
FILTER ( ?class IN (owl:Class, rdfs:Class, schema:Class) )
# don't check for general classes
FILTER ( ?T NOT IN ( owl:Thing, prov:Entity, rdf:Resource, rdf:Class, rdf:Property, schema:Property, schema:Class ))
Expand All @@ -44,13 +44,13 @@ rutg:RDFSRANGEC-MISS a rut:TestGenerator ;
?P1 (rdfs:range|schema:rangeIncludes) ?T .
# don't check for datatypes / literals here
FILTER NOT EXISTS {?T rdf:type/rdfs:subclassOf* rdfs:Literal }
FILTER NOT EXISTS {?T rdf:type/rdfs:subclassOf* rdfs:Datatype }
FILTER NOT EXISTS {?T rdf:type/rdfs:subclassOf* schema:DataType }
FILTER NOT EXISTS {?T rdf:type/rdfs:subClassOf* rdfs:Literal }
FILTER NOT EXISTS {?T rdf:type/rdfs:subClassOf* rdfs:Datatype }
FILTER NOT EXISTS {?T rdf:type/rdfs:subClassOf* schema:DataType }
# it must be defined that the range is a class
?T rdf:type/rdfs:subclassOf* ?class .
FILTER ( ?class IN (owl:Class, rdfs:Class) )
?T rdf:type/rdfs:subClassOf* ?class .
FILTER ( ?class IN (owl:Class, rdfs:Class, schema:Class) )
# don't check for general classes
FILTER ( ?T NOT IN ( owl:Thing, prov:Entity, rdf:Resource, rdf:Class, rdf:Property, schema:Property, schema:Class ))
Expand All @@ -64,20 +64,46 @@ rutg:RDFSRANGEC-MISS a rut:TestGenerator ;
rut:annotationValue rlog:WARN] ;
.

# Check for Literal
rutg:RDFSRANGEL a rut:TestGenerator ;
dcterms:description """Check all defined Literals if they are indeed literals"""@en ;
rut:sparqlGenerator """ select distinct ?P1 ('!' as ?NEG) ('isLiteral' as ?FUNC) ?DESCRIPTION where {
{ # xsd datatypes
?P1 rdfs:range ?D1 .
FILTER ( STRSTARTS(str(?D1), "http://www.w3.org/2001/XMLSchema#") ).
} UNION {
?P1 rdfs:range ?D1 .
?D1 rdf:type/rdfs:subClassOf* rdfs:Datatype .
} UNION {
?P1 rdfs:range ?D1 .
?P1 rdf:type/rdfs:subClassOf* owl:DatatypeProperty .
} UNION {
?P1 rdfs:range rdf:Literal .
} UNION {
?P1 schema:rangeIncludes ?D1 .
?D1 rdf:type|rdfs:subClassOf+ schema:DataType .
}
BIND (concat(str(?P1)," does contain a literal value") AS ?DESCRIPTION)} """ ;
rut:basedOnPattern rutp:OBJFUNC ;
rut:resultAnnotation [
a rut:ResultAnnotation ;
rut:annotationProperty rlog:level ;
rut:annotationValue rlog:ERROR] ;
.

# Datatype range
rutg:RDFSRANGED a rut:TestGenerator ;
dcterms:description """Generate all rdfs:range constrains defined in a schema"""@en ;
rut:sparqlGenerator """ select distinct ?P1 ?D1 ?DESCRIPTION where {
{
{ # xsd datatypes
?P1 rdfs:range ?D1 .
?P1 rdf:type <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
FILTER ( STRSTARTS(str(?D1), "http://www.w3.org/2001/XMLSchema#") ).
} UNION {
?P1 rdfs:range ?D1 .
?D1 rdf:type/rdfs:subclassOf* <http://www.w3.org/2000/01/rdf-schema#Datatype> .
?D1 rdf:type/rdfs:subClassOf* rdfs:Datatype .
} UNION {
?P1 rdfs:range ?D1 .
?P1 rdf:type/rdfs:subclassOf* <http://www.w3.org/2002/07/owl#DatatypeProperty> .
?P1 rdf:type/rdfs:subClassOf* owl:DatatypeProperty .
} FILTER ( (str(?D1) != "http://www.w3.org/2000/01/rdf-schema#Literal") &&
(str(?D1) != "http://www.w3.org/2001/XMLSchema#string") )
BIND (concat(str(?P1)," does not have datatype: ", str(?D1)) AS ?DESCRIPTION)} """ ;
Expand Down
44 changes: 44 additions & 0 deletions rdfunit-core/src/main/resources/org/aksw/rdfunit/patterns.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,50 @@ rutp:TRIPLE-V1 a rut:Parameter ;
dcterms:identifier "V1" ;
rut:parameterConstraint rut:None .


################################################################################
#### OBJFUNC
#### The object of a triple satisfies a function
################################################################################

rutp:OBJFUNC a rut:Pattern ;
dcterms:identifier "OBJFUNC" ;
dcterms:description """The object of a triple satisfies a function"""@en ;
rut:sparqlWherePattern """ {
?resource %%P1%% ?obj .
FILTER( %%NEG%% %%FUNC%% (?obj))
} """ ;
rut:sparqlPrevalencePattern """ SELECT (count( DISTINCT ?resource) AS ?total)
WHERE { ?resource %%P1%% ?value . }""" ;
rut:parameter rutp:OBJFUNC-P1 ;
rut:parameter rutp:OBJFUNC-NEG ;
rut:parameter rutp:OBJFUNC-FUNC ;
rut:resultAnnotation [
a rut:ResultAnnotation ;
rut:annotationProperty spin:violationPath ;
rut:annotationValue """%%P1%%"""
];
rut:resultAnnotation [
a rut:ResultAnnotation ;
rut:annotationProperty spin:violationValue ;
rut:annotationValue """?obj"""
];
.

rutp:OBJFUNC-P1 a rut:Parameter ;
dcterms:identifier "P1" ;
rut:parameterConstraint rut:Property .

rutp:OBJFUNC-NEG a rut:Parameter ;
dcterms:identifier "NEG" ;
rut:parameterConstraint rut:Operator ;
rut:constraintPattern """!|""" .

rutp:OBJFUNC-FUNC a rut:Parameter ;
dcterms:identifier "FUNC" ;
rut:parameterConstraint rut:None .


################################################################################
#### ONELANG
#### Resource has more than one plain literal of a certain language assigned
Expand Down

0 comments on commit 4c46ac9

Please sign in to comment.