Skip to content

Commit

Permalink
Fixed global variables issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bhorinrb committed Dec 19, 2024
1 parent ab0873a commit 89bf751
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/yatter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

def translate(yarrrml_data, mapping_format=RML_URI):
logger.info("Translating YARRRML mapping to [R2]RML")
added_sources = {}
added_targets = {}
yarrrml_data = normalize(yarrrml_data, added_sources, added_targets)
rml_mapping = [add_prefix(yarrrml_data)]
rml_mapping.extend(generate_database_connections(yarrrml_data))
rml_mapping.extend(add_logical_targets(yarrrml_data))
rml_mapping.extend(generate_database_connections(yarrrml_data, added_sources))
rml_mapping.extend(add_logical_targets(yarrrml_data, added_targets))
rml_mapping.extend(add_functions(yarrrml_data))

try:
Expand All @@ -24,7 +26,7 @@ def translate(yarrrml_data, mapping_format=RML_URI):
if mapping_format == R2RML_URI:
source_list = add_table(yarrrml_data, mapping)
else:
source_list = add_source(yarrrml_data, mapping)
source_list = add_source(yarrrml_data, mapping, added_sources)
subject_list = add_subject(yarrrml_data, mapping, mapping_format)
pred = add_predicate_object_maps(yarrrml_data, mapping, mapping_format)
it = 0
Expand Down
2 changes: 0 additions & 2 deletions src/yatter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,3 @@

logger = logging.getLogger(__name__)
coloredlogs.install(level='DEBUG', fmt='%(asctime)s,%(msecs)03d | %(levelname)s: %(message)s')

added_sources, added_targets = {}, {}
5 changes: 2 additions & 3 deletions src/yatter/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import rdflib
from .constants import *
from ruamel.yaml import YAML
from .constants import added_sources, added_targets




def add_source(data, mapping):
def add_source(data, mapping, added_sources={}):
source_template = "\t" + RML_LOGICAL_SOURCE + " [\n\t\ta " + RML_LOGICAL_SOURCE_CLASS + \
";\n\t\t" + RML_SOURCE + " "
final_list = []
Expand Down Expand Up @@ -142,7 +141,7 @@ def switch_in_reference_formulation(value, source_extension=None):
return switcher


def generate_database_connections(data):
def generate_database_connections(data, added_sources):
database = []
for mapping in data.get(YARRRML_MAPPINGS):
sources = data.get(YARRRML_MAPPINGS).get(mapping).get(YARRRML_SOURCES)
Expand Down
10 changes: 5 additions & 5 deletions src/yatter/target.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from .constants import *


def add_logical_targets(yarrrml_data):
def add_logical_targets(yarrrml_data, added_targets):
logical_targets = []
for target in added_targets:
logical_targets.extend(generate_added_logical_target(added_targets.get(target), target))
for mapping in yarrrml_data.get(YARRRML_MAPPINGS):
mapping_data = yarrrml_data.get(YARRRML_MAPPINGS).get(mapping)
add_internal_logical_target(mapping, mapping_data, logical_targets)
add_internal_logical_target(mapping, mapping_data, logical_targets, added_targets)
return logical_targets


def add_internal_logical_target(mapping_id, mapping_data, internal_targets, local_target_id=0):
def add_internal_logical_target(mapping_id, mapping_data, internal_targets, added_targets, local_target_id=0):
keys = mapping_data.keys()
for key in keys:
if type(mapping_data[key]) is list:
Expand All @@ -35,9 +35,9 @@ def add_internal_logical_target(mapping_id, mapping_data, internal_targets, loca
if type(value) is list:
for v in value:
if type(v) is dict:
add_internal_logical_target(mapping_id, v, internal_targets, local_target_id)
add_internal_logical_target(mapping_id, v, internal_targets, added_targets,local_target_id)
elif type(value) is dict:
add_internal_logical_target(mapping_id, value, internal_targets, local_target_id)
add_internal_logical_target(mapping_id, value, internal_targets, added_targets,local_target_id)
elif YARRRML_TARGETS in mapping_data[key]:
target_value = mapping_data[key][YARRRML_TARGETS]
logical_target_id = "logical_target_" + mapping_id + "_" + str(local_target_id)
Expand Down

0 comments on commit 89bf751

Please sign in to comment.