⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ontology.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if((a.getTerm(l) != null) && (a.getTerm(l).equals(label))) return a;
		}
		return null;
	}
	
	/** Create a new concept type in the hierarchy and returns it. */
	public ConceptType newConceptType(){
		ConceptType result = new ConceptType();
		conceptTypes.put(new Integer(result.getId()),result);
		return result;
	}
	
	/** Create a new concept type in the hierarchy and returns it. */
	public ConceptType newConceptType(int x, int y){
		ConceptType result = new ConceptType();
		result.setLocation(x,y);
		conceptTypes.put(new Integer(result.getId()),result);
		return result;
	}
	
	/** Create a new concept type in the hierarchy with the given Terms and returns it. */
	public ConceptType newConceptType(Terms t){
		ConceptType result = new ConceptType(t);
		conceptTypes.put(new Integer(result.getId()),result);
		return result;
	}
	
	/** Create a new concept type in the hierarchy with the given Terms and returns it. */
	public ConceptType newConceptType(Terms t,int x,int y){
		ConceptType result = new ConceptType(t);
		result.setLocation(x,y);
		conceptTypes.put(new Integer(result.getId()),result);
		return result;
	}
	
	/** Remove the specified concept type from the ontology and returns true if the removing 
	 *  works, returns false otherwise (in particular the universal concept type can not be 
	 *  removed. */
	public boolean removeConceptType(ConceptType ct){
		return (this.conceptTypes.remove(new Integer(ct.getId())) != null);
	}
	
	/** Create a new relation type in the hierarchy and returns it. By default, the arity is 2. */
	public RelationType newRelationType(){
		return this.newRelationType(2);
	}
	
	/** Create a new relation type in the hierarchy and returns it. By default, the arity is 2. */
	public RelationType newRelationType(int x, int y){
		return this.newRelationType(2,x,y);
	}
	 
	/** Create a new relation type in the hierarchy with the given Terms and returns it. 
	 *  By default, the arity is 2. */
	public RelationType newRelationType(Terms t){
		return this.newRelationType(t,2);
	}
	
	/** Create a new relation type in the hierarchy with the given Terms and returns it. 
	 *  By default, the arity is 2. */
	public RelationType newRelationType(Terms t,int x, int y){
		return this.newRelationType(t,2,x,y);
	}
	
	/** Create a new relation type in the hierarchy with the given arity and returns it. */
	public RelationType newRelationType(int arity){
		RelationType result = new RelationType(arity);
		relationTypes.put(new Integer(result.getId()),result);
		return result;
	}
	
	/** Create a new relation type in the hierarchy with the given arity and returns it. */
	public RelationType newRelationType(int arity,int x,int y){
		RelationType result = new RelationType(arity);
		result.setLocation(x,y);
		relationTypes.put(new Integer(result.getId()),result);
		return result;
	}
	
	/** Create a new relation type in the hierarchy with the given arity and the given Terms 
	 *  and returns it. */
	public RelationType newRelationType(Terms t,int arity){
		RelationType result = new RelationType(arity,t);
		relationTypes.put(new Integer(result.getId()),result);
		return result;
	}
	
	/** Create a new relation type in the hierarchy with the given arity and the given Terms 
	 *  and returns it. */
	public RelationType newRelationType(Terms t,int arity,int x, int y){
		RelationType result = new RelationType(arity,t);
		result.setLocation(x,y);
		relationTypes.put(new Integer(result.getId()),result);
		return result;
	}
	
	/** Remove the specified relation type from the ontology and returns true if the removing 
	 *  works, returns false otherwise (in particular the difference relation type can not be 
	 *  removed. */
	public boolean removeRelationType(RelationType rt){
		return (relationTypes.remove(new Integer(rt.getId())) != null);
	}
	
	/** Create a new individual and returns it. */
	public Individual newIndividual(Terms t,ConceptType ct){
		Individual result = new Individual(t,ct);
		individuals.put(new Integer(result.getId()),result);
		return result;
	}
	
	public void removeIndividual(Individual i){
		individuals.remove(new Integer(i.getId()));
		for(Iterator it = this.getConcepts().iterator();it.hasNext();){
			Concept c = (Concept) it.next();
			if((c.getIndividual() != null) && c.getIndividual().equals(i)) c.setIndividual(null);
		}
	}
	
	/** Returns the top concept type of the hierarchy, the first encountered if there are several 
	 *  concept types without parent, null if any (that is there is a loop in the hierarchy). */
	public ConceptType getTopConceptType(){
		for(Iterator i = conceptTypes.values().iterator();i.hasNext();){
			ConceptType ct = (ConceptType) i.next();
			if(ct.getParents().size() == 0) return ct;
		}
		return null;
	}
	
	/** Returns the top relation type of the hierarchy, the first encountered if there are several 
	 *  relation types without parent, null if any (that is there is a loop in the hierarchy). */
	public RelationType getTopRelationType(){
		for(Iterator i = relationTypes.values().iterator();i.hasNext();){
			RelationType rt = (RelationType) i.next();
			if(rt.getParents().size() == 0) return rt;
		}
		return null;
	}

	/** Add the specified axiom in the ontology. */
	public void addAxiom(Axiom a){
		axioms.put(new Integer(a.getId()),a);
	}
	
	/** Create a new axiom in the ontology an returns it. */
	public Axiom newAxiom(){
		Axiom result = new Axiom();
		axioms.put(new Integer(result.getId()),result);
		return result;
	}
	
	/** Create a new axiom with the given Terms and returns it. */
	public Axiom newAxiom(Terms t){
		Axiom result = new Axiom(t);
		axioms.put(new Integer(result.getId()),result);
		return result;
	}
	
	public void removeAxiom(Axiom a){
		axioms.remove(new Integer(a.getId()));
	}
	
	public void removeAxioms(LinkedList axiomList){
		for(Iterator i = axiomList.iterator();i.hasNext();){
			this.removeAxiom((Axiom) i.next());
		}
	}
	
	/** Remove the object from the ontology. Returns true if the object appears in the 
	 *  ontology, false otherwise. */
	public boolean removeObject(NamedObject no){
		if(conceptTypes.remove(new Integer(no.getId())) == null){
			if(relationTypes.remove(new Integer(no.getId())) == null){
				if(individuals.remove(new Integer(no.getId())) == null){
					if(axioms.remove(new Integer(no.getId())) == null) return false;
					else return true;
				}
				else return true;
			}
			else return true;
		}
		else return true;
	} 	
	
	/** Returns the list of concept types homonymous with ct for the given language. */
	public LinkedList getHomonymousCT(ConceptType ct,Language l){
		LinkedList result = new LinkedList();
		for(Iterator i = this.getConceptTypes().iterator();i.hasNext();){
			ConceptType contype = (ConceptType) i.next();
			if(!ct.equals(contype) && ct.getTerm(l).equals(contype.getTerm(l))) result.add(contype);
		}
		return result;
	}
		
	/** Organize the individuals by types. */
	public LinkedList getOrganizedIndividualsList(Language l){
		LinkedList result = new LinkedList();
		Object[] tab = individuals.values().toArray();
		if(tab.length != 0){
			for(int cpt = individuals.size();cpt > 1;cpt --){
				int key = 0;
				Individual indiv1 = (Individual) tab[0];
				for(int j = 1;j < cpt;j ++){
					Individual indiv2 = (Individual) tab[j];
					int comparison = indiv2.getType().getTerm(l).compareToIgnoreCase(indiv1.getType().getTerm(l));
					if((comparison > 0) || ((comparison == 0) && (indiv2.getTerm(l).compareToIgnoreCase(indiv1.getTerm(l)) > 0))){
						key = j;
						indiv1 = indiv2;
					}
					else{
						if(j == (cpt - 1)){
							tab[j] = indiv1;
							tab[key] = indiv2;
						}
					}
				}	
			}
			for(int i = 0;i < tab.length;i ++){
				result.add(tab[i]);
			}
		}
		return result;
	}
	
	/** Organize the concept types by terms. */
	public LinkedList getOrganizedConceptTypesList(Language l){
		LinkedList result = new LinkedList();
		Object[] tab = conceptTypes.values().toArray();
		if(tab.length != 0){
			for(int cpt = conceptTypes.size();cpt > 1;cpt --){
				int key = 0;
				ConceptType ct1 = (ConceptType) tab[0];
				for(int j = 1;j < cpt;j ++){
					ConceptType ct2 = (ConceptType) tab[j];
					if(ct2.getTerm(l).compareToIgnoreCase(ct1.getTerm(l)) > 0){
						key = j;
						ct1 = ct2;
					}
					else{
						if(j == (cpt - 1)){
							tab[j] = ct1;
							tab[key] = ct2;
						}
					}
				}	
			}
			for(int i = 0;i < tab.length;i ++){
				result.add(tab[i]);
			}
		}
		return result;
	}
	
	/** Organize the relation types by terms. */
	public LinkedList getOrganizedRelationTypesList(Language l){
		LinkedList result = new LinkedList();
		Object[] tab = relationTypes.values().toArray();
		if(tab.length != 0){
			for(int cpt = relationTypes.size();cpt > 1;cpt --){
				int key = 0;
				RelationType rt1 = (RelationType) tab[0];
				for(int j = 1;j < cpt;j ++){
					RelationType rt2 = (RelationType) tab[j];
					if(rt2.getTerm(l).compareToIgnoreCase(rt1.getTerm(l)) > 0){
						key = j;
						rt1 = rt2;
					}
					else{
						if(j == (cpt - 1)){
							tab[j] = rt1;
							tab[key] = rt2;
						}
					}
				}	
			}
			for(int i = 0;i < tab.length;i ++){
				result.add(tab[i]);
			}
		}
		return result;
	}

	/** Organize the axioms by terms. */
	public LinkedList getOrganizedAxiomsList(Language l){
		LinkedList result = new LinkedList();
		Object[] tab = axioms.values().toArray();
		if(tab.length != 0){
			for(int cpt = axioms.size();cpt > 1;cpt --){
				int key = 0;
				Axiom a1 = (Axiom) tab[0];
				for(int j = 1;j < cpt;j ++){
					Axiom a2 = (Axiom) tab[j];
					if(a2.getTerm(l).compareToIgnoreCase(a1.getTerm(l)) > 0){
						key = j;
						a1 = a2;
					}
					else{
						if(j == (cpt - 1)){
							tab[j] = a1;
							tab[key] = a2;
						}
					}
				}	
			}
			for(int i = 0;i < tab.length;i ++){
				result.add(tab[i]);
			}
		}
		return result;
	}	
	
}

⌨️ 快捷键说明

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