segmentation.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,418 行 · 第 1/4 页
JAVA
1,418 行
}
return result;
}
public OWLObject makePropositional(OWLPropertyAxiom ax) throws OWLException, URISyntaxException{
OWLDataFactory df = source.getOWLDataFactory();
OWLObject axiom = null;
if (ax instanceof OWLSubPropertyAxiom){
OWLDescription sub = df.getOWLClass(((OWLSubPropertyAxiom)ax).getSubProperty().getURI());
OWLDescription sup = df.getOWLClass(((OWLSubPropertyAxiom)ax).getSuperProperty().getURI());
axiom = df.getOWLSubClassAxiom(sub,sup);
}
if(ax instanceof OWLEquivalentPropertiesAxiom){
Set eqProperties = new HashSet();
eqProperties = ((OWLEquivalentPropertiesAxiom)ax).getProperties();
Set eqClasses = new HashSet();
Iterator iter = eqProperties.iterator();
while(iter.hasNext()){
OWLProperty prop = (OWLProperty)iter.next();
OWLClass cl = df.getOWLClass(prop.getURI());
eqClasses.add(cl);
}
axiom = df.getOWLEquivalentClassesAxiom(eqClasses);
}
if(ax instanceof OWLInversePropertyAxiom){
OWLObjectProperty prop = ((OWLInversePropertyAxiom)ax).getProperty();
OWLObjectProperty inv = ((OWLInversePropertyAxiom)ax).getInverseProperty();
Set eqClasses = new HashSet();
eqClasses.add(df.getOWLClass(prop.getURI()));
eqClasses.add(df.getOWLClass(inv.getURI()));
axiom = df.getOWLEquivalentClassesAxiom(eqClasses);
}
if (ax instanceof OWLFunctionalPropertyAxiom){
OWLDescription sub = df.getOWLClass(((OWLFunctionalPropertyAxiom)ax).getProperty().getURI());
OWLDescription sup = df.getOWLNot(sub);
axiom = df.getOWLSubClassAxiom(sub,sup);
}
//if (ax instanceof OWLInverseFunctionalPropertyAxiom){
//OWLDescription sub = df.getOWLClass(((OWLInverseFunctionalPropertyAxiom)ax).getProperty().getURI());
//OWLDescription sup = df.getOWLNothing();
//axiom = df.getOWLSubClassAxiom(sub,sup);
//}
return axiom;
}
public OWLObject makePropositional(OWLClassAxiom ax) throws OWLException, URISyntaxException{
OWLDataFactory df = source.getOWLDataFactory();
OWLObject axiom = null;
if (ax instanceof OWLSubClassAxiom){
OWLDescription sup = makePropositional(((OWLSubClassAxiom)ax).getSuperClass());
OWLDescription sub = makePropositional(((OWLSubClassAxiom)ax).getSubClass());
axiom = source.getOWLDataFactory().getOWLSubClassAxiom(sub,sup);
}
if (ax instanceof OWLEquivalentClassesAxiom ){
Set eqclasses = makePropositional(((OWLEquivalentClassesAxiom)ax).getEquivalentClasses());
axiom = source.getOWLDataFactory().getOWLEquivalentClassesAxiom(eqclasses);
}
if (ax instanceof OWLDisjointClassesAxiom){
Set disjointclasses = makePropositional(((OWLDisjointClassesAxiom)ax).getDisjointClasses());
axiom = source.getOWLDataFactory().getOWLDisjointClassesAxiom(disjointclasses);
}
return axiom;
}
public OWLClassAxiom replaceBottom(OWLClassAxiom ax, Set sig) throws OWLException, URISyntaxException{
OWLClassAxiom axiom = null;
if (ax instanceof OWLSubClassAxiom){
OWLDescription sup = replaceBottom(((OWLSubClassAxiom)ax).getSuperClass(), sig);
OWLDescription sub = replaceBottom(((OWLSubClassAxiom)ax).getSubClass(), sig);
axiom = source.getOWLDataFactory().getOWLSubClassAxiom(sub,sup);
}
if (ax instanceof OWLEquivalentClassesAxiom ){
Set eqclasses = replaceBottom(((OWLEquivalentClassesAxiom)ax).getEquivalentClasses(), sig);
axiom = source.getOWLDataFactory().getOWLEquivalentClassesAxiom(eqclasses);
}
if (ax instanceof OWLDisjointClassesAxiom){
Set disjointclasses = replaceBottom(((OWLDisjointClassesAxiom)ax).getDisjointClasses(), sig);
axiom = source.getOWLDataFactory().getOWLDisjointClassesAxiom(disjointclasses);
}
return axiom;
}
public boolean checkLocality(OWLPropertyAxiom ax, Set foreign) throws OWLException{
if (ax instanceof OWLSubPropertyAxiom){
if(!dualRoles && !foreign.contains(((OWLSubPropertyAxiom)ax).getSubProperty()))
return true;
if(dualRoles && !foreign.contains(((OWLSubPropertyAxiom)ax).getSuperProperty()))
return true;
}
if (ax instanceof OWLEquivalentPropertiesAxiom){
Set eqproperties = ((OWLEquivalentPropertiesAxiom)ax).getProperties();
Iterator i = eqproperties.iterator();
while(i.hasNext()){
OWLProperty prop = (OWLProperty)i.next();
if(foreign.contains(prop)){
return false;
}
}
return true;
}
if (ax instanceof OWLFunctionalPropertyAxiom){
if(!foreign.contains(((OWLFunctionalPropertyAxiom)ax).getProperty()) &&!dualRoles)
return true;
}
if (ax instanceof OWLInverseFunctionalPropertyAxiom){
if(!foreign.contains(((OWLInverseFunctionalPropertyAxiom)ax).getProperty()) &&!dualRoles)
return true;
}
if(ax instanceof OWLTransitivePropertyAxiom){
if(!foreign.contains(((OWLTransitivePropertyAxiom)ax).getProperty() ))
return true;
}
if(ax instanceof OWLSymmetricPropertyAxiom){
if(!foreign.contains(((OWLTransitivePropertyAxiom)ax).getProperty() ))
return true;
}
if(ax instanceof OWLInversePropertyAxiom){
if(!foreign.contains(((OWLInversePropertyAxiom)ax).getProperty()) &&
!foreign.contains(((OWLInversePropertyAxiom)ax).getInverseProperty() ) )
return true;
}
if(ax instanceof OWLPropertyDomainAxiom){
if(isNegativelyLocal(((OWLPropertyDomainAxiom)ax).getDomain(),foreign))
return true;
if(!foreign.contains(((OWLPropertyDomainAxiom)ax).getProperty())&& !dualRoles)
return true;
}
if(ax instanceof OWLObjectPropertyRangeAxiom){
if(isNegativelyLocal(((OWLObjectPropertyRangeAxiom)ax).getRange(),foreign))
return true;
else{
if(!foreign.contains(((OWLObjectPropertyRangeAxiom)ax).getProperty()) && !dualRoles)
return true;
}
}
if(ax instanceof OWLDataPropertyRangeAxiom){
if(!foreign.contains(((OWLDataPropertyRangeAxiom)ax).getProperty()) && !dualRoles)
return true;
}
return false;
}
/*
public void saveAxiom(OWLClassAxiom ax, String path) throws OWLException, FileNotFoundException, IOException{
OWLOntBuilder ob = new OWLOntBuilder();
ax.accept(ob);
OWLOntology temp = ob.currentOnt;
saveOntologyToDisk(temp, path);
}
*/
public boolean isPositivelyLocal(OWLDescription desc, Set foreign) throws OWLException{
if(desc.equals(this.nothing))
return true;
if (desc instanceof OWLClass){
if (!foreign.contains(desc) && !dualConcepts)
return true;
}
if(desc instanceof OWLDataSomeRestriction){
if(!foreign.contains(((OWLObjectSomeRestriction)desc).getProperty()) && !dualRoles)
return true;
}
if(desc instanceof OWLDataAllRestriction){
if(!foreign.contains(((OWLDataAllRestriction)desc).getProperty() )&&
dualRoles)
return true;
}
if(desc instanceof OWLObjectSomeRestriction){
if(isPositivelyLocal(((OWLObjectSomeRestriction)desc).getDescription(),foreign))
return true;
else{
if(!foreign.contains(((OWLObjectSomeRestriction)desc).getProperty()) && !dualRoles)
return true;
}
}
if(desc instanceof OWLObjectAllRestriction){
if(isPositivelyLocal(((OWLObjectAllRestriction)desc).getDescription(),foreign) &&
!foreign.contains(((OWLObjectAllRestriction)desc).getProperty() )&&
dualRoles)
return true;
}
if (desc instanceof OWLCardinalityRestriction)
{
try {
if(((OWLCardinalityRestriction)desc).isAtMost()){
if(dualRoles &&
!foreign.contains(((OWLCardinalityRestriction)desc).getProperty()))
return true;
}
if(((OWLCardinalityRestriction)desc).isAtLeast()){
if(!dualRoles &&
!foreign.contains(((OWLCardinalityRestriction)desc).getProperty()))
return true;
}
if(((OWLCardinalityRestriction)desc).isExactly()){
if(!foreign.contains(((OWLCardinalityRestriction)desc).getProperty()))
return true;
}
} catch (OWLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (desc instanceof OWLNot){
try {
if(this.isNegativelyLocal(((OWLNot)desc).getOperand(), foreign))
return true;
} catch (OWLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//At least one conjunct must be local
if (desc instanceof OWLAnd){
Iterator iter;
try {
iter = ((OWLAnd)desc).getOperands().iterator();
while(iter.hasNext()){
OWLDescription conjunct = (OWLDescription)iter.next();
if (this.isPositivelyLocal(conjunct, foreign))
return true;
}
} catch (OWLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
//All disjuncts must be local
if (desc instanceof OWLOr){
Iterator iter;
try {
iter = ((OWLOr)desc).getOperands().iterator();
while(iter.hasNext()){
OWLDescription disjunct = (OWLDescription)iter.next();
if (!(this.isPositivelyLocal(disjunct, foreign)))
return false;
}
return true;
} catch (OWLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
return false;
}
public boolean checkLocalityTrivial(OWLClassAxiom ax, Set sig, boolean dualConcepts, boolean dualRoles){
return false;
}
////////////////////////////////
public boolean isNegativelyLocal(OWLDescription desc, Set foreign) throws OWLException {
////////////////////////////////
if(desc.equals(this.thing))
return true;
if(desc instanceof OWLClass){
if(dualConcepts && !foreign.contains(desc))
return true;
}
if(desc instanceof OWLObjectSomeRestriction){
if(isNegativelyLocal(((OWLObjectSomeRestriction)desc).getDescription(),foreign) &&
!foreign.contains(((OWLObjectSomeRestriction)desc).getProperty() )&&
dualRoles)
return true;
}
if(desc instanceof OWLObjectAllRestriction){
if(isNegativelyLocal(((OWLObjectAllRestriction)desc).getDescription(),foreign))
return true;
else{
if(!foreign.contains(((OWLObjectAllRestriction)desc).getProperty()) && !dualRoles)
return true;
}
}
if (desc instanceof OWLCardinalityRestriction)
{
try {
if(((OWLCardinalityRestriction)desc).isAtLeast()){
if(dualRoles &&
!foreign.contains(((OWLCardinalityRestriction)desc).getProperty()))
return true;
}
if(((OWLCardinalityRestriction)desc).isAtMost()){
if(!dualRoles &&
!foreign.contains(((OWLCardinalityRestriction)desc).getProperty()))
return true;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?