Skip to content

Commit

Permalink
Merge pull request #392 from meaningfy-ws/feature/MWB12-44
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleanych authored Feb 4, 2025
2 parents c0d8575 + 41cae05 commit a507b58
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def validate(self, shacl_test_suite: SHACLTestSuiteState) -> SHACLQueryTestDataR
test_data=result_test_data
)
shacl_result.result_path = shacl_result.binding.result_path
shacl_result.source_constraint_component = shacl_result.binding.source_constraint_component
if self.ns_definitions:
shacl_result.binding.short_result_path = get_prefixed_ns_term(
ns_term=shacl_result.binding.result_path,
Expand All @@ -135,6 +136,7 @@ def validate(self, shacl_test_suite: SHACLTestSuiteState) -> SHACLQueryTestDataR
ns_term=shacl_result.binding.source_constraint_component,
ns_definitions=self.ns_definitions
)
shacl_result.short_source_constraint_component = shacl_result.binding.short_source_constraint_component
shacl_refined_result = None
if shacl_result.binding.result_severity.endswith("#Violation"):
shacl_refined_result = SHACLQueryRefinedResultType.VIOLATION.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ValidationSHACLQuery(BaseModel):
shacl_suite: Optional[SHACLValidationSuiteEntry] = None
result_path: Optional[str] = None
short_result_path: Optional[str] = None
source_constraint_component: Optional[str] = None
short_source_constraint_component: Optional[str] = None


class SHACLGraphResultBindingValue(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from mapping_workbench.backend.logger.services import mwb_logger
from mapping_workbench.backend.mapping_package.models.entity import MappingPackageState, MappingPackage
from mapping_workbench.backend.mapping_package.services.data import get_mapping_package_state_ns_definitions
from mapping_workbench.backend.ontology.services.terms import get_prefixed_ns_term
from mapping_workbench.backend.ontology_suite.models.ontology_file_resource import OntologyFileResource
from mapping_workbench.backend.package_validator.adapters.shacl_validator import SHACLValidator
from mapping_workbench.backend.package_validator.models.shacl_validation import SHACLQueryResult, \
Expand All @@ -20,27 +19,37 @@

def aggregate_shacl_tests_summary(
results: List[SHACLQueryResult],
ns_definitions: dict,
use_grouping: bool = True
) -> List[SHACLValidationSummaryRow]:
def get_path_uniq_key(shacl_suite_oid, result_path):
return str(shacl_suite_oid) + "__" + result_path
def get_path_uniq_key(shacl_suite_oid, result_path, source_constraint_component = ""):
return str(shacl_suite_oid) + "__" + result_path + (
("__" + source_constraint_component) if source_constraint_component else ""
)

shacl_result_paths: List[ValidationSHACLQuery] = []

paths_uniq_keys = set()
for result in results:
result_path = result.result_path if use_grouping else ""
path_uniq_key = get_path_uniq_key(result.shacl_suite.shacl_suite_oid, result_path)
result_path = ""
short_result_path = ""

if use_grouping:
result_path = result.result_path
short_result_path = result.short_result_path

path_uniq_key = get_path_uniq_key(
result.shacl_suite.shacl_suite_oid,
result_path,
result.source_constraint_component
)
if path_uniq_key not in paths_uniq_keys:
paths_uniq_keys.add(path_uniq_key)
shacl_result_paths.append(ValidationSHACLQuery(
shacl_suite=result.shacl_suite,
result_path=result_path,
short_result_path=get_prefixed_ns_term(
ns_term=result_path,
ns_definitions=ns_definitions
)
short_result_path=short_result_path,
source_constraint_component=result.short_source_constraint_component,
short_source_constraint_component=result.short_source_constraint_component
))

summary_results: List[SHACLValidationSummaryRow] = []
Expand All @@ -54,10 +63,9 @@ def get_path_uniq_key(shacl_suite_oid, result_path):
SHACLValidationSummaryRow(
shacl_suite=shacl_result_path.shacl_suite,
result_path=shacl_result_path.result_path,
short_result_path=get_prefixed_ns_term(
ns_term=shacl_result_path.result_path,
ns_definitions=ns_definitions
)
short_result_path=shacl_result_path.short_result_path,
source_constraint_component=shacl_result_path.short_source_constraint_component,
short_source_constraint_component=shacl_result_path.short_source_constraint_component
)
)
idx = len(summary_results) - 1
Expand Down Expand Up @@ -141,7 +149,6 @@ async def validate_tests_data_with_shacl_test_suites(
shacl_suites=shacl_suites,
results=aggregate_shacl_tests_summary(
results=union_shacl_suites_results(tests_data[idx].validation.shacl.results),
ns_definitions=ns_definitions,
use_grouping=False
)
)
Expand Down Expand Up @@ -198,19 +205,13 @@ async def validate_mapping_package_state_with_shacl(mapping_package_state: Mappi
mapping_package_state.test_data_suites[idx].validation.shacl = SHACLTestDataValidationResult(
summary=SHACLValidationSummary(
shacl_suites=shacl_suites,
results=aggregate_shacl_tests_summary(
results=test_data_suite_results,
ns_definitions=ns_definitions
)
results=aggregate_shacl_tests_summary(results=test_data_suite_results)
)
)

mapping_package_state.validation.shacl = SHACLTestDataValidationResult(
summary=SHACLValidationSummary(
shacl_suites=shacl_suites,
results=aggregate_shacl_tests_summary(
results=state_results,
ns_definitions=ns_definitions
)
results=aggregate_shacl_tests_summary(results=state_results)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const mapShaclResults = (result) => {
const resultArray = {}
resultArray["shacl_suite"] = result.shacl_suites?.[0]?.shacl_suite_id
resultArray["short_result_path"] = e.short_result_path
resultArray["short_source_constraint_component"] = e.short_source_constraint_component
resultArray["result"] = e.result
Object.entries(e.result).forEach(entry => {
const [key, value] = entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {useHighlighterTheme} from "src/hooks/use-highlighter-theme";
import TablePagination from 'src/sections/components/table-pagination';
import {TableFilterHeader} from "src/layouts/app/table-filter-header/table-filter-header";

const LocalHighlighter = ({text, language, theme}) => {
export const LocalHighlighter = ({text, language, theme}) => {
return text ? <SyntaxHighlighter
language={language}
wrapLines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter';
import TableSorterHeader from "src/sections/components/table-sorter-header";
import TablePagination from "src/sections/components/table-pagination";
import {TableFilterHeader} from "src/layouts/app/table-filter-header/table-filter-header";
import {LocalHighlighter} from "./list-table-file";

export const ListTable = (props) => {
const [descriptionDialog, setDescriptionDialog] = useState({open: false, title: "", text: ""})
Expand Down Expand Up @@ -126,8 +127,8 @@ export const ListTable = (props) => {
title="Test Suite"/>
</TableCell>
<TableCell width="25%">
<SorterHeader fieldName="conforms"
title="Conforms"/>
<SorterHeader fieldName="short_source_constraint_component"
title="Source Constraint Component"/>
</TableCell>
<TableCell>
<TableFilterHeader sort={sort}
Expand Down Expand Up @@ -156,7 +157,9 @@ export const ListTable = (props) => {
{item.shacl_suite}
</TableCell>
<TableCell>
{0}
<LocalHighlighter language='turtle'
text={item.short_source_constraint_component}
theme={syntaxHighlighterTheme}/>
</TableCell>
<TableCell>
<SyntaxHighlighter
Expand Down

0 comments on commit a507b58

Please sign in to comment.