[MOBY-guts] biomoby commit
Chris Dagdigian
dag at dev.open-bio.org
Tue Mar 27 15:25:32 UTC 2007
dag
Tue Mar 27 11:25:28 EDT 2007
Update of /home/repository/moby/s-moby/ontologies/src/java/org/semanticmoby/ontologies/util
In directory dev.open-bio.org:/home/dag/s-moby/ontologies/src/java/org/semanticmoby/ontologies/util
Modified Files:
OBOFileClassCreator.java OBOFileIndividualCreator.java
OwlFileSplitter.java
Log Message:
Removed MGED.tar.gz and replaced ~35 files per Teri Gomez @ NCGR
-- Chris Dagdigian
s-moby/ontologies/src/java/org/semanticmoby/ontologies/util OBOFileClassCreator.java,1.1,1.2 OBOFileIndividualCreator.java,1.5,1.6 OwlFileSplitter.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/s-moby/ontologies/src/java/org/semanticmoby/ontologies/util/OBOFileClassCreator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/s-moby/ontologies/src/java/org/semanticmoby/ontologies/util/OBOFileClassCreator.java 2006/12/04 00:26:55 1.1
+++ /home/repository/moby/s-moby/ontologies/src/java/org/semanticmoby/ontologies/util/OBOFileClassCreator.java 2007/03/27 15:25:28 1.2
@@ -199,19 +199,9 @@
// standard namespaces, plus namespaces for "obo" and this ontology
// file's namespace
RDFFormatter formatter = newRDFFormatter();
- if (date != null) {
- formatter.addNamespace("dc", "http://purl.org/dc/elements/1.1/");
- }
// Write the header out in a standard format
formatter.writeHeader(out);
-
- // If dc:date and dc:creator are used in the ontology, they must first
- // be declared to be annotation properties (see OWL reference manual)
- out.println();
- if (date != null) {
- out.println(" <owl:AnnotationProperty rdf:about=\"&dc;date\"/>");
- }
out.println();
// Write out the Ontology header, as well as version information, date,
@@ -219,16 +209,6 @@
out.println(" <owl:Ontology rdf:about=\"&" + namespacePrefix + ";owlOntology\">");
out.println();
- if (version != null) {
- out.println(" <owl:versionInfo>" + xmlSafeString(version) + "</owl:versionInfo>");
- if (date == null) {
- out.println();
- }
- }
- if (date != null) {
- out.println(" <dc:date>" + xmlSafeString(date) + "</dc:date>");
- out.println();
- }
for (Iterator it = classURIs.iterator(); it.hasNext();) {
String uri = it.next().toString();
out.println(" <owl:imports rdf:resource=\"&" + uri + "\"/>");
@@ -262,6 +242,10 @@
// Write the RDF header out in standard format
formatter.writeRDFHeader(out);
out.println();
+ out.println(" <owl:Ontology rdf:about=\"\">");
+ out.println(" <owl:imports rdf:resource=\"&" + namespacePrefix + ";owlOntology\"/>");
+ out.println(" </owl:Ontology>");
+ out.println();
// Write the term as an OWL class with associated annotation properties
out.println(" <owl:Class rdf:about=\"&" + term.getURI() + "\">");
@@ -275,13 +259,14 @@
formatter.writeWrapped(out, term.classDef, 12, null);
out.println();
out.println(" </obo:classDef>");
- out.println();
+ out.println();
}
if (term.classComment != null) {
out.println(" <obo:classComment>");
formatter.writeWrapped(out, term.classComment, 12, null);
out.println();
out.println(" </obo:classComment>");
+ out.println();
}
if (term.classIsObsolete != null) {
out.println(" <obo:classIsObsolete>" + term.classIsObsolete + "</obo:classIsObsolete>");
@@ -290,20 +275,19 @@
Iterator it = term.supers.iterator();
if (it.hasNext()) {
while (it.hasNext()) {
- String className = it.next().toString();
- out.println(" <rdfs:subClassOf rdf:resource=\"&" +
- namespacePrefix + ";" +
- className.replaceAll(":", "_") + "\"/>");
+ String className = (it.next().toString()).replaceAll(":", "_");
+ out.println(" <rdfs:subClassOf>");
+ out.println(" <owl:Class rdf:about=\"&" + namespacePrefix + ";" + className + "\"/>");
+ out.println(" </rdfs:subClassOf>");
}
out.println();
}
else {
- out.println(" <rdfs:subClassOf rdf:resource=\"&obo;Term\"/>");
+ out.println(" <rdfs:subClassOf>");
+ out.println(" <owl:Class rdf:about=\"&obo;Term\"/>");
+ out.println(" </rdfs:subClassOf>");
out.println();
}
- out.println(" <rdf:type rdf:resource=\"&owl;Ontology\"/>");
- out.println(" <owl:imports rdf:resource=\"&" + namespacePrefix + ";owlOntology\"/>");
- out.println(" <owl:imports rdf:resource=\"&obo;owlOntology\"/>");
out.println();
out.println(" </owl:Class>");
out.println();
===================================================================
RCS file: /home/repository/moby/s-moby/ontologies/src/java/org/semanticmoby/ontologies/util/OBOFileIndividualCreator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
===================================================================
RCS file: /home/repository/moby/s-moby/ontologies/src/java/org/semanticmoby/ontologies/util/OwlFileSplitter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/s-moby/ontologies/src/java/org/semanticmoby/ontologies/util/OwlFileSplitter.java 2007/01/15 23:13:23 1.3
+++ /home/repository/moby/s-moby/ontologies/src/java/org/semanticmoby/ontologies/util/OwlFileSplitter.java 2007/03/27 15:25:28 1.4
@@ -33,6 +33,11 @@
private Resource ontologyResource = null;
/**
+ * A resource referring to the base URI
+ */
+ private Resource baseURIResource = null;
+
+ /**
* The Jena model from which the components to be written are read
*/
private Model source = null;
@@ -52,18 +57,15 @@
this.contentWriter = writer;
this.contentFile = saveContents(in, inputName, writer);
- File owldocDir = new File(contentWriter.getContentDirectory(), "owldoc");
- owldocDir.mkdir();
-
- this.owldocWriter = new OwlDocWriter(contentFile, owldocDir);
-
try {
// Read the OWL file as a Jena2 Model object and replace hashes
// with slashes among the resources in the model
FileInputStream fileIn = new FileInputStream(contentFile);
this.source = ModelFactory.createDefaultModel();
source.read(fileIn, "");
- replaceHashesWithSlashes();
+ this.source = replaceHashesWithSlashes();
+ this.baseURIResource = ResourceFactory.createResource(
+ source.getNsPrefixURI(""));
} catch (Throwable t) {
IOException e = new IOException(
"Specified OWL file could not be parsed:");
@@ -157,13 +159,18 @@
* @throws IOException if any of these files could not be written
*/
public void process() throws Exception {
+
+// File owldocDir = new File(contentWriter.getContentDirectory(), "owldoc");
+// owldocDir.mkdir();
+// this.owldocWriter = new OwlDocWriter(contentFile, owldocDir);
+
writeContentFile();
writeOntologyFile();
writeFilesFor(OWL.Class);
writeFilesFor(OWL.DatatypeProperty);
writeFilesFor(OWL.ObjectProperty);
- owldocWriter.write();
- writeOwldocFiles();
+// owldocWriter.write();
+// writeOwldocFiles();
contentWriter.close();
}
@@ -174,39 +181,37 @@
* base-uri/name), and updates statements whose subjects or objects point
* at them to point at the replacement resources
*/
- private void replaceHashesWithSlashes() {
+ private Model replaceHashesWithSlashes() {
+
+ // A new model to return
+ Model newModel = ModelFactory.createDefaultModel();
+ newModel.setNsPrefixes(source.getNsPrefixMap());
// Collect all the non-blank resources that are declared to be of
// rdf:type owl:Class, owl:DatatypeProperty, or owl:ObjectProperty
List allResources = classesAndProperties(source);
- // Look at all the resources, and for those that have hashes,
- // create a replacement that has the hash changed to a slash
+ // Create a replacement for each resource, replacing a hash with a slash
Map newResources = new HashMap();
for (Iterator it = allResources.iterator(); it.hasNext();) {
Resource currentResource = (Resource) it.next();
String uri = currentResource.getURI();
- if (uri.indexOf('#') > -1) {
- newResources.put(
- currentResource,
- ResourceFactory.createResource(
- uri.replaceFirst("#", "/")));
- }
+ newResources.put(
+ currentResource,
+ ResourceFactory.createResource(
+ uri.indexOf('#') > -1
+ ? uri.replaceFirst("#", "/")
+ : uri));
}
- // Statements to remove (because their subjects need to be changed)
- // or add (because they replace the ones that need removing). These
- // are collected since it's unwise to modify the model while iterating
- // over its statements
- Model toRemove = ModelFactory.createDefaultModel();
- Model toAdd = ModelFactory.createDefaultModel();
-
- // Check each statement in the model to see if its subject
- // or object points to a resource that has a replacement
+ // Create a replacement statement for each one in the model,
+ // nd add the new statement to the new model
for (StmtIterator it = source.listStatements(); it.hasNext();) {
Statement stmt = it.nextStatement();
+
Resource subj = stmt.getSubject();
+ Property pred = stmt.getPredicate();
RDFNode obj = stmt.getObject();
// Check to see if there is a replacement resource for the
@@ -214,30 +219,15 @@
Resource newSubj = (Resource) newResources.get(subj);
Resource newObj = (Resource) newResources.get(obj);
- if (newSubj != null) {
- // The subject of a statement can't be changed, so a new
- // statement must be created and the old one marked for
- // removal. Note that the object of the statement could
- // also be in need of replacement, hence the check for
- // newObj
- toRemove.add(stmt);
- toAdd.add(
- source.createStatement(
- newSubj,
- stmt.getPredicate(),
- newObj == null ? obj : newObj));
-
- } else if (newObj != null) {
- // The object of a statement can be changed. Since we don't
- // need to add or remove any statements, it's safe to do it
- // right here in the loop
- stmt.changeObject(newObj);
- }
+ Statement newStmt = newModel.createStatement(
+ ((newSubj == null) ? subj : newSubj),
+ pred,
+ ((newObj == null) ? obj : newObj));
+
+ newModel.add(newStmt);
}
-
- // Remove the statements marked for removal and add their replacements
- source.remove(toRemove);
- source.add(toAdd);
+
+ return newModel;
}
/**
@@ -256,12 +246,12 @@
*/
private void writeOntologyFile() throws IOException {
- // Find the statement, if any, that says that some URI
- // is of rdf:type owl:Ontology.
+ // Find the statement, if any, that says that some URI
+ // is of rdf:type owl:Ontology.
StmtIterator it = source.listStatements(null, RDF.type, OWL.Ontology);
- if (! it.hasNext()) return;
-
- String uri = it.nextStatement().getSubject().getURI();
+ if (! it.hasNext()) return;
+
+ String uri = it.nextStatement().getSubject().getURI();
// The base URI of all elements will be the above URI with a
// trailing forward slash (if it doesn't already have one)
@@ -351,14 +341,12 @@
source, head, null, visited);
reachable.setNsPrefixes(source.getNsPrefixMap());
- // Assert that the resource is itself an ontology
- reachable.add(reachable.createStatement(
- head, RDF.type, OWL.Ontology));
-
// Import the owlOntology "master ontology"
if (ontologyResource != null) {
reachable.add(reachable.createStatement(
- head, OWL.imports, ontologyResource));
+ baseURIResource, RDF.type, OWL.Ontology));
+ reachable.add(reachable.createStatement(
+ baseURIResource, OWL.imports, ontologyResource));
}
reachable.write(contentWriter.outputStreamFor(elementName));
}
More information about the MOBY-guts
mailing list