Giter Site home page Giter Site logo

ontmalizer's Introduction

Ontmalizer License Info

Ontmalizer performs comprehensive transformations of XML Schemas (XSD) and XML data to RDF/OWL automatically. Through this tool, it is possible to create RDF/OWL representation of XML Schemas, and XML instances that comply with such XML Schemas.

The state of the art open source and/or free tools for RDFizing XSD and XML are not able to handle complex schemas and XML instances such as HL7 Clinical Document Architecture (CDA) R2. Only a few commercial tools such as TopBraid Composer are successfully able to do so. However, we do not want to use commercial tools in our SALUS Project: http://www.srdc.com.tr/projects/salus/. As a result, we implemented our own solution. We make use of Sun's XSOM library for processing XML Schemas, Apache Xerces for processing XML data and Apache Jena for managing RDF data.

Further information and technical details can be found in our blog post accessible at http://www.srdc.com.tr/projects/salus/blog/?p=189.

Installation

Apache Maven is required to build the Ontmalizer. Please visit http://maven.apache.org/ in order to install Maven on your system.

Under the root directory of the Ontmalizer project run the following:

$ ontmalizer> mvn install

In order to make a clean install run the following:

$ ontmalizer> mvn clean install

These will build the Ontmalizer and also run a number of test cases, which will transform some XML Schemas (e.g. HL7 CDA R2, SALUS Common Information Model) and corresponding XML instances to RDF/OWL.

Transforming XSD to RDF/OWL

XSD2OWLMapper is the main class to transform XML Schemas to RDF/OWL. The constructor of this class gets the root XSD file to be transformed. Configuration of the transformation operation is quite simple: the caller can set the prefixes for the object property and datatype property names to be created. Then, the call to the convertXSD2OWL() method performs the transformation.

