Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions brel/brel_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ def __init__(
self.__context: Context = context
self.__value: str = value

# first class citizens
# TODO think about this. is the id attribute an implementation detail?
def _get_id(self) -> str | None:
"""
:returns str|None: The id of the fact. Returns None if the fact does not have an id.
"""
return self.__id
"""[DEPRECATED] Use get_id() instead."""
return self.get_id()

def get_id(self) -> str | None:
"""
Expand All @@ -81,6 +77,10 @@ def get_value_as_str(self) -> str:
return self.__value

def get_value_as_int(self) -> int:
"""[DEPRECATED] Use int() instead."""
return int(self)

def __int__(self) -> int:
"""
:returns int: The value of the fact as an int
:raises ValueError: If the value of the fact does not resolve to an int
Expand All @@ -93,6 +93,10 @@ def get_value_as_int(self) -> int:
)

def get_value_as_float(self) -> float:
"""[DEPRECATED] Use float() instead."""
return float(self)

def __float__(self) -> float:
"""
:returns float: The value of the fact as a float
:raises ValueError: If the value of the fact does not resolve to a float
Expand All @@ -105,6 +109,10 @@ def get_value_as_float(self) -> float:
)

def get_value_as_bool(self) -> bool:
"""[DEPRECATED] Use bool() instead."""
return bool(self)

def __bool__(self) -> bool:
"""
:returns bool: The value of the fact as a bool
:raises ValueError: If the value of the fact does not resolve to a bool
Expand All @@ -115,7 +123,7 @@ def get_value_as_bool(self) -> bool:
return False
else:
raise ValueError(
f"Fact {self.__id} does not have a bool value. It has value {self.__value}, which does not resolve to a bool"
f"Fact {self.__id} does not have a bool value. It has value {self.__value}, which does not resolve to a bool."
)

def get_value(self) -> str:
Expand All @@ -125,9 +133,15 @@ def get_value(self) -> str:
return self.__value

def get_precision(self) -> float | None:
"""
:returns Any: The precision of the fact. Only applies to numeric facts.
"""
return self.__precision

def get_decimals(self) -> float | None:
"""
:returns Any: The decimals property of the fact. Only applies to numeric facts.
"""
return self.__decimals

def __str__(self) -> str:
Expand Down Expand Up @@ -202,6 +216,9 @@ def get_characteristic(self, aspect: Aspect) -> ICharacteristic | None:
"""
return self.__context.get_characteristic(aspect)

def __iter__(self):
return iter(self.convert_to_dict().items())

def convert_to_dict(
self,
languages: Optional[List[str]] = None,
Expand Down
2 changes: 1 addition & 1 deletion brel/parsers/XML/networks/xml_extended_link_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def parse_xml_link(
IResource | IReportElement | Fact
] = get_object_from_reference(link_element, context)

if not to_object:
if to_object is None:
continue

node_arcs = node_to_arcs[label]
Expand Down
Loading