make exporting work

This commit is contained in:
josch 2011-02-15 00:26:52 +01:00
parent 6234a89bbb
commit d51ed8d2f2
12 changed files with 134 additions and 63 deletions

View file

@ -1,5 +1,7 @@
package de.unibremen.informatik.hets.model;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class Actuals extends Spec {
public Actuals(String cont, String anno) {
super(cont, anno);
@ -9,6 +11,10 @@ public class Actuals extends Spec {
return content;
}
public String toString(OWLOntologyManager ontologymanager) {
return content + "\n";
}
public String toString() {
return content + "\n";
}

View file

@ -3,25 +3,37 @@ package de.unibremen.informatik.hets.model;
import de.unibremen.informatik.owl.OWLUtils;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.IRI;
import org.protege.editor.owl.model.OWLModelManager;
public class Basicspec extends Spec {
OWLOntology ontology;
String ontname;
public Basicspec(String cont, String anno) {
super(cont, anno);
}
public OWLOntology getOntology() {
return ontology;
public String getOntologyName() {
return ontname;
}
public void displayOntology(OWLModelManager owlmodelmanager, String iri) {
ontology = OWLUtils.displayOntology(owlmodelmanager, content, iri);
OWLUtils.displayOntology(owlmodelmanager, content, iri);
ontname = iri;
}
public void displayOntology(OWLModelManager owlmodelmanager, String iri, OWLOntology parent_ont, String parent_iri) {
ontology = OWLUtils.displayOntology(owlmodelmanager, content, parent_ont, iri, parent_iri);
public void displayOntology(OWLModelManager owlmodelmanager, String iri, String parent_iri) {
OWLUtils.displayOntology(owlmodelmanager, content, iri, parent_iri);
ontname = iri;
}
public String toString(OWLOntologyManager ontologymanager) {
return OWLUtils.dumpOntologyToString(ontologymanager, ontname);
}
public String toString() {
return content;
}
}

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.protege.editor.owl.model.OWLModelManager;
@ -20,7 +21,7 @@ public class HetFile {
specdefns.add(specdefn);
}
public String toString() {
public String toString(OWLOntologyManager ontologymanager) {
StringBuilder builder = new StringBuilder();
builder.append("library ");
@ -38,24 +39,16 @@ public class HetFile {
builder.append("\n\n");
}
builder.append(specdefn.toString());
builder.append(specdefn.toString(ontologymanager));
builder.append("\n");
}
return builder.toString();
}
public OWLOntology getOntologyByName(String name) {
for (SpecDefn specdefn : specdefns) {
if (specdefn.getLogic().equals("OWL") && specdefn.getName().equals(name)) {
return specdefn.getOntology();
}
}
return null;
}
public void displayOntologies(OWLModelManager manager) {
// TODO: this yet only supports basicspec and simple extension blocks
// needs heavy fixing..
for (SpecDefn specdefn : specdefns) {
if (specdefn.getLogic().equals("OWL")) {
@ -67,7 +60,7 @@ public class HetFile {
Spec spec = it.next();
if (spec instanceof Basicspec) {
if (parent_iri != "") {
((Basicspec)spec).displayOntology(manager, specdefn.getName(), getOntologyByName(parent_iri), parent_iri);
((Basicspec)spec).displayOntology(manager, specdefn.getName(), parent_iri);
} else {
((Basicspec)spec).displayOntology(manager, specdefn.getName());
}

View file

@ -1,5 +1,7 @@
package de.unibremen.informatik.hets.model;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class Spec {
protected String annotation;
protected String content;
@ -19,7 +21,7 @@ public class Spec {
annotation = null;
}
public String toString() {
public String toString(OWLOntologyManager ontologymanager) {
return content;
}

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class SpecDefn {
private ArrayList<Spec> specs;
@ -34,17 +35,7 @@ public class SpecDefn {
return specs.iterator();
}
// just return the first Basicspec for now
public OWLOntology getOntology() {
for (Spec spec : specs) {
if (spec instanceof Basicspec) {
return ((Basicspec)spec).getOntology();
}
}
return null;
}
public String toString() {
public String toString(OWLOntologyManager ontologymanager) {
StringBuilder builder = new StringBuilder();
if (annotation != null && annotation != "") {
@ -68,7 +59,13 @@ public class SpecDefn {
if (!(spec instanceof Union)) {
builder.append("\n");
}
builder.append(spec.toString());
// only use the manchester renderer on OWL basicspecs
if (logic.equals("OWL")) {
builder.append(spec.toString(ontologymanager));
} else {
builder.append(spec.toString());
}
if (it.hasNext()) {
builder.append("then");

View file

@ -3,6 +3,8 @@ package de.unibremen.informatik.hets.model;
import java.util.ArrayList;
import java.util.Iterator;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class Union extends Spec {
private ArrayList<Spec> specs;
@ -18,7 +20,7 @@ public class Union extends Spec {
}
}
public String toString() {
public String toString(OWLOntologyManager ontologymanager) {
StringBuilder builder = new StringBuilder();
Iterator<Spec> it = specs.iterator();

View file

@ -83,8 +83,10 @@ public class CGIImportHetsAction extends ProtegeOWLAction {
e.printStackTrace();
}
System.out.println(hetfile.toString());
//System.out.println(hetfile.toString());
hetfile.displayOntologies(this.getOWLModelManager());
ImportedHetFile.setHetFile(hetfile);
}
}

View file

@ -18,6 +18,7 @@ import org.semanticweb.owlapi.io.StreamDocumentTarget;
import org.semanticweb.owlapi.model.OWLOntology;
import de.unibremen.informatik.hets.protege.ImportHetsAction;
import de.unibremen.informatik.hets.model.HetFile;
import org.semanticweb.owlapi.model.IRI;
public class ExportHetsAction extends ProtegeOWLAction {
@ -42,27 +43,6 @@ public class ExportHetsAction extends ProtegeOWLAction {
// TODO Auto-generated method stub
}
String dumpOntologyToString(String name) {
String result;
OWLOntologyManager ontologymanager = this.getOWLModelManager().getOWLOntologyManager();
ByteArrayOutputStream outputstream = new ByteArrayOutputStream();
try {
ontologymanager.saveOntology(ontologymanager.getOntology(IRI.create("http://informatik.uni-bremen.de/hets/"+name+".het")), outputstream);
} catch (OWLOntologyStorageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
result = outputstream.toString();
result = result.replaceAll("(?m)^Prefix: .*$", "");
result = result.replaceAll("(?m)^Ontology: .*$", "");
result = result.replaceAll("(?m)^Import: .*$", "");
result = result.replaceAll("(?m)^\\s*$[\n\r]{1,}", "");
result = result.replaceAll("(?m)(^.*$)", " $1");
return result;
}
@Override
public void actionPerformed(ActionEvent e) {
/*
@ -81,6 +61,7 @@ public class ExportHetsAction extends ProtegeOWLAction {
}*/
/*
Set<String> exts = new HashSet<String>();
exts.add("het");
exts.add("owl");
@ -103,5 +84,26 @@ public class ExportHetsAction extends ProtegeOWLAction {
// TODO Auto-generated catch block
e1.printStackTrace();
}
*/
HetFile hetfile = ImportedHetFile.getHetFile();
Set<String> exts = new HashSet<String>();
exts.add("het");
exts.add("owl");
File f = UIUtil.saveFile(this.getOWLWorkspace(), "title", "description", exts, "foobar.het");
if (f.exists()) {
// TODO: ask if overwrite
f.delete();
}
try {
FileOutputStream outputFile = new FileOutputStream(f, true);
outputFile.write(hetfile.toString(this.getOWLModelManager().getOWLOntologyManager()).getBytes());
outputFile.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}

View file

@ -1,9 +1,11 @@
package de.unibremen.informatik.hets.protege;
import java.io.Writer;
import java.io.IOException;
import org.protege.editor.owl.ui.view.ontology.AbstractOntologyRenderingViewComponent;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.io.OWLRendererException;
import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxRenderer;
@ -15,10 +17,15 @@ public class HetCASLRenderingViewComponent extends AbstractOntologyRenderingView
private static final long serialVersionUID = 3845613418666267771L;
@Override
protected void renderOntology(OWLOntology ontology, Writer writer) throws Exception {
// TODO Auto-generated method stub
ManchesterOWLSyntaxRenderer ren = new ManchesterOWLSyntaxRenderer(getOWLModelManager().getOWLOntologyManager());
ren.render(ontology, writer);
writer.flush();
protected void renderOntology(OWLOntology ontology, Writer writer) {
try {
ManchesterOWLSyntaxRenderer ren = new ManchesterOWLSyntaxRenderer(getOWLModelManager().getOWLOntologyManager());
ren.render(ontology, writer);
writer.flush();
} catch (OWLRendererException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,22 @@
package de.unibremen.informatik.hets.protege;
import de.unibremen.informatik.hets.model.HetFile;
public class ImportedHetFile {
static HetFile hetfile;
static {
}
public ImportedHetFile() {
super();
}
public static void setHetFile(HetFile hf) {
hetfile = hf;
}
public static HetFile getHetFile() {
return hetfile;
}
}

View file

@ -64,11 +64,13 @@ public class OWLUtils {
return ont;
}
public static OWLOntology displayOntology(OWLModelManager owlmodelmanager, String ont_string, OWLOntology parent_ont, String iri, String parent_iri) {
public static OWLOntology displayOntology(OWLModelManager owlmodelmanager, String ont_string, String iri, String parent_iri) {
OWLOntologyManager manager = owlmodelmanager.getOWLOntologyManager();
manager.addOntologyStorer(new HetCASLOntologyStorer());
OWLOntology parent_ont = manager.getOntology(IRI.create("http://informatik.uni-bremen.de/hets/"+parent_iri+".het"));
System.out.println(parent_ont + ", " + parent_iri + ", " + iri);
if (parent_ont != null && parent_iri != "" && parent_iri != iri) {
OWLOntologyManager tempmanager = OWLManager.createOWLOntologyManager();
@ -125,4 +127,28 @@ public class OWLUtils {
return ontology1;
}
public static String dumpOntologyToString(OWLOntologyManager ontologymanager, String ontname) {
String result;
OWLOntology ont = ontologymanager.getOntology(IRI.create("http://informatik.uni-bremen.de/hets/"+ontname+".het"));
System.out.println("ontology: " + ont);
ByteArrayOutputStream outputstream = new ByteArrayOutputStream();
try {
ontologymanager.saveOntology(ont, outputstream);
} catch (OWLOntologyStorageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
result = outputstream.toString();
result = result.replaceAll("(?m)^Prefix: .*$", "");
result = result.replaceAll("(?m)^Ontology: .*$", "");
result = result.replaceAll("(?m)^Import: .*$", "");
result = result.replaceAll("(?m)^\\s*$[\n\r]{1,}", "");
result = result.replaceAll("(?m)(^.*$)", " $1");
return result;
}
}