Permalink
Browse files

Shapes: new experimental tool : XSD to OWL2 converter

  • Loading branch information...
1 parent 82a68d5 commit bce1c16dfaad1f0b246cca361fa673ba5d0022a7 @sotty sotty committed Feb 24, 2013
Showing with 6,829 additions and 1 deletion.
  1. +0 −1 drools-shapes/drools-shapes-generator/pom.xml
  2. +13 −0 drools-shapes/drools-shapes-xsd-processor-plugin/.gitignore
  3. +66 −0 drools-shapes/drools-shapes-xsd-processor-plugin/pom.xml
  4. +104 −0 ...-shapes/drools-shapes-xsd-processor-plugin/src/main/java/org/drools/shapes/xsd/Xsd2OwlPlugin.java
  5. +1 −0 .../drools-shapes-xsd-processor-plugin/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin
  6. +13 −0 drools-shapes/drools-shapes-xsd-processor/.gitignore
  7. +165 −0 drools-shapes/drools-shapes-xsd-processor/pom.xml
  8. +107 −0 drools-shapes/drools-shapes-xsd-processor/src/main/java/org/drools/shapes/xsd/Jaxplorer.java
  9. +44 −0 drools-shapes/drools-shapes-xsd-processor/src/main/java/org/drools/shapes/xsd/Xsd2Owl.java
  10. +24 −0 drools-shapes/drools-shapes-xsd-processor/src/main/java/org/drools/shapes/xsd/Xsd2OwlFactory.java
  11. +365 −0 drools-shapes/drools-shapes-xsd-processor/src/main/java/org/drools/shapes/xsd/Xsd2OwlImpl.java
  12. +42 −0 drools-shapes/drools-shapes-xsd-processor/src/main/resources/log4j.xml
  13. +962 −0 drools-shapes/drools-shapes-xsd-processor/src/main/resources/org/drools/shapes/xsd/drl/xsd2owl.drl
  14. +69 −0 ...s-shapes/drools-shapes-xsd-processor/src/main/resources/org/drools/shapes/xsd/drl/xsd2owl_bug.drl
  15. +116 −0 drools-shapes/drools-shapes-xsd-processor/src/main/resources/org/drools/shapes/xsd/xml.xsd
  16. +60 −0 drools-shapes/drools-shapes-xsd-processor/src/main/resources/org/drools/shapes/xsd/xmlschema.xjb
  17. +2,472 −0 drools-shapes/drools-shapes-xsd-processor/src/main/resources/org/drools/shapes/xsd/xmlschema.xsd
  18. +120 −0 drools-shapes/drools-shapes-xsd-processor/src/test/java/org/drools/shapes/xsd/AttrGroupTest.java
  19. +243 −0 ...ls-shapes/drools-shapes-xsd-processor/src/test/java/org/drools/shapes/xsd/ComplexAttribsTest.java
  20. +207 −0 ...s-shapes/drools-shapes-xsd-processor/src/test/java/org/drools/shapes/xsd/ComplexElementsTest.java
  21. +116 −0 drools-shapes/drools-shapes-xsd-processor/src/test/java/org/drools/shapes/xsd/ComplexNestedTest.java
  22. +262 −0 drools-shapes/drools-shapes-xsd-processor/src/test/java/org/drools/shapes/xsd/ElementRefsTest.java
  23. +116 −0 drools-shapes/drools-shapes-xsd-processor/src/test/java/org/drools/shapes/xsd/GroupCardTest.java
  24. +429 −0 drools-shapes/drools-shapes-xsd-processor/src/test/java/org/drools/shapes/xsd/SimpleTest.java
  25. +165 −0 drools-shapes/drools-shapes-xsd-processor/src/test/java/org/drools/shapes/xsd/TopElementsTest.java
  26. +70 −0 drools-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/attrGroup.xsd
  27. +63 −0 ...ls-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/complexAttribs.xsd
  28. +51 −0 ...s-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/complexElements.xsd
  29. +38 −0 drools-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/complexNested.xsd
  30. +43 −0 drools-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/elementRefs.xsd
  31. +40 −0 drools-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/groupCard.xsd
  32. +35 −0 drools-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/groupRefs.xsd
  33. +80 −0 drools-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/simple.xsd
  34. +50 −0 drools-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/simpleList.xsd
  35. +47 −0 drools-shapes/drools-shapes-xsd-processor/src/test/resources/org/drools/shapes/xsd/topElements.xsd
  36. +31 −0 drools-shapes/pom.xml
