Skip to content

Commit

Permalink
Added framework to convert the CDK data model into a JEna Model
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Oct 17, 2010
1 parent 5072305 commit 0fbe0e0
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.xml
Expand Up @@ -531,7 +531,7 @@
list="io,structgen"/>
<foreach target="compile-module" param="module"
parallel="${parallel}" maxthreads="${threadCount}"
list="pdb,smiles,sdg,inchi,libiocml"/>
list="pdb,smiles,sdg,inchi,libiocml,iordf"/>
<foreach target="compile-module" param="module"
parallel="${parallel}" maxthreads="${threadCount}"
list="control,extra,reaction,pdbcml,libiomd"/>
Expand Down Expand Up @@ -569,7 +569,7 @@
parallel="${parallel}" maxthreads="${threadCount}"
list="test-data,test-qsaratomic,test-qsarbond,
test-pdb,test-smiles,test-extra,test-atomtype,
test-structgen"/>
test-structgen,test-iordf"/>
<foreach target="compile-module" param="module" trim="true"
parallel="${parallel}" maxthreads="${threadCount}"
list="test-qsarmolecular,test-builder3d,test-datadebug,
Expand Down
Binary file added jar/jena/commons-logging-1.1.1.jar
Binary file not shown.
Binary file added jar/jena/icu4j_3_4.jar
Binary file not shown.
Binary file added jar/jena/iri.jar
Binary file not shown.
Binary file added jar/jena/jena.jar
Binary file not shown.
Binary file added jar/jena/slf4j-api-1.5.6.jar
Binary file not shown.
Binary file added jar/jena/slf4j-simple-1.5.0.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions src/META-INF/iordf.cdkdepends
@@ -0,0 +1,7 @@
cdk-annotation.jar
cdk-interfaces.jar
cdk-ioformats.jar
cdk-core.jar
cdk-standard.jar
cdk-atomtype.jar
cdk-io.jar
16 changes: 16 additions & 0 deletions src/META-INF/iordf.libdepends
@@ -0,0 +1,16 @@
vecmath1.2-1.14.jar
jena/antlr-2.7.5.jar
jena/arq-extra.jar
jena/arq.jar
jena/commons-logging-1.1.1.jar
jena/concurrent.jar
jena/icu4j_3_4.jar
jena/iri.jar
jena/jena.jar
jena/json.jar
jena/log4j-1.2.12.jar
jena/lucene-core-2.3.1.jar
jena/slf4j-simple-1.5.0.jar
jena/stax-api-1.0.jar
jena/wstx-asl-3.0.0.jar
jena/xml-apis.jar
13 changes: 13 additions & 0 deletions src/META-INF/test-iordf.cdkdepends
@@ -0,0 +1,13 @@
cdk-annotation.jar
cdk-interfaces.jar
cdk-ioformats.jar
cdk-core.jar
cdk-standard.jar
cdk-atomtype.jar
cdk-io.jar
cdk-iordf.jar
cdk-diff.jar
cdk-data.jar
cdk-nonotify.jar
cdk-test.jar
cdk-test-io.jar
2 changes: 2 additions & 0 deletions src/META-INF/test-iordf.devellibdepends
@@ -0,0 +1,2 @@
junit-4.5.jar

16 changes: 16 additions & 0 deletions src/META-INF/test-iordf.libdepends
@@ -0,0 +1,16 @@
vecmath1.2-1.14.jar
jena/antlr-2.7.5.jar
jena/arq-extra.jar
jena/arq.jar
jena/commons-logging-1.1.1.jar
jena/concurrent.jar
jena/icu4j_3_4.jar
jena/iri.jar
jena/jena.jar
jena/json.jar
jena/log4j-1.2.12.jar
jena/lucene-core-2.3.1.jar
jena/slf4j-simple-1.5.0.jar
jena/stax-api-1.0.jar
jena/wstx-asl-3.0.0.jar
jena/xml-apis.jar
63 changes: 63 additions & 0 deletions src/main/org/openscience/cdk/libio/jena/Convertor.java
@@ -0,0 +1,63 @@
/* Copyright (C) 2009 Egon Willighagen <egonw@users.sf.net>
*
* Contact: jchempaint-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.libio.jena;

import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IMolecule;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.RDF;

/**
* @cdk.module iordf
* @cdk.githash
* @cdk.keyword Resource Description Framework
* @cdk.keyword Jena
* @cdk.keyword RDF
* @cdk.keyword Web Ontology Language
* @cdk.keyword OWL
*/
public class Convertor {

public static Model molecule2Model(IMolecule molecule) {
Model model = ModelFactory.createOntologyModel();
model.setNsPrefix("cdk", "http://cdk.sourceforge.net/model.owl#");
Resource subject = model.createResource(
"http://cdk.sf.net/model/molecule/" + 1
);
model.add(
subject, RDF.type,
model.createResource("cdk:Molecule")
);
return model;
}

public static IMolecule model2Molecule(Model model,
IChemObjectBuilder builder) {
IMolecule mol = builder.newMolecule();
return mol;
}

}
53 changes: 53 additions & 0 deletions src/test/org/openscience/cdk/libio/jena/ConvertorTest.java
@@ -0,0 +1,53 @@
/* Copyright (C) 2009 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.libio.jena;

import junit.framework.Assert;

import org.junit.Test;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.nonotify.NNMolecule;
import org.openscience.cdk.nonotify.NoNotificationChemObjectBuilder;
import org.openscience.cdk.tools.diff.AtomContainerDiff;

import com.hp.hpl.jena.rdf.model.Model;

/**
* @cdk.module test-iordf
*/
public class ConvertorTest extends CDKTestCase {

private static IChemObjectBuilder builder =
NoNotificationChemObjectBuilder.getInstance();

@Test public void roundtripMolecule() {
IMolecule mol = new NNMolecule();
Model model = Convertor.molecule2Model(mol);
IMolecule rtMol = Convertor.model2Molecule(model, builder);
String diff = AtomContainerDiff.diff(mol, rtMol);
Assert.assertEquals(0, diff.length());
}

}

0 comments on commit 0fbe0e0

Please sign in to comment.