Modified: incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/XSDExtractor.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/XSDExtractor.java?rev=1180862&r1=1180861&r2=1180862&view=diff ============================================================================== --- incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/XSDExtractor.java (original) +++ incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/XSDExtractor.java Mon Oct 10 10:19:12 2011 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ package org.apache.stanbol.reengineer.xml; import java.io.IOException; @@ -9,6 +25,7 @@ import javax.xml.parsers.ParserConfigura import org.apache.stanbol.ontologymanager.ontonet.api.ONManager; import org.apache.stanbol.reengineer.base.api.DataSource; +import org.apache.stanbol.reengineer.base.api.ReengineeringException; import org.apache.stanbol.reengineer.base.api.util.ReengineerUriRefGenerator; import org.apache.stanbol.reengineer.xml.vocab.XSD_OWL; import org.apache.xerces.dom.PSVIDocumentImpl; @@ -38,6 +55,7 @@ import org.apache.xerces.xs.XSTypeDefini import org.apache.xerces.xs.datatypes.ObjectList; import org.semanticweb.owlapi.model.AddAxiom; import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; @@ -55,6 +73,8 @@ import org.w3c.dom.traversal.DocumentTra import org.w3c.dom.traversal.NodeFilter; import org.w3c.dom.traversal.NodeIterator; import org.w3c.dom.traversal.TreeWalker; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class XSDExtractor extends ReengineerUriRefGenerator { @@ -237,7 +257,7 @@ public class XSDExtractor extends Reengi XSD_OWL.type, attrResourceIRI, simpleTypeIRI))); log.debug("ATTRIBUTE USES REQUIRED " - + xsAttributeUseImpl.getAttrDeclaration().getTypeDefinition().getName()); + + xsAttributeUseImpl.getAttrDeclaration().getTypeDefinition().getName()); manager.applyChange(new AddAxiom(schemaOntology, createOWLObjectPropertyAssertionAxiom(factory, XSD_OWL.hasAttributeUse, complexType, attrResourceIRI))); @@ -394,35 +414,29 @@ public class XSDExtractor extends Reengi XSD_OWL.hasEnumeration, simpleType, enumerationIRI))); } + IRI option = null; try { // Whitepace /* - * This line, sometimes, generates an exception when try to get simple type definition for white - * space. However, even if there is the exception, the line returns the ZERO value, so in the - * catch block is perfomed the option with ZERO value that is WS_PRESERVE. + * This line, sometimes, generates an exception when trying to get simple type definition for + * white space. However, even if there is the exception, the line returns a zero value. In this + * case, the WS_PRESERVE option is set in the catch block. */ short whitespace = xsSimpleTypeDefinition.getWhitespace(); - if (whitespace == XSSimpleTypeDecl.WS_COLLAPSE) { - // Collapse - manager.applyChange(new AddAxiom(schemaOntology, createOWLObjectPropertyAssertionAxiom( - factory, XSD_OWL.hasWhitespace, simpleType, XSD_OWL.COLLAPSE))); - } else if (whitespace == XSSimpleTypeDecl.WS_PRESERVE) { - // Preserve - manager.applyChange(new AddAxiom(schemaOntology, createOWLObjectPropertyAssertionAxiom( - factory, XSD_OWL.hasWhitespace, simpleType, XSD_OWL.PRESERVE))); - } else if (whitespace == XSSimpleTypeDecl.WS_REPLACE) { - // Replace - manager.applyChange(new AddAxiom(schemaOntology, createOWLObjectPropertyAssertionAxiom( - factory, XSD_OWL.hasWhitespace, simpleType, XSD_OWL.REPLACE))); - } - - log.debug("WHITESPACE : " + whitespace); + if (whitespace == XSSimpleTypeDecl.WS_COLLAPSE) option = XSD_OWL.COLLAPSE; // Collapse + else if (whitespace == XSSimpleTypeDecl.WS_PRESERVE) option = XSD_OWL.PRESERVE; // Preserve + else if (whitespace == XSSimpleTypeDecl.WS_REPLACE) option = XSD_OWL.REPLACE; // Replace + log.debug("Whitespace facet value for XSD simple type definition is {}.", whitespace); } catch (DatatypeException e) { - // TODO Auto-generated catch block - /* In case of exception is run the option that preserves the simple type. */ - manager.applyChange(new AddAxiom(schemaOntology, createOWLObjectPropertyAssertionAxiom(factory, - XSD_OWL.hasWhitespace, simpleType, XSD_OWL.PRESERVE))); - log.warn("PROBLEM TO GET WHITE SPACE FROM SIMPLE TYPE DEFINITION", e); + // Exception fallback is to preserve the simple type definition. + log.warn( + "Unable to obtain whitespace facet value for simple type definition. Defaulting to WS_PRESERVE." + + "\n\tOriginal message follows :: {}", e.getMessage()); + option = XSD_OWL.PRESERVE; + } finally { + OWLAxiom axiom = createOWLObjectPropertyAssertionAxiom(factory, XSD_OWL.hasWhitespace, + simpleType, option); + if (option != null) manager.applyChange(new AddAxiom(schemaOntology, axiom)); } // ADD BASE TYPE @@ -510,7 +524,9 @@ public class XSDExtractor extends Reengi } - public OWLOntology getOntologySchema(String graphNS, IRI outputIRI, DataSource dataSource) { + public OWLOntology getOntologySchema(String graphNS, IRI outputIRI, DataSource dataSource) throws ReengineeringException { + + if (dataSource == null) throw new IllegalArgumentException("Data source cannot be null."); if (!graphNS.endsWith("#")) { graphNS += "#"; @@ -535,191 +551,204 @@ public class XSDExtractor extends Reengi PSVIDocumentImpl psviDocumentImpl = new PSVIDocumentImpl(); XSSimpleTypeDecl m; - if (dataSource != null) { - OWLOntologyManager ontologyManager = onManager.getOwlCacheManager(); - OWLDataFactory factory = onManager.getOwlFactory(); + OWLOntologyManager ontologyManager = onManager.getOwlCacheManager(); + OWLDataFactory factory = onManager.getOwlFactory(); - log.debug("XSD output IRI : " + outputIRI); + log.debug("XSD output IRI : " + outputIRI); - if (outputIRI != null) { - try { - dataSourceSchemaOntology = ontologyManager.createOntology(outputIRI); - } catch (OWLOntologyCreationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } else { - try { - dataSourceSchemaOntology = ontologyManager.createOntology(); - } catch (OWLOntologyCreationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + try { + if (outputIRI != null) dataSourceSchemaOntology = ontologyManager.createOntology(outputIRI); + else dataSourceSchemaOntology = ontologyManager.createOntology(); + } catch (OWLOntologyCreationException e) { + throw new ReengineeringException(e); + } - if (dataSourceSchemaOntology != null) { + if (dataSourceSchemaOntology != null) { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); + dbf.setNamespaceAware(true); - String id = "http://apache.org/xml/properties/dom/document-class-name"; - Object value = "org.apache.xerces.dom.PSVIDocumentImpl"; - try { - dbf.setAttribute(id, value); - dbf.setNamespaceAware(true); - dbf.setValidating(true); - dbf.setAttribute("http://apache.org/xml/features/validation/schema", Boolean.TRUE); - } catch (IllegalArgumentException e) { - log.error("Could not set parser property", e); - } + String id = "http://apache.org/xml/properties/dom/document-class-name"; + Object value = "org.apache.xerces.dom.PSVIDocumentImpl"; + try { + dbf.setAttribute(id, value); + dbf.setNamespaceAware(true); + dbf.setValidating(true); + dbf.setAttribute("http://apache.org/xml/features/validation/schema", Boolean.TRUE); + } catch (IllegalArgumentException e) { + log.error("Could not set parser property", e); + } + + DocumentBuilder db; + Document document; + + try { + db = dbf.newDocumentBuilder(); + + // FIXME hack for unit tests, this should have a configurable offline mode!!! + db.setEntityResolver(new EntityResolver() { + public InputSource resolveEntity(String publicId, String systemId) throws SAXException, + IOException { + if (systemId.endsWith("DWML.xsd")) { + InputStream dtdStream = XSDExtractor.class.getResourceAsStream("/xml/DWML.xsd"); + return new InputSource(dtdStream); + } + // else + // if (systemId.endsWith("ndfd_data.xsd")) + // { + // InputStream dtdStream = XSDExtractor.class + // .getResourceAsStream("/xml/ndfd_data.xsd"); + // return new InputSource(dtdStream); + // } + // else + // if (systemId.endsWith("meta_data.xsd")) + // { + // InputStream dtdStream = XSDExtractor.class + // .getResourceAsStream("/xml/meta_data.xsd"); + // return new InputSource(dtdStream); + // } + else { + return null; + } + } + }); - DocumentBuilder db; - Document document; + document = db.parse((InputStream) dataSource.getDataSource()); + Element root = document.getDocumentElement(); - try { - db = dbf.newDocumentBuilder(); + log.debug("Root is : " + root.getNodeName()); - document = db.parse((InputStream) dataSource.getDataSource()); - Element root = document.getDocumentElement(); + ElementPSVI rootPsvi = (ElementPSVI) root; - log.debug("Root is : " + root.getNodeName()); + XSModelImpl xsModel = (XSModelImpl) rootPsvi.getSchemaInformation(); - ElementPSVI rootPsvi = (ElementPSVI) root; + log.debug("Schema model : " + xsModel.getClass().getCanonicalName()); - XSModelImpl xsModel = (XSModelImpl) rootPsvi.getSchemaInformation(); + XSNamedMap xsNamedMap = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION); + for (int i = 0, j = xsNamedMap.getLength(); i < j; i++) { + XSObject xsObject = xsNamedMap.item(i); + if (xsObject instanceof XSElementDeclaration) { - log.debug("Schema model : " + xsModel.getClass().getCanonicalName()); + XSElementDeclaration xsElementDeclaration = (XSElementDeclaration) xsObject; - XSNamedMap xsNamedMap = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION); - for (int i = 0, j = xsNamedMap.getLength(); i < j; i++) { - XSObject xsObject = xsNamedMap.item(i); - if (xsObject instanceof XSElementDeclaration) { + String name = xsElementDeclaration.getName(); + if (name != null && !name.equals("")) { - XSElementDeclaration xsElementDeclaration = (XSElementDeclaration) xsObject; + IRI elementIndividual = IRI.create(graphNS + name); - String name = xsElementDeclaration.getName(); - if (name != null && !name.equals("")) { + OWLClassAssertionAxiom element = createOWLClassAssertionAxiom(factory, + XSD_OWL.Element, elementIndividual); + ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, element)); - IRI elementIndividual = IRI.create(graphNS + name); + OWLDataPropertyAssertionAxiom data = createOWLDataPropertyAssertionAxiom(factory, + XSD_OWL.name, elementIndividual, name); + ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, data)); - OWLClassAssertionAxiom element = createOWLClassAssertionAxiom(factory, - XSD_OWL.Element, elementIndividual); - ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, element)); + boolean boolValue = xsElementDeclaration.getAbstract(); + data = createOWLDataPropertyAssertionAxiom(factory, XSD_OWL.abstractProperty, + elementIndividual, boolValue); + ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, data)); - OWLDataPropertyAssertionAxiom data = createOWLDataPropertyAssertionAxiom( - factory, XSD_OWL.name, elementIndividual, name); - ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, data)); + XSTypeDefinition xsTypeDefinition = xsElementDeclaration.getTypeDefinition(); + String type = graphNS + xsTypeDefinition.getName(); - boolean boolValue = xsElementDeclaration.getAbstract(); - data = createOWLDataPropertyAssertionAxiom(factory, XSD_OWL.abstractProperty, - elementIndividual, boolValue); - ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, data)); + XSTypeDefinition baseTypeDefinition = xsTypeDefinition.getBaseType(); + short baseType = baseTypeDefinition.getTypeCategory(); - XSTypeDefinition xsTypeDefinition = xsElementDeclaration.getTypeDefinition(); - String type = graphNS + xsTypeDefinition.getName(); + OWLClassAssertionAxiom typeResource; + log.debug("SIMPLE TYPE PRINT " + XSTypeDefinition.SIMPLE_TYPE); + log.debug("COMPLEX TYPE PRINT " + XSTypeDefinition.COMPLEX_TYPE); - XSTypeDefinition baseTypeDefinition = xsTypeDefinition.getBaseType(); - short baseType = baseTypeDefinition.getTypeCategory(); + IRI typeIRI = IRI.create(type); - OWLClassAssertionAxiom typeResource; - log.debug("SIMPLE TYPE PRINT " + XSTypeDefinition.SIMPLE_TYPE); - log.debug("COMPLEX TYPE PRINT " + XSTypeDefinition.COMPLEX_TYPE); + if (baseType == XSTypeDefinition.SIMPLE_TYPE) { + log.debug("SIMPLE TYPE"); + typeResource = createOWLClassAssertionAxiom(factory, XSD_OWL.SimpleType, + typeIRI); + addSimpleType(graphNS, ontologyManager, factory, dataSourceSchemaOntology, + typeIRI, (XSSimpleTypeDecl) xsTypeDefinition); - IRI typeIRI = IRI.create(type); + } else { + log.debug("COMPLEX TYPE"); + typeResource = createOWLClassAssertionAxiom(factory, XSD_OWL.ComplexType, + typeIRI); - if (baseType == XSTypeDefinition.SIMPLE_TYPE) { - log.debug("SIMPLE TYPE"); - typeResource = createOWLClassAssertionAxiom(factory, XSD_OWL.SimpleType, - typeIRI); - addSimpleType(graphNS, ontologyManager, factory, - dataSourceSchemaOntology, typeIRI, - (XSSimpleTypeDecl) xsTypeDefinition); + addComplexType(graphNS, ontologyManager, factory, dataSourceSchemaOntology, + typeIRI, (XSComplexTypeDecl) xsTypeDefinition); + } - } else { - log.debug("COMPLEX TYPE"); - typeResource = createOWLClassAssertionAxiom(factory, XSD_OWL.ComplexType, - typeIRI); + ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, typeResource)); - addComplexType(graphNS, ontologyManager, factory, - dataSourceSchemaOntology, typeIRI, - (XSComplexTypeDecl) xsTypeDefinition); - } + // add the type property to the element declaration - ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, - typeResource)); + log.debug("---- graph NS : " + graphNS); + log.debug("---- type IRI : " + typeIRI.toString()); + OWLObjectPropertyAssertionAxiom hasType = createOWLObjectPropertyAssertionAxiom( + factory, XSD_OWL.type, elementIndividual, typeIRI); + ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, hasType)); + + // add the scope property to the element declaration + short scope = xsElementDeclaration.getScope(); + + OWLObjectPropertyAssertionAxiom scopeAxiom; + if (scope == XSConstants.SCOPE_ABSENT) { + // Scope absent + scopeAxiom = createOWLObjectPropertyAssertionAxiom(factory, XSD_OWL.hasScope, + elementIndividual, XSD_OWL.ScopeAbsent); + } else if (scope == XSConstants.SCOPE_LOCAL) { + scopeAxiom = createOWLObjectPropertyAssertionAxiom(factory, XSD_OWL.hasScope, + elementIndividual, XSD_OWL.ScopeLocal); + } else { + scopeAxiom = createOWLObjectPropertyAssertionAxiom(factory, XSD_OWL.hasScope, + elementIndividual, XSD_OWL.ScopeGlobal); + } - // add the type property to the element declaration + ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, scopeAxiom)); - log.debug("---- graph NS : " + graphNS); - log.debug("---- type IRI : " + typeIRI.toString()); - OWLObjectPropertyAssertionAxiom hasType = createOWLObjectPropertyAssertionAxiom( - factory, XSD_OWL.type, elementIndividual, typeIRI); - ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, hasType)); - - // add the scope property to the element declaration - short scope = xsElementDeclaration.getScope(); - - OWLObjectPropertyAssertionAxiom scopeAxiom; - if (scope == XSConstants.SCOPE_ABSENT) { - // Scope absent - scopeAxiom = createOWLObjectPropertyAssertionAxiom(factory, - XSD_OWL.hasScope, elementIndividual, XSD_OWL.ScopeAbsent); - } else if (scope == XSConstants.SCOPE_LOCAL) { - scopeAxiom = createOWLObjectPropertyAssertionAxiom(factory, - XSD_OWL.hasScope, elementIndividual, XSD_OWL.ScopeLocal); - } else { - scopeAxiom = createOWLObjectPropertyAssertionAxiom(factory, - XSD_OWL.hasScope, elementIndividual, XSD_OWL.ScopeGlobal); - } - - ontologyManager - .applyChange(new AddAxiom(dataSourceSchemaOntology, scopeAxiom)); - - // add the constraint type property to the element declaration - short constraingType = xsElementDeclaration.getConstraintType(); - OWLObjectPropertyAssertionAxiom constraintAxiom; - if (constraingType == XSConstants.VC_NONE) { - // Value constraint none - constraintAxiom = createOWLObjectPropertyAssertionAxiom(factory, - XSD_OWL.hasConstraintType, elementIndividual, XSD_OWL.VC_NONE); - } else if (constraingType == XSConstants.VC_DEFAULT) { - constraintAxiom = createOWLObjectPropertyAssertionAxiom(factory, - XSD_OWL.hasConstraintType, elementIndividual, XSD_OWL.VC_DEFAULT); - } else { - // Value constraint fixed - constraintAxiom = createOWLObjectPropertyAssertionAxiom(factory, - XSD_OWL.hasConstraintType, elementIndividual, XSD_OWL.VC_FIXED); - } + // add the constraint type property to the element declaration + short constraingType = xsElementDeclaration.getConstraintType(); + OWLObjectPropertyAssertionAxiom constraintAxiom; + if (constraingType == XSConstants.VC_NONE) { + // Value constraint none + constraintAxiom = createOWLObjectPropertyAssertionAxiom(factory, + XSD_OWL.hasConstraintType, elementIndividual, XSD_OWL.VC_NONE); + } else if (constraingType == XSConstants.VC_DEFAULT) { + constraintAxiom = createOWLObjectPropertyAssertionAxiom(factory, + XSD_OWL.hasConstraintType, elementIndividual, XSD_OWL.VC_DEFAULT); + } else { + // Value constraint fixed + constraintAxiom = createOWLObjectPropertyAssertionAxiom(factory, + XSD_OWL.hasConstraintType, elementIndividual, XSD_OWL.VC_FIXED); + } - ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, - constraintAxiom)); + ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, + constraintAxiom)); - // add the constraint value literal to the element delcaration - String contstraintValue = xsElementDeclaration.getConstraintValue(); - if (contstraintValue != null) { - - ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, - createOWLDataPropertyAssertionAxiom(factory, XSD_OWL.constraint, - elementIndividual, contstraintValue))); - } + // add the constraint value literal to the element delcaration + String contstraintValue = xsElementDeclaration.getConstraintValue(); + if (contstraintValue != null) { + ontologyManager.applyChange(new AddAxiom(dataSourceSchemaOntology, + createOWLDataPropertyAssertionAxiom(factory, XSD_OWL.constraint, + elementIndividual, contstraintValue))); } } - } - } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SAXException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } } + + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } }
Modified: incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/vocab/XML_OWL.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/vocab/XML_OWL.java?rev=1180862&r1=1180861&r2=1180862&view=diff ============================================================================== --- incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/vocab/XML_OWL.java (original) +++ incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/vocab/XML_OWL.java Mon Oct 10 10:19:12 2011 @@ -1,46 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ package org.apache.stanbol.reengineer.xml.vocab; import org.semanticweb.owlapi.model.IRI; - public class XML_OWL { - /** <p>The namespace of the vocabulary as a string</p> */ - public static final String NS = "http://ontologydesignpatterns.org/ont/iks/oxml.owl#"; - - /** <p>The namespace of the vocabulary as a string</p> */ - public static final String URI = "http://ontologydesignpatterns.org/ont/iks/oxml.owl"; - - /** <p>The namespace of the vocabulary as a string</p> - * @see #NS */ - - public static final IRI SpecialAttrs = IRI.create( NS+"SpecialAttrs" ); - - public static final IRI XMLElement = IRI.create( NS+"XMLElement" ); - - public static final IRI XMLAttribute = IRI.create( NS+"XMLAttribute" ); - - public static final IRI Node = IRI.create( NS+"Node" ); - - public static final IRI hasSpecialAttrs = IRI.create( NS+"hasSpecialAttrs" ); - - public static final IRI isSpecialAttrsOf = IRI.create( NS+"isSpecialAttrsOf" ); - - public static final IRI hasXMLAttribute = IRI.create( NS+"hasXMLAttribute" ); - - public static final IRI isXMLAttributeOf = IRI.create( NS+"isXMLAttributeOf" ); - - public static final IRI nodeName = IRI.create( NS+"nodeName" ); - - public static final IRI nodeValue = IRI.create( NS+"nodeValue" ); - - public static final IRI hasElementDeclaration = IRI.create( NS+"hasElementDeclaration" ); - - public static final IRI isElementDeclarationOf = IRI.create( NS+"isElementDeclarationOf" ); - - public static final IRI hasAttributeDeclaration = IRI.create( NS+"hasAttributeDeclaration" ); - - public static final IRI isAttributetDeclarationOf = IRI.create( NS+"isAttributeDeclarationOf" ); - - public static final IRI textContent = IRI.create( NS+"textContent" ); + /** + * <p> + * The namespace of the vocabulary as a string + * </p> + */ + public static final String NS = "http://www.ontologydesignpatterns.org/ont/iks/oxml.owl#"; + + /** + * <p> + * The namespace of the vocabulary as a string + * </p> + */ + public static final String URI = "http://www.ontologydesignpatterns.org/ont/iks/oxml.owl"; + + /** + * <p> + * The namespace of the vocabulary as a string + * </p> + * + * @see #NS + */ + + public static final IRI SpecialAttrs = IRI.create(NS + "SpecialAttrs"); + + public static final IRI XMLElement = IRI.create(NS + "XMLElement"); + + public static final IRI XMLAttribute = IRI.create(NS + "XMLAttribute"); + + public static final IRI Node = IRI.create(NS + "Node"); + + public static final IRI hasSpecialAttrs = IRI.create(NS + "hasSpecialAttrs"); + + public static final IRI isSpecialAttrsOf = IRI.create(NS + "isSpecialAttrsOf"); + + public static final IRI hasXMLAttribute = IRI.create(NS + "hasXMLAttribute"); + + public static final IRI isXMLAttributeOf = IRI.create(NS + "isXMLAttributeOf"); + + public static final IRI nodeName = IRI.create(NS + "nodeName"); + + public static final IRI nodeValue = IRI.create(NS + "nodeValue"); + + public static final IRI hasElementDeclaration = IRI.create(NS + "hasElementDeclaration"); + + public static final IRI isElementDeclarationOf = IRI.create(NS + "isElementDeclarationOf"); + + public static final IRI hasAttributeDeclaration = IRI.create(NS + "hasAttributeDeclaration"); + + public static final IRI isAttributetDeclarationOf = IRI.create(NS + "isAttributeDeclarationOf"); + + public static final IRI textContent = IRI.create(NS + "textContent"); } Modified: incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/vocab/XSD_OWL.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/vocab/XSD_OWL.java?rev=1180862&r1=1180861&r2=1180862&view=diff ============================================================================== --- incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/vocab/XSD_OWL.java (original) +++ incubator/stanbol/trunk/reengineer/xml/src/main/java/org/apache/stanbol/reengineer/xml/vocab/XSD_OWL.java Mon Oct 10 10:19:12 2011 @@ -5,7 +5,7 @@ import org.semanticweb.owlapi.model.IRI; public class XSD_OWL { /** <p>The namespace of the vocabulary as a string</p> */ - public static final String NS = "http://ontologydesignpatterns.org/ont/iks/oxsd.owl#"; + public static final String NS = "http://www.ontologydesignpatterns.org/ont/iks/oxsd.owl#"; /** <p>The namespace of the vocabulary as a string</p> * @see #NS */ Modified: incubator/stanbol/trunk/reengineer/xml/src/test/java/org/apache/stanbol/reengineer/xml/XMLReengineerTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/xml/src/test/java/org/apache/stanbol/reengineer/xml/XMLReengineerTest.java?rev=1180862&r1=1180861&r2=1180862&view=diff ============================================================================== --- incubator/stanbol/trunk/reengineer/xml/src/test/java/org/apache/stanbol/reengineer/xml/XMLReengineerTest.java (original) +++ incubator/stanbol/trunk/reengineer/xml/src/test/java/org/apache/stanbol/reengineer/xml/XMLReengineerTest.java Mon Oct 10 10:19:12 2011 @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ package org.apache.stanbol.reengineer.xml; +import static org.junit.Assert.*; + import java.io.InputStream; import java.util.Dictionary; import java.util.Hashtable; @@ -10,11 +28,14 @@ import org.apache.clerezza.rdf.core.spar import org.apache.clerezza.rdf.jena.sparql.JenaSparqlEngine; import org.apache.clerezza.rdf.simple.storage.SimpleTcProvider; import org.apache.stanbol.ontologymanager.ontonet.api.ONManager; +import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration; import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl; +import org.apache.stanbol.ontologymanager.ontonet.impl.OfflineConfigurationImpl; import org.apache.stanbol.reengineer.base.api.DataSource; import org.apache.stanbol.reengineer.base.api.Reengineer; import org.apache.stanbol.reengineer.base.api.util.ReengineerType; import org.apache.stanbol.reengineer.base.impl.ReengineerManagerImpl; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -23,20 +44,26 @@ import org.semanticweb.owlapi.model.OWLO public class XMLReengineerTest { - static DataSource dataSource; - static String graphNS; - static IRI outputIRI; - static Reengineer xmlExtractor; + private static DataSource dataSource; + private static String graphNS; + private static OfflineConfiguration offline; + private static IRI outputIRI; + private static Reengineer xmlExtractor; @BeforeClass public static void setupClass() { + + Dictionary<String,Object> conf = new Hashtable<String,Object>(); + conf.put(OfflineConfiguration.ONTOLOGY_PATHS, new String[] {"/meta"}); + offline = new OfflineConfigurationImpl(conf); + graphNS = "http://kres.iks-project.eu/reengineering/test"; outputIRI = IRI.create(graphNS); dataSource = new DataSource() { @Override public Object getDataSource() { - InputStream xmlStream = this.getClass().getResourceAsStream("/META-INF/test/weather.xml"); + InputStream xmlStream = this.getClass().getResourceAsStream("/xml/weather.xml"); return xmlStream; } @@ -47,31 +74,37 @@ public class XMLReengineerTest { @Override public String getID() { - // TODO Auto-generated method stub + // Not going to check ID return null; } }; + } @Test public void dataReengineeringTest() throws Exception { OWLOntology schemaOntology = xmlExtractor.schemaReengineering(graphNS, outputIRI, dataSource); - xmlExtractor.dataReengineering(graphNS, IRI.create(outputIRI.toString() + "_new"), dataSource, - schemaOntology); + assertNotNull(schemaOntology); + OWLOntology reengineered = xmlExtractor.dataReengineering(graphNS, + IRI.create(outputIRI.toString() + "_new"), dataSource, schemaOntology); + assertNotNull(reengineered); } @Test public void reengineeringTest() throws Exception { - xmlExtractor.reengineering(graphNS, outputIRI, dataSource); + OWLOntology reengineered = xmlExtractor.reengineering(graphNS, outputIRI, dataSource); + assertNotNull(reengineered); } @Test public void schemaReengineeringTest() throws Exception { - xmlExtractor.schemaReengineering(graphNS, outputIRI, dataSource); + OWLOntology schemaOntology = xmlExtractor.schemaReengineering(graphNS, outputIRI, dataSource); + assertNotNull(schemaOntology); } @Before public void setup() { + Dictionary<String,Object> emptyConf = new Hashtable<String,Object>(); class SpecialTcManager extends TcManager { @@ -86,13 +119,12 @@ public class XMLReengineerTest { WeightedTcProvider wtcp = new SimpleTcProvider(); TcManager tcm = new SpecialTcManager(qe, wtcp); - // Two different ontology storagez, the same sparql engine and tcprovider - ONManager onManager = new ONManagerImpl(tcm, wtcp, emptyConf); - xmlExtractor = new XMLExtractor(new ReengineerManagerImpl(new Hashtable<String,Object>()), onManager, - emptyConf); + // Two different ontology storages, the same sparql engine and tcprovider + ONManager onManager = new ONManagerImpl(tcm, wtcp, offline, emptyConf); + xmlExtractor = new XMLExtractor(new ReengineerManagerImpl(emptyConf), onManager, emptyConf); } - @Before + @After public void tearDown() { xmlExtractor = null; } Added: incubator/stanbol/trunk/reengineer/xml/src/test/resources/meta/oxml.owl URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/xml/src/test/resources/meta/oxml.owl?rev=1180862&view=auto ============================================================================== --- incubator/stanbol/trunk/reengineer/xml/src/test/resources/meta/oxml.owl (added) +++ incubator/stanbol/trunk/reengineer/xml/src/test/resources/meta/oxml.owl Mon Oct 10 10:19:12 2011 @@ -0,0 +1,154 @@ +<?xml version="1.0"?> +<rdf:RDF + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:schema="http://www.ontologydesignpatterns.org/ont/iks/oxsd.owl#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns="http://www.ontologydesignpatterns.org/ont/iks/oxml.owl#" + xmlns:xs="http://www.w3.org/2001/XMLSchema#" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xml:base="http://www.ontologydesignpatterns.org/ont/iks/oxml.owl"> + <owl:Ontology rdf:about="http://www.ontologydesignpatterns.org/ont/iks/oxml.owl"> + <owl:imports rdf:resource="http://www.ontologydesignpatterns.org/ont/iks/oxsd.owl"/> + <rdfs:comment>OWL ontology generated by the xsd2owl XML Style Sheet (http://rhizomik.net/redefer)</rdfs:comment> + <owl:versionInfo xml:lang="en">Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You 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. + </owl:versionInfo> + </owl:Ontology> + <owl:Class rdf:ID="SpecialAttrs"> + <rdfs:subClassOf> + <owl:Restriction> + <owl:onProperty> + <owl:DatatypeProperty rdf:ID="base"/> + </owl:onProperty> + <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger" + >0</owl:minCardinality> + </owl:Restriction> + </rdfs:subClassOf> + <rdfs:subClassOf> + <owl:Restriction> + <owl:onProperty> + <owl:DatatypeProperty rdf:ID="space"/> + </owl:onProperty> + <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger" + >0</owl:minCardinality> + </owl:Restriction> + </rdfs:subClassOf> + <rdfs:subClassOf> + <owl:Restriction> + <owl:onProperty> + <owl:DatatypeProperty rdf:ID="id"/> + </owl:onProperty> + <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger" + >0</owl:minCardinality> + </owl:Restriction> + </rdfs:subClassOf> + </owl:Class> + <owl:Class rdf:ID="XMLElement"> + <owl:disjointWith> + <owl:Class rdf:ID="XMLAttribute"/> + </owl:disjointWith> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >XML element</rdfs:label> + <rdfs:subClassOf> + <owl:Class rdf:ID="Node"/> + </rdfs:subClassOf> + </owl:Class> + <owl:Class rdf:about="#XMLAttribute"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >XML attribute</rdfs:label> + <rdfs:subClassOf> + <owl:Class rdf:about="#Node"/> + </rdfs:subClassOf> + <owl:disjointWith rdf:resource="#XMLElement"/> + </owl:Class> + <owl:Class rdf:about="#Node"> + <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >is XML attribute of</rdfs:label> + </owl:Class> + <owl:ObjectProperty rdf:ID="hasElementDeclaration"> + <rdfs:range rdf:resource="http://www.ontologydesignpatterns.org/ont/iks/oxsd.owl#Element"/> + <owl:inverseOf> + <owl:ObjectProperty rdf:ID="isElementDeclarationOf"/> + </owl:inverseOf> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >has element declaration</rdfs:label> + <rdfs:domain rdf:resource="#XMLElement"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:ID="isXMLAttributeOf"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >is XML attribute of</rdfs:label> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:ID="isSpecialAttrsOf"> + <rdfs:domain rdf:resource="#SpecialAttrs"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >is special attribute of</rdfs:label> + <rdfs:range rdf:resource="#XMLElement"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:ID="hasSpecialAttrs"> + <owl:inverseOf rdf:resource="#isSpecialAttrsOf"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >has special attributes</rdfs:label> + <rdfs:domain rdf:resource="#XMLElement"/> + <rdfs:range rdf:resource="#SpecialAttrs"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#isElementDeclarationOf"> + <rdfs:domain rdf:resource="http://www.ontologydesignpatterns.org/ont/iks/oxsd.owl#Element"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >is element declaration of</rdfs:label> + <rdfs:range rdf:resource="#XMLElement"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:ID="any"/> + <owl:ObjectProperty rdf:ID="hasAttributeDeclaration"> + <rdfs:range rdf:resource="http://www.ontologydesignpatterns.org/ont/iks/oxsd.owl#Attribute"/> + <rdfs:domain rdf:resource="#XMLAttribute"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >has attribute declaration</rdfs:label> + <owl:inverseOf> + <owl:ObjectProperty rdf:ID="isAttributeDeclarationOf"/> + </owl:inverseOf> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:ID="hasXMLAttribute"> + <rdfs:domain rdf:resource="#XMLElement"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >has XML attribute</rdfs:label> + <owl:inverseOf rdf:resource="#isXMLAttributeOf"/> + <rdfs:range rdf:resource="#XMLAttribute"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#isAttributeDeclarationOf"> + <rdfs:domain rdf:resource="http://www.ontologydesignpatterns.org/ont/iks/oxsd.owl#Attribute"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >is attribute declaration of</rdfs:label> + <rdfs:range rdf:resource="#XMLAttribute"/> + </owl:ObjectProperty> + <owl:DatatypeProperty rdf:ID="textContent"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >textContent</rdfs:label> + <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> + <rdfs:domain rdf:resource="#XMLElement"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#id"> + <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:ID="nodeValue"> + <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >node value</rdfs:label> + <rdfs:domain rdf:resource="#Node"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:ID="nodeName"> + <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >node name</rdfs:label> + <rdfs:domain rdf:resource="#Node"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#base"> + <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#anyURI"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:ID="lang"/> +</rdf:RDF> + +<!-- Created with TopBraid Composer -->