XSD2OWLMapper is able to print the output ontology in one of these formats: RDF/XML, RDF/XML-ABBREV, N-TRIPLE and N3. An example transformation routine is provided below for the HL7 CDA R2 XML Schema:

    // This part converts XML schema to OWL ontology.
    XSD2OWLMapper mapping = new XSD2OWLMapper(new File("src/test/resources/CDA/CDA.xsd"));
    mapping.setObjectPropPrefix("");
    mapping.setDataTypePropPrefix("");
    mapping.convertXSD2OWL();

    // This part prints the ontology to the specified file.
    FileOutputStream ont;
    try {
        File f = new File("src/test/resources/output/cda-ontology.n3");
        f.getParentFile().mkdirs();
        ont = new FileOutputStream(f);
        mapping.writeOntology(ont, "N3");
        ont.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

Transforming XML to RDF/OWL

XML2OWLMapper is the main class to transform XML data to RDF/OWL by creating instances of the necessary OWL classes, RDFS datatypes, OWL datatype and object properties. The constructor of this class gets the XML file to be transformed together with an instance of XSD2OWLMapper that is already initialized with the corresponding XML Schema of the XML data. No other configuration is necessary for the transformation operation; the prefixes for the object property and datatype property names to be created are gathered from the XSD2OWLMapper configuration. Then, the call to the convertXML2OWL() method performs the transformation.

Similar to XSD2OWLMapper, XML2OWLMapper is able to print the output ontology instance in one of these formats: RDF/XML, RDF/XML-ABBREV, N-TRIPLE and N3. An example transformation routine is provided below for a complete HL7 CDA R2 instance, which is compliant with the HL7/ASTM Continuity of Care Document (CCD) and IHE Patient Care Coordination (PCC) templates:

    // This part converts XML schema to OWL ontology.
    XSD2OWLMapper mapping = new XSD2OWLMapper(new File("src/test/resources/CDA/CDA.xsd"));
    mapping.setObjectPropPrefix("");
    mapping.setDataTypePropPrefix("");
    mapping.convertXSD2OWL();

    // This part converts XML instance to RDF data model.
    XML2OWLMapper generator = new XML2OWLMapper(
        new File("src/test/resources/CDA/SALUS-sample-full-CDA-instance.xml"), mapping);
    generator.convertXML2OWL();
    
    // This part prints the RDF data model to the specified file.
    try{
        File f = new File("src/test/resources/output/salus-cda-instance.n3");
        f.getParentFile().mkdirs();
        FileOutputStream fout = new FileOutputStream(f);
        generator.writeModel(fout, "N3");
        fout.close();

    } catch (Exception e){
        e.printStackTrace();
    }

Please refer to our blog post (http://www.srdc.com.tr/projects/salus/blog/?p=189) for further details.

ontmalizer's People

Contributors

bdevloed avatar galbiston avatar lewismc avatar msfyuksel avatar rahmivolkan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ontmalizer's Issues

Lowering RDF to XML

Hi,

I need to implement conversion from RDF message to XML according to a specific xml schema in order to be compliant with legacy system.
Are you working also on the implementation of lowering conversion process?
Let me know, please
Thanks so much for your contribution.

G

using XSD with import statements

I have an XSD schema file that imports types from a different namespace. It seems like Ontmalizer ignores import statements: if I save the model as TTL, there's no mention of the elements with the imported types, and when I try to load a document, it fails.

Are imports supposed to work, or is this a known limitation?

non-deterministic behavior in ontmalizer

Build from latest in github and testing with a simple schema and conforming XML instance and using example code from the blog post (Ontmalizer...).

I am able to map the schema and then when trying to map instance document, non-deterministically, sometimes a reasonable n3 file is generated and sometimes XML2OWLMapper throws an exception when traversing one of the attributes in the first child element of the instance document.

Repeated trials with the same XMLSchema and sample instance documents sometimes fail and sometimes not, and when there is an exception it is not always at the same attribute - I put Logger calls in XML2OWLMapper on calls to traverseChildren and in traverseAttributes. Here is the exception that is thrown (the stacktrace is below):

Exception in thread "main" org.apache.jena.ontology.ConversionException: Cannot convert node http://www.srdc.com.tr/ontmalizer#hasValue to OntProperty

The exception, when it occurs, does not occur on the same attribute but always on some attribute of the first child element of the instance document.

The java test, a sample run, schema and instance file are attached as ontmalizer-nd-issue.zip

enumeration documentation is not parsed and included in OWL output

My source XML Schema has enumerations, which are correctly parsed by Ontmalizer. However, within each of my enumerations is documentation. It looks like this:

<xs:simpleType name="issuesYears">
	<xs:restriction base="xs:unsignedInt">
		<xs:enumeration value="1">
			<xs:annotation>
				<xs:documentation xml:lang="en">Less than one year</xs:documentation>
			</xs:annotation>
		</xs:enumeration>
		<xs:enumeration value="2">
			<xs:annotation>
				<xs:documentation xml:lang="en">1 to 2 years</xs:documentation>
			</xs:annotation>
		</xs:enumeration>	
                    <xs:enumeration value="3">
			<xs:annotation>
				<xs:documentation xml:lang="en">3 to 5 or more years</xs:documentation>
			</xs:annotation>
		</xs:enumeration>	

And the resulting OWL is:

http://www.hudhdx.info/Resources/Vendors/FY2022/HUD_HMIS.xsd#issuesYears_Enumeration

:issuesYears_Enumeration rdf:type owl:NamedIndividual ,
dtype:Enumeration ;
dtype:hasValue :issuesYears_1 ,
:issuesYears_2 ,
:issuesYears_3 .

It would be great if Ontmalizer picked up these changes, and added the documentation to describe the enumeration values.

Bump up version number and release to Maven Central

Hi Mustafa,

So I have an outstanding pull request - it's nothing major, just a minor addition to allow loading XSDs from resources on the classpath (e.g. XSD files bundled as resources in JARs on the classpath).

But if you merge that pull request, would you consider bumping the version number of Ontmalizer and also releasing to Maven Central from now on? That would make it super-easy for us here to pick up the latest pull-request changes, while also making further updates much easier to consume (i.e. we'd just need to bump the dependency version in our project POMs (which of course point to Maven Central), and everything else would 'just work').

Cheers,

Pat.

Usage Question

How do I use this tool from the command line or is a plugin for a framework? Protege, Eclipse?

This is on 64bit Ubuntu 14.04 LTS.

It appears to have built okay.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:15.255s
[INFO] Finished at: Fri Aug 22 14:44:31 BRT 2014
[INFO] Final Memory: 18M/98M
[INFO] ------------------------------------------------------------------------

Making it executable and then running:
$ ./ontmalizer-1.0.0.jar mlhim244.xsd

where mlhim244.xsd is the schema to translate, yields this output:

./ontmalizer-1.0.0.jar: line 1: $'PK\003\004': command not found
./ontmalizer-1.0.0.jar: line 2: $'\217u\026E': command not found
./ontmalizer-1.0.0.jar: line 3: $'\023\313R\363x\271\234J3sJ\300\342%\231\271\020n\212\256WJ6\310ls=\203x3S^.^.PK\003\004': command not found
K-_��ϳR0�3��r,J��,K-��V��+����R�KRSt�_���ETA-INF/MANIFEST.MF�M��LK-.
��3R�: No such file or directory
./ontmalizer-1.0.0.jar: line 4: {u�E�tr/PK��: No such file or directory
./ontmalizer-1.0.0.jar: line 5: {u�Etr/com/PK��: No such file or directory
./ontmalizer-1.0.0.jar: line 6: {u�E
tr/com/srdc/PK��: No such file or directory
./ontmalizer-1.0.0.jar: line 7: {u�E�tr/com/srdc/ontmalizer/PK��: No such file or directory
./ontmalizer-1.0.0.jar: line 8: {u�E�tr/com/srdc/ontmalizer/data/PK��: No such file or directory
./ontmalizer-1.0.0.jar: line 9: {u�E�tr/com/srdc/ontmalizer/helper/PK��: No such file or directory
./ontmalizer-1.0.0.jar: line 10: syntax error near unexpected token `$'\241\005Z''
./ontmalizer-1.0.0.jar: line 10: {u�E�aZ�����/tr/com/srdc/ontmalizer/data/TypedResource.class��MO�@���͇��(�Z>E�P�.E�"�!5����#�F�R S�TT�?'

Thoughts? Help?

Thanks.

Please Help. XML to OWL

Hi,
A question, I want to transform an xml file to owl, but when for example I put these lines of code:
XSD2OWLMapper mapping = new XSD2OWLMapper(new File("C:/Users/usuario/Desktop/report1.xsd"));
mapping.setObjectPropPrefix("");
mapping.setDataTypePropPrefix("");
mapping.convertXSD2OWL();

// This part converts XML instance to RDF data model.
XML2OWLMapper generator = new XML2OWLMapper(
    new File("C:/Users/usuario/Desktop/report.xml"), mapping);
generator.convertXML2OWL();

// This part prints the RDF data model to the specified file.
try{
    File f = new File("C:/Users/usuario/Desktop/report1.n3");
    f.getParentFile().mkdirs();
    FileOutputStream fout = new FileOutputStream(f);
    generator.writeModel(fout, "N3");
    fout.close();

} catch (Exception e){
    e.printStackTrace();
}
    
  I have this error:

3050 [main] WARN org.apache.jena.rdf.model.impl.RDFDefaultErrorHandler - unknown-source: {W136} Relative URIs are not permitted in RDF: specifically <ont-policy.rdf>
These are the files I'm using

files.zip

I do not know why, please help. I will be grateful if you give me some hints.

java.lang.InternalError: unresolved reference

When trying to map a specific xsd file I got an exception which I can not solve.
Exception in thread "main" java.lang.InternalError: unresolved reference at com.sun.xml.xsom.impl.parser.DelayedRef._get(DelayedRef.java:103) at com.sun.xml.xsom.impl.parser.DelayedRef$Element.get(DelayedRef.java:199) at com.sun.xml.xsom.impl.ElementDecl.getSubstAffiliation(ElementDecl.java:115) at com.sun.xml.xsom.impl.ElementDecl.updateSubstitutabilityMap(ElementDecl.java:179) at com.sun.xml.xsom.impl.parser.ParserContext.getResult(ParserContext.java:141) at com.sun.xml.xsom.parser.XSOMParser.getResult(XSOMParser.java:214) at tr.com.srdc.ontmalizer.XSD2OWLMapper.parseXSD(XSD2OWLMapper.java:128) at tr.com.srdc.ontmalizer.XSD2OWLMapper.<init>(XSD2OWLMapper.java:96) at test.main(test.java:13)
the xsd file is quite big and includes some import. I can share it in case it is required.
Any help would be much appreciated.

Transforming XML/XSD to OWL

Hi, I'm trying to convert a schema using your tool, but i meet some issues and I can't clarify them. As an input I use the official PLCopen (Industry description language - http://www.plcopen.org/pages/tc6_xml/) XSD file and when I check the ontology output it is not consistent and i get some Anonymous classes. I'm attaching both files (input and output) for reference. When I load the ontology in Protege I get also many errors(screenshot attached). I will be grateful if you give me some hints.
files.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.