pynmms.rdf.closure¶
pynmms.rdf.closure
¶
Semi-naive closure of Horn rules over triples.
Two uses:
- :meth:
ClosureEngine.close-- full closure of a small graph (the in-memory backend's regime materialisation, and the test oracle's counterpart). - :meth:
ClosureEngine.extend-- the per-node step of a regime base: given a store that already holdscl_R(G)and a small set of extra triples (the atoms proof rules have moved into Γ), derivecl_R(G ∪ extras) \ cl_R(G)by firing only rules with at least one premise matching a new triple. Remaining premises are joined against the store's closure and the new set. Cost is proportional to the new triples and their joins, never to |G|.
Rules are range-restricted (def:entailmentregime), so every conclusion is ground.
Join = Callable[[list[Pattern], Bindings], Iterable[Bindings]]
module-attribute
¶
Answer several patterns at once against the store: all extensions of the given bindings that make every pattern a store triple. One round trip on a remote backend.
ClosureEngine
¶
Fires a regime's rules semi-naively.
Source code in src/pynmms/rdf/closure.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
close(triples)
¶
Full closure of triples under the regime, axioms included.
Source code in src/pynmms/rdf/closure.py
extend(extras, store_lookup, store_contains, store_join=None)
¶
Close store ∪ extras incrementally.
Returns the set of triples in the closure that are not in the store (the extras themselves included) and whether ⊥ was derived. With store_join the pattern rules batch their store-side premises into one query per firing (procedural rules still use store_lookup).
Source code in src/pynmms/rdf/closure.py
apply(pattern, b)
¶
Substitute b into pattern; unbound variables stay variables.
The result is loosely typed: callers narrow it with :func:is_ground
before treating it as a triple.
Source code in src/pynmms/rdf/closure.py
ground(pattern, b)
¶
Substitute b into a pattern every variable of which b binds.
Source code in src/pynmms/rdf/closure.py
instantiate(pattern, b)
¶
Substitute b into pattern as a lookup key; unbound variables become None.
Source code in src/pynmms/rdf/closure.py
is_ground(pattern)
¶
join_patterns(patterns, bindings, lookup)
¶
All extensions of bindings making every pattern a triple of lookup.
Source code in src/pynmms/rdf/closure.py
match_patterns(patterns, lookup)
¶
Find one instance mapping making every pattern a triple in lookup.
This is the witness search of lem:witnesschar: with the blank nodes of a
succedent graph H as variables, H is entailed iff some binding puts
all of μ(H) in the closure. Returns the binding or None.
Source code in src/pynmms/rdf/closure.py
order_patterns(patterns, bindings)
¶
Greedy join order: at each step the pattern with the most bound terms.
A pattern query such as ?b a C . ?b name "x" must start from the
name, which matches once, not from the class, which matches every member.
Source code in src/pynmms/rdf/closure.py
unify(pattern, t, bindings=None)
¶
Extend bindings so that pattern matches the ground triple t, or None.
A variable already bound to a different term fails the match; the input bindings are not modified.