OWLATermObjectRenderer.java revision 75a666ae9c75f3c3d836e6a7874f99e9199a304d
import aterm.*;
/**
* Author: Heng Jiang <br>
* The University Of Bremen <br>
* Date: 10-2007 <br><br>
*/
public class OWLATermObjectRenderer implements OWLObjectVisitor {
private OWLOntologyXMLNamespaceManager nsm;
private OWLOntology ontology;
int lastNewLinePos;
private boolean writeEntitiesAsIRIs;
private boolean isEntity;
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
"y", "z" };
// ATermFactory factory = new PureFactory();
private ATermList declarationsList;
private ATermList annotationsList;
private ATermList annotationAxiomsList;
public OWLATermObjectRenderer(OWLOntology ontology, Writer writer, OWLOntologyManager owlOntologyManager) {
writeEntitiesAsIRIs = false;
isEntity = false;
// namespaceMap.put(ontology.getURI().toString() + "#", "");
// namespaceMap.put(Namespaces.OWL.toString(), "owl");
// namespaceMap.put(Namespaces.RDFS.toString(), "rdfs");
// namespaceMap.put(Namespaces.RDF.toString(), "rdf");
// namespaceMap.put(Namespaces.XSD.toString(), "xsd");
// namespaceMap.put(nsm.getDefaultNamespace(), "a");
{
{
continue;
}
}
}
writeEntitiesAsIRIs = false;
isEntity = false;
// namespaceMap.put(ontology.getURI().toString() + "#", "");
// namespaceMap.put(Namespaces.OWL.toString(), "owl");
// namespaceMap.put(Namespaces.RDFS.toString(), "rdfs");
// namespaceMap.put(Namespaces.RDF.toString(), "rdf");
// namespaceMap.put(Namespaces.XSD.toString(), "xsd");
// namespaceMap.put(nsm.getDefaultNamespace(), "a");
{
{
continue;
}
}
}
}
{
{
}
else
{
}
}
private ATermAppl renderNamespaces() {
int index =0;
continue;
}
}
}
}
// Done in-line?
}
{
}
// private AFun getFuncFromVocabulary(OWLDatatypeRestriction v, int number)
// {
// // getShortName() - problem
// return af.factory.makeAFun(v.getDatatype(), number, true);
//}
{
// getShortName() - problem
}
int index = 0;
}else{
}
return strToATermAppl(result.append(iriString.substring(ns.length(), iriString.length())).toString());
}
}
}
int index = 0;
}else{
}
return strToATermAppl(result.append(iriString.substring(ns.length(), iriString.length())).toString());
}
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
{
ATermAppl ontoUri = strToATermAppl("<" + manager.getOntologyDocumentIRI(ontology).toString() + ">");
//Ontology annotations are now stored directly in an ontology and not as axioms in an ontology
}
// NO LONGER AN AXIOM IN OWL 2.0
// for (OWLImportsDeclaration decl : ontology.getImportsDeclarations()) {
// importsList = af.factory.makeList(term(decl), importsList);
//}
}
}
}
}
}
}
}
}
}
/* for (OWLSubPropertyChainOfAxiom ax : ontology.getPropertyChain()) {
propAxiomList = af.factory.makeList(term(ax), propAxiomList);
}*/
return af.factory.makeAppl(af.ontologyFunc, ontoUri, importsList, annoList, declarationsList.concat(classAxiomList.reverse().concat(propAxiomList.reverse().concat(individualList.reverse().concat(annotationAxiomsList)))));
}
{
}
}
}
{
}
}
{
}
{
}
}
{
}
}
try{
if (annotation.isLabel()) {
}
else if (annotation.isComment()) {
}
else {
}
}catch(OWLException e)
{
e.printStackTrace();
}
}
/* public void visit(OWLAnnotationObject annotation) {
try{
this.writeEntitiesAsIRIs = true;
ATerm annoValue = term(annotation);
this.writeEntitiesAsIRIs = false;
annoVV = af.factory.makeAppl(af.UntypedConstantFunc, annoValue);
ATermAppl annoIri = renderIri(annotation.getValue());
term = af.factory.makeAppl(af. explicitAnnoFunc, annoIri, annoVV);
}catch(OWLException e)
{
System.err.println("error by make term of annotation value: " + annotation);
e.printStackTrace();
}
}
*/
try{
}catch(OWLException e){
e.printStackTrace();
}
}
// public void visit(OWLAnnotationAxiom axiom) {
// done inline
//}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs =false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs =false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
// No longer an axiom on OWL 2.0
// public void visit(OWLImportsDeclaration axiom) {
// ATermList annoOfAxiom = renderAnnotations(axiom);
// ATermAppl uri =
// term = renderIri(axiom.getImportedOntologyURI());;
// }
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
term = af.factory.makeAppl(af.subObjPropOfFunc, annoOfAxiom, af.factory.makeAppl(af.objPropExpressionFunc, sub), sup);
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
if(!writeEntitiesAsIRIs) {
}else{
}
}
private ATermAppl renderRestriction(OWLXMLVocabulary v, OWLCardinalityRestriction restriction) throws OWLException{
this.writeEntitiesAsIRIs = true;
}
this.writeEntitiesAsIRIs = false;
if(restriction.isQualified()){
}else{
}
}
private ATermAppl renderRestriction(OWLXMLVocabulary v, OWLQuantifiedRestriction restriction) throws OWLException{
}
private ATermAppl renderRestriction(OWLXMLVocabulary v, OWLPropertyExpression propE, OWLObject filler) throws OWLException{
this.writeEntitiesAsIRIs = false;
}
try{
}catch(OWLException e){
e.printStackTrace();
}
}
private ATermAppl renderRestriction(OWLXMLVocabulary v, OWLQuantifiedRestriction restriction, List l) throws OWLException{
// return renderRestriction(v, restriction.getProperty(), restriction.getFiller());
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
this.writeEntitiesAsIRIs = false;
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
// if(filler instanceof OWLIndividual) this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
this.writeEntitiesAsIRIs = true;
this.writeEntitiesAsIRIs = false;
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
}
try{
}
}catch(OWLException e)
{
e.printStackTrace();
}
}
try{
}catch(OWLException e)
{
e.printStackTrace();
}
}
/* public void visit(OWLTypedConstant node) {
String lit = modSpecialCodes(node.getLiteral());
URI uri = node.getDatatype().getURI();
String pa = this.reverseLookUp(uri);
term = af.factory.makeAppl(af.typedConstantFunc, af.factory.parse("\"" + lit + "^^" + pa + "\""));
}
*/
}
}
}
/* public void visit(OWLUntypedConstant node) {
String lang = "";
if(node.hasLang()){
lang = "@" + node.getLang();
}
String cons = modSpecialCodes(node.getLiteral()) + lang;
term = af.factory.makeAppl(af.UntypedConstantFunc, af.factory.parse("\"" + cons + "\""));
}
*/
if (!writeEntitiesAsIRIs) {
}else{
}
}
if (!writeEntitiesAsIRIs) {
if(isEntity){
term = af.factory.makeAppl(af.factory.makeAFun("ObjectProperty", 1, false), renderIri(property.getIRI()));
} else {
}
}else{
}
/*
AFun func = this.getFuncFromVocabulary(OBJECT_PROPERTY, 1);
if (!writeEnitiesAsURIs) {
term = af.factory.makeAppl(func, renderIri(property.getIRI()));
}else{
term = renderIri(property.getIRI());
}*/
}
try{
// AFun func = getFuncFromVocabulary(INVERSE_OBJECT_PROPERTY, 1);
}catch(OWLException e)
{
e.printStackTrace();
}
}
if (!writeEntitiesAsIRIs || isEntity) {
}else{
}
}
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
throw new RuntimeException("NOT IMPLEMENTED!");
}
/*
public void visit(SWRLSameAsAtom node) {
throw new RuntimeException("NOT IMPLEMENTED!");
}
*/
}
reset();
d.accept(this);
if(a == null) {
throw new OWLOntologyStorageException("Cannot create ATerm from description " + d);
}
return a;
}
private void reset()
{
}
{
return this.term;
}
}