├── LICENSE ├── README.md ├── docs ├── allclasses-frame.html ├── allclasses-noframe.html ├── astrea │ ├── generators │ │ ├── OwlGenerator.html │ │ ├── class-use │ │ │ └── OwlGenerator.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ └── model │ │ ├── ShaclFromOwl.html │ │ ├── class-use │ │ └── ShaclFromOwl.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-files │ ├── index-1.html │ ├── index-2.html │ ├── index-3.html │ ├── index-4.html │ └── index-5.html ├── index.html ├── overview-frame.html ├── overview-summary.html ├── overview-tree.html ├── package-list ├── script.js └── stylesheet.css ├── material ├── .DS_Store ├── Astrea-KG-latest.ttl ├── Astrea-KG.ttl ├── OWL.csv ├── Queries.csv ├── RDFS.csv ├── SHACL.csv ├── XSD-coverage.xlsx ├── XSD.csv └── mappings │ ├── astrea.json │ └── constructs.json ├── mvn-install.sh ├── pom.xml └── src ├── main └── java │ └── astrea │ ├── generators │ ├── OptimisedOwlGenerator.java │ └── OwlGenerator.java │ └── model │ └── ShaclFromOwl.java └── test └── java └── test ├── optimised ├── owl │ ├── AnnotationPropertiesTest.java │ ├── CardinalityTest.java │ ├── DatatypeTest.java │ ├── EquialityTest.java │ ├── FillerInformationTest.java │ ├── PropertyCharacteristicsTest.java │ ├── PropertyRestrictionsTest.java │ └── RDFSchemaFeaturesTest.java └── shapes │ ├── CardinalityConstraintTest.java │ ├── LogicalConstraintsTest.java │ ├── NonValidatingPropertyShapeCharacteristicsTest.java │ ├── OtherConstraints.java │ ├── PropertyPairConstraintTest.java │ ├── StringBasedConstraintTest.java │ └── ValueTypeConstraintTest.java └── queries ├── AnnotationPropertiesTest.java ├── CardinalityConstraintTest.java ├── CardinalityTest.java ├── DatatypeTest.java ├── EqualityTest.java ├── FillerInformationTest.java ├── LogicalConstraintsTest.java ├── NonValidatingPropertyShapeCharacteristicsTest.java ├── OtherConstraints.java ├── PropertyCharacteristicsTest.java ├── PropertyPairConstraintTest.java ├── PropertyRestrictionsTest.java ├── RDFSchemaFeaturesTest.java ├── ShapeBasedConstraintsTest.java ├── StringBasedConstraintTest.java ├── ValueTypeConstraintTest.java ├── catalogue └── TestCatalogue.java └── datatypes └── InjectedDatatypesTest.java /README.md: -------------------------------------------------------------------------------- 1 | # Astrea 2 | 3 | Astrea is a software capable of generate SHACL shapes from one or more given ontologies. It relies on a set of equivalences between the [OWL2](https://www.w3.org/TR/owl2-overview/) constructs and the [SHACL](https://www.w3.org/TR/shacl/) constructs, which are exploit by means of a set of [SPARQL queries](https://www.w3.org/TR/sparql11-query/). The idea behind Astrea is to rely on a set of mappings between such specifications, and a list of queries so by just applying the queries over one or more owl files the associated shapes can be generated. 4 | 5 | In this repository the software provided imports all the ontologies associated to the construct owl:imports for an input ontology, in addition in its methods counts with the option of importing more than one ontology URL to generate their shapes. Consider that the shapes generated are associated only to the types and properties specified in the ontology, therefore providing more than one URL can be useful if one ontology references elements from another but it does not import it. 6 | 7 | The [Astrea resources](https://github.com/oeg-upm/Astrea/tree/master/material), besides the java library which latest version [can be downloaded from the releases tab](https://github.com/oeg-upm/Astrea/releases), include the following elements: 8 | * Mappings.xlsx: a set of mappings that hold the equivalences between OWL and SHACL constructs. 9 | * OWL.csv, RDFS.csv, SHACL.csv, XSD.csv: the constructs from the OWL, RDFS, XSD, and SHACL that exists in these specifications 10 | * Queries.csv: the queries to generate the SHACL shapes, this file contains also all the statements that are required from the OWL, RDFS, and XSD to generate a shapes, as well as, all the constructs belonging to SHACL that the output shape contains. 11 | * astrea-dataset.zip: is a RDF dataset that contains all the Astrea resources modelled according to the [Astrea ontology](https://w3id.org/def/astrea#). This dataset is also available at [https://astrea.helio.linkeddata.es/](https://astrea.helio.linkeddata.es/) for live queries or to download. 12 | * Java Documentation: is available at https://oeg-upm.github.io/Astrea/ 13 | 14 | 15 | **Astrea Demo:** Astrea has been integrated as a [web service and published online](https://astrea.linkeddata.es/). In addition, the source code of this demo can be found at [its GitHub repository](https://github.com/oeg-upm/astrea-web) 16 | 17 | ## 1 - Install Astrea 18 | In order to use the Astrea as java library for third-party components there are two approaches: import the library as a *jar* or install Astrea as a local maven dependency and then use your *pom.xml* to import it. Following we provide a guide for both options. 19 | 20 | #### 1.1 Import Astrea as a jar 21 | Download the last release from our GitHub. Then, import the *jar* file in a project . 22 | #### 1.2 Instaling as local maven dependency 23 | Astrea can be installed as a local dependency. For this purpose download the code from this repository: 24 | ````` 25 | git clone https://github.com/oeg-upm/Astrea.git 26 | ````` 27 | Then, install the project as a local maven dependency, for which you can run the script that we provide 28 | ````` 29 | bash mvn-install.sh 30 | ````` 31 | Finally, import in a project the Astrea maven dependency using the following code in your *pom.xml*: 32 | ```` 33 | 34 | oeg.validation 35 | astrea 36 | 1.2.1 37 | 38 | ```` 39 | Alternatively, Astrea can be installed as a local dependency following these steps: 40 | 1. Compile the project: 41 | ```` 42 | mvn clean package -Dskiptests 43 | ```` 44 | 2. Compile the project: 45 | ```` 46 | mvn install:install-file -Dfile=./target/astrea-1.2.1.jar -DgroupId=oeg.validation -DartifactId=astrea -Dversion=1.2.1 -Dpackaging=jar 47 | ```` 48 | 3. Import the dependency in your project using the pom file relying on the previous snipped 49 | 50 | ## 2 - Quick start 51 | Astrea can be used as a java library for third-party java projects, in you code create an instance of our Astrea object as follows: 52 | ```` 53 | ShaclFromOwl sharper = new OwlGenerator(); 54 | ```` 55 | Having this object the shapes, which will be provided as [jena]([https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Model.html](https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Model.html)) Models, can be generated using different methods: 56 | 57 | - Using the URL of an ontology 58 | ```` 59 | Model shapes = sharper.fromURL("http://iot.linkeddata.es/def/core/ontology.ttl"); 60 | ```` 61 | - Using a list containing the URLs of several ontologies 62 | ```` 63 | List ontologies = new ArrayList<>(); 64 | ontologies.add("http://iot.linkeddata.es/def/core/ontology.ttl"); 65 | ... 66 | Model shapes = sharper.fromURLs(ontologies); 67 | ```` 68 | - Using an ontology in memory, consider that the [formats supported are the ones specified in jena]([https://jena.apache.org/documentation/io/](https://jena.apache.org/documentation/io/)) 69 | ````` 70 | Model shapes = sharper.fromOwl(String owlContent, String format); 71 | ````` 72 | - Using an jena model 73 | ````` 74 | Model ontologyModel = ModelFactory.createDefaultModel(); 75 | // insert content in the variable ontologyModel 76 | Model shapes = sharper.fromModel(ontologyModel); 77 | ````` 78 | 79 | **Keep in mind that Astrea will automatically include all the ontologies that are specified under the owl:imports statement, and therefore, it will generate their shapes as well.** 80 | 81 | **To check other constructors of the OwlGenerator class read our [java doc](https://oeg-upm.github.io/Astrea/)** 82 | -------------------------------------------------------------------------------- /docs/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/astrea/generators/class-use/OwlGenerator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Uses of Class astrea.generators.OwlGenerator 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Uses of Class
astrea.generators.OwlGenerator

74 |
75 |
No usage of astrea.generators.OwlGenerator
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 94 |
95 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /docs/astrea/generators/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | astrea.generators 7 | 8 | 9 | 10 | 11 | 12 |

astrea.generators

13 |
14 |

Classes

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/astrea/generators/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | astrea.generators 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Package astrea.generators

74 |
75 |
76 | 95 |
96 | 97 |
98 | 99 | 100 | 101 | 102 | 103 | 104 | 114 |
115 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /docs/astrea/generators/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | astrea.generators Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Hierarchy For Package astrea.generators

74 | Package Hierarchies: 75 | 78 |
79 |
80 |

Class Hierarchy

81 | 88 |
89 | 90 |
91 | 92 | 93 | 94 | 95 | 96 | 97 | 107 |
108 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /docs/astrea/generators/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Uses of Package astrea.generators 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Uses of Package
astrea.generators

74 |
75 |
No usage of astrea.generators
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 94 |
95 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /docs/astrea/model/class-use/ShaclFromOwl.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Uses of Interface astrea.model.ShaclFromOwl 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Uses of Interface
astrea.model.ShaclFromOwl

74 |
75 |
76 | 117 |
118 | 119 |
120 | 121 | 122 | 123 | 124 | 125 | 126 | 136 |
137 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /docs/astrea/model/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | astrea.model 7 | 8 | 9 | 10 | 11 | 12 |

astrea.model

13 |
14 |

Interfaces

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/astrea/model/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | astrea.model 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Package astrea.model

74 |
75 |
76 | 95 |
96 | 97 |
98 | 99 | 100 | 101 | 102 | 103 | 104 | 114 |
115 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /docs/astrea/model/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | astrea.model Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Hierarchy For Package astrea.model

74 | Package Hierarchies: 75 | 78 |
79 |
80 |

Interface Hierarchy

81 | 84 |
85 | 86 |
87 | 88 | 89 | 90 | 91 | 92 | 93 | 103 |
104 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /docs/astrea/model/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Uses of Package astrea.model 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Uses of Package
astrea.model

74 |
75 |
76 | 110 |
111 | 112 |
113 | 114 | 115 | 116 | 117 | 118 | 119 | 129 |
130 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /docs/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Constant Field Values 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Constant Field Values

74 |

Contents

75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 94 |
95 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /docs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Deprecated List 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Deprecated API

74 |

Contents

75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 94 |
95 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /docs/index-files/index-1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | A-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
A F G O S  73 | 74 | 75 |

A

76 |
77 |
astrea.model - package astrea.model
78 |
 
79 |
80 | A F G O S 
81 | 82 |
83 | 84 | 85 | 86 | 87 | 88 | 89 | 99 |
100 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /docs/index-files/index-2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | F-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
A F G O S  73 | 74 | 75 |

F

76 |
77 |
fetchQueries() - Method in class astrea.generators.OwlGenerator
78 |
79 |
This constructor fetches the queries from the provided SPARQL endpoint
80 |
81 |
fromModel(Model) - Method in class astrea.generators.OwlGenerator
82 |
 
83 |
fromModel(Model) - Method in interface astrea.model.ShaclFromOwl
84 |
85 |
This method aims at generating the SHACL shapes from a jena Model containing the content of one or more ontologies
86 |
87 |
fromOwl(String, String) - Method in class astrea.generators.OwlGenerator
88 |
 
89 |
fromOwl(String, String) - Method in interface astrea.model.ShaclFromOwl
90 |
91 |
This method aims at generating the SHACL shapes from the content in memory of one or more ontologies
92 |
93 |
fromURL(String) - Method in class astrea.generators.OwlGenerator
94 |
 
95 |
fromURL(String) - Method in interface astrea.model.ShaclFromOwl
96 |
97 |
This method aims at generating the SHACL shapes from the url of an ontology
98 |
99 |
fromURLs(List<String>) - Method in class astrea.generators.OwlGenerator
100 |
 
101 |
fromURLs(List<String>) - Method in interface astrea.model.ShaclFromOwl
102 |
103 |
This method aims at generating the SHACL shapes from a set of ontology urls
104 |
105 |
106 | A F G O S 
107 | 108 |
109 | 110 | 111 | 112 | 113 | 114 | 115 | 125 |
126 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /docs/index-files/index-3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | G-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
A F G O S  73 | 74 | 75 |

G

76 |
77 |
getEndpoint() - Method in class astrea.generators.OwlGenerator
78 |
 
79 |
getQueries() - Method in class astrea.generators.OwlGenerator
80 |
81 |
This method returns the list of SPARQL queries that are used to generate the SHACL shapes
82 |
83 |
84 | A F G O S 
85 | 86 |
87 | 88 | 89 | 90 | 91 | 92 | 93 | 103 |
104 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /docs/index-files/index-4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | O-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
A F G O S  73 | 74 | 75 |

O

76 |
77 |
OwlGenerator - Class in astrea.generators
78 |
79 |
This class implements the ShaclFromOwl interface.
80 |
81 |
OwlGenerator() - Constructor for class astrea.generators.OwlGenerator
82 |
83 |
This constructor relies on the public available dataset of Astrea.
84 |
85 |
OwlGenerator(String) - Constructor for class astrea.generators.OwlGenerator
86 |
87 |
This constructor could receive any other version of the Astrea's dataset published in a SPARQL endpoint, as far as it follows the Astrea's dataset model.
88 |
89 |
OwlGenerator(File) - Constructor for class astrea.generators.OwlGenerator
90 |
91 |
This constructor fetches the queries from the provided RDF dataset
92 |
93 |
94 | A F G O S 
95 | 96 |
97 | 98 | 99 | 100 | 101 | 102 | 103 | 113 |
114 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /docs/index-files/index-5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | S-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
A F G O S  73 | 74 | 75 |

S

76 |
77 |
setEndpoint(String) - Method in class astrea.generators.OwlGenerator
78 |
 
79 |
setQueries(List<String>) - Method in class astrea.generators.OwlGenerator
80 |
81 |
This method allows to set the list of SPARQL queries used to generate the SHACL shapes
82 |
83 |
ShaclFromOwl - Interface in astrea.model
84 |
85 |
This interface represents an Astrea object that is able to produce SHACL shapes for a given ontology.
86 |
87 |
88 | A F G O S 
89 | 90 |
91 | 92 | 93 | 94 | 95 | 96 | 97 | 107 |
108 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Generated Documentation (Untitled) 7 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | <noscript> 69 | <div>JavaScript is disabled on your browser.</div> 70 | </noscript> 71 | <h2>Frame Alert</h2> 72 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /docs/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview List 7 | 8 | 9 | 10 | 11 | 12 |
All Classes
13 |
14 |

Packages

15 | 19 |
20 |

 

21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/overview-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 |
Packages 
PackageDescription
astrea.generators 
astrea.model 
90 |
91 | 92 |
93 | 94 | 95 | 96 | 97 | 98 | 99 | 109 |
110 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /docs/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 |
44 | 71 | 72 |
73 |

Hierarchy For All Packages

74 | Package Hierarchies: 75 | 79 |
80 |
81 |

