SPARQL Inferencing Notation (SPIN) is a W3C Member Submission that specifies a SPARQL-based rule and constraint language for the Semantic Web. SPIN is also a mechanism to represent reusable SPARQL queries as templates and to define new SPARQL functions.
From spinrdf.org:
SPIN is a W3C Member Submission that has become the de-facto industry standard to represent SPARQL rules and constraints on Semantic Web models. SPIN also provides meta-modeling capabilities that allow users to define their own SPARQL functions and query templates.
Before you explore SPIN further, you may want to read From SPIN to SHACL.