Skip to content

Commit 8adc706

Browse files
committed
exclude BNodes from being the result of a fix_var_mutation
BNodes are treated similar to unprojectable variables in SPARQL. Should a BNode be the result of a fix_var, it would just replace the projectable var with an unprojectable one, but have tricky implications later in simplify_pattern as BNodes would be seen as fixed nodes while from a SPARQL perspective they are not.
1 parent c02d892 commit 8adc706

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gp_learner.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import deap.base
3232
import deap.tools
3333
import numpy as np
34+
from rdflib import BNode
3435
from rdflib import Literal
3536
from rdflib import URIRef
3637
from rdflib import Variable
@@ -483,6 +484,10 @@ def mutate_fix_var_filter(item_counts):
483484
i
484485
)
485486
del item_counts[i]
487+
if isinstance(i, BNode):
488+
# make sure that BNodes stay variables
489+
logger.info('removed BNode from mutate_fix_var')
490+
del item_counts[i]
486491

487492

488493
@exception_stack_catcher
@@ -550,7 +555,7 @@ def mutate_simplify_pattern(gp):
550555
logger.debug('simplifying pattern\n%s', gp.to_sparql_select_query())
551556

552557
# remove parallel variable edges (single variables only)
553-
# e.g., [ :x, ?v1 ?y . :x ?v2 ?y. ]
558+
# e.g., [ :x ?v1 ?y . :x ?v2 ?y. ]
554559
identifier_counts = gp.identifier_counts()
555560
edges = gp.edges
556561
edge_vars = [edge for edge in edges if isinstance(edge, Variable)]
@@ -578,7 +583,6 @@ def mutate_simplify_pattern(gp):
578583

579584
# remove unrestricting leaf edges (single occurring vars only) and leaves
580585
# behind fixed nodes
581-
# FIXME: BNodes aren't fixed nodes
582586
# more explicit: such edges are
583587
# - single occurrence edge vars with a single occ gen var node,
584588
# so (x, ?vp, ?vn) or (?vn, ?vp, x)
@@ -616,6 +620,7 @@ def mutate_simplify_pattern(gp):
616620
# TODO: maybe remove disconnected components (relevance in reality?)
617621

618622
if len(gp) < 1:
623+
# for example: ?s ?v1 ?v2 .
619624
logger.info(
620625
'simplification of the following pattern resulted in empty pattern,'
621626
' returning original pattern:\n%s',

0 commit comments

Comments
 (0)