turtleentityrenderer.java

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

JAVA
1,609
字号
				} else if ( restriction.isAtMost() ) {					uri = new URI(OWL_MAXCARDINALITY);					print( SPACE + SPACE + encodeHLink(uri, shortForms.shortForm(uri)) + TAB + restriction.getAtMost());				} else 	if ( restriction.isAtLeast() ) {					uri = new URI(OWL_MINCARDINALITY);					print( SPACE + SPACE + encodeHLink(uri, shortForms.shortForm(uri)) + TAB + restriction.getAtLeast());				}				pw.print(BREAK);				print(" ]");			}			catch(Exception ex)			{ ex.printStackTrace(); }				}		// done		public void visit( OWLDataCardinalityRestriction restriction ) throws OWLException {			try			{						pw.print("[ " + SPACE);				URI uri = new URI(OWL_RESTRICTION);				pw.print( encodeHLink(RDF_TYPE_URI, "a") + TAB +						encodeHLink(uri, shortForms.shortForm(uri)) + ";" + BREAK);							uri = new URI(OWL_ONPROPERTY);				print( SPACE + SPACE + encodeHLink(uri, shortForms.shortForm(uri)) + TAB);								restriction.getDataProperty().accept( this );								pw.print(";"+BREAK);  // avoid syntax indentation								if ( restriction.isExactly() ) {					uri = new URI(OWL_CARDINALITY);					print( SPACE + SPACE + encodeHLink(uri, shortForms.shortForm(uri)) + TAB + restriction.getAtLeast());				} else if ( restriction.isAtMost() ) {					uri = new URI(OWL_MAXCARDINALITY);					print( SPACE + SPACE + encodeHLink(uri, shortForms.shortForm(uri)) + TAB + restriction.getAtMost());				} else 	if ( restriction.isAtLeast() ) {					uri = new URI(OWL_MINCARDINALITY);					print( SPACE + SPACE + encodeHLink(uri, shortForms.shortForm(uri)) + TAB + restriction.getAtLeast());				}				pw.print(BREAK);				print(" ]");			}			catch(Exception ex)			{ ex.printStackTrace(); }		}		// done			public void visit( OWLDataValueRestriction restriction ) throws OWLException {			try			{						pw.print("[ " + SPACE);				URI uri = new URI(OWL_RESTRICTION);				pw.print( encodeHLink(RDF_TYPE_URI, "a") + TAB +						encodeHLink(uri, shortForms.shortForm(uri)) + ";" + BREAK);							uri = new URI(OWL_ONPROPERTY);				print( SPACE + SPACE + encodeHLink(uri, shortForms.shortForm(uri)) + TAB);				restriction.getDataProperty().accept( this );								pw.print(";"+BREAK);  // avoid syntax indentation				uri = new URI(OWL_HASVALUE);				print( SPACE + SPACE + encodeHLink(uri, shortForms.shortForm(uri)) + TAB);				restriction.getValue().accept( this );				println();				print(" ]");			}			catch(Exception ex)			{ ex.printStackTrace(); }		}		public void visit( OWLEquivalentClassesAxiom axiom ) throws OWLException {			pw.print("!!OWLEquivalentClassesAxiom!!");			/*			try			{				URI uri = new URI(OWL_EQUIVALENTCLASS);				for ( Iterator it = axiom.getEquivalentClasses().iterator(); it.hasNext(); ) {					OWLDescription eq = (OWLDescription)it.next();					print( encodeHLink(uri, myQNameProvider.shortForm(uri)) + TAB);					reset();					if (!(eq instanceof OWLClass))  // only indent if eq is an anon class					{						indentLevel ++;						pw.print(BREAK + getIndentString());					}					eq.accept( this );							if (!(eq instanceof OWLClass)) // un-indent						indentLevel --;					pw.print(result() + ";" + BREAK);				}			}						catch (Exception ex)			{ ex.printStackTrace(); }			*/		}		public void visit( OWLDisjointClassesAxiom axiom ) throws OWLException {			pw.print("!!OWLDisjointClassesAxiom!!");			/*			try			{				URI uri = new URI(OWL_DISJOINTWITH);				for ( Iterator it = axiom.getDisjointClasses().iterator(); it.hasNext(); ) 				{									OWLDescription desc = (OWLDescription)it.next();					reset();					desc.accept( this );					print(encodeHLink(uri, myQNameProvider.shortForm(uri)) + TAB + result() + ";" + BREAK);									}			}			catch (Exception ex)			{ ex.printStackTrace(); }			*/		}		// done ... untested		public void visit( OWLSubClassAxiom axiom ) throws OWLException {			pw.print("!!OWLSubClassAxiom!!");/*			pw.print(" ????? SubClassOf(");			axiom.getSubClass().accept( this );			pw.print(" ");			axiom.getSuperClass().accept( this );			pw.print(") ??????");			*/		}		public void visit( OWLEquivalentPropertiesAxiom axiom ) throws OWLException {			pw.print("!!OWLEquivalentPropertiesAxiom!!");			/*			pw.print("EquivalentProperties(");			for ( Iterator it = axiom.getProperties().iterator();			it.hasNext(); ) {				OWLProperty prop = (OWLProperty) it.next();				prop.accept( this );				if (it.hasNext()) {					pw.print(" ");				}			}			pw.print(")");			*/		}		public void visit( OWLSubPropertyAxiom axiom ) throws OWLException {			pw.print("!!OWLSubPropertyAxiom!!");			/*			pw.print("SubPropertyOf(");			axiom.getSubProperty().accept( this );			pw.print(" ");			axiom.getSuperProperty().accept( this );			pw.print(")");			*/		}		public void visit( OWLDifferentIndividualsAxiom ax) throws OWLException {			pw.print("!!OWLDifferentIndividualsAxiom!!");			/*			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("!!OWLSameIndividualsAxiom!!");			/*			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(")");			*/		}		// done		public void visit( OWLDataType ocdt ) throws OWLException {			pw.print( encodeHLink(ocdt.getURI(), shortForms.shortForm(ocdt.getURI())) );		}		// done		public void visit( OWLDataEnumeration enumeration ) throws OWLException {			try			{									URI uri = new URI(OWL_ONEOF);				print( encodeHLink(uri, shortForms.shortForm(uri)) + TAB + "("+ SPACE);				indentLevel ++;				for ( Iterator it = enumeration.getValues().iterator();it.hasNext(); ) {					OWLDescription desc = (OWLDescription) it.next();					pw.print(getIndentString());					desc.accept( this );					if (it.hasNext()) {						println(BREAK);					}				}				indentLevel --;				pw.print(SPACE + ")" + SPACE);			}			catch (Exception ex)			{ throw new OWLException(ex.toString()); }		}				// done		public void visit( OWLClass clazz ) throws OWLException {			pw.print( encodeHLink(clazz.getURI(), shortForms.shortForm( clazz.getURI() )));		}				// done		public void visit( OWLIndividual ind ) throws OWLException {			if ( ind.isAnonymous() ) {				pw.print( "[ ]" );  // anonymous individual			} else {				pw.print( encodeHLink(ind.getURI(), shortForms.shortForm(ind.getURI())) );			}		}		// done		public void visit( OWLObjectProperty prop ) throws OWLException {			pw.print( encodeHLink(prop.getURI(), shortForms.shortForm( prop.getURI())) );		}				// done		public void visit( OWLDataProperty prop ) throws OWLException {			pw.print( encodeHLink(prop.getURI(), shortForms.shortForm( prop.getURI())) );		}		public void visit(OWLAnnotationProperty arg0) throws OWLException {			// TODO Auto-generated method stub					}		public void visit(OWLAnnotationInstance arg0) throws OWLException {			// TODO Auto-generated method stub					}		public void visit(OWLFrame arg0) throws OWLException {			// TODO Auto-generated method stub					}		public void visit(OWLOntology arg0) throws OWLException {			// TODO Auto-generated method stub					}				private String getIndentString()		{			String indentation = "";			for (int i = 0; i < indentLevel; i ++)				indentation = indentation + TAB;						return indentation;		}						// private convenient printing functions to use correct indentation		private void print(String toBeWritten)		{ pw.print(getIndentString() + toBeWritten); }				private void println(String toBeWritten)		{  pw.println(getIndentString()+ toBeWritten + BREAK); }				private void println()		{  pw.print(BREAK); }		/* (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					}			}			protected class TurtleShortFormProvider extends DefaultShortFormProvider	{		 public String shortForm(URI uri) 		 {		 	String name = super.shortForm( uri );		 	if ( name.indexOf(":") == -1 )		 		name = ":" + name;		 	return name;		 }	}		private static final String TURTLE_NAME = "Turtle";	private static final String TURTLE_CONTENT_TYPE = "text/html";	private static final String TAB = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";	private static final String SPACE = "&nbsp;";	private static final String BREAK = "<br>";	private static final String LT = "&lt;";	private static final String GT = "&gt;";			private List myUserNS;	private Set  myAllURIs;	private QNameShortFormProvider myQNameProvider;	private SwoopModel myModel;	private static final String PERIOD = "  .";		public void render(OWLEntity entity, SwoopModel swoopModel, Writer writer) throws RendererException {	    try{	    	fontSize = swoopModel.getFontSize();	    	OWLOntology ontology = swoopModel.getSelectedOntology();	    	URI logical = ontology.getLogicalURI();	    	String defaultNS = logical + "#";	    	//System.out.println( defaultNS );	    		    	this.myAllURIs = OntologyHelper.allURIs(ontology);	    	this.myQNameProvider = new QNameShortFormProvider();	    	this.myModel = swoopModel;			StringWriter sw = new StringWriter();			PrintWriter buffer = new PrintWriter(sw);			StringWriter sw2 = new StringWriter();			PrintWriter buffer2 = new PrintWriter(sw2);	    	

⌨️ 快捷键说明

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