make exporting work
This commit is contained in:
parent
6234a89bbb
commit
d51ed8d2f2
12 changed files with 134 additions and 63 deletions
|
@ -1,5 +1,7 @@
|
||||||
package de.unibremen.informatik.hets.model;
|
package de.unibremen.informatik.hets.model;
|
||||||
|
|
||||||
|
import org.semanticweb.owlapi.model.OWLOntologyManager;
|
||||||
|
|
||||||
public class Actuals extends Spec {
|
public class Actuals extends Spec {
|
||||||
public Actuals(String cont, String anno) {
|
public Actuals(String cont, String anno) {
|
||||||
super(cont, anno);
|
super(cont, anno);
|
||||||
|
@ -9,6 +11,10 @@ public class Actuals extends Spec {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString(OWLOntologyManager ontologymanager) {
|
||||||
|
return content + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return content + "\n";
|
return content + "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,25 +3,37 @@ package de.unibremen.informatik.hets.model;
|
||||||
import de.unibremen.informatik.owl.OWLUtils;
|
import de.unibremen.informatik.owl.OWLUtils;
|
||||||
|
|
||||||
import org.semanticweb.owlapi.model.OWLOntology;
|
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;
|
import org.protege.editor.owl.model.OWLModelManager;
|
||||||
|
|
||||||
public class Basicspec extends Spec {
|
public class Basicspec extends Spec {
|
||||||
OWLOntology ontology;
|
String ontname;
|
||||||
|
|
||||||
public Basicspec(String cont, String anno) {
|
public Basicspec(String cont, String anno) {
|
||||||
super(cont, anno);
|
super(cont, anno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OWLOntology getOntology() {
|
public String getOntologyName() {
|
||||||
return ontology;
|
return ontname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayOntology(OWLModelManager owlmodelmanager, String iri) {
|
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) {
|
public void displayOntology(OWLModelManager owlmodelmanager, String iri, String parent_iri) {
|
||||||
ontology = OWLUtils.displayOntology(owlmodelmanager, content, parent_ont, iri, 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.semanticweb.owlapi.model.OWLOntology;
|
import org.semanticweb.owlapi.model.OWLOntology;
|
||||||
|
import org.semanticweb.owlapi.model.OWLOntologyManager;
|
||||||
|
|
||||||
import org.protege.editor.owl.model.OWLModelManager;
|
import org.protege.editor.owl.model.OWLModelManager;
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ public class HetFile {
|
||||||
specdefns.add(specdefn);
|
specdefns.add(specdefn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString(OWLOntologyManager ontologymanager) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append("library ");
|
builder.append("library ");
|
||||||
|
@ -38,24 +39,16 @@ public class HetFile {
|
||||||
builder.append("\n\n");
|
builder.append("\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(specdefn.toString());
|
builder.append(specdefn.toString(ontologymanager));
|
||||||
builder.append("\n");
|
builder.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.toString();
|
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) {
|
public void displayOntologies(OWLModelManager manager) {
|
||||||
// TODO: this yet only supports basicspec and simple extension blocks
|
// TODO: this yet only supports basicspec and simple extension blocks
|
||||||
|
// needs heavy fixing..
|
||||||
|
|
||||||
for (SpecDefn specdefn : specdefns) {
|
for (SpecDefn specdefn : specdefns) {
|
||||||
if (specdefn.getLogic().equals("OWL")) {
|
if (specdefn.getLogic().equals("OWL")) {
|
||||||
|
@ -67,7 +60,7 @@ public class HetFile {
|
||||||
Spec spec = it.next();
|
Spec spec = it.next();
|
||||||
if (spec instanceof Basicspec) {
|
if (spec instanceof Basicspec) {
|
||||||
if (parent_iri != "") {
|
if (parent_iri != "") {
|
||||||
((Basicspec)spec).displayOntology(manager, specdefn.getName(), getOntologyByName(parent_iri), parent_iri);
|
((Basicspec)spec).displayOntology(manager, specdefn.getName(), parent_iri);
|
||||||
} else {
|
} else {
|
||||||
((Basicspec)spec).displayOntology(manager, specdefn.getName());
|
((Basicspec)spec).displayOntology(manager, specdefn.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package de.unibremen.informatik.hets.model;
|
package de.unibremen.informatik.hets.model;
|
||||||
|
|
||||||
|
import org.semanticweb.owlapi.model.OWLOntologyManager;
|
||||||
|
|
||||||
public class Spec {
|
public class Spec {
|
||||||
protected String annotation;
|
protected String annotation;
|
||||||
protected String content;
|
protected String content;
|
||||||
|
@ -19,7 +21,7 @@ public class Spec {
|
||||||
annotation = null;
|
annotation = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString(OWLOntologyManager ontologymanager) {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.semanticweb.owlapi.model.OWLOntology;
|
import org.semanticweb.owlapi.model.OWLOntology;
|
||||||
|
import org.semanticweb.owlapi.model.OWLOntologyManager;
|
||||||
|
|
||||||
public class SpecDefn {
|
public class SpecDefn {
|
||||||
private ArrayList<Spec> specs;
|
private ArrayList<Spec> specs;
|
||||||
|
@ -34,17 +35,7 @@ public class SpecDefn {
|
||||||
return specs.iterator();
|
return specs.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
// just return the first Basicspec for now
|
public String toString(OWLOntologyManager ontologymanager) {
|
||||||
public OWLOntology getOntology() {
|
|
||||||
for (Spec spec : specs) {
|
|
||||||
if (spec instanceof Basicspec) {
|
|
||||||
return ((Basicspec)spec).getOntology();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
if (annotation != null && annotation != "") {
|
if (annotation != null && annotation != "") {
|
||||||
|
@ -68,7 +59,13 @@ public class SpecDefn {
|
||||||
if (!(spec instanceof Union)) {
|
if (!(spec instanceof Union)) {
|
||||||
builder.append("\n");
|
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()) {
|
if (it.hasNext()) {
|
||||||
builder.append("then");
|
builder.append("then");
|
||||||
|
|
|
@ -3,6 +3,8 @@ package de.unibremen.informatik.hets.model;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.semanticweb.owlapi.model.OWLOntologyManager;
|
||||||
|
|
||||||
public class Union extends Spec {
|
public class Union extends Spec {
|
||||||
private ArrayList<Spec> specs;
|
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();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
Iterator<Spec> it = specs.iterator();
|
Iterator<Spec> it = specs.iterator();
|
||||||
|
|
|
@ -83,8 +83,10 @@ public class CGIImportHetsAction extends ProtegeOWLAction {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(hetfile.toString());
|
//System.out.println(hetfile.toString());
|
||||||
|
|
||||||
hetfile.displayOntologies(this.getOWLModelManager());
|
hetfile.displayOntologies(this.getOWLModelManager());
|
||||||
|
|
||||||
|
ImportedHetFile.setHetFile(hetfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.semanticweb.owlapi.io.StreamDocumentTarget;
|
||||||
import org.semanticweb.owlapi.model.OWLOntology;
|
import org.semanticweb.owlapi.model.OWLOntology;
|
||||||
|
|
||||||
import de.unibremen.informatik.hets.protege.ImportHetsAction;
|
import de.unibremen.informatik.hets.protege.ImportHetsAction;
|
||||||
|
import de.unibremen.informatik.hets.model.HetFile;
|
||||||
import org.semanticweb.owlapi.model.IRI;
|
import org.semanticweb.owlapi.model.IRI;
|
||||||
|
|
||||||
public class ExportHetsAction extends ProtegeOWLAction {
|
public class ExportHetsAction extends ProtegeOWLAction {
|
||||||
|
@ -42,27 +43,6 @@ public class ExportHetsAction extends ProtegeOWLAction {
|
||||||
// TODO Auto-generated method stub
|
// 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
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
/*
|
/*
|
||||||
|
@ -81,6 +61,7 @@ public class ExportHetsAction extends ProtegeOWLAction {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
Set<String> exts = new HashSet<String>();
|
Set<String> exts = new HashSet<String>();
|
||||||
exts.add("het");
|
exts.add("het");
|
||||||
exts.add("owl");
|
exts.add("owl");
|
||||||
|
@ -103,5 +84,26 @@ public class ExportHetsAction extends ProtegeOWLAction {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e1.printStackTrace();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
package de.unibremen.informatik.hets.protege;
|
package de.unibremen.informatik.hets.protege;
|
||||||
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.protege.editor.owl.ui.view.ontology.AbstractOntologyRenderingViewComponent;
|
import org.protege.editor.owl.ui.view.ontology.AbstractOntologyRenderingViewComponent;
|
||||||
import org.semanticweb.owlapi.model.OWLOntology;
|
import org.semanticweb.owlapi.model.OWLOntology;
|
||||||
|
import org.semanticweb.owlapi.io.OWLRendererException;
|
||||||
|
|
||||||
import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxRenderer;
|
import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxRenderer;
|
||||||
|
|
||||||
|
@ -15,10 +17,15 @@ public class HetCASLRenderingViewComponent extends AbstractOntologyRenderingView
|
||||||
private static final long serialVersionUID = 3845613418666267771L;
|
private static final long serialVersionUID = 3845613418666267771L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderOntology(OWLOntology ontology, Writer writer) throws Exception {
|
protected void renderOntology(OWLOntology ontology, Writer writer) {
|
||||||
// TODO Auto-generated method stub
|
try {
|
||||||
ManchesterOWLSyntaxRenderer ren = new ManchesterOWLSyntaxRenderer(getOWLModelManager().getOWLOntologyManager());
|
ManchesterOWLSyntaxRenderer ren = new ManchesterOWLSyntaxRenderer(getOWLModelManager().getOWLOntologyManager());
|
||||||
ren.render(ontology, writer);
|
ren.render(ontology, writer);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
} catch (OWLRendererException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -64,11 +64,13 @@ public class OWLUtils {
|
||||||
return ont;
|
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();
|
OWLOntologyManager manager = owlmodelmanager.getOWLOntologyManager();
|
||||||
|
|
||||||
manager.addOntologyStorer(new HetCASLOntologyStorer());
|
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);
|
System.out.println(parent_ont + ", " + parent_iri + ", " + iri);
|
||||||
if (parent_ont != null && parent_iri != "" && parent_iri != iri) {
|
if (parent_ont != null && parent_iri != "" && parent_iri != iri) {
|
||||||
OWLOntologyManager tempmanager = OWLManager.createOWLOntologyManager();
|
OWLOntologyManager tempmanager = OWLManager.createOWLOntologyManager();
|
||||||
|
@ -125,4 +127,28 @@ public class OWLUtils {
|
||||||
|
|
||||||
return ontology1;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue