FuXi SPARQL Reasoning

SPARQL as the rules language - forward and backward chaining inference

5 N3 Rules
N3 Rules

FuXi Rule Definitions

FuXi uses SPARQL Graph Patterns as the antecedent (body) of Horn rules in N3 format. The => operator concludes the consequent (head). Each rule shows:

Rule 1: Adult Classification

If Person has age >= 18, infer Adult category

FuXi Logic (N3):

{ ?person ex:hasAge ?age . FILTER(?age >= 18) } => { ?person ex:ageCategory "Adult" } .

→ Generated SPARQL:

SELECT ?person ?age FROM <fuxi-demo> WHERE { ?person a ex:Person ; ex:hasAge ?age FILTER(?age >= 18) }
Run Rule Query

Rule 2: Minor Classification

If Person has age < 18, infer Minor category

FuXi Logic (N3):

{ ?person ex:hasAge ?age . FILTER(?age < 18) } => { ?person ex:ageCategory "Minor" } .

→ Generated SPARQL:

SELECT ?person ?age FROM <fuxi-demo> WHERE { ?person a ex:Person ; ex:hasAge ?age FILTER(?age < 18) }
Run Rule Query

Rule 3: Same Age Group

Two persons within 5 years share age group

FuXi Logic (N3):

{ ?p1 ex:hasAge ?a1 . ?p2 ex:hasAge ?a2 . FILTER(abs(?a1 - ?a2) <= 5) } => { ?p1 ex:sameAgeGroupAs ?p2 } .

→ Generated SPARQL:

SELECT ?p1 ?a1 ?p2 ?a2 FROM <fuxi-demo> WHERE { ?p1 a ex:Person ; ex:hasAge ?a1 . ?p2 a ex:Person ; ex:hasAge ?a2 . FILTER(abs(?a1 - ?a2) <= 5) }
Run Rule Query

Rule 4: Senior Classification

If Person has age >= 65, infer Senior category

FuXi Logic (N3):

{ ?person ex:hasAge ?age . FILTER(?age >= 65) } => { ?person ex:ageCategory "Senior" } .

→ Generated SPARQL:

SELECT ?person ?age FROM <fuxi-demo> WHERE { ?person a ex:Person ; ex:hasAge ?age FILTER(?age >= 65) }
Run Rule Query
Inference

Forward Chaining Results

5
Rules
3
Inferred Facts
100%
Coverage
RETE
Algorithm

FuXi Logic (N3 consequent → CONSTRUCT template):

# N3: { ?person ex:ageCategory "Adult" } # ↓ converts to ↓ # CONSTRUCT template ex:Alice ex:ageCategory "Adult" . ex:Bob ex:ageCategory "Adult" . ex:Carol ex:ageCategory "Adult" .

→ Generated SPARQL CONSTRUCT:

PREFIX ex: <http://example.org/> CONSTRUCT { ?s ex:ageCategory "Adult" } FROM <fuxi-demo> WHERE { ?s a ex:Person ; ex:hasAge ?age FILTER(?age >= 18) }
Run CONSTRUCT Query
Commands

FuXi CLI Execution

Forward Chaining (RETE Network)

Execute all N3 rules against fact graph, derive all inferred facts

fuxi.core facts.n3

Backward Chaining with Proof

Answer specific query, generate proof graph

fuxi.proof --why='ASK { eg:bob ex:isBrotherOf eg:joe }' facts.n3

OWL 2 RL Reasoning

Validate ontology, perform OWL entailment

fuxi.owl --dlp --method=bfp ontology.ttl

1. Install FuXi

Ensure Python 3.8+ is installed, then run:

pip install fuxi

2. Create Facts File

Create your base RDF triples in Turtle format:

@prefix ex: . ex:alice ex:hasAge 30 . ex:bob ex:hasAge 25 .

3. Write N3 Rules

Define Horn logic rules with SPARQL patterns:

{ ?p ex:hasAge ?a . FILTER(?a >= 18) } => { ?p ex:ageCategory "Adult" } .

4. Run Forward Chaining

Use RETE algorithm for exhaustive inference:

fuxi.core facts.n3 rules.n3 # Output: inferred.n3

5. Query with Backward Chaining

Use BFP for targeted queries:

fuxi.proof --why='SELECT ?p WHERE { ?p ex:ageCategory "Adult" }' facts.n3

How this FuXi demo was created from scratch:

1. Create RDF Sample Data

Write Turtle file with sample persons, properties, and values

  • Define schema classes (ex:Person) and properties (ex:hasAge)
  • Add instance data (Alice:30, Bob:25, Carol:35)

2. Load Data to SPARQL Endpoint

Upload Turtle to Virtuoso via SPARQL UPDATE or DAV

  • Use named graph http://example.org/fuxi-demo
  • Verify: SELECT COUNT(*) FROM <fuxi-demo> { ?s ?p ?o }

3. Test SPARQL Operations

Run SELECT, CONSTRUCT, DESCRIBE queries to verify data

  • Test basic connectivity and triple count
  • Verify entity types and schema
  • Test CONSTRUCT with inference patterns

5. Generate HTML Infographic

Transform RDF to interactive HTML with CSS styling

  • Add entity hyperlinks via URIBurner resolver
  • Include Run Query buttons with encoded SPARQL

6. Create Markdown Documentation

Generate .md file summarizing rules and test results

  • Document all 11 SPARQL test operations
  • Link to RDF, HTML, and endpoint resources
FAQ

FuXi Logic → SPARQL Translation

FuXi Logic (N3):

{ ?person ex:hasAge ?age . FILTER(?age >= 18) } => { ?person ex:ageCategory "Adult" } .

Translates to SPARQL:

SELECT ?person ?age FROM <http://example.org/fuxi-demo> WHERE { ?person a ex:Person ; ex:hasAge ?age FILTER(?age >= 18) }

Run This Query

FuXi Logic (N3):

{ ?person ex:hasAge ?age . FILTER(?age < 18) } => { ?person ex:ageCategory "Minor" } .

Translates to SPARQL:

SELECT ?person ?age FROM <http://example.org/fuxi-demo> WHERE { ?person a ex:Person ; ex:hasAge ?age FILTER(?age < 18) }

Run This Query

FuXi Logic (N3):

{ ?p1 ex:hasAge ?a1 . ?p2 ex:hasAge ?a2 . FILTER(abs(?a1 - ?a2) <= 5) } => { ?p1 ex:sameAgeGroupAs ?p2 } .

Translates to SPARQL:

SELECT ?p1 ?a1 ?p2 ?a2 FROM <http://example.org/fuxi-demo> WHERE { ?p1 a ex:Person ; ex:hasAge ?a1 . ?p2 a ex:Person ; ex:hasAge ?a2 . FILTER(abs(?a1 - ?a2) <= 5) }

Run This Query

FuXi Logic (N3):

{ ?person ex:hasAge ?age . FILTER(?age >= 65) } => { ?person ex:ageCategory "Senior" } .

Translates to SPARQL:

SELECT ?person ?age FROM <http://example.org/fuxi-demo> WHERE { ?person a ex:Person ; ex:hasAge ?age FILTER(?age >= 65) }

Run This Query

FuXi Logic (N3 consequent):

{ ?person ex:ageCategory "Adult" } (derived from Rule 1)

Translates to SPARQL CONSTRUCT:

PREFIX ex: <http://example.org/> CONSTRUCT { ?s ex:ageCategory "Adult" } FROM <http://example.org/fuxi-demo> WHERE { ?s a ex:Person ; ex:hasAge ?age FILTER(?age >= 18) }

Run This Query

FuXi uses SPARQL Graph Patterns as the antecedent (body) of Horn rules in N3 format. The rule { ?s ex:parentOf ?o } => { ?s ex:relatedTo ?o } uses SPARQL WHERE clause syntax to match triples in the fact graph, then infers the conclusion triple. This makes SPARQL both the query language AND the rules language.

Forward chaining (bottom-up) uses the RETE algorithm to exhaustively apply N3 rules against the fact graph. Starting with base facts, it repeatedly applies rules until no new facts can be derived. Command: fuxi.core facts.n3

Backward chaining (top-down) uses BFP (Breadth-First Proof) to answer queries by finding proofs without deriving all possible facts. More efficient for targeted queries. Command: fuxi.proof --why='SPARQL query' facts.n3

Glossary

FuXi Terms

N3 Rules Notation3 format for expressing Horn logic rules - antecedent => consequent
RETE Algorithm Efficient forward-chaining algorithm used by FuXi for rule-based inference
BFP (Breadth-First Proof) Backward-chaining decision procedure in FuXi for query-focused reasoning
OWL 2 RL OWL 2 RL profile - a tractable subset of OWL for rule-based reasoning
Horn Logic A subset of first-order logic with rules of the form if antecedent then consequent
Forward Chaining Bottom-up reasoning - start with facts, apply rules to derive all conclusions
Backward Chaining Top-down reasoning - start with goal, work backwards to find supporting facts