}
protected Automaton buildCompleteAutomataForProperties(OWLObjectPropertyExpression propertyToBuildAutomatonFor,Map<OWLObjectPropertyExpression,Set<OWLObjectPropertyExpression>> inversePropertiesMap,Map<OWLObjectPropertyExpression,Automaton> individualAutomata,Map<OWLObjectPropertyExpression,Automaton> completeAutomata,Graph<OWLObjectPropertyExpression> inversedPropertyDependencyGraph, Set<OWLObjectPropertyExpression> symmetricObjectProperties, Set<OWLObjectPropertyExpression> transitiveProperties) {
if (completeAutomata.containsKey(propertyToBuildAutomatonFor))
return completeAutomata.get(propertyToBuildAutomatonFor);
else if (completeAutomata.containsKey(propertyToBuildAutomatonFor.getInverseProperty().getSimplified()) && !individualAutomata.containsKey(propertyToBuildAutomatonFor)) {
Automaton mirroredCopy=getMirroredCopy(completeAutomata.get(propertyToBuildAutomatonFor.getInverseProperty().getSimplified()));
completeAutomata.put(propertyToBuildAutomatonFor,mirroredCopy);
return mirroredCopy;
}
//if the role has no sub-role which is complex and we need to completely construct its automaton
if (inversedPropertyDependencyGraph.getSuccessors(propertyToBuildAutomatonFor).isEmpty()) {
Automaton automatonForLeafProperty=individualAutomata.get(propertyToBuildAutomatonFor);
//if the individual automaton for the role is empty
if (automatonForLeafProperty==null) {
Set<OWLObjectPropertyExpression> inverses=inversePropertiesMap.get(propertyToBuildAutomatonFor);
boolean noInversePropertyWithAutomaton=true;
//if it has declared inverse roles
if (inverses!=null) {
for (OWLObjectPropertyExpression inverse : inverses)
if (individualAutomata.containsKey(inverse) && !inverse.equals(propertyToBuildAutomatonFor)) {
automatonForLeafProperty=getMirroredCopy(buildCompleteAutomataForProperties(inverse,inversePropertiesMap,individualAutomata,completeAutomata,inversedPropertyDependencyGraph, symmetricObjectProperties,transitiveProperties));
automatonForLeafProperty=minimizeAndNormalizeAutomaton(automatonForLeafProperty);
completeAutomata.put(propertyToBuildAutomatonFor,automatonForLeafProperty);
noInversePropertyWithAutomaton=false;
break;
}
}
//else if Inv(R) has an automaton
else if (individualAutomata.containsKey(propertyToBuildAutomatonFor.getInverseProperty().getSimplified())) {
automatonForLeafProperty=getMirroredCopy(buildCompleteAutomataForProperties(propertyToBuildAutomatonFor.getInverseProperty().getSimplified(),inversePropertiesMap,individualAutomata,completeAutomata,inversedPropertyDependencyGraph,symmetricObjectProperties,transitiveProperties));
if (!completeAutomata.containsKey(propertyToBuildAutomatonFor)) {
automatonForLeafProperty=minimizeAndNormalizeAutomaton(automatonForLeafProperty);
completeAutomata.put(propertyToBuildAutomatonFor,automatonForLeafProperty);
}
else
automatonForLeafProperty=completeAutomata.get(propertyToBuildAutomatonFor);
noInversePropertyWithAutomaton=false;
}
//if no inverse (either declared or Inv(R)) has an automaton
if (noInversePropertyWithAutomaton) {
automatonForLeafProperty=new Automaton();
State initial=automatonForLeafProperty.addState(true,false);
State accepting=automatonForLeafProperty.addState(false,true);
try {
automatonForLeafProperty.addTransition(new Transition(initial,propertyToBuildAutomatonFor,accepting));
}
catch (NoSuchStateException e) {
throw new IllegalArgumentException("Could not create automaton for property at the bottom of hierarchy (simple property).");
}
finalizeConstruction(completeAutomata,propertyToBuildAutomatonFor,automatonForLeafProperty,symmetricObjectProperties,transitiveProperties);
}
}
else {
if (propertyToBuildAutomatonFor.getInverseProperty().getSimplified().isAnonymous() && individualAutomata.containsKey(propertyToBuildAutomatonFor.getInverseProperty().getSimplified())) {
Automaton inversePropertyAutomaton=buildCompleteAutomataForProperties(propertyToBuildAutomatonFor.getInverseProperty().getSimplified(),inversePropertiesMap,individualAutomata,completeAutomata,inversedPropertyDependencyGraph,symmetricObjectProperties,transitiveProperties);
increaseAutomatonWithInversePropertyAutomaton(automatonForLeafProperty,getMirroredCopy(inversePropertyAutomaton));
if (!completeAutomata.containsKey(propertyToBuildAutomatonFor))
finalizeConstruction(completeAutomata,propertyToBuildAutomatonFor,automatonForLeafProperty,symmetricObjectProperties,transitiveProperties);
else
automatonForLeafProperty=completeAutomata.get(propertyToBuildAutomatonFor);
}
else {
increaseWithDefinedInverseIfNecessary(propertyToBuildAutomatonFor,automatonForLeafProperty,inversePropertiesMap,individualAutomata);
finalizeConstruction(completeAutomata,propertyToBuildAutomatonFor,automatonForLeafProperty,symmetricObjectProperties,transitiveProperties);
}
}
return automatonForLeafProperty;
}
else {
Automaton biggerPropertyAutomaton=individualAutomata.get(propertyToBuildAutomatonFor);
if (biggerPropertyAutomaton==null) {
biggerPropertyAutomaton=new Automaton();
State initialState=biggerPropertyAutomaton.addState(true,false);
State finalState=biggerPropertyAutomaton.addState(false,true);
Transition transition=new Transition(initialState,propertyToBuildAutomatonFor,finalState);
try {
biggerPropertyAutomaton.addTransition(transition);
}
catch (NoSuchStateException e) {
throw new IllegalArgumentException("Could not create automaton");
}
for (OWLObjectPropertyExpression smallerProperty : inversedPropertyDependencyGraph.getSuccessors(propertyToBuildAutomatonFor)) {
Automaton smallerPropertyAutomaton=buildCompleteAutomataForProperties(smallerProperty,inversePropertiesMap,individualAutomata,completeAutomata,inversedPropertyDependencyGraph,symmetricObjectProperties,transitiveProperties);
automataConnector(biggerPropertyAutomaton,smallerPropertyAutomaton,transition);
try {
biggerPropertyAutomaton.addTransition(new Transition(initialState,smallerProperty,finalState));
}
catch (NoSuchStateException e) {
throw new IllegalArgumentException("Could not create automaton");
}
}
if (propertyToBuildAutomatonFor.getInverseProperty().getSimplified().isAnonymous() && individualAutomata.containsKey(propertyToBuildAutomatonFor.getInverseProperty().getSimplified())) {
Automaton inversePropertyAutomaton=buildCompleteAutomataForProperties(propertyToBuildAutomatonFor.getInverseProperty().getSimplified(),inversePropertiesMap,individualAutomata,completeAutomata,inversedPropertyDependencyGraph,symmetricObjectProperties,transitiveProperties);
increaseAutomatonWithInversePropertyAutomaton(biggerPropertyAutomaton,getMirroredCopy(inversePropertyAutomaton));
if (!completeAutomata.containsKey(propertyToBuildAutomatonFor))
finalizeConstruction(completeAutomata,propertyToBuildAutomatonFor,biggerPropertyAutomaton,symmetricObjectProperties,transitiveProperties);
else
biggerPropertyAutomaton=completeAutomata.get(propertyToBuildAutomatonFor);
}
else {
increaseWithDefinedInverseIfNecessary(propertyToBuildAutomatonFor,biggerPropertyAutomaton,inversePropertiesMap,individualAutomata);
if (!completeAutomata.containsKey(propertyToBuildAutomatonFor))
finalizeConstruction(completeAutomata,propertyToBuildAutomatonFor,biggerPropertyAutomaton,symmetricObjectProperties,transitiveProperties);
else
biggerPropertyAutomaton=completeAutomata.get(propertyToBuildAutomatonFor);
}
}
else {
for (OWLObjectPropertyExpression smallerProperty : inversedPropertyDependencyGraph.getSuccessors(propertyToBuildAutomatonFor)) {
boolean someInternalTransitionMatched=false;
for (Object transitionObject : biggerPropertyAutomaton.delta()) {
Transition transition=(Transition)transitionObject;
if (transition.label()!=null && transition.label().equals(smallerProperty)) {
Automaton smallerPropertyAutomaton=buildCompleteAutomataForProperties(smallerProperty,inversePropertiesMap,individualAutomata,completeAutomata,inversedPropertyDependencyGraph,symmetricObjectProperties,transitiveProperties);
if (smallerPropertyAutomaton.delta().size()!=1)
automataConnector(biggerPropertyAutomaton,smallerPropertyAutomaton,transition);
someInternalTransitionMatched=true;
}
}
if (!someInternalTransitionMatched) {
Automaton smallerPropertyAutomaton=buildCompleteAutomataForProperties(smallerProperty,inversePropertiesMap,individualAutomata,completeAutomata,inversedPropertyDependencyGraph,symmetricObjectProperties,transitiveProperties);
Transition initial2TerminalTransition=(Transition)biggerPropertyAutomaton.deltaFrom((State)biggerPropertyAutomaton.initials().iterator().next(),(State)biggerPropertyAutomaton.terminals().iterator().next()).iterator().next();
automataConnector(biggerPropertyAutomaton,smallerPropertyAutomaton,initial2TerminalTransition);
}
}
}
if (propertyToBuildAutomatonFor.getInverseProperty().getSimplified().isAnonymous() && individualAutomata.containsKey(propertyToBuildAutomatonFor.getInverseProperty().getSimplified())) {
Automaton inversePropertyAutomaton=buildCompleteAutomataForProperties(propertyToBuildAutomatonFor.getInverseProperty().getSimplified(),inversePropertiesMap,individualAutomata,completeAutomata,inversedPropertyDependencyGraph,symmetricObjectProperties,transitiveProperties);
increaseAutomatonWithInversePropertyAutomaton(biggerPropertyAutomaton,getMirroredCopy(inversePropertyAutomaton));
if (!completeAutomata.containsKey(propertyToBuildAutomatonFor))
finalizeConstruction(completeAutomata,propertyToBuildAutomatonFor,biggerPropertyAutomaton,symmetricObjectProperties,transitiveProperties);
else
biggerPropertyAutomaton=completeAutomata.get(propertyToBuildAutomatonFor);