How to Validate Semantic References

Validate ConceptIds against the SEA-Forge™ Knowledge Graph to ensure semantic anchoring is correct.

Prerequisites

Quick Validation (just recipe)

1
2
3
4
5
# Validate a single file
just semantic-validate .github/skills/my-skill/SKILL.md

# Validate all skills
just semantic-validate-all

Manual SPARQL Validation

1. Check if a Concept Exists

1
2
3
4
5
6
PREFIX sea: <http://sea-forge.org/ontology#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

ASK {
  sea:BoundedContext a owl:Class .
}

Run via curl:

1
2
3
curl -X POST "http://localhost:7200/repositories/sea" \
  -H "Content-Type: application/sparql-query" \
  -d 'ASK { <http://sea-forge.org/ontology#BoundedContext> a owl:Class . }'

Expected output: true if concept exists

1
2
3
4
5
6
7
PREFIX sea: <http://sea-forge.org/ontology#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?related ?label WHERE {
  sea:BoundedContext rdfs:subClassOf ?related .
  OPTIONAL { ?related rdfs:label ?label }
}

3. Validate Multiple ConceptIds

For CADSL artifacts with semanticRefs, manually check each:

1
2
3
4
5
# artifact.yaml
semanticRefs:
  - conceptId: "sea:BoundedContext"  # ✅ Valid
  - conceptId: "sea:Deployment"      # ✅ Valid
  - conceptId: "sea:UnknownThing"    # ❌ Not found

Validation Script (Python)

Create a validation script for your project:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# validate_concepts.py
import yaml
import requests

def validate_concept(concept_id: str) -> bool:
    """Check if a ConceptId exists in Knowledge Graph."""
    namespace, name = concept_id.split(":")
    uri = f"http://sea-forge.org/ontology#{name}"

    query = f'ASK {{ <{uri}> a ?type }}'
    response = requests.post(
        "http://localhost:7200/repositories/sea",
        headers={"Content-Type": "application/sparql-query"},
        data=query
    )
    return response.json().get("boolean", False)

def validate_artifact(artifact_path: str):
    """Validate all semanticRefs in a CADSL artifact."""
    with open(artifact_path) as f:
        artifact = yaml.safe_load(f)

    refs = artifact.get("semanticRefs", [])
    for ref in refs:
        concept_id = ref.get("conceptId")
        valid = validate_concept(concept_id)
        status = "" if valid else ""
        print(f"{status} {concept_id}")

if __name__ == "__main__":
    import sys
    validate_artifact(sys.argv[1])

Usage:

1
python validate_concepts.py artifact.yaml

Best Practices

  1. Validate before committing - Check all new semanticRefs
  2. Use specific concepts - Avoid generic concepts like sea:Thing
  3. Include domain concepts - Mix core ontology with domain-specific
  4. Check related concepts - Use SPARQL to discover better matches