Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yatter2 #1

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
00adfd8
Added poetry config file and changes in normalization
bhorinrb Oct 3, 2024
d1abc40
Testing poetry
bhorinrb Oct 14, 2024
0c9ab82
Test poetry
bhorinrb Oct 14, 2024
2b186e6
Testing poetry
bhorinrb Oct 24, 2024
28a2127
Testing poetry
bhorinrb Oct 24, 2024
4dfc41a
Testing poetry
bhorinrb Oct 28, 2024
81509d3
Added tests
bhorinrb Oct 29, 2024
b20ad4e
Testing poetry
bhorinrb Oct 30, 2024
36e8c57
Testing poetry
bhorinrb Oct 30, 2024
3afb790
Testing normalization
bhorinrb Nov 7, 2024
d113f67
Simplifying code
bhorinrb Nov 27, 2024
6c43f1d
Patching code
bhorinrb Dec 2, 2024
aeb5e6c
Changed log errors
bhorinrb Dec 3, 2024
78999c3
Updated Predicateobject maps
bhorinrb Dec 5, 2024
ef667da
Solved errors
bhorinrb Dec 5, 2024
56f1bd6
Solved errors with error management
bhorinrb Dec 6, 2024
1d9ad8a
Solved errors on translate
bhorinrb Dec 10, 2024
cf60093
Deleting unused constants
bhorinrb Dec 11, 2024
3bdcd64
Simplifying code
bhorinrb Dec 11, 2024
a509185
Fixed targets errors
bhorinrb Dec 11, 2024
13d1b3c
Fixed errors
bhorinrb Dec 11, 2024
294b1dc
Fixed errors
bhorinrb Dec 11, 2024
ca24f92
Fixed errors in subjects content
bhorinrb Dec 12, 2024
0a550d0
Adding first cc test-cases
dachafra Dec 13, 2024
564a233
Adding seconds cc test-cases
dachafra Dec 13, 2024
27e718c
Adding third set of cc test-cases
dachafra Dec 13, 2024
f5711c7
renaming folders
dachafra Dec 14, 2024
f9dedfe
Fixed source structure
bhorinrb Dec 17, 2024
ab0873a
Fixed targets structure
bhorinrb Dec 18, 2024
89bf751
Fixed global variables issues
bhorinrb Dec 19, 2024
b69f3c5
Simplified code
bhorinrb Dec 19, 2024
cb55dd9
solving some typos in the output mappings
dachafra Dec 19, 2024
e8b1faf
Fixed python version
bhorinrb Dec 19, 2024
c77ce80
Simplified normalize code
bhorinrb Dec 19, 2024
ac545fe
Simplified code
bhorinrb Dec 24, 2024
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
9 changes: 4 additions & 5 deletions .github/workflows/testgha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel pytest DeepDiff
pip install -r requirements.txt
pip install poetry
poetry update
- name: Build yatter
run: |
cd src
pip install .
poetry install --with test
- name: Test with pytest
run: |
pytest
poetry run pytest
22 changes: 21 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,24 @@
lib/__pychache__
.idea
venv
.pytest_cache
.pytest_cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be removed, just add src/yatter/pycache

tempReadme.md
src/yatter/__pycache__/termmap.cpython-311.pyc
src/yatter/__pycache__/target.cpython-311.pyc
src/yatter/__pycache__/subject.cpython-311.pyc
src/yatter/__pycache__/source.cpython-311.pyc
src/yatter/__pycache__/predicateobject.cpython-311.pyc
src/yatter/__pycache__/normalization.cpython-311.pyc
src/yatter/__pycache__/mapping.cpython-311.pyc
src/yatter/__pycache__/graph.cpython-311.pyc
src/yatter/__pycache__/function.cpython-311.pyc
src/yatter/__pycache__/constants.cpython-311.pyc
src/yatter/__pycache__/__main__.cpython-311.pyc
src/yatter/__pycache__/__init__.cpython-311.pyc
src/yatter/__init__.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this ignored?

