description.java

来自「Semantic Web Ontology Editor」· Java 代码 · 共 464 行 · 第 1/2 页

JAVA
464
字号
					URI xsdType = new URI(xsd+valueDatatype);					OWLDataValue propDataVal = ourOntology.getOWLDataFactory().getOWLConcreteData(xsdType, "EN", propValue);					change = new AddDataPropertyInstance(ourOntology, instance, (OWLDataProperty) annoteaProp, propDataVal, null);										break;									case 2: // object property					annoteaProp = (OWLObjectProperty) Annotea.INSTANCE.annoteaMap.get(propName);					change = new AddObjectPropertyInstance(ourOntology, instance, (OWLObjectProperty) annoteaProp, (OWLIndividual) propValue, null);					break;								}			change.accept((ChangeVisitor) ourOntology);		}		catch (Exception e) {			e.printStackTrace();		}			}		public URI[] getAnnotates() {		return annotates;	}		public String getBody() {		return body;	}		public String getBodyType() {		return bodyType;	}		public URL getLocation() {		return location;	}		public void setAnnotates(URI[] annotated) {		this.annotates = annotated;	}		public void setBody(String body) {		this.body = body;	}		public void setBody(String body, String type) {		setBody(body);		setBodyType(type);	}		public void setBodyType(String type) {		this.bodyType = type;	}		public void setLocation(URL location) {		this.location = location;	}		public String getAuthor() {		return this.author;	}	public String getCreated() {		return this.created;	}		public void setAuthor(String author) {		this.author = author;	}	public void setCreated(String created) {		this.created = created;	}		public OWLClass getAnnotationType() {		return this.annotationType;	}		public void setAnnotationType(OWLClass type) {		this.annotationType = type;	}		public List getOntologyChangeSet() {		return this.ontologyChangeSet;	}		public void setOntologyChangeSet(List changeSet) {		this.ontologyChangeSet = new ArrayList(changeSet);	}		protected String stripHTML(String html) {		html = html.replaceAll("&", "&amp;");		html = html.replaceAll("<", "&lt;");		html = html.replaceAll(">", "&gt;");		return html;	}		public String getAnnotatedEntityDefinition() {		return annotatedEntityDefinition;	}		public void setAnnotatedEntityDefinition(String annotatedEntityDefinition) {		this.annotatedEntityDefinition = annotatedEntityDefinition;	}		public boolean equals(Object obj) {		if (obj instanceof Description) {			Description desc = (Description) obj;			boolean match = true;						if (desc.annotatedEntityDefinition!=null && this.annotatedEntityDefinition!=null) {				if (!desc.annotatedEntityDefinition.equals(this.annotatedEntityDefinition)) match = false;			}			if (desc.annotates!=null && this.annotates!=null) {				if (!desc.annotates.equals(this.annotates)) match = false;			}			if (desc.annotationType!=null && this.annotationType!=null) {				try {					if (!desc.annotationType.equals(this.annotationType)) match = false;				} catch (Exception e) {					e.printStackTrace();				}			}			if (desc.author!=null && this.author!=null) {				if (!desc.author.equals(this.author)) match = false;			}			if (desc.body!=null && this.body!=null) {				if (!desc.body.equals(this.body)) match = false;			}			if (desc.bodyType!=null && this.bodyType!=null) {				if (!desc.bodyType.equals(this.bodyType)) match = false;			}			if (desc.created!=null && this.created!=null) {				if (!desc.created.equals(this.created)) match = false;			}			if (desc.location!=null && this.location!=null) {				if (!desc.location.equals(this.location)) match = false;			}			if (desc.ontologyChangeSet!=null && this.ontologyChangeSet!=null) {				if (!desc.ontologyChangeSet.equals(this.ontologyChangeSet)) match = false;			}							return match;		}		return false;	}		/*	 * Serialize the Description object into a String	 * Dont write all its components, only those needed to represent	 * SwoopChange objects i.e. author of change, date, comment on change,	 * uris the change refers to and serialized version of the change object	 */	public String serializeIntoString(SwoopModel swoopModel) throws OWLException {		String ser = "";				ser = "AUTHOR={"+ this.author + "}"+separator;		ser += "DATE={"+ this.created + "}"+separator;		ser += "COMMENT={" + this.annotatedEntityDefinition + "}"+separator;		ser += "BODY={" + this.body + "}"+separator;				ser += "URIS = {";		for (int i=0; i<this.annotates.length; i++) {			ser += this.annotates[i].toString() + ",";		}		ser += "}"+separator;				if (this.ontologyChangeSet.size()>0) {			// serialize changes in RDF/XML and add them in the BODY			ChangeLog clog = new ChangeLog(null, swoopModel);			OntologyChangeRenderer oc = new OntologyChangeRenderer(clog);			OWLOntology changeOnt = oc.serializeOntologyChanges(this.ontologyChangeSet);			CorrectedRDFRenderer rdfRend = new CorrectedRDFRenderer();			StringWriter st = new StringWriter();			try {				rdfRend.renderOntology(changeOnt, st);			} catch (RendererException e) {				e.printStackTrace();			}			ser += "CHANGE={" + st.toString() + "}"+separator;		}		return ser;	}		/*	 * Deserialize a description string into Description object	 */	public void deserializeFromString(String ser, SwoopModel swoopModel) throws OWLException {		String[] parts = splitString(ser);		this.author = this.getBracketed(parts[0]);		this.created = this.getBracketed(parts[1]);		this.annotatedEntityDefinition = this.getBracketed(parts[2]);		this.body = this.getBracketed(parts[3]);				String uris = this.getBracketed(parts[4]);		String[] uriparts = uris.split(",");		this.annotates = new URI[uriparts.length];		for (int i=0; i<uriparts.length; i++) {			try {				this.annotates[i] = new URI(uriparts[i]);			} catch (URISyntaxException e) {				e.printStackTrace();			}		}				String body = this.getBracketed(parts[5]);		// deserialize body to get change set		ChangeLog clog = new ChangeLog(null, swoopModel);		OntologyChangeRenderer oc = new OntologyChangeRenderer(clog);				OWLOntology changeOnt = swoopModel.loadOntologyInRDF(new StringReader(body), URI.create(""));		this.ontologyChangeSet = oc.deserializeOntologyChanges(changeOnt);			}		private String getBracketed(String part) {		return part.substring(part.indexOf("{")+1, part.lastIndexOf("}"));	}		private String[] splitString(String str) {				List parts = new ArrayList();		int pointer = 0;		while (str.indexOf(separator, pointer)>=0) {			String part = str.substring(pointer, str.indexOf(separator, pointer));			pointer = str.indexOf(separator, pointer)+1;			parts.add(part);		}		Object[] obj = parts.toArray();		String[] spl = new String[obj.length];		for (int i=0; i<obj.length; i++) {			spl[i] = obj[i].toString();		}		return spl;	}}

⌨️ 快捷键说明

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