Class Hierarchy

82 | 89 |

Interface Hierarchy

90 | 93 |
94 | 95 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 112 |
113 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /docs/package-list: -------------------------------------------------------------------------------- 1 | astrea.generators 2 | astrea.model 3 | -------------------------------------------------------------------------------- /docs/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /material/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oeg-upm/astrea/149bad81c9dd63dd22d9a5ab8fd1b2846eb3faa2/material/.DS_Store -------------------------------------------------------------------------------- /material/RDFS.csv: -------------------------------------------------------------------------------- 1 | construct;type;name;description http://www.w3.org/2000/01/rdf-schema#Class;http://www.w3.org/2000/01/rdf-schema#Class;Class;The class of classes. http://www.w3.org/2000/01/rdf-schema#Resource;http://www.w3.org/2000/01/rdf-schema#Class;Resource;The class resource, everything. http://www.w3.org/2000/01/rdf-schema#Literal;http://www.w3.org/2000/01/rdf-schema#Class;Literal;The class of literal values, eg. textual strings and integers. http://www.w3.org/2000/01/rdf-schema#Container;http://www.w3.org/2000/01/rdf-schema#Class;Container;The class of RDF containers. http://www.w3.org/2000/01/rdf-schema#ContainerMembershipProperty;http://www.w3.org/2000/01/rdf-schema#Class;ContainerMembershipProperty;"The class of container membership properties, rdf:_1, rdf:_2, ..., 2 | all of which are sub-properties of 'member'." http://www.w3.org/2000/01/rdf-schema#Datatype;http://www.w3.org/2000/01/rdf-schema#Class;Datatype;The class of RDF datatypes. http://www.w3.org/2000/01/rdf-schema#subPropertyOf;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property;subPropertyOf;The subject is a subproperty of a property. http://www.w3.org/2000/01/rdf-schema#subClassOf;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property;subClassOf;The subject is a subclass of a class. http://www.w3.org/2000/01/rdf-schema#domain;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property;domain;A domain of the subject property. http://www.w3.org/2000/01/rdf-schema#range;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property;range;A range of the subject property. http://www.w3.org/2000/01/rdf-schema#comment;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property;comment;A description of the subject resource. http://www.w3.org/2000/01/rdf-schema#label;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property;label;A human-readable name for the subject. http://www.w3.org/2000/01/rdf-schema#isDefinedBy;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property;isDefinedBy;The defininition of the subject resource. http://www.w3.org/2000/01/rdf-schema#seeAlso;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property;seeAlso;Further information about the subject resource. http://www.w3.org/2000/01/rdf-schema#member;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property;member;A member of the subject resource. http://www.w3.org/2000/01/rdf-schema#Class;http://www.w3.org/2000/01/rdf-schema#Resource;Class;The class of classes. http://www.w3.org/2000/01/rdf-schema#Resource;http://www.w3.org/2000/01/rdf-schema#Resource;Resource;The class resource, everything. http://www.w3.org/2000/01/rdf-schema#Literal;http://www.w3.org/2000/01/rdf-schema#Resource;Literal;The class of literal values, eg. textual strings and integers. http://www.w3.org/2000/01/rdf-schema#Container;http://www.w3.org/2000/01/rdf-schema#Resource;Container;The class of RDF containers. http://www.w3.org/2000/01/rdf-schema#ContainerMembershipProperty;http://www.w3.org/2000/01/rdf-schema#Resource;ContainerMembershipProperty;"The class of container membership properties, rdf:_1, rdf:_2, ..., 3 | all of which are sub-properties of 'member'." http://www.w3.org/2000/01/rdf-schema#Datatype;http://www.w3.org/2000/01/rdf-schema#Resource;Datatype;The class of RDF datatypes. -------------------------------------------------------------------------------- /material/XSD-coverage.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oeg-upm/astrea/149bad81c9dd63dd22d9a5ab8fd1b2846eb3faa2/material/XSD-coverage.xlsx -------------------------------------------------------------------------------- /material/XSD.csv: -------------------------------------------------------------------------------- 1 | construct;name http://www.w3.org/2001/XMLSchema#enumeration;xsd:enumeration http://www.w3.org/2001/XMLSchema#fractionDigits;xsd:fractionDigits http://www.w3.org/2001/XMLSchema#length;xsd:length http://www.w3.org/2001/XMLSchema#list;xsd:list http://www.w3.org/2001/XMLSchema#maxExclusive;xsd:maxExclusive http://www.w3.org/2001/XMLSchema#maxInclusive;xsd:maxInclusive http://www.w3.org/2001/XMLSchema#maxLength;xsd:maxLength http://www.w3.org/2001/XMLSchema#minExclusive;xsd:minExclusive http://www.w3.org/2001/XMLSchema#minInclusive;xsd:minInclusive http://www.w3.org/2001/XMLSchema#minLength;xsd:minLength http://www.w3.org/2001/XMLSchema#pattern;xsd:pattern http://www.w3.org/2001/XMLSchema#restriction;xsd:restriction http://www.w3.org/2001/XMLSchema#simpleType;xsd:simpleType http://www.w3.org/2001/XMLSchema#simpleType;xsd:simpleType http://www.w3.org/2001/XMLSchema#totalDigits;xsd:totalDigits http://www.w3.org/2001/XMLSchema#union;xsd:union http://www.w3.org/2001/XMLSchema#whiteSpace;xsd:whiteSpace http://www.w3.org/2001/XMLSchema#facet;xsd:facet http://www.w3.org/2001/XMLSchema#localSimpleType;xsd:localSimpleType http://www.w3.org/2001/XMLSchema#noFixedFacet;xsd:noFixedFacet http://www.w3.org/2001/XMLSchema#numFacet;xsd:numFacet http://www.w3.org/2001/XMLSchema#simpleType;xsd:simpleType http://www.w3.org/2001/XMLSchema#topLevelSimpleType;xsd:topLevelSimpleType http://www.w3.org/2001/XMLSchema#anyURI;xsd:anyURI http://www.w3.org/2001/XMLSchema#base64Binary;xsd:base64Binary http://www.w3.org/2001/XMLSchema#boolean;xsd:boolean http://www.w3.org/2001/XMLSchema#byte;xsd:byte http://www.w3.org/2001/XMLSchema#date;xsd:date http://www.w3.org/2001/XMLSchema#dateTime;xsd:dateTime http://www.w3.org/2001/XMLSchema#decimal;xsd:decimal http://www.w3.org/2001/XMLSchema#derivationControl;xsd:derivationControl http://www.w3.org/2001/XMLSchema#double;xsd:double http://www.w3.org/2001/XMLSchema#duration;xsd:duration http://www.w3.org/2001/XMLSchema#ENTITIES;xsd:ENTITIES http://www.w3.org/2001/XMLSchema#ENTITY;xsd:ENTITY http://www.w3.org/2001/XMLSchema#float;xsd:float http://www.w3.org/2001/XMLSchema#gDay;xsd:gDay http://www.w3.org/2001/XMLSchema#gMonth;xsd:gMonth http://www.w3.org/2001/XMLSchema#gMonthDay;xsd:gMonthDay http://www.w3.org/2001/XMLSchema#gYear;xsd:gYear http://www.w3.org/2001/XMLSchema#gYearMonth;xsd:gYearMonth http://www.w3.org/2001/XMLSchema#hexBinary;xsd:hexBinary http://www.w3.org/2001/XMLSchema#ID;xsd:ID http://www.w3.org/2001/XMLSchema#IDREF;xsd:IDREF http://www.w3.org/2001/XMLSchema#IDREFS;xsd:IDREFS http://www.w3.org/2001/XMLSchema#int;xsd:int http://www.w3.org/2001/XMLSchema#integer;xsd:integer http://www.w3.org/2001/XMLSchema#language;xsd:language http://www.w3.org/2001/XMLSchema#long;xsd:long http://www.w3.org/2001/XMLSchema#Name;xsd:Name http://www.w3.org/2001/XMLSchema#NCName;xsd:NCName http://www.w3.org/2001/XMLSchema#negativeInteger;xsd:negativeInteger http://www.w3.org/2001/XMLSchema#NMTOKEN;xsd:NMTOKEN http://www.w3.org/2001/XMLSchema#NMTOKENS;xsd:NMTOKENS http://www.w3.org/2001/XMLSchema#nonNegativeInteger;xsd:nonNegativeInteger http://www.w3.org/2001/XMLSchema#nonPositiveInteger;xsd:nonPositiveInteger http://www.w3.org/2001/XMLSchema#normalizedString;xsd:normalizedString http://www.w3.org/2001/XMLSchema#NOTATION;xsd:NOTATION http://www.w3.org/2001/XMLSchema#positiveInteger;xsd:positiveInteger http://www.w3.org/2001/XMLSchema#QName;xsd:QName http://www.w3.org/2001/XMLSchema#short;xsd:short http://www.w3.org/2001/XMLSchema#simpleDerivationSet;xsd:simpleDerivationSet http://www.w3.org/2001/XMLSchema#string;xsd:string http://www.w3.org/2001/XMLSchema#time;xsd:time http://www.w3.org/2001/XMLSchema#token;xsd:token http://www.w3.org/2001/XMLSchema#unsignedByte;xsd:unsignedByte http://www.w3.org/2001/XMLSchema#unsignedInt;xsd:unsignedInt http://www.w3.org/2001/XMLSchema#unsignedLong;xsd:unsignedLong http://www.w3.org/2001/XMLSchema#unsignedShort;xsd:unsignedShort http://www.w3.org/2001/XMLSchema#facets;xsd:facets http://www.w3.org/2001/XMLSchema#simpleDerivation;xsd:simpleDerivation http://www.w3.org/2001/XMLSchema#simpleRestrictionModel;xsd:simpleRestrictionModel http://www.w3.org/2001/XMLSchema#yearMonthDuration;xsd:yearMonthDuration http://www.w3.org/2001/XMLSchema#dayTimeDuration;xsd:dayTimeDuration http://www.w3.org/2001/XMLSchema#dateTimeStamp;xsd:dateTimeStamp -------------------------------------------------------------------------------- /material/mappings/astrea.json: -------------------------------------------------------------------------------- 1 | { 2 | "datasources" : [ 3 | { 4 | "id" : "Table of Astrea Queries", 5 | "type" : "CsvDatasource", 6 | "arguments" : [";"], 7 | "connector" : { 8 | "arguments" : ["./mappings/data/Queries.csv"], 9 | "type" : "LocalFileConnector", 10 | } 11 | } 12 | ], 13 | "resource_rules" : [ 14 | { 15 | "id" : "Astrea SHACL pattern", 16 | "datasource_ids" : ["Table of Astrea Queries"], 17 | "subject" : "http://astrea.helio.linkeddata.es/[REPLACE(hashCode(TRIM({Graph Pattern Target})),'-','1')]", 18 | "properties" : [ 19 | { 20 | "predicate" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", 21 | "object" : "https://w3id.org/def/astrea#Pattern", 22 | "is_literal" : "False" 23 | },{ 24 | "predicate" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", 25 | "object" : "https://w3id.org/def/astrea#SHACLPattern", 26 | "is_literal" : "False" 27 | },{ 28 | "predicate" : "https://w3id.org/def/astrea#statement", 29 | "object" : "{Graph Pattern Target}", 30 | "datatype" : "http://www.w3.org/2001/XMLSchema#string", 31 | "is_literal" : "True" 32 | },{ 33 | "predicate" : "https://w3id.org/def/astrea#involves", 34 | "object" : "http://astrea.helio.linkeddata.es/[splitBy(TRIM({SHACL Construct}),'\\s*,\\s*')]", 35 | "is_literal" : "False" 36 | },{ 37 | "predicate" : "https://w3id.org/def/astrea#isMappedTo", 38 | "object" : "http://astrea.helio.linkeddata.es/[REPLACE(hashCode(TRIM({Graph Pattern Source})),'-','1')]", 39 | "is_literal" : "False" 40 | } 41 | ] 42 | },{ 43 | "id" : "Astrea Ontology pattern", 44 | "datasource_ids" : ["Table of Astrea Queries"], 45 | "subject" : "http://astrea.helio.linkeddata.es/[REPLACE(hashCode(TRIM({Graph Pattern Source})),'-','1')]", 46 | "properties" : [ 47 | { 48 | "predicate" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", 49 | "object" : "https://w3id.org/def/astrea#Pattern", 50 | "is_literal" : "False" 51 | },{ 52 | "predicate" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", 53 | "object" : "https://w3id.org/def/astrea#OWLPattern", 54 | "is_literal" : "False" 55 | },{ 56 | "predicate" : "https://w3id.org/def/astrea#statement", 57 | "object" : "{Graph Pattern Source}", 58 | "datatype" : "http://www.w3.org/2001/XMLSchema#string", 59 | "is_literal" : "True" 60 | },{ 61 | "predicate" : "https://w3id.org/def/astrea#isTranslatedBy", 62 | "object" : "http://astrea.helio.linkeddata.es/[REPLACE(hashCode(TRIM(STRINGENCODE({QUERY}))),'-','1')]", 63 | "is_literal" : "False" 64 | },{ 65 | "predicate" : "https://w3id.org/def/astrea#involves", 66 | "object" : "http://astrea.helio.linkeddata.es/[splitBy(TRIM({OWL Construct}),'\\s*,\\s*')]", 67 | "is_literal" : "False" 68 | } 69 | ] 70 | },{ 71 | "id" : "Astrea Mappings", 72 | "datasource_ids" : ["Table of Astrea Queries"], 73 | "subject" : "http://astrea.helio.linkeddata.es/[REPLACE(hashCode(TRIM(STRINGENCODE({QUERY}))),'-','1')]", 74 | "properties" : [ 75 | { 76 | "predicate" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", 77 | "object" : "https://w3id.org/def/astrea#MappingImplementation", 78 | "is_literal" : "False" 79 | }, 80 | { 81 | "predicate" : "https://w3id.org/def/astrea#query", 82 | "object" : "[TRIM({QUERY})]", 83 | "datatype" : "http://www.w3.org/2001/XMLSchema#string", 84 | "is_literal" : "True" 85 | },{ 86 | "predicate" : "https://w3id.org/def/astrea#hasTarget", 87 | "object" : "http://astrea.helio.linkeddata.es/[REPLACE(hashCode(TRIM({Graph Pattern Target})),'-','1')]", 88 | "is_literal" : "False" 89 | } 90 | ] 91 | } 92 | ] 93 | } -------------------------------------------------------------------------------- /mvn-install.sh: -------------------------------------------------------------------------------- 1 | # 1. Install the helio-core dependency in your local repository using this script 2 | mvn clean install -DskipTests 3 | mvn install:install-file -Dfile=./target/astrea-1.2.1.jar -DgroupId=oeg.validation -DartifactId=astrea -Dversion=1.2.1 -Dpackaging=jar 4 | 5 | # 2. You are ready to go and use the framework -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | oeg.validation 4 | astrea 5 | 1.2.1 6 | Astrea 7 | Astrea: SHACL shapes generation from ontologies 8 | 9 | 10 | 11 | 1.8 12 | 1.8 13 | UTF-8 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | 21 | org.apache.jena 22 | apache-jena-libs 23 | 3.13.0 24 | pom 25 | 26 | 27 | 28 | junit 29 | junit 30 | 4.13.1 31 | test 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/java/astrea/model/ShaclFromOwl.java: -------------------------------------------------------------------------------- 1 | package astrea.model; 2 | 3 | import java.util.List; 4 | import org.apache.jena.rdf.model.Model; 5 | /** 6 | *

