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

Feature/ted 1292 #459

Merged
merged 2 commits into from
Mar 15, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ infra/airflow/logs/scheduler/latest
infra/airflow/requirements.txt

.~lock*
~$*
infra/airflow-cluster/requirements.txt
node_modules
tests/reports/allure/report/
Expand Down
3 changes: 2 additions & 1 deletion ted_sws/data_sampler/services/notice_xml_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ted_sws.core.model.metadata import XMLMetadata
from ted_sws.core.model.notice import Notice
from ted_sws.data_manager.adapters.notice_repository import NoticeRepository
from ted_sws.mapping_suite_processor.adapters.conceptual_mapping_reader import ConceptualMappingReader
from ted_sws.resources import XSLT_FILES_PATH
import xml.etree.ElementTree as XMLElementTree
import re
Expand Down Expand Up @@ -85,7 +86,7 @@ def _xpath_generator(xml_file):

xpath = "/" + '/'.join(path)

if xpath.startswith(base_xpath + "/"):
if xpath.startswith(ConceptualMappingReader.base_xpath_as_prefix(base_xpath)):
attributes = list(el.attrib.keys())
if len(attributes) > 0:
for attr in attributes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ class ConceptualMappingReader:
This adapter can be used to read a MappingSuite Conceptual Mapping
"""

@classmethod
def base_xpath_as_prefix(cls, base_xpath: str) -> str:
return base_xpath + ("/" if not base_xpath.endswith("/") else "")

@classmethod
def xpath_with_base(cls, xpath: str, base_xpath: str = "") -> str:
# xpath is absolute
if xpath.startswith("/"):
return xpath
base_xpath = cls.base_xpath_as_prefix(base_xpath) if xpath else base_xpath
return base_xpath + xpath

@classmethod
def _read_pd_value(cls, value, default=""):
if pd.isna(value):
Expand Down Expand Up @@ -226,7 +238,7 @@ def _read_conceptual_mapping_xpaths(cls, rules_df: pd.DataFrame, base_xpath: str
row_xpaths = xpath_row.split('\n')
for xpath in row_xpaths:
if xpath:
xpath = base_xpath + "/" + xpath
xpath = cls.xpath_with_base(xpath, base_xpath)
if xpath not in processed_xpaths:
form_fields = [df_sform_field_ids[idx], df_sform_field_names[idx]]
cm_xpath: ConceptualMappingXPATH = ConceptualMappingXPATH(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ted_sws.mapping_suite_processor import CONCEPTUAL_MAPPINGS_METADATA_SHEET_NAME, \
CONCEPTUAL_MAPPINGS_RULES_SHEET_NAME, RULES_FIELD_XPATH, RULES_E_FORM_BT_NAME, RULES_SF_FIELD_ID, \
RULES_E_FORM_BT_ID, RULES_SF_FIELD_NAME
from ted_sws.mapping_suite_processor.adapters.conceptual_mapping_reader import ConceptualMappingReader
from ted_sws.notice_validator import BASE_XPATH_FIELD
from ted_sws.resources.prefixes import PREFIXES_DEFINITIONS

Expand All @@ -21,7 +22,7 @@

DEFAULT_RQ_NAME = 'sparql_query_'

SPARQL_PREFIX_PATTERN = re.compile('(?:\\s+|^)(\\w+)?:')
SPARQL_PREFIX_PATTERN = re.compile('(?:\\s+|^)([\\w\\-]+)?:')
SPARQL_PREFIX_LINE = 'PREFIX {prefix}: <{value}>'
SPARQL_LOGGER_NAME = "SPARQL"

Expand All @@ -34,8 +35,9 @@ def get_sparql_prefixes(sparql_q: str) -> list:
def concat_field_xpath(base_xpath: str, field_xpath: str, separator: str = ", ") -> str:
base_xpath = base_xpath if not pd.isna(base_xpath) else ''
field_xpath = field_xpath if not pd.isna(field_xpath) else ''
base_xpath = (base_xpath + "/") if field_xpath else base_xpath
return separator.join([base_xpath + xpath for xpath in field_xpath.splitlines()])
return separator.join(
[ConceptualMappingReader.xpath_with_base(xpath, base_xpath) for xpath in field_xpath.splitlines()]
)


def _get_elem_reference(class_value: str, cl_dfs: dict, field_xpath: list) -> str:
Expand Down
3 changes: 2 additions & 1 deletion ted_sws/notice_validator/adapters/xpath_coverage_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ted_sws.core.model.transform import ConceptualMapping, ConceptualMappingXPATH, MappingSuite
from ted_sws.core.model.validation_report import ReportNotice
from ted_sws.data_sampler.services.notice_xml_indexer import index_notice
from ted_sws.mapping_suite_processor.adapters.conceptual_mapping_reader import ConceptualMappingReader
from ted_sws.notice_validator.resources.templates import TEMPLATE_METADATA_KEY
from ted_sws.notice_transformer.services.notice_transformer import transform_report_notices

Expand Down Expand Up @@ -103,7 +104,7 @@ def based_xpaths(cls, xpaths: List[str], base_xpath: str) -> List[str]:
:param base_xpath:
:return:
"""
base_xpath += "/" if not base_xpath.endswith("/") else ""
base_xpath = ConceptualMappingReader.base_xpath_as_prefix(base_xpath)
return list(filter(lambda xpath: xpath.startswith(base_xpath), xpaths))

def xpath_coverage_validation_summary_report(self,
Expand Down
Binary file not shown.
Binary file not shown.