abstractsyntaxentityrenderer.java

来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,981 行 · 第 1/5 页

JAVA
1,981
字号
			}			pw.print(")");		}		public void visit( OWLSubPropertyAxiom axiom ) throws OWLException {			pw.print("SubPropertyOf(");			axiom.getSubProperty().accept( this );			pw.print(" ");			axiom.getSuperProperty().accept( this );			pw.print(")");		}		public void visit( OWLDifferentIndividualsAxiom ax) throws OWLException {			pw.print("DifferentIndividuals(");			for ( Iterator it = ax.getIndividuals().iterator();			it.hasNext(); ) {				OWLIndividual desc = (OWLIndividual) it.next();				desc.accept( this );				if (it.hasNext()) {					pw.print(" ");				}			}			pw.print(")");		}		public void visit( OWLSameIndividualsAxiom ax) throws OWLException {			pw.print("SameIndividual(");			for ( Iterator it = ax.getIndividuals().iterator();			it.hasNext(); ) {				OWLIndividual desc = (OWLIndividual) it.next();				desc.accept( this );				if (it.hasNext()) {					pw.print(" ");				}			}			pw.print(")");		}		public void visit( OWLDataType ocdt ) throws OWLException {			pw.print( escape(shortForms.shortForm( ocdt.getURI() )) );		}		public void visit( OWLDataEnumeration enumeration ) throws OWLException {			pw.print("oneOf(");			for ( Iterator it = enumeration.getValues().iterator();			it.hasNext(); ) {				OWLDataValue desc = (OWLDataValue) it.next();				desc.accept( this );				if (it.hasNext()) {					pw.print(" ");				}			}			pw.print(")");		}				public void visit( OWLClass clazz ) throws OWLException {			if (noLinks) {				pw.print(INDENT + shortForm( clazz.getURI() ));							}			else {				pw.print(INDENT + "<a href=\"" + escape(clazz.getURI()) + "\">" + escape(shortForm( clazz.getURI() )) + "</a>" );			}		}				public void visit( OWLIndividual ind ) throws OWLException {			if ( ind.isAnonymous() ) {				pw.print( "Anonymous individual" );			} else {				if (noLinks) {					pw.print( shortForm( ind.getURI() )  );				}				else {					pw.print( "<a href=\"" + escape(ind.getURI()) + "\">" + escape(shortForm( ind.getURI() )) + "</a>" );				}			}		}		public void visit( OWLObjectProperty prop ) throws OWLException {			if (noLinks) {				pw.print(shortForm( prop.getURI() )  );			}			else {				pw.print("<a href=\"" + escape(prop.getURI()) + "\">" + escape(shortForm( prop.getURI() )) + "</a>" );			}					}						public void visit( OWLDataProperty prop ) throws OWLException {			if (noLinks) {				pw.print(shortForm( prop.getURI() )  );			}			else {				pw.print("<a href=\"" + prop.getURI() + "\">" + shortForm( prop.getURI() ) + "</a>" );			}				}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLAnnotationProperty)		 */		public void visit(OWLAnnotationProperty arg0) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLAnnotationInstance)		 */		public void visit(OWLAnnotationInstance arg0) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLFrame)		 */		public void visit(OWLFrame arg0) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLOntology)		 */		public void visit(OWLOntology arg0) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLFunctionalPropertyAxiom)		 */		public void visit(OWLFunctionalPropertyAxiom node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLInverseFunctionalPropertyAxiom)		 */		public void visit(OWLInverseFunctionalPropertyAxiom node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLTransitivePropertyAxiom)		 */		public void visit(OWLTransitivePropertyAxiom node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLSymmetricPropertyAxiom)		 */		public void visit(OWLSymmetricPropertyAxiom node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLInversePropertyAxiom)		 */		public void visit(OWLInversePropertyAxiom node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLPropertyDomainAxiom)		 */		public void visit(OWLPropertyDomainAxiom node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLObjectPropertyRangeAxiom)		 */		public void visit(OWLObjectPropertyRangeAxiom node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLDataPropertyRangeAxiom)		 */		public void visit(OWLDataPropertyRangeAxiom node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLObjectPropertyInstance)		 */		public void visit(OWLObjectPropertyInstance node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLDataPropertyInstance)		 */		public void visit(OWLDataPropertyInstance node) throws OWLException {			// TODO Auto-generated method stub					}		/* (non-Javadoc)		 * @see org.semanticweb.owl.model.OWLObjectVisitor#visit(org.semanticweb.owl.model.OWLIndividualTypeAssertion)		 */		public void visit(OWLIndividualTypeAssertion node) throws OWLException {			// TODO Auto-generated method stub					}			}				public String getContentType() {		return contentType;	}		public String getName() {		return "Abstract Syntax";	}		/* (non-Javadoc)	 * @see org.mindswap.swoop.BaseEntityRenderer#initVisitor()	 */	public SwoopRenderingVisitor createVisitor() {		//if editorEnabled then nolinks=true		return new AbstractSyntaxVisitor(this, editorEnabled);	}	 public void setEditorEnabled(boolean mode) {				editorEnabled = mode;		if (mode) contentType = "text/plain";		else contentType = "text/html";	}		 	 /**		 * Render the ontology in RDF/XML but skip rendering of a particular entity		 * This is used (during update) to support editing inside the RDF/XML renderer		 * @param ontology		 * @param skip - element skipped during printing		 * @param only - only elements in this set are printed 		 * @param writer		 * @throws RendererException		 */	    public void renderOntology(SwoopModel swoopModel, OWLOntology ontology, OWLEntity skip, String newEntityCode, Writer writer)	        throws RendererException {	        // this.ontology = ontology;	        try {	        		        	this.swoopModel = swoopModel; 	            	            this.allURIs = OntologyHelper.allURIs(ontology);	            	            				this.reasoner = swoopModel.getReasoner();								this.writer = writer;				this.pw = new PrintWriter(writer);								this.editorEnabled = swoopModel.getEditorEnabled();				this.showInherited = swoopModel.getShowInherited();				this.showDivisions = swoopModel.getShowDivisions();				this.showImports = swoopModel.getShowImports();					           //this.visitor = new CorrectedRDFXMLVisitor(this);	            //****************************************************	            //changed for Econnections	            //****************************************************	            this.visitor = new AbstractSyntaxVisitor(this,true);	            visitor.reset();	        //	visitor.setProperty(null);	        //	visitor.setPropertyObject(null);	            //***************************************************		    //	            this.baseURI = swoopModel.getSelectedOntology().getURI().toString();	            this.qnameProvider = new QNameShortFormProvider();	            generateShortNames();	            writeTextHeader();	            for (Iterator it =	                orderedEntities(ontology.getObjectProperties()).iterator();	                it.hasNext();	                ) {	            	OWLObjectProperty prop = (OWLObjectProperty) it.next();	                if (!prop.equals(skip)) renderTextObjectProperty( prop);	                else pw.println(newEntityCode); 	            }	            pw.println("\n");	            	            for (Iterator it =	                orderedEntities(ontology.getDataProperties()).iterator();	                it.hasNext();	                ) {	            	OWLDataProperty prop = (OWLDataProperty) it.next();	            	if (!prop.equals(skip)) renderTextDataProperty( prop);	            	else pw.println(newEntityCode);	            }	            pw.println();	            for (Iterator it =	                orderedEntities(ontology.getClasses()).iterator();	                it.hasNext();	                ) {	            	OWLClass cla = (OWLClass) it.next();	                if (skip==null || !cla.equals(skip)) 	                	renderTextClass(cla);	                else pw.println(newEntityCode); 	            }	         	           	            pw.println();	            for (Iterator it =	                orderedEntities(ontology.getIndividuals()).iterator();	                it.hasNext();	                ) {	            	OWLIndividual ind = (OWLIndividual) it.next();	                if (!ind.equals(skip)) renderTextIndividual( ind);	                else pw.println(newEntityCode);	            }	            pw.println();	            for (Iterator it =	                orderedEntities(ontology.getClassAxioms()).iterator();	                it.hasNext();	                ) {	                renderTextClassAxiom((OWLClassAxiom) it.next());	            }	            	            for (Iterator it =	                orderedEntities(ontology.getPropertyAxioms()).iterator();	                it.hasNext();	                ) {	                renderTextPropertyAxiom((OWLPropertyAxiom) it.next());	            }		    		    writeFooter();		    pw.flush();	        } catch (OWLException ex) {	            throw new RendererException(ex.getMessage());	        }			    }	    	/* Well dodgy coding */	protected void renderAnnotationContent(Object o) throws OWLException {		if (o instanceof URI) {			escape(o);		} else if (o instanceof OWLIndividual) {			OWLIndividual ind = (OWLIndividual) o;			if (ind.isAnonymous()) {				print(escape(ind.getAnonId()));			} else {				print(escape(ind.getURI()));			}		} else if (o instanceof OWLDataValue) {			OWLDataValue dv = (OWLDataValue) o;			print("\"" + escape(dv.getValue()) + "\"");			/* Only show it if it's not string */			URI dvdt = dv.getURI();			String dvlang = dv.getLang();			if (dvdt != null) {				print("^^" + escape(dvdt));				// 		if (!dv.getURI().toString().equals(				// XMLSchemaSimpleDatatypeVocabulary.INSTANCE.getString())) {				// 		    print( "^^" + dv.getURI() );				// 		}			} else {				if (dvlang != null) {					print("@" + escape(dvlang));				}			}		} else {			print("\""+escape(o)+"\"");		}	}	/** Render the annotations for an object */	protected void renderAnnotations(OWLNamedObject object ) throws OWLException {		/* Bit nasty this -- annotations result in a new axiom */		if (!object.getAnnotations(reasoner.getOntology()).isEmpty()) {			for (Iterator it = object.getAnnotations(reasoner.getOntology()).iterator(); it.hasNext();) {				OWLAnnotationInstance oai = (OWLAnnotationInstance) it.next();				print( TAB + "annotation(" + shortForm(oai.getProperty().getURI()) + " ");				/* Just whack out the content. This isn't quite right... */				renderAnnotationContent(oai.getContent());				//		print( "\"" + oai.getContent() + "\"" );				print(")");				/* Do we need to do this??? */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?