This interface represents an Astrea object that is able to produce SHACL shapes for a given ontology.

7 | *

An ontology is a formal description of knowledge as a set of concepts within a domain and the relationships that hold between them.

8 | *

This kind of objects exploits the restrictions explicit in such formal descriptions to produce a set of SHACL shapes.

9 | */ 10 | public interface ShaclFromOwl { 11 | /** 12 | * This method aims at generating the SHACL shapes from the url of an ontology 13 | * @param owlUrl an ontology url 14 | * @return a jena {@link Model} containing the SHACL shapes generated 15 | */ 16 | public Model fromURL(String owlUrl); 17 | /** 18 | * This method aims at generating the SHACL shapes from a set of ontology urls 19 | * @param owlUrls a list of onotlogies urls 20 | * @return a jena {@link Model} containing the SHACL shapes generated 21 | */ 22 | public Model fromURLs(List owlUrls); 23 | /** 24 | * This method aims at generating the SHACL shapes from the content in memory of one or more ontologies 25 | * @param owlContent the content of one or more ontologies 26 | * @param format a valid jena format 27 | * @return a jena {@link Model} containing the SHACL shapes generated 28 | */ 29 | public Model fromOwl(String owlContent, String format); 30 | /** 31 | * This method aims at generating the SHACL shapes from a jena {@link Model} containing the content of one or more ontologies 32 | * @param ontology a {@link Model} containing the content of one or more ontologies 33 | * @return a jena {@link Model} containing the SHACL shapes generated 34 | */ 35 | public Model fromModel(Model ontology); 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/owl/CardinalityTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.owl; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.ResourceFactory; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import astrea.generators.OptimisedOwlGenerator; 9 | import astrea.model.ShaclFromOwl; 10 | 11 | 12 | /** 13 | * This unitary Test class aim at validating our proposal with all the UC of https://spinrdf.org/shacl-and-owl.html 14 | * @author Andrea Cimmino Arriaga, Alba Fernandez Izquierdo 15 | * 16 | */ 17 | public class CardinalityTest { 18 | 19 | // Extracted from: https://www.w3.org/2006/time#s 20 | public static final String CARDINALITY_OWL_FRAGMENT_WITH_OWL_CARDINALITY = "@prefix : .\n" + 21 | "@prefix dct: .\n" + 22 | "@prefix owl: .\n" + 23 | "@prefix rdf: .\n" + 24 | "@prefix rdfs: .\n" + 25 | "@prefix skos: .\n" + 26 | "@prefix xsd: ." + 27 | ":Duration\n" + 28 | " rdf:type owl:Class ;\n" + 29 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 30 | " rdfs:label \"Time duration\"@en ;\n" + 31 | " rdfs:subClassOf :TemporalDuration ;\n" + 32 | " rdfs:subClassOf [\n" + 33 | " rdf:type owl:Restriction ;\n" + 34 | " owl:cardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 35 | " owl:onProperty :numericDuration ;\n" + 36 | " ] ;\n" + 37 | " rdfs:subClassOf [\n" + 38 | " rdf:type owl:Restriction ;\n" + 39 | " owl:minCardinality \"2\"^^xsd:nonNegativeInteger ;\n" + 40 | " owl:onProperty :unitType ;\n" + 41 | " ] ;\n" + 42 | " rdfs:subClassOf [\n" + 43 | " rdf:type owl:Restriction ;\n" + 44 | " owl:maxCardinality \"3\"^^xsd:nonNegativeInteger ;\n" + 45 | " owl:onProperty :month ;\n" + 46 | " ] ;\n" + 47 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 48 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 49 | ".\n"; 50 | 51 | private static final String SH_MAX_COUNT = "http://www.w3.org/ns/shacl#maxCount"; 52 | private static final String SH_MIN_COUNT = "http://www.w3.org/ns/shacl#minCount"; 53 | 54 | 55 | 56 | @Test 57 | public void compliantWithOwlCardinality() { 58 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 59 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_WITH_OWL_CARDINALITY, "TURTLE"); 60 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 61 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_MIN_COUNT), ResourceFactory.createTypedLiteral(1)); 62 | Assert.assertTrue(condition); 63 | } 64 | 65 | @Test 66 | public void compliantWithOwlMinCardinality() { 67 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 68 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_WITH_OWL_CARDINALITY, "TURTLE"); 69 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MIN_COUNT), ResourceFactory.createTypedLiteral(2)); 70 | Assert.assertTrue(condition); 71 | } 72 | 73 | 74 | @Test 75 | public void compliantWithOwlMaxCardinality() { 76 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 77 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_WITH_OWL_CARDINALITY, "TURTLE"); 78 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(3)); 79 | Assert.assertTrue(condition); 80 | } 81 | 82 | 83 | 84 | 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/owl/DatatypeTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.owl; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.ResourceFactory; 5 | import org.apache.jena.vocabulary.RDF; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import astrea.generators.OptimisedOwlGenerator; 10 | import astrea.model.ShaclFromOwl; 11 | 12 | public class DatatypeTest { 13 | 14 | public static final String OWL_FRAGMENT_OF_A_DATA_PROPERTY = "@prefix : .\n" + 15 | "@prefix dct: .\n" + 16 | "@prefix owl: .\n" + 17 | "@prefix rdf: .\n" + 18 | "@prefix rdfs: .\n" + 19 | "@prefix skos: .\n" + 20 | "@prefix xsd: .\n" + 21 | ":minute\n" + 22 | " rdf:type owl:DatatypeProperty ;\n" + 23 | " rdfs:comment \"Minute position in a calendar-clock system.\"@en ;\n" + 24 | " rdfs:domain :GeneralDateTimeDescription ;\n" + 25 | " rdfs:label \"minute\"@en ;\n" + 26 | " rdfs:range xsd:nonNegativeInteger ;\n" + 27 | " skos:definition \"Minute position in a calendar-clock system.\"@en ;\n" + 28 | "."; 29 | public static final String OWL_FRAGMENT_OF_RDF_DATA_PROPERTY = "@prefix : .\n" + 30 | "@prefix dct: .\n" + 31 | "@prefix owl: .\n" + 32 | "@prefix rdf: .\n" + 33 | "@prefix rdfs: .\n" + 34 | "@prefix skos: .\n" + 35 | "@prefix xsd: .\n" + 36 | ":minute\n" + 37 | " rdf:type rdf:Property ;\n" + 38 | " rdfs:comment \"Minute position in a calendar-clock system.\"@en ;\n" + 39 | " rdfs:domain :GeneralDateTimeDescription ;\n" + 40 | " rdfs:label \"minute\"@en ;\n" + 41 | " rdfs:range xsd:nonNegativeInteger ;\n" + 42 | " skos:definition \"Minute position in a calendar-clock system.\"@en ;\n" + 43 | "."; 44 | 45 | public static final String OWL_FRAGMENT_OF_A_OBJECT_PROPERTY = "@prefix : .\n" + 46 | "@prefix dct: .\n" + 47 | "@prefix owl: .\n" + 48 | "@prefix rdf: .\n" + 49 | "@prefix rdfs: .\n" + 50 | "@prefix skos: .\n" + 51 | "@prefix xsd: .\n" + 52 | ":monthOfYear\n" + 53 | " rdf:type owl:ObjectProperty ;\n" + 54 | " rdfs:comment \"The month of the year, whose value is a member of the class time:MonthOfYear\"@en ;\n" + 55 | " rdfs:domain :GeneralDateTimeDescription ;\n" + 56 | " rdfs:label \"month of year\"@en ;\n" + 57 | " rdfs:range :MonthOfYear ;\n" + 58 | " skos:definition \"The month of the year, whose value is a member of the class time:MonthOfYear\"@en ;\n" + 59 | " skos:editorialNote \"Feature at risk - added in 2017 revision, and not yet widely used. \"@en ;\n" + 60 | "."; 61 | 62 | public static final String OWL_FRAGMENT_OF_RDF_OBJECT_PROPERTY = "@prefix : .\n" + 63 | "@prefix dct: .\n" + 64 | "@prefix owl: .\n" + 65 | "@prefix rdf: .\n" + 66 | "@prefix rdfs: .\n" + 67 | "@prefix skos: .\n" + 68 | "@prefix xsd: .\n" + 69 | ":monthOfYear\n" + 70 | " rdf:type rdf:Property ;\n" + 71 | " rdfs:comment \"The month of the year, whose value is a member of the class time:MonthOfYear\"@en ;\n" + 72 | " rdfs:domain :GeneralDateTimeDescription ;\n" + 73 | " rdfs:label \"month of year\"@en ;\n" + 74 | " rdfs:range :MonthOfYear ;\n" + 75 | " skos:definition \"The month of the year, whose value is a member of the class time:MonthOfYear\"@en ;\n" + 76 | " skos:editorialNote \"Feature at risk - added in 2017 revision, and not yet widely used. \"@en ;\n" + 77 | "."; 78 | 79 | 80 | private static final String SH_PROPERTY_SHAPE = "http://www.w3.org/ns/shacl#PropertyShape"; 81 | 82 | // Testing creation of sh:NodeShape from owl:Class 83 | 84 | @Test 85 | public void createNodeShapeFromOwlClass() { 86 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 87 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_OF_RDF_OBJECT_PROPERTY, "TURTLE"); 88 | Boolean condition = shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_PROPERTY_SHAPE)); 89 | Assert.assertTrue(condition); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/owl/EquialityTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.owl; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.ResourceFactory; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import astrea.generators.OptimisedOwlGenerator; 9 | import astrea.model.ShaclFromOwl; 10 | 11 | public class EquialityTest { 12 | 13 | public static final String ANNOTATION_PROPERTIES_OWL_FRAGMENT ="@prefix foaf: .\n" + 14 | "@prefix owl: .\n" + 15 | "@prefix dc11: .\n" + 16 | "@prefix wot: .\n" + 17 | "@prefix rdfs: .\n" + 18 | "@prefix ns0: .\n" + 19 | "@prefix schema: .\n" + 20 | "@prefix geo: .\n" + 21 | "@prefix dc: .\n" + 22 | "@prefix rdf: .\n" + 23 | "@prefix skos: .\n" + 24 | "\n" + 25 | "foaf:maker\n" + 26 | " a rdf:Property, owl:ObjectProperty ;\n" + 27 | " ns0:term_status \"stable\" ;\n" + 28 | " rdfs:label \"maker\" ;\n" + 29 | " rdfs:comment \"An agent that made this thing.\" ;\n" + 30 | " owl:equivalentProperty dc:creator ;\n" + 31 | " rdfs:domain owl:Thing ;\n" + 32 | " rdfs:range foaf:Agent ;\n" + 33 | " rdfs:isDefinedBy foaf: ;\n" + 34 | " owl:inverseOf foaf:made ."; 35 | 36 | 37 | public static final String SH_EQUIVALENT = "http://www.w3.org/ns/shacl#equivalent"; 38 | public static final String SH_DATATYPE = "http://www.w3.org/ns/shacl#datatype"; 39 | public static final String SH_CLASS = "http://www.w3.org/ns/shacl#class"; 40 | 41 | // -- Tests for NodeShapes 42 | @Test 43 | public void compliantWithShNameNodeShape() { 44 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 45 | Model shapes = sharper.fromOwl(ANNOTATION_PROPERTIES_OWL_FRAGMENT, "TURTLE"); 46 | 47 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_EQUIVALENT), ResourceFactory.createResource("http://purl.org/dc/terms/creator")); 48 | condition &= !shapes.contains(null, ResourceFactory.createProperty(SH_DATATYPE), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/Agent")); 49 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_CLASS), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/Agent")); 50 | 51 | Assert.assertTrue(condition); 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/owl/FillerInformationTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.owl; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.RDFNode; 5 | import org.apache.jena.rdf.model.ResourceFactory; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import astrea.generators.OptimisedOwlGenerator; 10 | import astrea.model.ShaclFromOwl; 11 | 12 | public class FillerInformationTest { 13 | 14 | private static final String HAS_VALUE_OWL_FRAGMENT_WITH_HAS_VALUE = "@prefix : .\n" + 15 | "@prefix dct: .\n" + 16 | "@prefix owl: .\n" + 17 | "@prefix rdf: .\n" + 18 | "@prefix rdfs: .\n" + 19 | "@prefix skos: .\n" + 20 | "@prefix xsd: ." + 21 | ":January\n" + 22 | " rdf:type owl:Class ;\n" + 23 | " rdf:type owl:DeprecatedClass ;\n" + 24 | " rdfs:label \"January\" ;\n" + 25 | " rdfs:subClassOf :DateTimeDescription ;\n" + 26 | " rdfs:subClassOf [\n" + 27 | " rdf:type owl:Restriction ;\n" + 28 | " owl:hasValue :unitMonth ;\n" + 29 | " owl:onProperty :unitType ;\n" + 30 | " ] ;\n" + 31 | " rdfs:subClassOf [\n" + 32 | " rdf:type owl:Restriction ;\n" + 33 | " owl:hasValue \"--01\" ;\n" + 34 | " owl:onProperty :month ;\n" + 35 | " ] ;\n" + 36 | " owl:deprecated \"true\"^^xsd:boolean ;\n" + 37 | " skos:historyNote \"This class was present in the 2006 version of OWL-Time. It was presented as an example of how DateTimeDescription could be specialized, but does not belong in the revised ontology. \" ;\n" + 38 | "."; 39 | 40 | private static final String HAS_VALUE_OWL_FRAGMENT_WITHOUT_HAS_VALUE = "@prefix : .\n" + 41 | "@prefix dct: .\n" + 42 | "@prefix owl: .\n" + 43 | "@prefix rdf: .\n" + 44 | "@prefix rdfs: .\n" + 45 | "@prefix skos: .\n" + 46 | "@prefix xsd: ." + 47 | ":January\n" + 48 | " rdf:type owl:Class ;\n" + 49 | " rdf:type owl:DeprecatedClass ;\n" + 50 | " rdfs:label \"January\" ;\n" + 51 | " rdfs:subClassOf :DateTimeDescription ;\n" + 52 | " rdfs:subClassOf [\n" + 53 | " rdf:type owl:Restriction ;\n" + 54 | " owl:onProperty :unitType ;\n" + 55 | " ] ;\n" + 56 | " rdfs:subClassOf [\n" + 57 | " rdf:type owl:Restriction ;\n" + 58 | " owl:onProperty :month ;\n" + 59 | " ] ;\n" + 60 | " owl:deprecated \"true\"^^xsd:boolean ;\n" + 61 | " skos:historyNote \"This class was present in the 2006 version of OWL-Time. It was presented as an example of how DateTimeDescription could be specialized, but does not belong in the revised ontology. \" ;\n" + 62 | "."; 63 | private static final String SH_HAS_VALUE = "http://www.w3.org/ns/shacl#hasValue"; 64 | 65 | @Test 66 | public void hasValueWithLiteral() { 67 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 68 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_HAS_VALUE, "TURTLE"); 69 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_HAS_VALUE), ResourceFactory.createPlainLiteral("--01")); 70 | Assert.assertTrue(condition); 71 | } 72 | 73 | @Test 74 | public void hasValueWithUri() { 75 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 76 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_HAS_VALUE, "TURTLE"); 77 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_HAS_VALUE), ResourceFactory.createResource("http://www.w3.org/2006/time#unitMonth")); 78 | Assert.assertTrue(condition); 79 | } 80 | 81 | @Test 82 | public void hasValueMissing() { 83 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 84 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITHOUT_HAS_VALUE, "TURTLE"); 85 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_HAS_VALUE), (RDFNode) null); 86 | Assert.assertFalse(condition); 87 | } 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/owl/PropertyCharacteristicsTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.owl; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.RDFNode; 5 | import org.apache.jena.rdf.model.ResourceFactory; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import astrea.generators.OptimisedOwlGenerator; 10 | import astrea.model.ShaclFromOwl; 11 | 12 | public class PropertyCharacteristicsTest { 13 | 14 | private static final String HAS_VALUE_OWL_FRAGMENT_WITH_FUNCTIONAL_PROPERTY = "@prefix : .\n" + 15 | "@prefix dct: .\n" + 16 | "@prefix owl: .\n" + 17 | "@prefix rdf: .\n" + 18 | "@prefix rdfs: .\n" + 19 | "@prefix skos: .\n" + 20 | "@prefix xsd: ." + 21 | ":hasTRS\n" + 22 | " rdf:type owl:FunctionalProperty ;\n" + 23 | " rdf:type owl:ObjectProperty ;\n" + 24 | " rdfs:comment \"The temporal reference system used by a temporal position or extent description. \"@en ;\n" + 25 | " rdfs:domain [\n" + 26 | " rdf:type owl:Class ;\n" + 27 | " owl:unionOf (\n" + 28 | " :TemporalPosition\n" + 29 | " :GeneralDurationDescription\n" + 30 | " ) ;\n" + 31 | " ] ;\n" + 32 | " rdfs:label \"Temporal reference system used\"@en ;\n" + 33 | " rdfs:range :TRS ;\n" + 34 | " skos:definition \"The temporal reference system used by a temporal position or extent description. \"@en ;\n" + 35 | "."; 36 | private static final String HAS_VALUE_OWL_FRAGMENT_WITHOUT_FUNCTIONAL_PROPERTY = "@prefix : .\n" + 37 | "@prefix dct: .\n" + 38 | "@prefix owl: .\n" + 39 | "@prefix rdf: .\n" + 40 | "@prefix rdfs: .\n" + 41 | "@prefix skos: .\n" + 42 | "@prefix xsd: ." + 43 | ":hasTRS\n" + 44 | // " rdf:type owl:FunctionalProperty ;\n" + Missing line 45 | " rdf:type owl:ObjectProperty ;\n" + 46 | " rdfs:comment \"The temporal reference system used by a temporal position or extent description. \"@en ;\n" + 47 | " rdfs:domain [\n" + 48 | " rdf:type owl:Class ;\n" + 49 | " owl:unionOf (\n" + 50 | " :TemporalPosition\n" + 51 | " :GeneralDurationDescription\n" + 52 | " ) ;\n" + 53 | " ] ;\n" + 54 | " rdfs:label \"Temporal reference system used\"@en ;\n" + 55 | " rdfs:range :TRS ;\n" + 56 | " skos:definition \"The temporal reference system used by a temporal position or extent description. \"@en ;\n" + 57 | "."; 58 | 59 | private static final String HAS_VALUE_OWL_FRAGMENT_WITH_INVERSE_FUNCTIONAL_PROPERTY_OP = "@prefix : .\n" + 60 | "@prefix dct: .\n" + 61 | "@prefix owl: .\n" + 62 | "@prefix rdf: .\n" + 63 | "@prefix rdfs: .\n" + 64 | "@prefix skos: .\n" + 65 | "@prefix xsd: ." + 66 | "@prefix foaf: .\n" + 67 | "foaf:mbox\n" + 68 | " a rdf:Property, owl:InverseFunctionalProperty, owl:ObjectProperty ;\n" + 69 | " foaf:term_status \"stable\" ;\n" + 70 | " rdfs:label \"personal mailbox\" ;\n" + 71 | " rdfs:comment \"A personal mailbox, ie. an Internet mailbox associated with exactly one owner, the first owner of this mailbox. This is a 'static inverse functional property', in that there is (across time and change) at most one individual that ever has any particular value for foaf:mbox.\" ;\n" + 72 | " rdfs:domain foaf:Agent ;\n" + 73 | " rdfs:range owl:Thing ;\n" + 74 | " rdfs:isDefinedBy foaf: .\n"; 75 | private static final String HAS_VALUE_OWL_FRAGMENT_WITH_INVERSE_FUNCTIONAL_PROPERTY_DP = "@prefix : .\n" + 76 | "@prefix dct: .\n" + 77 | "@prefix owl: .\n" + 78 | "@prefix rdf: .\n" + 79 | "@prefix rdfs: .\n" + 80 | "@prefix skos: .\n" + 81 | "@prefix xsd: ." + 82 | "@prefix foaf: .\n" + 83 | "foaf:mbox_sha1sum\n" + 84 | " a rdf:Property, owl:InverseFunctionalProperty, owl:DatatypeProperty ;\n" + 85 | " foaf:term_status \"testing\" ;\n" + 86 | " rdfs:label \"sha1sum of a personal mailbox URI name\" ;\n" + 87 | " rdfs:comment \"The sha1sum of the URI of an Internet mailbox associated with exactly one owner, the first owner of the mailbox.\" ;\n" + 88 | " rdfs:domain foaf:Agent ;\n" + 89 | " rdfs:range rdfs:Literal ;\n" + 90 | " rdfs:isDefinedBy foaf: ."; 91 | 92 | 93 | 94 | private static final String SH_MAX_COUNT = "http://www.w3.org/ns/shacl#maxCount"; 95 | private static final String SH_INVERSE_PATH = "http://www.w3.org/ns/shacl#inversePath"; 96 | private static final String SH_PATH = "http://www.w3.org/ns/shacl#path"; 97 | 98 | @Test 99 | public void hasShMaxCount() { 100 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 101 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_FUNCTIONAL_PROPERTY, "TURTLE"); 102 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 103 | Assert.assertTrue(condition); 104 | } 105 | 106 | @Test 107 | public void hasNotShMaxCount() { 108 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 109 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITHOUT_FUNCTIONAL_PROPERTY, "TURTLE"); 110 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 111 | Assert.assertFalse(condition); 112 | } 113 | 114 | 115 | @Test 116 | public void hasInverseFunctionalWithOP() { 117 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 118 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_INVERSE_FUNCTIONAL_PROPERTY_OP, "TURTLE"); 119 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 120 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_INVERSE_PATH), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/mbox")); 121 | condition &= !shapes.contains(null, ResourceFactory.createProperty(SH_PATH), (RDFNode) null); 122 | Assert.assertTrue(condition); 123 | } 124 | 125 | @Test 126 | public void hasInverseFunctionalWithDP() { 127 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 128 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_INVERSE_FUNCTIONAL_PROPERTY_DP, "TURTLE"); 129 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 130 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_INVERSE_PATH), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/mbox_sha1sum")); 131 | condition &= !shapes.contains(null, ResourceFactory.createProperty(SH_PATH), (RDFNode) null); 132 | Assert.assertTrue(condition); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/owl/PropertyRestrictionsTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.owl; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.ResourceFactory; 5 | import org.apache.jena.vocabulary.RDF; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import astrea.generators.OptimisedOwlGenerator; 10 | import astrea.model.ShaclFromOwl; 11 | 12 | public class PropertyRestrictionsTest { 13 | 14 | 15 | public static final String OWL_FRAGMENT_OF_OWL_CLASS = "@prefix : .\n" + 16 | "@prefix dct: .\n" + 17 | "@prefix owl: .\n" + 18 | "@prefix rdf: .\n" + 19 | "@prefix rdfs: .\n" + 20 | "@prefix skos: .\n" + 21 | "@prefix xsd: .\n" + 22 | ":Duration\n" + 23 | " rdf:type owl:Class ;\n" + 24 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 25 | " rdfs:label \"Time duration\"@en ;\n" + 26 | " rdfs:subClassOf :TemporalDuration ;\n" + 27 | " rdfs:subClassOf [\n" + 28 | " rdf:type owl:Restriction ;\n" + 29 | " owl:cardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 30 | " owl:onProperty :numericDuration ;\n" + 31 | " ] ;\n" + 32 | " rdfs:subClassOf [\n" + 33 | " rdf:type owl:Restriction ;\n" + 34 | " owl:cardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 35 | " owl:onProperty :unitType ;\n" + 36 | " ] ;\n" + 37 | " rdfs:subClassOf [\n" + 38 | " rdf:type owl:Restriction ;\n" + 39 | " owl:allValuesFrom xsd:gMonth ;\n" + 40 | " owl:onProperty :month ;\n" + 41 | " ] ;" + 42 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 43 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 44 | "."; 45 | 46 | 47 | private static final String SH_NODE_SHAPE = "http://www.w3.org/ns/shacl#NodeShape"; 48 | private static final String SH_PROPERTY_SHAPE = "http://www.w3.org/ns/shacl#PropertyShape"; 49 | private static final String SH_PATH = "http://www.w3.org/ns/shacl#path"; 50 | 51 | 52 | @Test 53 | public void createEmbeddedPorpertyShapeFromOnProperty() { 54 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 55 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_OF_OWL_CLASS, "TURTLE"); 56 | Boolean condition = shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_NODE_SHAPE)); 57 | condition &= shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_PROPERTY_SHAPE)); 58 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_PATH), ResourceFactory.createResource("http://www.w3.org/2006/time#numericDuration")); 59 | Assert.assertTrue(condition); 60 | } 61 | 62 | 63 | @Test 64 | public void createEmbeddedPorpertyShapeFromAllValuesFrom() { 65 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 66 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_OF_OWL_CLASS, "TURTLE"); 67 | Boolean condition = shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_NODE_SHAPE)); 68 | condition &= shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_PROPERTY_SHAPE)); 69 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_PATH), ResourceFactory.createResource("http://www.w3.org/2006/time#numericDuration")); 70 | Assert.assertTrue(condition); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/shapes/CardinalityConstraintTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.shapes; 2 | 3 | import astrea.generators.OptimisedOwlGenerator; 4 | import astrea.model.ShaclFromOwl; 5 | import org.apache.jena.rdf.model.Model; 6 | import org.apache.jena.rdf.model.ResourceFactory; 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | 10 | public class CardinalityConstraintTest { 11 | // Extracted from: https://www.w3.org/2006/time#s 12 | public static final String CARDINALITY_OWL_FRAGMENT_MIN_COUNT = "@prefix : .\n" + 13 | "@prefix dct: .\n" + 14 | "@prefix owl: .\n" + 15 | "@prefix rdf: .\n" + 16 | "@prefix rdfs: .\n" + 17 | "@prefix skos: .\n" + 18 | "@prefix xsd: ." + 19 | ":Duration\n" + 20 | " rdf:type owl:Class ;\n" + 21 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 22 | " rdfs:label \"Time duration\"@en ;\n" + 23 | " rdfs:subClassOf :TemporalDuration ;\n" + 24 | " rdfs:subClassOf [\n" + 25 | " rdf:type owl:Restriction ;\n" + 26 | " owl:minCardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 27 | " owl:onProperty :unitType ;\n" + 28 | " ] ;\n" + 29 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 30 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 31 | ".\n"; 32 | // Extracted from: https://www.w3.org/2006/time#s --> modified 33 | public static final String CARDINALITY_OWL_FRAGMENT_MAX_COUNT = "@prefix : .\n" + 34 | "@prefix dct: .\n" + 35 | "@prefix owl: .\n" + 36 | "@prefix rdf: .\n" + 37 | "@prefix rdfs: .\n" + 38 | "@prefix skos: .\n" + 39 | "@prefix xsd: ." + 40 | ":Duration\n" + 41 | " rdf:type owl:Class ;\n" + 42 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 43 | " rdfs:label \"Time duration\"@en ;\n" + 44 | " rdfs:subClassOf :TemporalDuration ;\n" + 45 | " rdfs:subClassOf [\n" + 46 | " rdf:type owl:Restriction ;\n" + 47 | " owl:maxCardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 48 | " owl:onProperty :unitType ;\n" + 49 | " ] ;\n" + 50 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 51 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 52 | ".\n"; 53 | 54 | private static final String SH_MAX_COUNT = "http://www.w3.org/ns/shacl#maxCount"; 55 | private static final String SH_MIN_COUNT = "http://www.w3.org/ns/shacl#minCount"; 56 | 57 | @Test 58 | public void compliantWithShMinCountShape() { 59 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 60 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_MIN_COUNT, "TURTLE"); 61 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MIN_COUNT),ResourceFactory.createTypedLiteral(1)); 62 | Assert.assertTrue(condition); 63 | } 64 | 65 | @Test 66 | public void compliantWithShMaxCountShape() { 67 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 68 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_MAX_COUNT, "TURTLE"); 69 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT),ResourceFactory.createTypedLiteral(1)); 70 | Assert.assertTrue(condition); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/shapes/LogicalConstraintsTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.shapes; 2 | 3 | import astrea.generators.OptimisedOwlGenerator; 4 | import astrea.model.ShaclFromOwl; 5 | 6 | import org.apache.jena.rdf.model.Model; 7 | import org.apache.jena.rdf.model.RDFNode; 8 | import org.apache.jena.rdf.model.ResourceFactory; 9 | import org.apache.jena.vocabulary.RDF; 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | 13 | public class LogicalConstraintsTest { 14 | 15 | 16 | public static final String OWL_FRAGMENT_AND = "@prefix owl: .\n"+ 17 | "\n" + 18 | " a owl:Class ;\n" + 19 | " owl:intersectionOf (\n" + 20 | " \n" + 21 | " \n" + 22 | " ) ."; 23 | 24 | public static final String OWL_FRAGMENT_NOT = "@prefix owl: .\n" + 25 | "@prefix dc11: .\n" + 26 | "@prefix dc: .\n" + 27 | "@prefix xsd: .\n" + 28 | "@prefix rdfs: ."+ 29 | "\n" + 30 | " a owl:Class ;\n" + 31 | " owl:complementOf ."; 32 | 33 | public static final String OWL_FRAGMENT_NOT_PROP = "@prefix owl: .\n" + 34 | "@prefix dc11: .\n" + 35 | "@prefix dc: .\n" + 36 | "@prefix xsd: .\n" + 37 | "@prefix rdfs: ."+ 38 | "\n" + 39 | " a owl:Class ;\n" + 40 | " owl:complementOf [\n" + 41 | " a owl:Restriction ;\n" + 42 | " owl:onProperty ;\n" + 43 | " owl:hasValue \n" + 44 | " ] ."; 45 | 46 | public static final String OWL_FRAGMENT_OR = "@prefix : .\n" + 47 | "@prefix dct: .\n" + 48 | "@prefix owl: .\n" + 49 | "@prefix rdf: .\n" + 50 | "@prefix rdfs: .\n" + 51 | "@prefix skos: .\n" + 52 | "@prefix xsd: ."+ 53 | ":TemporalEntity\n" + 54 | " rdf:type owl:Class ;\n" + 55 | " rdfs:comment \"A temporal interval or instant.\"@en ;\n" + 56 | " rdfs:label \"Temporal entity\"@en ;\n" + 57 | " rdfs:subClassOf owl:Thing ;\n" + 58 | " owl:unionOf (\n" + 59 | " :Instant\n" + 60 | " :Interval\n" + 61 | " ) ;\n" + 62 | " skos:definition \"A temporal interval or instant.\"@en ;\n" + 63 | "."; 64 | 65 | 66 | private static final String SH_AND = "http://www.w3.org/ns/shacl#and"; 67 | private static final String SH_NOT = "http://www.w3.org/ns/shacl#not"; 68 | private static final String SH_PROPERTY_SHAPE = "http://www.w3.org/ns/shacl#PropertyShape"; 69 | private static final String SH_PATH= "http://www.w3.org/ns/shacl#path"; 70 | private static final String SH_OR= "http://www.w3.org/ns/shacl#or"; 71 | 72 | 73 | @Test 74 | public void compliantWithShAndShape() { 75 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 76 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_AND, "TURTLE"); 77 | 78 | Boolean condition = shapes.containsResource(ResourceFactory.createResource("http://njh.me/#BurgundyShape")); 79 | condition &= shapes.containsResource(ResourceFactory.createResource("http://njh.me/#WhiteWineShape")); 80 | condition &= shapes.containsResource(ResourceFactory.createResource(SH_AND)); 81 | 82 | Assert.assertTrue(condition); 83 | } 84 | 85 | @Test 86 | public void compliantWithShNotShape() { 87 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 88 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_NOT, "TURTLE"); 89 | Boolean condition = shapes.contains(ResourceFactory.createResource("http://www.co-ode.org/ontologies/pizza/pizza.owl#NonConsumableThingShape"), 90 | ResourceFactory.createProperty(SH_NOT), ResourceFactory.createResource("http://www.co-ode.org/ontologies/pizza/pizza.owl#ConsumableThingShape")); 91 | 92 | Assert.assertTrue(condition); 93 | } 94 | 95 | @Test 96 | public void compliantWithShNotPropertyShape() { 97 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 98 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_NOT_PROP, "TURTLE"); 99 | Boolean condition = shapes.contains(ResourceFactory.createResource("http://www.co-ode.org/ontologies/pizza/pizza.owl#WineShape"), 100 | ResourceFactory.createProperty(SH_NOT), (RDFNode) null); 101 | condition &= shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_PROPERTY_SHAPE)); 102 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_PATH), ResourceFactory.createResource("http://www.co-ode.org/ontologies/pizza/pizza.owl#locatedIn")); 103 | Assert.assertTrue(condition); 104 | } 105 | 106 | 107 | @Test 108 | public void compliantWithShOrShape() { 109 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 110 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_OR, "TURTLE"); 111 | Boolean condition = shapes.containsResource(ResourceFactory.createResource("http://www.w3.org/2006/time#InstantShape")); 112 | condition &= shapes.containsResource(ResourceFactory.createResource("http://www.w3.org/2006/time#IntervalShape")); 113 | condition &= shapes.containsResource(ResourceFactory.createResource(SH_OR)); 114 | Assert.assertTrue(condition); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/shapes/NonValidatingPropertyShapeCharacteristicsTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.shapes; 2 | 3 | import astrea.generators.OptimisedOwlGenerator; 4 | import astrea.model.ShaclFromOwl; 5 | import org.apache.jena.rdf.model.Model; 6 | import org.apache.jena.rdf.model.ResourceFactory; 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | 10 | public class NonValidatingPropertyShapeCharacteristicsTest { 11 | 12 | private static final String OWL_FRAGMENT_FOR_NAME_DESC = "@prefix : .\n" + 13 | "@prefix dct: .\n" + 14 | "@prefix owl: .\n" + 15 | "@prefix rdf: .\n" + 16 | "@prefix rdfs: .\n" + 17 | "@prefix skos: .\n" + 18 | "@prefix xsd: ." + 19 | ":Duration\n" + 20 | " rdf:type owl:Class ;\n" + 21 | " rdfs:label \"the duration label\"@en ;\n" + 22 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 23 | " rdfs:subClassOf :TemporalDuration ;\n" + 24 | " rdfs:subClassOf [\n" + 25 | " rdf:type owl:Restriction ;\n" + 26 | " owl:minCardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 27 | " owl:onProperty :unitType ;\n" + 28 | " ] ;\n" + 29 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 30 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 31 | ".\n"; 32 | 33 | public static final String SH_NAME = "http://www.w3.org/ns/shacl#name"; 34 | public static final String SH_DESCRIPTION = "http://www.w3.org/ns/shacl#description"; 35 | 36 | @Test 37 | public void compliantWithShNameShape() { 38 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 39 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_FOR_NAME_DESC, "TURTLE"); 40 | 41 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_NAME), ResourceFactory.createLangLiteral("the duration label", "en")); 42 | Assert.assertTrue(condition); 43 | } 44 | 45 | @Test 46 | public void compliantWithShDescriptionShape() { 47 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 48 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_FOR_NAME_DESC, "TURTLE"); 49 | 50 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_DESCRIPTION), 51 | ResourceFactory.createLangLiteral("Duration of a temporal extent expressed as a number scaled by a temporal unit", "en")); 52 | Assert.assertTrue(condition); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/shapes/OtherConstraints.java: -------------------------------------------------------------------------------- 1 | package test.optimised.shapes; 2 | 3 | import astrea.generators.OptimisedOwlGenerator; 4 | import astrea.generators.OwlGenerator; 5 | import astrea.model.ShaclFromOwl; 6 | 7 | import org.apache.jena.rdf.model.Model; 8 | import org.apache.jena.rdf.model.RDFNode; 9 | import org.apache.jena.rdf.model.ResourceFactory; 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | 13 | public class OtherConstraints { 14 | 15 | private static final String OWL_FRAGMENT_HAS_VALUE ="@prefix : .\n" + 16 | "@prefix dct: .\n" + 17 | "@prefix owl: .\n" + 18 | "@prefix rdf: .\n" + 19 | "@prefix rdfs: .\n" + 20 | "@prefix skos: .\n" + 21 | "@prefix xsd: ."+ 22 | ":DateTimeDescription\n" + 23 | " rdf:type owl:Class ;\n" + 24 | " rdfs:comment \"Description of date and time structured with separate values for the various elements of a calendar-clock system. The temporal reference system is fixed to Gregorian Calendar, and the range of year, month, day properties restricted to corresponding XML Schema types xsd:gYear, xsd:gMonth and xsd:gDay, respectively.\"@en ;\n" + 25 | " rdfs:label \"Date-Time description\"@en ;\n" + 26 | " rdfs:subClassOf [\n" + 27 | " rdf:type owl:Restriction ;\n" + 28 | " owl:hasValue ;\n" + 29 | " owl:onProperty :hasTRS ;\n" + 30 | " ] ;\n" + 31 | " skos:definition \"Description of date and time structured with separate values for the various elements of a calendar-clock system. The temporal reference system is fixed to Gregorian Calendar, and the range of year, month, day properties restricted to corresponding XML Schema types xsd:gYear, xsd:gMonth and xsd:gDay, respectively.\"@en ;\n" + 32 | "."; 33 | 34 | public static final String OWL_FRAGMENT_IN = "@prefix owl: .\n"+ 35 | "\n" + 36 | " a owl:Class ;\n" + 37 | " owl:oneOf (\n" + 38 | " \n" + 39 | " \n" + 40 | " \n" + 41 | " ) ."; 42 | 43 | private static final String SH_HAS_VALUE = "http://www.w3.org/ns/shacl#hasValue"; 44 | private static final String SH_IN = "http://www.w3.org/ns/shacl#in"; 45 | 46 | @Test 47 | public void compliantWithShHasValueShape() { 48 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 49 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_HAS_VALUE, "TURTLE"); 50 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_HAS_VALUE), ResourceFactory.createResource("http://www.opengis.net/def/uom/ISO-8601/0/Gregorian")); 51 | Assert.assertTrue(condition); 52 | } 53 | 54 | 55 | @Test 56 | public void compliantWithShInShape() { 57 | ShaclFromOwl sharper = new OwlGenerator(); 58 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_IN, "TURTLE"); 59 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_IN), (RDFNode) null) 60 | & shapes.containsResource(ResourceFactory.createResource("http://njh.me/#DryShape")) 61 | & shapes.containsResource(ResourceFactory.createResource("http://njh.me/#OffDryShape")) 62 | & shapes.containsResource(ResourceFactory.createResource("http://njh.me/#SweetShape")); 63 | Assert.assertTrue(condition); 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/shapes/PropertyPairConstraintTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.shapes; 2 | 3 | import astrea.generators.OptimisedOwlGenerator; 4 | import astrea.model.ShaclFromOwl; 5 | import org.apache.jena.rdf.model.Model; 6 | import org.apache.jena.rdf.model.ResourceFactory; 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | 10 | public class PropertyPairConstraintTest { 11 | 12 | 13 | // Extracted from: https://www.w3.org/2006/time#s 14 | public static final String OWL_FRAGMENT_EQUIVANCE = "@prefix foaf: .\n" + 15 | "@prefix owl: .\n" + 16 | "@prefix dc11: .\n" + 17 | "@prefix wot: .\n" + 18 | "@prefix rdfs: .\n" + 19 | "@prefix ns0: .\n" + 20 | "@prefix schema: .\n" + 21 | "@prefix geo: .\n" + 22 | "@prefix dc: .\n" + 23 | "@prefix rdf: .\n" + 24 | "@prefix skos: ." + 25 | "foaf:Person\n" + 26 | " a rdfs:Class, owl:Class ;\n" + 27 | " rdfs:label \"Person\" ;\n" + 28 | " rdfs:comment \"A person.\" ;\n" + 29 | " ns0:term_status \"stable\" ;\n" + 30 | " owl:equivalentClass schema:Person, ;\n" + 31 | " rdfs:isDefinedBy foaf: ;\n"; 32 | 33 | 34 | public static final String OWL_FRAGMENT_DISJOINT = "@prefix foaf: .\n" + 35 | "@prefix owl: .\n" + 36 | "@prefix dc11: .\n" + 37 | "@prefix wot: .\n" + 38 | "@prefix rdfs: .\n" + 39 | "@prefix ns0: .\n" + 40 | "@prefix schema: .\n" + 41 | "@prefix geo: .\n" + 42 | "@prefix dc: .\n" + 43 | "@prefix rdf: .\n" + 44 | "@prefix skos: ." + 45 | "foaf:Person\n" + 46 | " a rdfs:Class, owl:Class ;\n" + 47 | " rdfs:label \"Person\" ;\n" + 48 | " rdfs:comment \"A person.\" ;\n" + 49 | " ns0:term_status \"stable\" ;\n" + 50 | " rdfs:isDefinedBy foaf: ;\n" + 51 | " owl:disjointWith foaf:Organization, foaf:Project "; 52 | 53 | private static final String SH_EQUALS = "http://www.w3.org/ns/shacl#equals"; 54 | private static final String SH_DISJOINT = "http://www.w3.org/ns/shacl#disjoint"; 55 | 56 | 57 | @Test 58 | public void compliantWithShEqualsShape() { 59 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 60 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_EQUIVANCE, "TURTLE"); 61 | Boolean condition = shapes.contains(ResourceFactory.createResource("http://xmlns.com/foaf/0.1/PersonShape"), 62 | ResourceFactory.createProperty(SH_EQUALS), ResourceFactory.createResource("http://www.w3.org/2000/10/swap/pim/contact#Person")); 63 | condition &= shapes.contains(ResourceFactory.createResource("http://xmlns.com/foaf/0.1/PersonShape"), 64 | ResourceFactory.createProperty(SH_EQUALS), ResourceFactory.createResource("http://schema.org/Person")); 65 | 66 | Assert.assertTrue(condition); 67 | } 68 | 69 | @Test 70 | public void compliantWithShDisjointShape() { 71 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 72 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_DISJOINT, "TURTLE"); 73 | Boolean condition = shapes.contains(ResourceFactory.createResource("http://xmlns.com/foaf/0.1/PersonShape"), 74 | ResourceFactory.createProperty(SH_DISJOINT), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/Organization")); 75 | condition &= shapes.contains(ResourceFactory.createResource("http://xmlns.com/foaf/0.1/PersonShape"), 76 | ResourceFactory.createProperty(SH_DISJOINT), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/Project")); 77 | Assert.assertTrue(condition); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/test/optimised/shapes/ValueTypeConstraintTest.java: -------------------------------------------------------------------------------- 1 | package test.optimised.shapes; 2 | 3 | import astrea.generators.OptimisedOwlGenerator; 4 | import astrea.generators.OwlGenerator; 5 | import astrea.model.ShaclFromOwl; 6 | import org.apache.jena.rdf.model.Model; 7 | import org.apache.jena.rdf.model.ResourceFactory; 8 | import org.junit.Assert; 9 | import org.junit.Test; 10 | 11 | public class ValueTypeConstraintTest { 12 | 13 | public static final String OWL_FRAGMENT_FOR_SHCLASS="@prefix : .\n" + 14 | "@prefix owl: .\n" + 15 | "@prefix rdf: .\n" + 16 | "@prefix xml: .\n" + 17 | "@prefix xsd: .\n" + 18 | "@prefix rdfs: .\n" + 19 | "@base ."+ 20 | " rdf:type owl:Class ;\n" + 21 | " rdfs:subClassOf ,\n" + 22 | " [ rdf:type owl:Restriction ;\n" + 23 | " owl:onProperty ;\n" + 24 | " owl:allValuesFrom \n" + 25 | " ] ;\n" + 26 | " rdfs:comment \"This class represents the top-level feature type. This class is equivalent to GFI_Feature defined in ISO 19156:2011, and it is superclass of all feature types\" ;\n" + 27 | " rdfs:isDefinedBy ;\n" + 28 | " rdfs:label \"Feature\" .\n"; 29 | 30 | public static final String OWL_FRAGMENT_FOR_SHDATATYPE="@prefix : .\n" + 31 | "@prefix owl: .\n" + 32 | "@prefix rdf: .\n" + 33 | "@prefix xml: .\n" + 34 | "@prefix xsd: .\n" + 35 | "@prefix rdfs: .\n" + 36 | "@base ."+ 37 | ":Event rdf:type owl:Class ;\n" + 38 | " rdfs:subClassOf [ rdf:type owl:Restriction ;\n" + 39 | " owl:onProperty :version ;\n" + 40 | " owl:allValuesFrom xsd:string\n" + 41 | " ] ;\n" + 42 | " rdfs:comment \"An event is a notification from the utility to demand side resources requesting load shed starting at a specific time, over a specified duration, and may include targeting information designating specific resources that should participate in the event\" ;\n" + 43 | " rdfs:isDefinedBy \"OpenADR 2.0 Demand Response Program Implementation Guide\" ;\n" + 44 | " rdfs:label \"Event\" ."; 45 | 46 | public static final String OWL_FRAGMENT_FOR_SH_DP ="@prefix : .\n" + 47 | "@prefix dct: .\n" + 48 | "@prefix owl: .\n" + 49 | "@prefix rdf: .\n" + 50 | "@prefix rdfs: .\n" + 51 | "@prefix skos: .\n" + 52 | "@prefix xsd: .\n" + 53 | ":day rdf:type owl:DatatypeProperty ;\n" + 54 | " rdfs:comment \"Day position in a calendar-clock system\" ."; 55 | 56 | public static final String OWL_FRAGMENT_FOR_SH_OP = "@prefix : .\n" + 57 | "@prefix dct: .\n" + 58 | "@prefix owl: .\n" + 59 | "@prefix rdf: .\n" + 60 | "@prefix rdfs: .\n" + 61 | "@prefix skos: .\n" + 62 | "@prefix xsd: ." + 63 | ":hasDuration rdf:type owl:ObjectProperty ;\n" + 64 | " rdfs:comment \"Duration of a temporal entity, expressed as a scaled value or nominal value\"@en ;\n" + 65 | " rdfs:label \"has duration\"@en ;\n" + 66 | " rdfs:range :Duration ;\n" + 67 | " rdfs:subPropertyOf :hasTemporalDuration ;\n" + 68 | " skos:definition \"Duration of a temporal entity, event or activity, or thing, expressed as a scaled value\"@en ;\n" + 69 | "."; 70 | 71 | 72 | public static final String SH_CLASS= "http://www.w3.org/ns/shacl#class"; 73 | public static final String SH_DATATYPE= "http://www.w3.org/ns/shacl#datatype"; 74 | public static final String SH_NODEKIND= "http://www.w3.org/ns/shacl#nodeKind"; 75 | public static final String SH_IRI= "http://www.w3.org/ns/shacl#IRI"; 76 | public static final String SH_IRI_OR_BLANK= "http://www.w3.org/ns/shacl#BlankNodeOrIRI"; 77 | public static final String SH_LITERAL= "http://www.w3.org/ns/shacl#Literal"; 78 | 79 | @Test 80 | public void compliantWithShClassShape() { 81 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 82 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_FOR_SHCLASS, "TURTLE"); 83 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_CLASS), ResourceFactory.createResource("http://www.opengis.net/ont/geosparql#Geometry")); 84 | condition &= !shapes.containsResource(ResourceFactory.createProperty(SH_DATATYPE)); 85 | Assert.assertTrue(condition); 86 | } 87 | 88 | @Test 89 | public void compliantWithShDatatypeShape() { 90 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 91 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_FOR_SHDATATYPE, "TURTLE"); 92 | 93 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_DATATYPE), ResourceFactory.createResource("http://www.w3.org/2001/XMLSchema#string")); 94 | condition &= !shapes.containsResource(ResourceFactory.createProperty(SH_CLASS)); 95 | Assert.assertTrue(condition); 96 | } 97 | 98 | @Test 99 | public void compliantWithShNodeKindShape() { 100 | ShaclFromOwl sharper = new OptimisedOwlGenerator(); 101 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_FOR_SHCLASS, "TURTLE"); 102 | 103 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_NODEKIND), ResourceFactory.createResource(SH_IRI)); 104 | Assert.assertTrue(condition); 105 | } 106 | @Test 107 | public void compliantWithShNodeKindOP() { 108 | ShaclFromOwl sharper = new OwlGenerator(); 109 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_FOR_SH_OP, "TURTLE"); 110 | 111 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_NODEKIND), ResourceFactory.createResource(SH_IRI_OR_BLANK)); 112 | Assert.assertTrue(condition); 113 | } 114 | 115 | @Test 116 | public void compliantWithShNodeKindDP() { 117 | ShaclFromOwl sharper = new OwlGenerator(); 118 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_FOR_SH_DP, "TURTLE"); 119 | 120 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_NODEKIND), ResourceFactory.createResource(SH_LITERAL)); 121 | Assert.assertTrue(condition); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/test/java/test/queries/CardinalityConstraintTest.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | import astrea.generators.OwlGenerator; 4 | import astrea.model.ShaclFromOwl; 5 | import org.apache.jena.rdf.model.Model; 6 | import org.apache.jena.rdf.model.ResourceFactory; 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | 10 | public class CardinalityConstraintTest { 11 | // Extracted from: https://www.w3.org/2006/time#s 12 | public static final String CARDINALITY_OWL_FRAGMENT_MIN_COUNT = "@prefix : .\n" + 13 | "@prefix dct: .\n" + 14 | "@prefix owl: .\n" + 15 | "@prefix rdf: .\n" + 16 | "@prefix rdfs: .\n" + 17 | "@prefix skos: .\n" + 18 | "@prefix xsd: ." + 19 | ":Duration\n" + 20 | " rdf:type owl:Class ;\n" + 21 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 22 | " rdfs:label \"Time duration\"@en ;\n" + 23 | " rdfs:subClassOf :TemporalDuration ;\n" + 24 | " rdfs:subClassOf [\n" + 25 | " rdf:type owl:Restriction ;\n" + 26 | " owl:minCardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 27 | " owl:onProperty :unitType ;\n" + 28 | " ] ;\n" + 29 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 30 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 31 | ".\n"; 32 | // Extracted from: https://www.w3.org/2006/time#s --> modified 33 | public static final String CARDINALITY_OWL_FRAGMENT_MAX_COUNT = "@prefix : .\n" + 34 | "@prefix dct: .\n" + 35 | "@prefix owl: .\n" + 36 | "@prefix rdf: .\n" + 37 | "@prefix rdfs: .\n" + 38 | "@prefix skos: .\n" + 39 | "@prefix xsd: ." + 40 | ":Duration\n" + 41 | " rdf:type owl:Class ;\n" + 42 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 43 | " rdfs:label \"Time duration\"@en ;\n" + 44 | " rdfs:subClassOf :TemporalDuration ;\n" + 45 | " rdfs:subClassOf [\n" + 46 | " rdf:type owl:Restriction ;\n" + 47 | " owl:maxCardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 48 | " owl:onProperty :unitType ;\n" + 49 | " ] ;\n" + 50 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 51 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 52 | ".\n"; 53 | 54 | private static final String SH_MAX_COUNT = "http://www.w3.org/ns/shacl#maxCount"; 55 | private static final String SH_MIN_COUNT = "http://www.w3.org/ns/shacl#minCount"; 56 | 57 | @Test 58 | public void compliantWithShMinCountShape() { 59 | OwlGenerator sharper = new OwlGenerator(); 60 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_MIN_COUNT, "TURTLE"); 61 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MIN_COUNT),ResourceFactory.createTypedLiteral(1)); 62 | Assert.assertTrue(condition); 63 | } 64 | 65 | @Test 66 | public void compliantWithShMaxCountShape() { 67 | ShaclFromOwl sharper = new OwlGenerator(); 68 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_MAX_COUNT, "TURTLE"); 69 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT),ResourceFactory.createTypedLiteral(1)); 70 | Assert.assertTrue(condition); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/test/queries/CardinalityTest.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.ResourceFactory; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import astrea.generators.OwlGenerator; 9 | import astrea.model.ShaclFromOwl; 10 | 11 | 12 | /** 13 | * This unitary Test class aim at validating our proposal with all the UC of https://spinrdf.org/shacl-and-owl.html 14 | * @author Andrea Cimmino Arriaga, Alba Fernandez Izquierdo 15 | * 16 | */ 17 | public class CardinalityTest { 18 | 19 | // Extracted from: https://www.w3.org/2006/time#s 20 | public static final String CARDINALITY_OWL_FRAGMENT_WITH_OWL_CARDINALITY = "@prefix : .\n" + 21 | "@prefix dct: .\n" + 22 | "@prefix owl: .\n" + 23 | "@prefix rdf: .\n" + 24 | "@prefix rdfs: .\n" + 25 | "@prefix skos: .\n" + 26 | "@prefix xsd: ." + 27 | ":Duration\n" + 28 | " rdf:type owl:Class ;\n" + 29 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 30 | " rdfs:label \"Time duration\"@en ;\n" + 31 | " rdfs:subClassOf :TemporalDuration ;\n" + 32 | " rdfs:subClassOf [\n" + 33 | " rdf:type owl:Restriction ;\n" + 34 | " owl:cardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 35 | " owl:onProperty :numericDuration ;\n" + 36 | " ] ;\n" + 37 | " rdfs:subClassOf [\n" + 38 | " rdf:type owl:Restriction ;\n" + 39 | " owl:minCardinality \"2\"^^xsd:nonNegativeInteger ;\n" + 40 | " owl:onProperty :unitType ;\n" + 41 | " ] ;\n" + 42 | " rdfs:subClassOf [\n" + 43 | " rdf:type owl:Restriction ;\n" + 44 | " owl:maxCardinality \"3\"^^xsd:nonNegativeInteger ;\n" + 45 | " owl:onProperty :month ;\n" + 46 | " ] ;\n" + 47 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 48 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 49 | ".\n"; 50 | 51 | private static final String SH_MAX_COUNT = "http://www.w3.org/ns/shacl#maxCount"; 52 | private static final String SH_MIN_COUNT = "http://www.w3.org/ns/shacl#minCount"; 53 | 54 | 55 | 56 | @Test 57 | public void compliantWithOwlCardinality() { 58 | ShaclFromOwl sharper = new OwlGenerator(); 59 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_WITH_OWL_CARDINALITY, "TURTLE"); 60 | 61 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 62 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_MIN_COUNT), ResourceFactory.createTypedLiteral(1)); 63 | Assert.assertTrue(condition); 64 | } 65 | 66 | @Test 67 | public void compliantWithOwlMinCardinality() { 68 | ShaclFromOwl sharper = new OwlGenerator(); 69 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_WITH_OWL_CARDINALITY, "TURTLE"); 70 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MIN_COUNT), ResourceFactory.createTypedLiteral(2)); 71 | Assert.assertTrue(condition); 72 | } 73 | 74 | 75 | @Test 76 | public void compliantWithOwlMaxCardinality() { 77 | ShaclFromOwl sharper = new OwlGenerator(); 78 | Model shapes = sharper.fromOwl(CARDINALITY_OWL_FRAGMENT_WITH_OWL_CARDINALITY, "TURTLE"); 79 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(3)); 80 | Assert.assertTrue(condition); 81 | } 82 | 83 | 84 | 85 | 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/test/queries/DatatypeTest.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | public class DatatypeTest { 4 | 5 | public static final String OWL_FRAGMENT_OF_A_DATA_PROPERTY = "@prefix : .\n" + 6 | "@prefix dct: .\n" + 7 | "@prefix owl: .\n" + 8 | "@prefix rdf: .\n" + 9 | "@prefix rdfs: .\n" + 10 | "@prefix skos: .\n" + 11 | "@prefix xsd: .\n" + 12 | ":minute\n" + 13 | " rdf:type owl:DatatypeProperty ;\n" + 14 | " rdfs:comment \"Minute position in a calendar-clock system.\"@en ;\n" + 15 | " rdfs:domain :GeneralDateTimeDescription ;\n" + 16 | " rdfs:label \"minute\"@en ;\n" + 17 | " rdfs:range xsd:nonNegativeInteger ;\n" + 18 | " skos:definition \"Minute position in a calendar-clock system.\"@en ;\n" + 19 | "."; 20 | public static final String OWL_FRAGMENT_OF_RDF_DATA_PROPERTY = "@prefix : .\n" + 21 | "@prefix dct: .\n" + 22 | "@prefix owl: .\n" + 23 | "@prefix rdf: .\n" + 24 | "@prefix rdfs: .\n" + 25 | "@prefix skos: .\n" + 26 | "@prefix xsd: .\n" + 27 | ":minute\n" + 28 | " rdf:type rdf:Property ;\n" + 29 | " rdfs:comment \"Minute position in a calendar-clock system.\"@en ;\n" + 30 | " rdfs:domain :GeneralDateTimeDescription ;\n" + 31 | " rdfs:label \"minute\"@en ;\n" + 32 | " rdfs:range xsd:nonNegativeInteger ;\n" + 33 | " skos:definition \"Minute position in a calendar-clock system.\"@en ;\n" + 34 | "."; 35 | 36 | public static final String OWL_FRAGMENT_OF_A_OBJECT_PROPERTY = "@prefix : .\n" + 37 | "@prefix dct: .\n" + 38 | "@prefix owl: .\n" + 39 | "@prefix rdf: .\n" + 40 | "@prefix rdfs: .\n" + 41 | "@prefix skos: .\n" + 42 | "@prefix xsd: .\n" + 43 | ":monthOfYear\n" + 44 | " rdf:type owl:ObjectProperty ;\n" + 45 | " rdfs:comment \"The month of the year, whose value is a member of the class time:MonthOfYear\"@en ;\n" + 46 | " rdfs:domain :GeneralDateTimeDescription ;\n" + 47 | " rdfs:label \"month of year\"@en ;\n" + 48 | " rdfs:range :MonthOfYear ;\n" + 49 | " skos:definition \"The month of the year, whose value is a member of the class time:MonthOfYear\"@en ;\n" + 50 | " skos:editorialNote \"Feature at risk - added in 2017 revision, and not yet widely used. \"@en ;\n" + 51 | "."; 52 | 53 | public static final String OWL_FRAGMENT_OF_RDF_OBJECT_PROPERTY = "@prefix : .\n" + 54 | "@prefix dct: .\n" + 55 | "@prefix owl: .\n" + 56 | "@prefix rdf: .\n" + 57 | "@prefix rdfs: .\n" + 58 | "@prefix skos: .\n" + 59 | "@prefix xsd: .\n" + 60 | ":monthOfYear\n" + 61 | " rdf:type rdf:Property ;\n" + 62 | " rdfs:comment \"The month of the year, whose value is a member of the class time:MonthOfYear\"@en ;\n" + 63 | " rdfs:domain :GeneralDateTimeDescription ;\n" + 64 | " rdfs:label \"month of year\"@en ;\n" + 65 | " rdfs:range :MonthOfYear ;\n" + 66 | " skos:definition \"The month of the year, whose value is a member of the class time:MonthOfYear\"@en ;\n" + 67 | " skos:editorialNote \"Feature at risk - added in 2017 revision, and not yet widely used. \"@en ;\n" + 68 | "."; 69 | 70 | 71 | //private static final String SH_PROPERTY_SHAPE = "http://www.w3.org/ns/shacl#PropertyShape"; 72 | 73 | // Testing creation of sh:NodeShape from owl:Class 74 | 75 | /*@Test --> Not supporting rdf:Property since we cannot know if it is a data property or object property 76 | public void createNodeShapeFromOwlClass() { 77 | ShaclFromOwl sharper = new OwlGenerator(); 78 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_OF_RDF_OBJECT_PROPERTY, "TURTLE"); 79 | shapes.write(System.out,"TURTLE"); 80 | Boolean condition = shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_PROPERTY_SHAPE)); 81 | Assert.assertTrue(condition); 82 | }*/ 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/test/queries/EqualityTest.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.ResourceFactory; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import astrea.generators.OwlGenerator; 9 | import astrea.model.ShaclFromOwl; 10 | 11 | public class EqualityTest { 12 | 13 | public static final String ANNOTATION_PROPERTIES_OWL_FRAGMENT ="@prefix foaf: .\n" + 14 | "@prefix owl: .\n" + 15 | "@prefix dc11: .\n" + 16 | "@prefix wot: .\n" + 17 | "@prefix rdfs: .\n" + 18 | "@prefix ns0: .\n" + 19 | "@prefix schema: .\n" + 20 | "@prefix geo: .\n" + 21 | "@prefix dc: .\n" + 22 | "@prefix rdf: .\n" + 23 | "@prefix skos: .\n" + 24 | "\n" + 25 | "foaf:maker\n" + 26 | " a rdf:Property, owl:ObjectProperty ;\n" + 27 | " ns0:term_status \"stable\" ;\n" + 28 | " rdfs:label \"maker\" ;\n" + 29 | " rdfs:comment \"An agent that made this thing.\" ;\n" + 30 | " owl:equivalentProperty dc:creator ;\n" + 31 | " rdfs:domain owl:Thing ;\n" + 32 | " rdfs:range foaf:Agent ;\n" + 33 | " rdfs:isDefinedBy foaf: ;\n" + 34 | " owl:inverseOf foaf:made ."; 35 | 36 | 37 | public static final String SH_EQUIVALENT = "http://www.w3.org/ns/shacl#equals"; 38 | public static final String SH_DATATYPE = "http://www.w3.org/ns/shacl#datatype"; 39 | public static final String SH_CLASS = "http://www.w3.org/ns/shacl#class"; 40 | 41 | // -- Tests for NodeShapes 42 | @Test 43 | public void compliantWithShNameNodeShape() { 44 | ShaclFromOwl sharper = new OwlGenerator(); 45 | Model shapes = sharper.fromOwl(ANNOTATION_PROPERTIES_OWL_FRAGMENT, "TURTLE"); 46 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_EQUIVALENT), ResourceFactory.createResource("http://purl.org/dc/terms/creator")); 47 | condition &= !shapes.contains(null, ResourceFactory.createProperty(SH_DATATYPE), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/Agent")); 48 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_CLASS), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/Agent")); 49 | 50 | Assert.assertTrue(condition); 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/test/queries/FillerInformationTest.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.RDFNode; 5 | import org.apache.jena.rdf.model.ResourceFactory; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import astrea.generators.OwlGenerator; 10 | import astrea.model.ShaclFromOwl; 11 | 12 | public class FillerInformationTest { 13 | 14 | private static final String HAS_VALUE_OWL_FRAGMENT_WITH_HAS_VALUE = "@prefix : .\n" + 15 | "@prefix dct: .\n" + 16 | "@prefix owl: .\n" + 17 | "@prefix rdf: .\n" + 18 | "@prefix rdfs: .\n" + 19 | "@prefix skos: .\n" + 20 | "@prefix xsd: ." + 21 | ":January\n" + 22 | " rdf:type owl:Class ;\n" + 23 | " rdf:type owl:DeprecatedClass ;\n" + 24 | " rdfs:label \"January\" ;\n" + 25 | " rdfs:subClassOf :DateTimeDescription ;\n" + 26 | " rdfs:subClassOf [\n" + 27 | " rdf:type owl:Restriction ;\n" + 28 | " owl:hasValue :unitMonth ;\n" + 29 | " owl:onProperty :unitType ;\n" + 30 | " ] ;\n" + 31 | " rdfs:subClassOf [\n" + 32 | " rdf:type owl:Restriction ;\n" + 33 | " owl:hasValue \"--01\" ;\n" + 34 | " owl:onProperty :month ;\n" + 35 | " ] ;\n" + 36 | " owl:deprecated \"true\"^^xsd:boolean ;\n" + 37 | " skos:historyNote \"This class was present in the 2006 version of OWL-Time. It was presented as an example of how DateTimeDescription could be specialized, but does not belong in the revised ontology. \" ;\n" + 38 | "."; 39 | 40 | private static final String HAS_VALUE_OWL_FRAGMENT_WITHOUT_HAS_VALUE = "@prefix : .\n" + 41 | "@prefix dct: .\n" + 42 | "@prefix owl: .\n" + 43 | "@prefix rdf: .\n" + 44 | "@prefix rdfs: .\n" + 45 | "@prefix skos: .\n" + 46 | "@prefix xsd: ." + 47 | ":January\n" + 48 | " rdf:type owl:Class ;\n" + 49 | " rdf:type owl:DeprecatedClass ;\n" + 50 | " rdfs:label \"January\" ;\n" + 51 | " rdfs:subClassOf :DateTimeDescription ;\n" + 52 | " rdfs:subClassOf [\n" + 53 | " rdf:type owl:Restriction ;\n" + 54 | " owl:onProperty :unitType ;\n" + 55 | " ] ;\n" + 56 | " rdfs:subClassOf [\n" + 57 | " rdf:type owl:Restriction ;\n" + 58 | " owl:onProperty :month ;\n" + 59 | " ] ;\n" + 60 | " owl:deprecated \"true\"^^xsd:boolean ;\n" + 61 | " skos:historyNote \"This class was present in the 2006 version of OWL-Time. It was presented as an example of how DateTimeDescription could be specialized, but does not belong in the revised ontology. \" ;\n" + 62 | "."; 63 | private static final String SH_HAS_VALUE = "http://www.w3.org/ns/shacl#hasValue"; 64 | 65 | @Test 66 | public void hasValueWithLiteral() { 67 | ShaclFromOwl sharper = new OwlGenerator(); 68 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_HAS_VALUE, "TURTLE"); 69 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_HAS_VALUE), ResourceFactory.createPlainLiteral("--01")); 70 | Assert.assertTrue(condition); 71 | } 72 | 73 | @Test 74 | public void hasValueWithUri() { 75 | ShaclFromOwl sharper = new OwlGenerator(); 76 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_HAS_VALUE, "TURTLE"); 77 | 78 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_HAS_VALUE), ResourceFactory.createResource("http://www.w3.org/2006/time#unitMonth")); 79 | Assert.assertTrue(condition); 80 | } 81 | 82 | @Test 83 | public void hasValueMissing() { 84 | ShaclFromOwl sharper = new OwlGenerator(); 85 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITHOUT_HAS_VALUE, "TURTLE"); 86 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_HAS_VALUE), (RDFNode) null); 87 | Assert.assertFalse(condition); 88 | } 89 | 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/test/queries/NonValidatingPropertyShapeCharacteristicsTest.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | import astrea.generators.OwlGenerator; 4 | import astrea.model.ShaclFromOwl; 5 | import org.apache.jena.rdf.model.Model; 6 | import org.apache.jena.rdf.model.ResourceFactory; 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | 10 | public class NonValidatingPropertyShapeCharacteristicsTest { 11 | 12 | private static final String OWL_FRAGMENT_FOR_NAME_DESC = "@prefix : .\n" + 13 | "@prefix dct: .\n" + 14 | "@prefix owl: .\n" + 15 | "@prefix rdf: .\n" + 16 | "@prefix rdfs: .\n" + 17 | "@prefix skos: .\n" + 18 | "@prefix xsd: ." + 19 | ":Duration\n" + 20 | " rdf:type owl:Class ;\n" + 21 | " rdfs:label \"the duration label\"@en ;\n" + 22 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 23 | " rdfs:subClassOf :TemporalDuration ;\n" + 24 | " rdfs:subClassOf [\n" + 25 | " rdf:type owl:Restriction ;\n" + 26 | " owl:minCardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 27 | " owl:onProperty :unitType ;\n" + 28 | " ] ;\n" + 29 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 30 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 31 | ".\n"; 32 | 33 | public static final String SH_NAME = "http://www.w3.org/ns/shacl#name"; 34 | public static final String SH_DESCRIPTION = "http://www.w3.org/ns/shacl#description"; 35 | 36 | @Test 37 | public void compliantWithShNameShape() { 38 | ShaclFromOwl sharper = new OwlGenerator(); 39 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_FOR_NAME_DESC, "TURTLE"); 40 | 41 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_NAME), ResourceFactory.createLangLiteral("the duration label", "en")); 42 | Assert.assertTrue(condition); 43 | } 44 | 45 | @Test 46 | public void compliantWithShDescriptionShape() { 47 | ShaclFromOwl sharper = new OwlGenerator(); 48 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_FOR_NAME_DESC, "TURTLE"); 49 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_DESCRIPTION), 50 | ResourceFactory.createLangLiteral("Duration of a temporal extent expressed as a number scaled by a temporal unit", "en")); 51 | Assert.assertTrue(condition); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/test/queries/OtherConstraints.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | import astrea.generators.OwlGenerator; 4 | import astrea.model.ShaclFromOwl; 5 | 6 | import org.apache.jena.rdf.model.Model; 7 | import org.apache.jena.rdf.model.RDFNode; 8 | import org.apache.jena.rdf.model.ResourceFactory; 9 | import org.junit.Assert; 10 | import org.junit.Test; 11 | 12 | public class OtherConstraints { 13 | 14 | private static final String OWL_FRAGMENT_HAS_VALUE ="@prefix : .\n" + 15 | "@prefix dct: .\n" + 16 | "@prefix owl: .\n" + 17 | "@prefix rdf: .\n" + 18 | "@prefix rdfs: .\n" + 19 | "@prefix skos: .\n" + 20 | "@prefix xsd: ."+ 21 | ":DateTimeDescription\n" + 22 | " rdf:type owl:Class ;\n" + 23 | " rdfs:comment \"Description of date and time structured with separate values for the various elements of a calendar-clock system. The temporal reference system is fixed to Gregorian Calendar, and the range of year, month, day properties restricted to corresponding XML Schema types xsd:gYear, xsd:gMonth and xsd:gDay, respectively.\"@en ;\n" + 24 | " rdfs:label \"Date-Time description\"@en ;\n" + 25 | " rdfs:subClassOf [\n" + 26 | " rdf:type owl:Restriction ;\n" + 27 | " owl:hasValue ;\n" + 28 | " owl:onProperty :hasTRS ;\n" + 29 | " ] ;\n" + 30 | " skos:definition \"Description of date and time structured with separate values for the various elements of a calendar-clock system. The temporal reference system is fixed to Gregorian Calendar, and the range of year, month, day properties restricted to corresponding XML Schema types xsd:gYear, xsd:gMonth and xsd:gDay, respectively.\"@en ;\n" + 31 | "."; 32 | 33 | public static final String OWL_FRAGMENT_IN = "@prefix owl: .\n"+ 34 | "\n" + 35 | " a owl:Class ;\n" + 36 | " owl:oneOf (\n" + 37 | " \n" + 38 | " \n" + 39 | " \n" + 40 | " ) ."; 41 | 42 | 43 | 44 | private static final String SH_HAS_VALUE = "http://www.w3.org/ns/shacl#hasValue"; 45 | private static final String SH_IN = "http://www.w3.org/ns/shacl#in"; 46 | 47 | @Test 48 | public void compliantWithShHasValueShape() { 49 | ShaclFromOwl sharper = new OwlGenerator(); 50 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_HAS_VALUE, "TURTLE"); 51 | 52 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_HAS_VALUE), ResourceFactory.createResource("http://www.opengis.net/def/uom/ISO-8601/0/Gregorian")); 53 | Assert.assertTrue(condition); 54 | } 55 | 56 | 57 | @Test 58 | public void compliantWithShInShape() { 59 | ShaclFromOwl sharper = new OwlGenerator(); 60 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_IN, "TURTLE"); 61 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_IN), (RDFNode) null) 62 | & shapes.containsResource(ResourceFactory.createResource("https://astrea.linkeddata.es/shapes#6e6ce7f54207f8740e927008c6de69b3")) 63 | & shapes.containsResource(ResourceFactory.createResource("https://astrea.linkeddata.es/shapes#1114148e7eeeaccf8b51c06e0ce981b7")) 64 | & shapes.containsResource(ResourceFactory.createResource("https://astrea.linkeddata.es/shapes#e250b67865c6fabd97b6d97e06639a95")); 65 | Assert.assertTrue(condition); 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/test/queries/PropertyCharacteristicsTest.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.RDFNode; 5 | import org.apache.jena.rdf.model.ResourceFactory; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import astrea.generators.OwlGenerator; 10 | import astrea.model.ShaclFromOwl; 11 | 12 | public class PropertyCharacteristicsTest { 13 | 14 | private static final String HAS_VALUE_OWL_FRAGMENT_WITH_FUNCTIONAL_PROPERTY = "@prefix : .\n" + 15 | "@prefix dct: .\n" + 16 | "@prefix owl: .\n" + 17 | "@prefix rdf: .\n" + 18 | "@prefix rdfs: .\n" + 19 | "@prefix skos: .\n" + 20 | "@prefix xsd: ." + 21 | ":hasTRS\n" + 22 | " rdf:type owl:FunctionalProperty ;\n" + 23 | " rdf:type owl:ObjectProperty ;\n" + 24 | " rdfs:comment \"The temporal reference system used by a temporal position or extent description. \"@en ;\n" + 25 | " rdfs:domain [\n" + 26 | " rdf:type owl:Class ;\n" + 27 | " owl:unionOf (\n" + 28 | " :TemporalPosition\n" + 29 | " :GeneralDurationDescription\n" + 30 | " ) ;\n" + 31 | " ] ;\n" + 32 | " rdfs:label \"Temporal reference system used\"@en ;\n" + 33 | " rdfs:range :TRS ;\n" + 34 | " skos:definition \"The temporal reference system used by a temporal position or extent description. \"@en ;\n" + 35 | "."; 36 | private static final String HAS_VALUE_OWL_FRAGMENT_WITHOUT_FUNCTIONAL_PROPERTY = "@prefix : .\n" + 37 | "@prefix dct: .\n" + 38 | "@prefix owl: .\n" + 39 | "@prefix rdf: .\n" + 40 | "@prefix rdfs: .\n" + 41 | "@prefix skos: .\n" + 42 | "@prefix xsd: ." + 43 | ":hasTRS\n" + 44 | // " rdf:type owl:FunctionalProperty ;\n" + Missing line 45 | " rdf:type owl:ObjectProperty ;\n" + 46 | " rdfs:comment \"The temporal reference system used by a temporal position or extent description. \"@en ;\n" + 47 | " rdfs:domain [\n" + 48 | " rdf:type owl:Class ;\n" + 49 | " owl:unionOf (\n" + 50 | " :TemporalPosition\n" + 51 | " :GeneralDurationDescription\n" + 52 | " ) ;\n" + 53 | " ] ;\n" + 54 | " rdfs:label \"Temporal reference system used\"@en ;\n" + 55 | " rdfs:range :TRS ;\n" + 56 | " skos:definition \"The temporal reference system used by a temporal position or extent description. \"@en ;\n" + 57 | "."; 58 | 59 | private static final String HAS_VALUE_OWL_FRAGMENT_WITH_INVERSE_FUNCTIONAL_PROPERTY_OP = "@prefix : .\n" + 60 | "@prefix dct: .\n" + 61 | "@prefix owl: .\n" + 62 | "@prefix rdf: .\n" + 63 | "@prefix rdfs: .\n" + 64 | "@prefix skos: .\n" + 65 | "@prefix xsd: ." + 66 | "@prefix foaf: .\n" + 67 | "foaf:mbox\n" + 68 | " a rdf:Property, owl:InverseFunctionalProperty, owl:ObjectProperty ;\n" + 69 | " foaf:term_status \"stable\" ;\n" + 70 | " rdfs:label \"personal mailbox\" ;\n" + 71 | " rdfs:comment \"A personal mailbox, ie. an Internet mailbox associated with exactly one owner, the first owner of this mailbox. This is a 'static inverse functional property', in that there is (across time and change) at most one individual that ever has any particular value for foaf:mbox.\" ;\n" + 72 | " rdfs:domain foaf:Agent ;\n" + 73 | " rdfs:range owl:Thing ;\n" + 74 | " rdfs:isDefinedBy foaf: .\n"; 75 | 76 | 77 | 78 | 79 | 80 | private static final String HAS_VALUE_OWL_FRAGMENT_WITH_INVERSE_FUNCTIONAL_PROPERTY_DP = "@prefix : .\n" + 81 | "@prefix dct: .\n" + 82 | "@prefix owl: .\n" + 83 | "@prefix rdf: .\n" + 84 | "@prefix rdfs: .\n" + 85 | "@prefix skos: .\n" + 86 | "@prefix xsd: ." + 87 | "@prefix foaf: .\n" + 88 | "foaf:mbox_sha1sum\n" + 89 | " a rdf:Property, owl:InverseFunctionalProperty, owl:DatatypeProperty ;\n" + 90 | " foaf:term_status \"testing\" ;\n" + 91 | " rdfs:label \"sha1sum of a personal mailbox URI name\" ;\n" + 92 | " rdfs:comment \"The sha1sum of the URI of an Internet mailbox associated with exactly one owner, the first owner of the mailbox.\" ;\n" + 93 | " rdfs:domain foaf:Agent ;\n" + 94 | " rdfs:range rdfs:Literal ;\n" + 95 | " rdfs:isDefinedBy foaf: ."; 96 | 97 | 98 | 99 | private static final String SH_MAX_COUNT = "http://www.w3.org/ns/shacl#maxCount"; 100 | private static final String SH_INVERSE_PATH = "http://www.w3.org/ns/shacl#inversePath"; 101 | private static final String SH_PATH = "http://www.w3.org/ns/shacl#path"; 102 | 103 | @Test 104 | public void hasShMaxCount() { 105 | ShaclFromOwl sharper = new OwlGenerator(); 106 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_FUNCTIONAL_PROPERTY, "TURTLE"); 107 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 108 | Assert.assertTrue(condition); 109 | } 110 | 111 | @Test 112 | public void hasNotShMaxCount() { 113 | ShaclFromOwl sharper = new OwlGenerator(); 114 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITHOUT_FUNCTIONAL_PROPERTY, "TURTLE"); 115 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 116 | Assert.assertFalse(condition); 117 | } 118 | 119 | 120 | @Test 121 | public void hasInverseFunctionalWithOP() { 122 | ShaclFromOwl sharper = new OwlGenerator(); 123 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_INVERSE_FUNCTIONAL_PROPERTY_OP, "TURTLE"); 124 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 125 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_INVERSE_PATH), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/mbox")); 126 | condition &= !shapes.contains(null, ResourceFactory.createProperty(SH_PATH), (RDFNode) null); 127 | Assert.assertTrue(condition); 128 | } 129 | 130 | @Test 131 | public void hasInverseFunctionalWithDP() { 132 | ShaclFromOwl sharper = new OwlGenerator(); 133 | Model shapes = sharper.fromOwl(HAS_VALUE_OWL_FRAGMENT_WITH_INVERSE_FUNCTIONAL_PROPERTY_DP, "TURTLE"); 134 | Boolean condition = shapes.contains(null, ResourceFactory.createProperty(SH_MAX_COUNT), ResourceFactory.createTypedLiteral(1)); 135 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_INVERSE_PATH), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/mbox_sha1sum")); 136 | condition &= !shapes.contains(null, ResourceFactory.createProperty(SH_PATH), (RDFNode) null); 137 | Assert.assertTrue(condition); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/test/java/test/queries/PropertyPairConstraintTest.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | import astrea.generators.OwlGenerator; 4 | import astrea.model.ShaclFromOwl; 5 | import org.apache.jena.rdf.model.Model; 6 | import org.apache.jena.rdf.model.NodeIterator; 7 | import org.apache.jena.rdf.model.Resource; 8 | import org.apache.jena.rdf.model.ResourceFactory; 9 | import org.apache.jena.vocabulary.RDF; 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | 13 | public class PropertyPairConstraintTest { 14 | 15 | 16 | // Extracted from: https://www.w3.org/2006/time#s 17 | public static final String OWL_FRAGMENT_EQUIVANCE = "@prefix foaf: .\n" + 18 | "@prefix owl: .\n" + 19 | "@prefix dc11: .\n" + 20 | "@prefix wot: .\n" + 21 | "@prefix rdfs: .\n" + 22 | "@prefix ns0: .\n" + 23 | "@prefix schema: .\n" + 24 | "@prefix geo: .\n" + 25 | "@prefix dc: .\n" + 26 | "@prefix rdf: .\n" + 27 | "@prefix skos: ." + 28 | "foaf:Person\n" + 29 | " a rdfs:Class, owl:Class ;\n" + 30 | " rdfs:label \"Person\" ;\n" + 31 | " rdfs:comment \"A person.\" ;\n" + 32 | " ns0:term_status \"stable\" ;\n" + 33 | " owl:equivalentClass schema:Person, ;\n" + 34 | " rdfs:isDefinedBy foaf: ;\n"; 35 | 36 | 37 | public static final String OWL_FRAGMENT_DISJOINT = "@prefix foaf: .\n" + 38 | "@prefix owl: .\n" + 39 | "@prefix dc11: .\n" + 40 | "@prefix wot: .\n" + 41 | "@prefix rdfs: .\n" + 42 | "@prefix ns0: .\n" + 43 | "@prefix schema: .\n" + 44 | "@prefix geo: .\n" + 45 | "@prefix dc: .\n" + 46 | "@prefix rdf: .\n" + 47 | "@prefix skos: ." + 48 | "foaf:Person\n" + 49 | " a rdfs:Class, owl:Class ;\n" + 50 | " rdfs:label \"Person\" ;\n" + 51 | " rdfs:comment \"A person.\" ;\n" + 52 | " ns0:term_status \"stable\" ;\n" + 53 | " rdfs:isDefinedBy foaf: ;\n" + 54 | " owl:disjointWith foaf:Organization, foaf:Project "; 55 | 56 | private static final String SH_TARGET_CLASS= "http://www.w3.org/ns/shacl#targetClass"; 57 | private static final String SH_NOT = "http://www.w3.org/ns/shacl#not"; 58 | private static final String SH_CLASS = "http://www.w3.org/ns/shacl#class"; 59 | private static final String SH_PROPERTYSHAPE = "http://www.w3.org/ns/shacl#PropertyShape"; 60 | 61 | @Test 62 | public void compliantWithShEqualsShape() { 63 | ShaclFromOwl sharper = new OwlGenerator(); 64 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_EQUIVANCE, "TURTLE"); 65 | Boolean condition = shapes.contains(null, 66 | ResourceFactory.createProperty(SH_TARGET_CLASS), ResourceFactory.createResource("http://www.w3.org/2000/10/swap/pim/contact#Person")); 67 | condition &= shapes.contains(null, 68 | ResourceFactory.createProperty(SH_TARGET_CLASS), ResourceFactory.createResource("http://schema.org/Person")); 69 | condition &= shapes.contains(null, 70 | ResourceFactory.createProperty(SH_TARGET_CLASS), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/Person")); 71 | Assert.assertTrue(condition); 72 | } 73 | 74 | @Test 75 | public void compliantWithShDisjointShape() { 76 | ShaclFromOwl sharper = new OwlGenerator(); 77 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_DISJOINT, "TURTLE"); 78 | NodeIterator iterator = shapes.listObjectsOfProperty(ResourceFactory.createProperty(SH_NOT)); 79 | Boolean condition = iterator.hasNext(); 80 | while(iterator.hasNext()) { 81 | Resource rangeURI = iterator.next().asResource(); 82 | Boolean subCondition1= shapes.contains(rangeURI, RDF.type, ResourceFactory.createProperty(SH_PROPERTYSHAPE)); 83 | Boolean subCondition21= shapes.contains(rangeURI, ResourceFactory.createProperty(SH_CLASS), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/Organization")); 84 | Boolean subCondition22 = shapes.contains(rangeURI, ResourceFactory.createProperty(SH_CLASS), ResourceFactory.createResource("http://xmlns.com/foaf/0.1/Project")); 85 | condition &= subCondition1 & (subCondition21||subCondition22); 86 | } 87 | 88 | Assert.assertTrue(condition); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/test/java/test/queries/PropertyRestrictionsTest.java: -------------------------------------------------------------------------------- 1 | package test.queries; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.apache.jena.rdf.model.ResourceFactory; 5 | import org.apache.jena.vocabulary.RDF; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import astrea.generators.OwlGenerator; 10 | import astrea.model.ShaclFromOwl; 11 | 12 | public class PropertyRestrictionsTest { 13 | 14 | 15 | public static final String OWL_FRAGMENT_OF_OWL_CLASS = "@prefix : .\n" + 16 | "@prefix dct: .\n" + 17 | "@prefix owl: .\n" + 18 | "@prefix rdf: .\n" + 19 | "@prefix rdfs: .\n" + 20 | "@prefix skos: .\n" + 21 | "@prefix xsd: .\n" + 22 | ":Duration\n" + 23 | " rdf:type owl:Class ;\n" + 24 | " rdfs:comment \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 25 | " rdfs:label \"Time duration\"@en ;\n" + 26 | " rdfs:subClassOf :TemporalDuration ;\n" + 27 | " rdfs:subClassOf [\n" + 28 | " rdf:type owl:Restriction ;\n" + 29 | " owl:cardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 30 | " owl:onProperty :numericDuration ;\n" + 31 | " ] ;\n" + 32 | " rdfs:subClassOf [\n" + 33 | " rdf:type owl:Restriction ;\n" + 34 | " owl:cardinality \"1\"^^xsd:nonNegativeInteger ;\n" + 35 | " owl:onProperty :unitType ;\n" + 36 | " ] ;\n" + 37 | " rdfs:subClassOf [\n" + 38 | " rdf:type owl:Restriction ;\n" + 39 | " owl:allValuesFrom xsd:gMonth ;\n" + 40 | " owl:onProperty :month ;\n" + 41 | " ] ;" + 42 | " skos:definition \"Duration of a temporal extent expressed as a number scaled by a temporal unit\"@en ;\n" + 43 | " skos:note \"Alternative to time:DurationDescription to support description of a temporal duration other than using a calendar/clock system.\"@en ;\n" + 44 | "."; 45 | 46 | 47 | private static final String SH_NODE_SHAPE = "http://www.w3.org/ns/shacl#NodeShape"; 48 | private static final String SH_PROPERTY_SHAPE = "http://www.w3.org/ns/shacl#PropertyShape"; 49 | private static final String SH_PATH = "http://www.w3.org/ns/shacl#path"; 50 | 51 | 52 | @Test 53 | public void createEmbeddedPorpertyShapeFromOnProperty() { 54 | ShaclFromOwl sharper = new OwlGenerator(); 55 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_OF_OWL_CLASS, "TURTLE"); 56 | 57 | Boolean condition = shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_NODE_SHAPE)); 58 | condition &= shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_PROPERTY_SHAPE)); 59 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_PATH), ResourceFactory.createResource("http://www.w3.org/2006/time#numericDuration")); 60 | Assert.assertTrue(condition); 61 | } 62 | 63 | 64 | @Test 65 | public void createEmbeddedPorpertyShapeFromAllValuesFrom() { 66 | ShaclFromOwl sharper = new OwlGenerator(); 67 | Model shapes = sharper.fromOwl(OWL_FRAGMENT_OF_OWL_CLASS, "TURTLE"); 68 | Boolean condition = shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_NODE_SHAPE)); 69 | condition &= shapes.contains(null, RDF.type, ResourceFactory.createResource(SH_PROPERTY_SHAPE)); 70 | condition &= shapes.contains(null, ResourceFactory.createProperty(SH_PATH), ResourceFactory.createResource("http://www.w3.org/2006/time#numericDuration")); 71 | Assert.assertTrue(condition); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/test/queries/catalogue/TestCatalogue.java: -------------------------------------------------------------------------------- 1 | package test.queries.catalogue; 2 | 3 | import org.apache.jena.rdf.model.Model; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | import astrea.generators.OwlGenerator; 8 | import astrea.model.ShaclFromOwl; 9 | 10 | public class TestCatalogue { 11 | 12 | 13 | @Test 14 | public void testTime() { 15 | ShaclFromOwl sharper = new OwlGenerator(); 16 | Model shapes = sharper.fromURL("https://www.w3.org/2006/time"); 17 | Assert.assertFalse(shapes.isEmpty()); 18 | } 19 | 20 | 21 | @Test 22 | public void testSAREF() { 23 | ShaclFromOwl sharper = new OwlGenerator(); 24 | Model shapes = sharper.fromURL("https://w3id.org/saref"); 25 | Assert.assertFalse(shapes.isEmpty()); 26 | } 27 | 28 | @Test 29 | public void testSAREF4ENV() { 30 | ShaclFromOwl sharper = new OwlGenerator(); 31 | Model shapes = sharper.fromURL("https://mariapoveda.github.io/saref-ext/OnToology/SAREF4ENV/ontology/saref4envi.ttl/documentation/ontology.ttl"); 32 | Assert.assertFalse(shapes.isEmpty()); 33 | } 34 | 35 | @Test 36 | public void testVICINITYcore() { 37 | ShaclFromOwl sharper = new OwlGenerator(); 38 | Model shapes = sharper.fromURL("http://iot.linkeddata.es/def/core/ontology.ttl"); 39 | Assert.assertFalse(shapes.isEmpty()); 40 | } 41 | 42 | 43 | @Test 44 | public void testWoTMappings() { 45 | ShaclFromOwl sharper = new OwlGenerator(); 46 | Model shapes = sharper.fromURL("http://iot.linkeddata.es/def/wot-mappings/ontology.xml"); 47 | Assert.assertFalse(shapes.isEmpty()); 48 | } 49 | 50 | 51 | @Test 52 | public void testDELTAcore() { 53 | ShaclFromOwl sharper = new OwlGenerator(); 54 | Model shapes = sharper.fromURL("http://delta.linkeddata.es/def/core/ontology.json"); 55 | Assert.assertFalse(shapes.isEmpty()); 56 | } 57 | 58 | 59 | @Test 60 | public void testSAREF4BLDG() { 61 | ShaclFromOwl sharper = new OwlGenerator(); 62 | Model shapes = sharper.fromURL("https://mariapoveda.github.io/saref-ext/OnToology/SAREF4BLD/ontology/saref4bldg.ttl/documentation/ontology.ttl"); 63 | shapes.write(System.out,"TURTLE"); 64 | Assert.assertFalse(shapes.isEmpty()); 65 | } 66 | 67 | } 68 | --------------------------------------------------------------------------------