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

Updated reports + tests #291

Merged
merged 1 commit into from
Oct 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ def mapping_suite_processor_generate_metadata(mapping_suite_path: pathlib.Path,
metadata.update(hashing_metadata)

with open(output_metadata_file_path, 'w') as metadata_file:
metadata_file.write(json.dumps(metadata))
metadata_file.write(json.dumps(metadata, indent=2))
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
SPARQL_LOGGER_NAME = "SPARQL"


def get_sparql_prefixes(sparql_q: str) -> set:
def get_sparql_prefixes(sparql_q: str) -> list:
finds: list = re.findall(SPARQL_PREFIX_PATTERN, sparql_q)
return set(finds)
return sorted(set(finds))


def concat_field_xpath(base_xpath: str, field_xpath: str, separator: str = ", ") -> str:
Expand Down Expand Up @@ -69,15 +69,23 @@ def _generate_subject_type(class_path: str, cl_dfs: dict, field_xpath: str) -> s
return f"?this rdf:type {subject_reference} ." if subject_reference else ''


def _generate_object_type(class_path: str, cl_dfs: dict, field_xpath: str) -> str:
# Temporary solution
class_path = class_path.split(' / ')[-1]
if 'at-voc:' in class_path:
return ''

object_reference = _get_elem_reference(class_path, cl_dfs,
field_xpath.split('/') if not pd.isna(field_xpath) else '')
return f"?value rdf:type {object_reference} ." if object_reference else ''
# Could be used later
# def _generate_object_type(class_path: str, cl_dfs: dict, field_xpath: str) -> str:
# """
# This method determines SPARQL query object type base on some rules
# :param class_path:
# :param cl_dfs:
# :param field_xpath:
# :return:
# """
# # Temporary solution (could be used in the future)
# class_path = class_path.split(' / ')[-1]
# if 'at-voc:' in class_path:
# return ''
#
# object_reference = _get_elem_reference(class_path, cl_dfs,
# field_xpath.split('/') if not pd.isna(field_xpath) else '')
# return f"?value rdf:type {object_reference} ." if object_reference else ''


def sparql_validation_generator(data: pd.DataFrame, base_xpath: str, controlled_list_dfs: dict,
Expand Down
8 changes: 5 additions & 3 deletions ted_sws/notice_packager/services/notice_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,18 @@ def pack(self, save_to: PATH_TYPE) -> str:
with open(package_path, "rb") as f:
raw_archive_content = f.read()

# TODO: clear out the return
if save_to is None:
# If no save_to path is specified, then just return the package content as string
archive_content = base64.b64encode(raw_archive_content)
return str(archive_content, 'utf-8')
else:
if save_to: # file or folder to save the archive to
if save_to:
# If save_to path is not empty, then create, write the package and return the destination path
save_to_path = Path(save_to)
if os.path.isdir(save_to_path):
save_to_path /= archive_name
self.__write_to_file(save_to_path, raw_archive_content, 'wb')
return str(save_to_path)
else: # save_to=""
else:
# If save_to is empty (save_to="") then return the created package source path
return package_path
55 changes: 55 additions & 0 deletions tests/test_data/resources/mapping_files/award_criterion_type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"head": {
"link": [],
"vars": [
"code",
"conceptURI"
]
},
"results": {
"distinct": false,
"ordered": true,
"bindings": [
{
"code": {
"type": "literal",
"value": "OP_DATPRO"
},
"conceptURI": {
"type": "uri",
"value": "http://publications.europa.eu/resource/authority/award-criterion-type/OP_DATPRO"
}
},
{
"code": {
"type": "literal",
"value": "cost"
},
"conceptURI": {
"type": "uri",
"value": "http://publications.europa.eu/resource/authority/award-criterion-type/cost"
}
},
{
"code": {
"type": "literal",
"value": "price"
},
"conceptURI": {
"type": "uri",
"value": "http://publications.europa.eu/resource/authority/award-criterion-type/price"
}
},
{
"code": {
"type": "literal",
"value": "quality"
},
"conceptURI": {
"type": "uri",
"value": "http://publications.europa.eu/resource/authority/award-criterion-type/quality"
}
}
]
}
}
26 changes: 26 additions & 0 deletions tests/test_data/resources/mapping_files/buyer_legal_type.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
xmlElement,code,conceptURI
,OP_DATPRO,http://publications.europa.eu/resource/authority/buyer-legal-type/OP_DATPRO
NATIONAL_AGENCY,body-pl,http://publications.europa.eu/resource/authority/buyer-legal-type/body-pl
REGIONAL_AGENCY,body-pl,http://publications.europa.eu/resource/authority/buyer-legal-type/body-pl
BODY_PUBLIC,body-pl,http://publications.europa.eu/resource/authority/buyer-legal-type/body-pl
,body-pl-cga,http://publications.europa.eu/resource/authority/buyer-legal-type/body-pl-cga
,body-pl-la,http://publications.europa.eu/resource/authority/buyer-legal-type/body-pl-la
,body-pl-ra,http://publications.europa.eu/resource/authority/buyer-legal-type/body-pl-ra
MINISTRY,cga,http://publications.europa.eu/resource/authority/buyer-legal-type/cga
,def-cont,http://publications.europa.eu/resource/authority/buyer-legal-type/def-cont
,eu-ins-bod-ag,http://publications.europa.eu/resource/authority/buyer-legal-type/eu-ins-bod-ag
,int-org,http://publications.europa.eu/resource/authority/buyer-legal-type/int-org
,la,http://publications.europa.eu/resource/authority/buyer-legal-type/la
,org-sub,http://publications.europa.eu/resource/authority/buyer-legal-type/org-sub
,org-sub-cga,http://publications.europa.eu/resource/authority/buyer-legal-type/org-sub-cga
,org-sub-la,http://publications.europa.eu/resource/authority/buyer-legal-type/org-sub-la
,org-sub-ra,http://publications.europa.eu/resource/authority/buyer-legal-type/org-sub-ra
,pub-undert,http://publications.europa.eu/resource/authority/buyer-legal-type/pub-undert
,pub-undert-cga,http://publications.europa.eu/resource/authority/buyer-legal-type/pub-undert-cga
,pub-undert-la,http://publications.europa.eu/resource/authority/buyer-legal-type/pub-undert-la
,pub-undert-ra,http://publications.europa.eu/resource/authority/buyer-legal-type/pub-undert-ra
,ra,http://publications.europa.eu/resource/authority/buyer-legal-type/ra
,spec-rights-entity,http://publications.europa.eu/resource/authority/buyer-legal-type/spec-rights-entity
EU_INSTITUTION,eu-int-org,http://publications.europa.eu/resource/authority/buyer-legal-type/eu-int-org
REGIONAL_AUTHORITY,rl-aut,http://publications.europa.eu/resource/authority/buyer-legal-type/rl-aut
,grp-p-aut,http://publications.europa.eu/resource/authority/buyer-legal-type/grp-p-aut
Loading