NeuroLang / NeuroLang

Neurolang enables the analysis of NeuroImaging data through probabilistic logic programming. It seamlessly allow to combine, images, databases, and ontologies within a single framework.
BSD 3-Clause "New" or "Revised" License
6 stars 11 forks source link

Projection on attributes represented as Symbol #235

Closed tgy closed 4 years ago

tgy commented 4 years ago

In the following self-contained example, I try to apply a projection where the attributes are defined as a tuple of Symbols.

from typing import AbstractSet

from neurolang.expressions import Constant, Symbol
from neurolang.utils.relational_algebra_set import (
    NamedRelationalAlgebraFrozenSet,
)
from neurolang.relational_algebra import RelationalAlgebraSolver, Projection

relation = Constant[AbstractSet](
    NamedRelationalAlgebraFrozenSet(
        iterable=[("a", "b"), ("c", "d")], columns=["x", "y"]
    )
)
proj = Projection(relation, (Symbol("x"),))
solver = RelationalAlgebraSolver()
result = solver.walk(proj)

However, this doesn't work and yield the following error

Traceback (most recent call last):
  File "/tmp/test.py", line 17, in <module>
    result = solver.walk(proj)
  File "/Users/viovene/p/neurolang/neurolang/expression_walker.py", line 110, in walk
    return self.match(expression)
  File "/Users/viovene/p/neurolang/neurolang/expression_pattern_matching.py", line 295, in match
    result_expression = action(self, expression)
  File "/Users/viovene/p/neurolang/neurolang/relational_algebra.py", line 185, in ra_projection
    cols = tuple(v.value for v in projection.attributes)
  File "/Users/viovene/p/neurolang/neurolang/relational_algebra.py", line 185, in <genexpr>
    cols = tuple(v.value for v in projection.attributes)
  File "/Users/viovene/p/neurolang/neurolang/expressions.py", line 254, in __getattr__
    return object.__getattribute__(self, attr)
AttributeError: 'Symbol' object has no attribute 'value'

because the current implementation relies on the attributes being Constant[str].

Is this expected behaviour? If so, what is the general rule of when to use Symbol or Constant[str] when defining RA operations on the attributes of the relation?

tgy commented 4 years ago

The solution should be to use Constant(ColumnStr('my_column')) instead