Skip to content

Commit

Permalink
Fix performance regression in incremental reasoning. (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
balhoff authored Sep 29, 2024
1 parent 639b48d commit e502ef9
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@ object Reasoner {
if ranges.nonEmpty
} yield subprop -> (if (ranges.size == 1) ranges.head else ranges.reduce(Conjunction))
val rules = axioms.collect { case r: Rule => r }
val ruleSignature = rules.flatMap(_.signature).collect {
case ac: AtomicConcept => ConceptInclusion(ac, Top)
case i: Individual => ConceptInclusion(Nominal(i), Top)
}
val anonymousRulePredicates = rules.flatMap(_.body.collect {
case ConceptAtom(concept, _) if concept.isAnonymous => ConceptInclusion(concept, Top)
})
val concIncs = axioms.collect { case ci: ConceptInclusion => ci } ++ anonymousRulePredicates
val concIncs = axioms.collect { case ci: ConceptInclusion => ci } ++ anonymousRulePredicates ++ ruleSignature
val ruleEngine = RuleEngine(rules)
val wm = ruleEngine.emptyMemory
assert(concIncs, ReasonerState.empty.copy(hier = hier, hierList = hierList, hierComps = hierComps, roleRanges = roleRanges, ruleEngine = ruleEngine, wm = wm, queueDelegates = delegates, disableBottom = disableBottom))
}

def assert(axioms: Set[ConceptInclusion], reasoner: ReasonerState): ReasonerState = {
val ruleConcepts = reasoner.ruleEngine.rules.flatMap(_.signature).collect {
case ac: AtomicConcept => ac
case i: Individual => Nominal(i)
}
val distinctConcepts = axioms.flatMap {
case ConceptInclusion(subclass, superclass) => Set(subclass, superclass)
}.flatMap(_.conceptSignature)
Expand All @@ -163,7 +163,7 @@ object Reasoner {
}
val negativeSelfRestrictions = axioms.flatMap(_.subclass.conceptSignature).collect { case sr: SelfRestriction => sr.role -> sr }.toMap
val updatedAssertions = additionalAxioms.toList ::: axioms.toList
val todo = mutable.Stack.from[QueueExpression](ruleConcepts.toList ::: conceptsToQueue.toList ::: updatedAssertions)
val todo = mutable.Stack.from[QueueExpression](conceptsToQueue.toList ::: updatedAssertions)
computeClosure(reasoner.copy(
assertions = reasoner.assertions ::: updatedAssertions,
assertedNegativeSelfRestrictionsByRole = negativeSelfRestrictions),
Expand Down

0 comments on commit e502ef9

Please sign in to comment.