@@ -112,7 +112,6 @@
<dependency>
<groupId>org.semanticweb</groupId>
<artifactId>HermiT</artifactId>
- <version>1.3.6</version>
<exclusions>
<exclusion>
<groupId>owlapi</groupId>
@@ -0,0 +1,13 @@
+/target
+/local
+
+# Eclipse, Netbeans and IntelliJ files
+/.*
+!.gitignore
+/nbproject
+/*.ipr
+/*.iws
+/*.iml
+
+# Repository wide ignore mac DS_Store files
+.DS_Store
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2013 JBoss Inc
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-shapes</artifactId>
+ <version>0.5.6.Final</version>
+ </parent>
+
+ <groupId>org.drools</groupId>
+ <artifactId>drools-shapes-xsd-processor-plugin</artifactId>
+ <version>0.5.6.Final</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>Drools Shapes :: XSD -> OWL2 converter plugin</name>
+ <description>Allows to use the XSD to OWL2 converter during the maven build process</description>
+
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-shapes-xsd-processor</artifactId>
+ <version>${chance.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
@@ -0,0 +1,104 @@
+package org.drools.shapes.xsd;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.coode.owlapi.turtle.TurtleOntologyFormat;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.w3._2001.xmlschema.Schema;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.util.List;
+
+/**
+ * Goal
+ *
+ * @goal generate-owl
+ *
+ * @phase generate-sources
+ * @requiresDependencyResolution compile
+ */
+public class Xsd2OwlPlugin extends AbstractMojo {
+
+ /**
+ * @parameter
+ */
+ private List<String> schemaLocations;
+
+ public List<String> getSchemaLocations() {
+ return schemaLocations;
+ }
+
+ public void setSchemaLocations(List<String> schemaLocations) {
+ this.schemaLocations = schemaLocations;
+ }
+
+
+ /**
+ * @parameter default-value="./target/generated-sources"
+ */
+ private File outputDirectory;
+
+ public File getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ public void setOutputDirectory(File outputDirectory) {
+ this.outputDirectory = outputDirectory;
+ }
+
+
+
+ /**
+ * @parameter default-value="false"
+ */
+ private boolean checkConsistency;
+
+ public boolean isCheckConsistency() {
+ return checkConsistency;
+ }
+
+ public void setCheckConsistency(boolean checkConsistency) {
+ this.checkConsistency = checkConsistency;
+ }
+
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ try {
+ for ( String loc : schemaLocations ) {
+ System.out.println( ">> Looking for " + loc );
+ Xsd2Owl converter = Xsd2OwlImpl.getInstance();
+
+ URL url = new File( loc ).toURI().toURL();
+ System.out.println( "FOUND URL " + url );
+ if ( url != null ) {
+ Schema x = converter.parse( url );
+
+ OWLOntology onto = converter.transform( x, url, false, checkConsistency );
+
+ if ( ! outputDirectory.exists() ) {
+ outputDirectory.mkdirs();
+ }
+
+ //TODO Add more formats
+ String src = loc.substring( loc.lastIndexOf( File.separator ) ) + ".ttl";
+ converter.stream( onto,
+ new FileOutputStream( outputDirectory.getPath() + "/" + src ),
+
+ new TurtleOntologyFormat()
+ );
+ } else {
+ System.err.println( "Alas, resource " + loc + " was not found from" + new File(".").getAbsolutePath() );
+ }
+ }
+
+ } catch ( Exception e ) {
+ System.out.println( e.getMessage() );
+ }
+ }
+}
+
+
+
@@ -0,0 +1 @@
+org.drools.shapes.xsd.Xsd2OwlPlugin
@@ -0,0 +1,13 @@
+/target
+/local
+
+# Eclipse, Netbeans and IntelliJ files
+/.*
+!.gitignore
+/nbproject
+/*.ipr
+/*.iws
+/*.iml
+
+# Repository wide ignore mac DS_Store files
+.DS_Store
@@ -0,0 +1,165 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2011 JBoss Inc
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-shapes</artifactId>
+ <version>0.5.6.Final</version>
+ </parent>
+
+ <groupId>org.drools</groupId>
+ <artifactId>drools-shapes-xsd-processor</artifactId>
+ <version>0.5.6.Final</version>
+
+ <name>Drools Shapes :: XSD -> OWL2 converter</name>
+ <description>Processes XSD schemas and infers an OWL2 conceptual model based on the original schema</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-compiler</artifactId>
+ <version>${drools.version}</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ </dependency>
+
+
+ <dependency>
+ <groupId>net.sourceforge.owlapi</groupId>
+ <artifactId>owlapi-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.owlapi</groupId>
+ <artifactId>owlapi-apibinding</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.owlapi</groupId>
+ <artifactId>owlapi-parsers</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.owlapi</groupId>
+ <artifactId>owlapi-tools</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.owlapi</groupId>
+ <artifactId>owlapi-impl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.semanticweb</groupId>
+ <artifactId>HermiT</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>owlapi</groupId>
+ <artifactId>owlapi-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.7</version>
+ <executions>
+ <execution>
+ <id>include-generated-sources</id>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${basedir}/target/generated-sources/java</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jaxb2-maven-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>xjc</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <outputDirectory>${basedir}/target/generated-sources/java</outputDirectory>
+ <schemaDirectory>${basedir}/src/main/resources/org/drools/shapes/xsd</schemaDirectory>
+ <bindingDirectory>${basedir}/src/main/resources/org/drools/shapes/xsd</bindingDirectory>
+ <extension>true</extension>
+ <clearOutputDir>true</clearOutputDir>
+ <arguments>-no-header</arguments> <!-- -Xannotate -->
+ </configuration>
+ <!--dependencies>
+ <dependency>
+ <groupId>org.jvnet.jaxb2_commons</groupId>
+ <artifactId>jaxb2-basics</artifactId>
+ <version>0.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jvnet.jaxb2_commons</groupId>
+ <artifactId>jaxb2-basics-annotate</artifactId>
+ <version>0.6.2</version>
+ </dependency>
+ </dependencies-->
+ </plugin>
+
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
Oops, something went wrong.

0 comments on commit bce1c16

Please sign in to comment.