Skip to content
Open
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
13 changes: 13 additions & 0 deletions validation/error-test-files/AF/af10115-fail.sbgn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sbgn xmlns="http://sbgn.org/libsbgn/0.3">
<map id="map1" language="activity flow">
<glyph id="glyph1" class="biological activity">
<label text="A"/>
<bbox x="26.0" y="30.0" w="108.0" h="60.0"/>
</glyph>
<glyph id="glyph2" class="biological activity">
<label text="B"/>
<bbox x="80.0" y="30.0" w="108.0" h="60.0"/>
</glyph>
</map>
</sbgn>
26 changes: 26 additions & 0 deletions validation/error-test-files/AF/af10115-pass.sbgn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sbgn xmlns="http://sbgn.org/libsbgn/0.3">
<map id="map1" language="activity flow">
<glyph id="glyph2" class="biological activity">
<label text="A"/>
<bbox y="30.0" x="26.0" h="60.0" w="108.0"/>
</glyph>
<glyph id="glyph3" class="biological activity">
<label text="B"/>
<bbox y="20.0" x="286.0" h="60.0" w="108.0"/>
</glyph>
<glyph id="glyph4" class="not">
<bbox y="89.0" x="179.0" h="42.0" w="42.0"/>
<port y="110.0" x="158.0" id="glyph4.1"/>
<port y="110.0" x="242.0" id="glyph4.2"/>
</glyph>
<arc target="glyph4.1" source="glyph2" id="arc0" class="logic arc">
<start y="90.0" x="126.8"/>
<end y="110.0" x="158.0"/>
</arc>
<arc target="glyph3" source="glyph4.2" id="arc2" class="positive influence">
<start y="110.0" x="242.0"/>
<end y="73.14286" x="286.0"/>
</arc>
</map>
</sbgn>
38 changes: 38 additions & 0 deletions validation/rules/sbgn_af.sch
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Schematron validation for SBGN AF
<iso:active pattern="af10112"/>
<iso:active pattern="af10113"/>
<iso:active pattern="af10114"/>
<iso:active pattern="af10115"/>
</iso:phase>

<iso:pattern id="00000">
Expand Down Expand Up @@ -259,6 +260,43 @@ Schematron validation for SBGN AF
</iso:assert>
</iso:rule>
</iso:pattern>

<iso:pattern id="af10115">
<iso:rule context="sbgn:map/sbgn:glyph[
@class= 'biological activity' or
@class = 'phenotype' or
@class = 'submap' or
@class = 'and' or
@class = 'or' or
@class = 'not' or
@class = 'delay'
]">
<iso:let name="id" value="@id"/>
<iso:assert
id="af10115"
name="check-overlapping-nodes"
role="error"
test="not(following-sibling::sbgn:glyph[
(@class= 'biological activity' or
@class = 'phenotype' or
@class = 'submap' or
@class = 'and' or
@class = 'or' or
@class = 'not' or
@class = 'delay')
and (
(number(sbgn:bbox/@x) &lt;= number(current()/sbgn:bbox/@x) + number(current()/sbgn:bbox/@w)) and
(number(sbgn:bbox/@x) + number(sbgn:bbox/@w) >= number(current()/sbgn:bbox/@x)) and
(number(sbgn:bbox/@y) &lt;= number(current()/sbgn:bbox/@y) + number(current()/sbgn:bbox/@h)) and
(number(sbgn:bbox/@y) + number(sbgn:bbox/@h) >= number(current()/sbgn:bbox/@y))
)

]
)"
diagnostics="id">Illegal overlapping nodes are not allowed in SBGN AF.
</iso:assert>
</iso:rule>
</iso:pattern>

<iso:diagnostics>
<iso:diagnostic id="id"><iso:value-of select="$id"/></iso:diagnostic>
Expand Down
124 changes: 124 additions & 0 deletions validation/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import subprocess
from pathlib import Path

# --------------------
# Global configuration
# --------------------

SAXON_JAR = Path("lib/saxon9he.jar")
SCHEMATRON_DIR = Path("schematron")
RULES_DIR = Path("rules")
TESTS_DIR = Path("error-test-files")
SVRL_ROOT = Path("svrl")


# --------------------
# Utility
# --------------------

def run(cmd):
print("▶", " ".join(cmd))
subprocess.run(cmd, check=True)


# --------------------
# Compile step
# --------------------

def compile_schematron(language: str):
"""
Compile Schematron rules for a given SBGN language (pd / er / af)
into an XSLT validator.
"""
language = language.lower()

sch_file = RULES_DIR / f"sbgn_{language}.sch"
step1 = Path(f"sbgn_{language}.step1.sch")
step2 = Path(f"sbgn_{language}.step2.sch")
validator = Path(f"sbgn_{language}_validator.xsl")

print(f"\n=== Compiling Schematron for {language.upper()} ===")

# Step 1: expand includes
run([
"java", "-jar", str(SAXON_JAR),
"-s:" + str(sch_file),
"-xsl:" + str(SCHEMATRON_DIR / "iso_dsdl_include.xsl"),
"-o:" + str(step1)
])

# Step 2: expand abstract patterns
run([
"java", "-jar", str(SAXON_JAR),
"-s:" + str(step1),
"-xsl:" + str(SCHEMATRON_DIR / "iso_abstract_expand.xsl"),
"-o:" + str(step2)
])

# Step 3: compile to SVRL-producing XSLT
run([
"java", "-jar", str(SAXON_JAR),
"-s:" + str(step2),
"-xsl:" + str(SCHEMATRON_DIR / "iso_svrl_for_xslt1.xsl"),
"-o:" + str(validator)
])

print(f" Validator created: {validator}")
return validator


# --------------------
# Validation step
# --------------------

def validate_sbgn(language: str, sbgn_file: Path):
"""
Validate a single SBGN file and write SVRL output.
"""
language = language.upper()

validator = Path(f"sbgn_{language.lower()}_validator.xsl")
svrl_dir = SVRL_ROOT / language
svrl_dir.mkdir(parents=True, exist_ok=True)

output = svrl_dir / (sbgn_file.stem + ".svrl")

print(f"\n=== Validating {sbgn_file.name} ({language}) ===")

run([
"java", "-jar", str(SAXON_JAR),
"-s:" + str(sbgn_file),
"-xsl:" + str(validator),
"-o:" + str(output)
])

print(f"SVRL written to {output}")


# --------------------
# Batch validation
# --------------------

def validate_all(language: str):
"""
Validate all test files for a given language.
"""
language = language.upper()
test_dir = TESTS_DIR / language

for sbgn in sorted(test_dir.glob("*.sbgn")):
validate_sbgn(language, sbgn)


# --------------------
# Entry point
# --------------------

if __name__ == "__main__":

pd = "pd"
af = "af"
er = "er"
#compile_schematron(pd)
compile_schematron(af)
validate_all(af)