Skip to content

Commit

Permalink
Defined a new format, serializing the CDK data model into the
Browse files Browse the repository at this point in the history
Web Ontology Language (OWL) in the Notation3 (N3) format.
  • Loading branch information
egonw committed Oct 17, 2010
1 parent a94b926 commit 5072305
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
102 changes: 102 additions & 0 deletions src/main/org/openscience/cdk/io/formats/CDKOWLFormat.java
@@ -0,0 +1,102 @@
/* Copyright (C) 2009 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This library 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.
*
* This library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.io.formats;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.tools.DataFeatures;

/**
* Serializes a CDK model into the Web Ontology Language using the
* N3 format.
*
* @cdk.module ioformats
* @cdk.githash
* @cdk.set io-formats
*/
@TestClass("org.openscience.cdk.io.formats.CDKOWLFormatTest")
public class CDKOWLFormat implements IChemFormatMatcher {

private static IResourceFormat myself = null;

private CDKOWLFormat() {}

@TestMethod("testResourceFormatSet")
public static IResourceFormat getInstance() {
if (myself == null) myself = new CDKOWLFormat();
return myself;
}

@TestMethod("testGetFormatName")
public String getFormatName() {
return "CDK OWL (N3)";
}

@TestMethod("testGetMIMEType")
public String getMIMEType() {
return "text/n3";
}
@TestMethod("testGetPreferredNameExtension")
public String getPreferredNameExtension() {
return getNameExtensions()[0];
}
@TestMethod("testGetNameExtensions")
public String[] getNameExtensions() {
return new String[]{"n3"};
}

@TestMethod("testGetReaderClassName")
public String getReaderClassName() {
return "org.openscience.cdk.io.rdf.CDKOWLReader";
}
@TestMethod("testGetWriterClassName")
public String getWriterClassName() {
return "org.openscience.cdk.io.rdf.CDKOWLWriter";
}

public boolean matches(int lineNumber, String line) {
if (line.startsWith("PREFIX") &&
line.contains("http://cdk.sourceforge.net/model.owl#")) {
return true;
}
return false;
}

@TestMethod("testIsXMLBased")
public boolean isXMLBased() {
return false;
}

@TestMethod("testGetSupportedDataFeatures")
public int getSupportedDataFeatures() {
return DataFeatures.HAS_2D_COORDINATES |
DataFeatures.HAS_3D_COORDINATES |
DataFeatures.HAS_ATOM_PARTIAL_CHARGES |
DataFeatures.HAS_ATOM_FORMAL_CHARGES |
DataFeatures.HAS_ATOM_MASS_NUMBERS |
DataFeatures.HAS_ATOM_ISOTOPE_NUMBERS |
DataFeatures.HAS_GRAPH_REPRESENTATION |
DataFeatures.HAS_ATOM_ELEMENT_SYMBOL;
}

@TestMethod("testGetRequiredDataFeatures")
public int getRequiredDataFeatures() {
return DataFeatures.NONE;
}
}
38 changes: 38 additions & 0 deletions src/test/org/openscience/cdk/io/formats/CDKOWLFormatTest.java
@@ -0,0 +1,38 @@
/* $Revision$ $Author$ $Date$
*
* Copyright (C) 2008 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@slists.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.io.formats;

/**
* @cdk.module test-ioformats
*/
public class CDKOWLFormatTest extends ChemFormatMatcherTest {

public CDKOWLFormatTest() {
super.setChemFormatMatcher(
(IChemFormatMatcher)CDKOWLFormat.getInstance()
);
}

}
Expand Up @@ -35,6 +35,7 @@
import org.openscience.cdk.io.formats.BGFFormatTest;
import org.openscience.cdk.io.formats.BSFormatTest;
import org.openscience.cdk.io.formats.CACheFormatTest;
import org.openscience.cdk.io.formats.CDKOWLFormatTest;
import org.openscience.cdk.io.formats.CIFFormatTest;
import org.openscience.cdk.io.formats.CMLFormatTest;
import org.openscience.cdk.io.formats.CMLRSSFormatTest;
Expand Down Expand Up @@ -134,6 +135,7 @@
CacaoCartesianFormatTest.class,
CacaoInternalFormatTest.class,
CACheFormatTest.class,
CDKOWLFormatTest.class,
Chem3D_Cartesian_1FormatTest.class,
Chem3D_Cartesian_2FormatTest.class,
ChemDrawFormatTest.class,
Expand Down

0 comments on commit 5072305

Please sign in to comment.