long addCardinalityRestriction(OWLObjectCardinalityRestriction desc) { long restriction = getOrCreateNode(getIri(desc), OwlLabels.OWL_ANONYMOUS); graph.setNodeProperty(restriction, "cardinality", desc.getCardinality()); long property = getOrCreateNode(getIri(desc.getProperty())); getOrCreateRelationship(restriction, property, OwlRelationships.PROPERTY); long cls = getOrCreateNode(getIri(desc.getFiller())); getOrCreateRelationship(restriction, cls, OwlRelationships.CLASS); return restriction; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (!(obj instanceof OWLObjectCardinalityRestriction)) { return false; } return getProperty().equals( ((OWLObjectCardinalityRestriction) obj).getProperty()); }
@Override protected int compareObjectOfSameType(OWLObject object) { OWLObjectCardinalityRestriction other = (OWLObjectCardinalityRestriction) object; int diff = getProperty().compareTo(other.getProperty()); if (diff != 0) { return diff; } diff = getCardinality() - other.getCardinality(); if (diff != 0) { return diff; } return getFiller().compareTo(other.getFiller()); }
private void visitCardinalityRestriction(OWLObjectCardinalityRestriction cardinalityRestriction) { OWLClassExpression filler = cardinalityRestriction.getFiller(); OWLObjectPropertyExpression property = cardinalityRestriction.getProperty(); String fillerName, comperator; if (cardinalityRestriction instanceof OWLObjectMinCardinality) comperator = "<"; else if (cardinalityRestriction instanceof OWLObjectMaxCardinality) comperator = ">"; else comperator = "="; if (filler instanceof OWLObjectComplementOf){ OWLClassExpression operand = ((OWLObjectComplementOf) filler).getOperand(); fillerName = mapper.getPredicateName(((OWLObjectComplementOf) filler).getOperand().asOWLClass()); fillerName = ASP2CoreSymbols.NAF + " " + fillerName; if (isAuxiliaryClass(operand.asOWLClass())) auxClasses.add(operand.asOWLClass()); } else if (filler instanceof OWLObjectOneOf) { System.out.println("Shouldn't be here anymore"); //TODO: in case of a max-cardinality we will never end up within here, // since the normalization for max-cardinality uses an "optimization". OWLObjectOneOf oneOf = (OWLObjectOneOf) filler; OWLClass auxOneOf= getOneOfAuxiliaryClass(oneOf); fillerName = mapper.getPredicateName(auxOneOf); } else { assert filler instanceof OWLClass; fillerName = mapper.getPredicateName(filler.asOWLClass()); if (isAuxiliaryClass(filler.asOWLClass())) auxClasses.add(filler.asOWLClass()); } assert property instanceof OWLObjectProperty; boolean isInverseOf = false; if(property instanceof OWLObjectInverseOf) { isInverseOf = true; property = ((OWLObjectInverseOf) property).getInverse(); } else { } String propertyName = mapper.getPredicateName(property.asOWLObjectProperty()); String currentVar = var.currentVar(); String nextVar = var.nextVariable(); String classVar = nextVar; if (isInverseOf) { String temp = currentVar; currentVar = nextVar; nextVar = temp; } writer.print("#count{"); writer.print(classVar + "," + propertyName + ":"); writer.print(propertyName); writer.print(ASP2CoreSymbols.BRACKET_OPEN); writer.print(currentVar); writer.print(ASP2CoreSymbols.ARG_SEPERATOR); writer.print(nextVar); writer.print(ASP2CoreSymbols.BRACKET_CLOSE); writer.print(ASP2CoreSymbols.CONJUNCTION); writer.print(fillerName); writer.print(ASP2CoreSymbols.BRACKET_OPEN); writer.print(classVar); writer.print(ASP2CoreSymbols.BRACKET_CLOSE); writer.print("}" + comperator + cardinalityRestriction.getCardinality()); var.reset(); }