test/normalize/NORMKEYS-01/mapping_normalized.yml
test/normalize/NORMKEYS-01/mapping.yml
mapping.rml.ttl
test/rml-io/YARRRMLTC-0036/__pycache__/test_yarrrmltc0036.cpython-311-pytest-8.3.3.pyc
*.pyc
/src/outputNEW.ttl
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[tool.poetry]
name = "yatter"
version = "1.1.4"
description = "The tool translates mapping rules from YARRRML in a turtle-based serialization of RML or R2RML."
authors = ["David Chaves <[email protected]>", "Rubén Buján <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.8"
ruamel-yaml = "^0.17.21"
rdflib = "^6.2.0"
coloredlogs = "^15.0.1"

[tool.poetry.group.test.dependencies]
pytest = "^8.3.3"
setuptools = "^75.1.0"
wheel = "^0.44.0"
DeepDiff = "^8.0.1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


17 changes: 10 additions & 7 deletions src/yatter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
from .constants import *
from .mapping import add_prefix, add_mapping, add_inverse_prefix, get_non_asserted_mappings, merge_mapping_section_by_key
from .source import get_initial_sources, add_source, generate_database_connections, add_table, add_inverse_source
from .source import add_source, generate_database_connections, add_table, add_inverse_source
from .subject import add_subject, add_inverse_subject
from .predicateobject import add_predicate_object_maps, add_inverse_pom
from .target import add_logical_targets
from .function import add_functions
from .normalization import normalize
import rdflib
import ruamel.yaml as yaml


def translate(yarrrml_data, mapping_format=RML_URI):
logger.info("Translating YARRRML mapping to [R2]RML")

list_initial_sources = get_initial_sources(yarrrml_data)
external_sources = {}
external_targets = {}
yarrrml_data = normalize(yarrrml_data, external_sources, external_targets)
rml_mapping = [add_prefix(yarrrml_data)]
rml_mapping.extend(generate_database_connections(yarrrml_data, list_initial_sources))
rml_mapping.extend(add_logical_targets(yarrrml_data))
rml_mapping.extend(generate_database_connections(yarrrml_data, external_sources))
rml_mapping.extend(add_logical_targets(yarrrml_data, external_targets))
rml_mapping.extend(add_functions(yarrrml_data))

try:
mappings, mapping_format = get_non_asserted_mappings(yarrrml_data, mapping_format)
for mapping in yarrrml_data.get(YARRRML_MAPPINGS):
if mapping_format == R2RML_URI:
source_list = add_table(yarrrml_data, mapping, list_initial_sources)
source_list = add_table(yarrrml_data, mapping)
else:
source_list = add_source(yarrrml_data, mapping, list_initial_sources)
source_list = add_source(yarrrml_data, mapping, external_sources)
subject_list = add_subject(yarrrml_data, mapping, mapping_format)
pred = add_predicate_object_maps(yarrrml_data, mapping, mapping_format)
it = 0
Expand Down
42 changes: 14 additions & 28 deletions src/yatter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@

YARRRML_PREFIXES = 'prefixes'
YARRRML_SOURCES = 'sources'
YARRRML_SOURCE = 'source'
YARRRML_TABLE = 'table'
YARRRML_ACCESS = 'access'
YARRRML_QUERY = 'query'
Expand All @@ -124,35 +123,25 @@

YARRRML_MAPPINGS = 'mappings' # used for mappings in conditions and mappings main key
YARRRML_MAPPING = 'mapping'
YARRRRL_MAPPINGS_SHORTCUT = 'm'

YARRRML_SUBJECTS_SHORTCUT = 's'
YARRRML_SUBJECT = 'subject'
YARRRML_SUBJECTS = 'subjects'

YARRRML_AUTHORS = 'authors'
YARRRML_GRAPHS = 'graphs'
YARRRML_GRAPH = 'graph'
YARRRML_GRAPH_SHORTCUT = 'g'

YARRRML_PREDICATEOBJECT = 'predicateobjects'
YARRRML_PREDICATEOBJECT_SHORTCUT = 'po'
YARRRML_PREDICATEOBJECT_SHORTCUT = 'po' #eliminar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eliminar?


YARRRML_PREDICATES = 'predicates'
YARRRML_PREDICATE = 'predicate'
YARRRML_PREDICATES_SHORTCUT = 'p'
YARRRML_OBJECTS = 'objects'
YARRRML_OBJECT = 'objects'
YARRRML_OBJECT_SHORTCUT = 'o'
YARRRML_VALUE = 'value'
YARRRML_VALUE_SHORTCUT = 'v'
YARRRML_DATATYPE = 'datatype'
YARRRML_LANGUAGE = 'language'

YARRRML_CONDITION = 'condition'
YARRRML_EQUAL = 'equal'
YARRRML_JOIN = 'join'
YARRRML_PARAMETERS = 'parameters' #used for conditions and functions
YARRRML_PARAMETERS_SHORTCUT = 'pms'


YARRRML_IRI = '~iri'
YARRRML_LANG = '~lang'
Expand All @@ -166,22 +155,19 @@
YARRRML_COMPRESSION = 'compression'

YARRRML_FUNCTION = 'function'
YARRRML_FUNCTION_SHORTCUT_A = 'fn'
YARRRML_FUNCTION_SHORTCUT_B = 'f'

YARRRML_PARAMETER = 'parameter'
YARRRML_PARAMETER_SHORTCUT = 'p'

YARRRML_MAPPING_KEYS = [YARRRML_MAPPINGS, YARRRML_MAPPING, YARRRRL_MAPPINGS_SHORTCUT]
YARRRML_SUBJECT_KEYS = [YARRRML_SUBJECTS, YARRRML_SUBJECT, YARRRML_SUBJECTS_SHORTCUT]
YARRRML_POM_KEYS = [YARRRML_PREDICATEOBJECT, YARRRML_PREDICATEOBJECT_SHORTCUT]
YARRRML_GRAPH_KEYS = [YARRRML_GRAPHS, YARRRML_GRAPH, YARRRML_GRAPH_SHORTCUT]
YARRRML_PREDICATE_KEYS = [YARRRML_PREDICATES, YARRRML_PREDICATE, YARRRML_PREDICATES_SHORTCUT]
YARRRML_OBJECT_KEYS = [YARRRML_OBJECTS, YARRRML_OBJECT, YARRRML_OBJECT_SHORTCUT]
YARRRML_FUNCTION_KEYS = [YARRRML_FUNCTION, YARRRML_FUNCTION_SHORTCUT_A, YARRRML_FUNCTION_SHORTCUT_B]
YARRRML_PARAMETERS_KEYS = [YARRRML_PARAMETERS, YARRRML_PARAMETERS_SHORTCUT]
YARRRML_PARAMETER_KEYS = [YARRRML_PARAMETER, YARRRML_PARAMETER_SHORTCUT]
YARRRML_VALUE_KEYS = [YARRRML_VALUE, YARRRML_VALUE_SHORTCUT]
YARRRML_MAPPING_KEYS = [YARRRML_MAPPINGS, YARRRML_MAPPING]
YARRRML_SUBJECT_KEYS = [YARRRML_SUBJECTS]
YARRRML_POM_KEYS = [YARRRML_PREDICATEOBJECT]
YARRRML_GRAPH_KEYS = [YARRRML_GRAPHS]
YARRRML_PREDICATE_KEYS = [YARRRML_PREDICATES]
YARRRML_OBJECT_KEYS = [YARRRML_OBJECTS]
YARRRML_FUNCTION_KEYS = [YARRRML_FUNCTION]
YARRRML_PARAMETERS_KEYS = [YARRRML_PARAMETERS]
YARRRML_PARAMETER_KEYS = [YARRRML_PARAMETER]
YARRRML_VALUE_KEYS = [YARRRML_VALUE]


YARRRML_OUTPUT_FORMAT = {
Expand Down Expand Up @@ -226,4 +212,4 @@
}

logger = logging.getLogger(__name__)
coloredlogs.install(level='DEBUG', fmt='%(asctime)s,%(msecs)03d | %(levelname)s: %(message)s')
coloredlogs.install(level='DEBUG', fmt='%(asctime)s,%(msecs)03d | %(levelname)s: %(message)s')
10 changes: 8 additions & 2 deletions src/yatter/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,14 @@ def generate_extended_join(yarrrml_data):
for value in equals:
parameters = []
conditions = value.replace("(","",1).rsplit(")",1)[0].split(",")
parameters.append(['str1',conditions[0]])
parameters.append(['str2', conditions[1]])
expanded_param = dict()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this can be done in one or two lines?

expanded_param[YARRRML_PARAMETER] = 'str1'
expanded_param[YARRRML_VALUE] = conditions[0]
parameters.append(expanded_param)
expanded_param = dict()
expanded_param[YARRRML_PARAMETER] = 'str2'
expanded_param[YARRRML_VALUE] = conditions[1]
parameters.append(expanded_param)
extended_join[YARRRML_CONDITION].append({YARRRML_FUNCTION: YARRRML_EQUAL, YARRRML_PARAMETERS: parameters})

return extended_join
Expand Down
16 changes: 8 additions & 8 deletions src/yatter/mapping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .import *
from . import *

prefixes = {}


def add_mapping(mapping, mappings, it):
map_template = "<" + mapping + "_" + str(it) + "> a "
if mappings[mapping]:
Expand Down Expand Up @@ -58,7 +60,6 @@ def add_prefix(data):


def check_common_prefixes(prefix_uri, common_prefixes):

if prefix_uri == R2RML_URI:
common_prefixes.append("r2rml")
elif prefix_uri == RML_URI:
Expand Down Expand Up @@ -106,8 +107,8 @@ def get_non_asserted_mappings(yarrrml_data, mapping_format):
for value in yarrrml_data.get(YARRRML_MAPPINGS).get(mapping).get(key):
if type(value) is dict:
star_data = [value]
if YARRRML_OBJECT_SHORTCUT in value:
star_data = value[YARRRML_OBJECT_SHORTCUT]
if YARRRML_OBJECTS in value:
star_data = value[YARRRML_OBJECTS]
for val in star_data:
if YARRRML_NON_ASSERTED in val:
mappings[val[YARRRML_NON_ASSERTED]] = "non_asserted"
Expand All @@ -118,9 +119,8 @@ def get_non_asserted_mappings(yarrrml_data, mapping_format):
return mappings, mapping_format



def merge_mapping_section_by_key(key,yarrrml_list):
output = {key:{}}
def merge_mapping_section_by_key(key, yarrrml_list):
output = {key: {}}
for yarrrml_mapping in yarrrml_list:
output[key] = output[key] | yarrrml_mapping
return output
return output
Loading
Loading