📄 signature.java
字号:
package toocom.ocgl;
import java.util.*;
/**
* This class represents the signature of a relation type. The first index of a signature is 1.
*
* @author Fr閐閞ic F黵st
*/
public class Signature{
private ConceptType[] conceptTypes;
/** Creates the Signature class with the given arity and UNIVERSAL_CONCEPT_TYPE concept types.
* This method can throws an IndexOutOfBounsException if the given arity is less than the
* CGConstants.RELATION_TYPE_MIN_ARITY and greater than the CGConstants.RELATION_TYPE_MAX_ARITY.
*/
public Signature(int arity) throws IndexOutOfBoundsException{
if((arity >= CGConstants.RELATION_TYPE_MIN_ARITY) && ((arity <= CGConstants.RELATION_TYPE_MAX_ARITY))){
this.conceptTypes = new ConceptType[arity];
}
else throw new IndexOutOfBoundsException("Signature arity must be greater than 1");
}
/** Creates the Signature class with the given list of concept types. This method can throws an
* IndexOutOfBounsException if the size of the given list is less than the
* CGConstants.RELATION_TYPE_MIN_ARITY and greater than the CGConstants.RELATION_TYPE_MAX_ARITY.
*/
public Signature(LinkedList conceptTypeList){
if((conceptTypeList.size() >= CGConstants.RELATION_TYPE_MIN_ARITY) &&
((conceptTypeList.size() <= CGConstants.RELATION_TYPE_MAX_ARITY))){
this.conceptTypes = new ConceptType[conceptTypeList.size()];
int cpt = 0;
for(Iterator i = conceptTypeList.iterator();i.hasNext();cpt ++){
this.conceptTypes[cpt] = (ConceptType) i.next();
}
}
else throw new IndexOutOfBoundsException("Signature arity must be greater than 1");
}
/** Returns the arity of the signature. */
public int getArity(){
return this.conceptTypes.length;
}
/** Modify the arity of the signature. If the new arity is less than (or equal to) the old one,
* only the concept types at the 1..new arity index are kept. If the new arity is greater than
* the old one, the arity is increase but no concept types are added at the end of the signature.
* New concept types must be added using the setConceptType method. This method can throws an
* IndexOutOfBounsException if the given arity is less than the
* CGConstants.RELATION_TYPE_MIN_ARITY and greater than the CGConstants.RELATION_TYPE_MAX_ARITY.
*/
public void setArity(int arity) throws IndexOutOfBoundsException{
if((arity >= CGConstants.RELATION_TYPE_MIN_ARITY) && ((arity <= CGConstants.RELATION_TYPE_MAX_ARITY))){
if(arity < this.conceptTypes.length){
ConceptType[] newCTTab = new ConceptType[arity];
for(int cpt = 0;cpt < arity;cpt ++){
newCTTab[cpt] = conceptTypes[cpt];
}
conceptTypes = newCTTab;
}
if(arity > this.conceptTypes.length){
ConceptType[] newCTTab = new ConceptType[arity];
for(int cpt = 0;cpt < conceptTypes.length;cpt ++){
newCTTab[cpt] = conceptTypes[cpt];
}
conceptTypes = newCTTab;
}
}
else throw new IndexOutOfBoundsException("Signature arity must be greater than 1");
}
/** Returns the previous concept type at the given index and replace it by the given concept type
* if index > 0 and index <= arity, returns null otherwise. */
public ConceptType setConceptType(ConceptType conceptType, int index){
if((index > 0) && (index <= this.conceptTypes.length)){
ConceptType result = conceptTypes[index - 1];
this.conceptTypes[index - 1] = conceptType;
return result;
}
else return null;
}
/** Return the concept type at the given index (1 <= index <= arity) if it exists, null otherwise. */
public ConceptType getConceptType(int index){
if((index > 0) && (index <= this.conceptTypes.length)){
return this.conceptTypes[index - 1];
}
else return null;
}
public String toString(Language l){
String result = "(";
for(int i = 0;i < conceptTypes.length;i ++){
ConceptType ct = conceptTypes[i];
if(ct != null) result = result + ct.getTerm(l);
else result = result + CGConstants.UNDEFINED_ELEMENT;
if(i < (conceptTypes.length - 1)) result = result + ",";
else result = result + ")";
}
return result;
}
/** Returns true if the concept types linked by this relation type are the same than those
* linked by the given one. */
public boolean equals(Signature s){
if(this.getArity() == s.getArity()){
for(int i = 1;i <= this.getArity();i ++){
ConceptType ct1 = this.getConceptType(i);
ConceptType ct2 = s.getConceptType(i);
if(((ct1 == null) && (ct2 != null)) || ((ct1 != null) && (ct2 == null)) || ((ct1 != null) && (ct2 != null) && !ct1.equals(ct2))) return false;
}
return true;
}
else return false;
}
/** Return true if a subsomption link exists from this signature to the given one (this concept types
* linked by this signature are sort of concept types linked by s). */
public boolean isA(Signature s){
if(this.getArity() == s.getArity()){
for(int i = 1;i <= this.getArity();i ++){
if(!this.getConceptType(i).isA(s.getConceptType(i))) return false;
}
return true;
}
else return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -