Wiki › Component

SPARQL engine (chaipat.cc)

Article
From Chaipat's knowledge graph

The SPARQL engine in src/kg.js stores the knowledge graph of chaipat.cc and answers SPARQL SELECT queries over it, in plain JavaScript, inside the visitor's browser. Factual answers can be checked in the SPARQL tab, which shows the queries used with their rows and timings. Finding an entity or choosing its live site, about page or source code is a separate catalog operation, not a reason to invent a SPARQL answer.

What it supports

  • PREFIX, SELECT with DISTINCT and *
  • triple patterns with ;, , and a
  • OPTIONAL, UNION and nested groups
  • FILTER with comparisons, &&, ||, !, and the functions CONTAINS, LCASE, UCASE, STR, REGEX, STRSTARTS, STRENDS, BOUND, ISIRI, ISLITERAL, YEAR and SUBSTR
  • ORDER BY (numbers compare as numbers; rows without the value go last), LIMIT, OFFSET

How it works

Terms are kept in one short text form (id:JAIST, "2024-07"), and three indexes (by subject, predicate and object) let each pattern start from its smallest candidate list. The graph is loaded together with its ontology: the reasoner adds the facts the ontology implies, and a query can be run on the stated facts alone, which is how the SPARQL tab tells how many rows came from reasoning. The Turtle parser reads the files.

src/resources.js is another pure consumer of this graph API. It gathers typed entities, their labels and aliases, descriptions and relationships into a catalog, and reads explicit live and repository properties for resource actions. Its local about addresses do not depend on whether a written wiki article exists. The graph remains the source of truth in both Node.js and the browser; the generated search catalog is only a snapshot, not a second database or a replacement query engine.

The shared answer composer in src/answer.js can cite graph facts it actually reads, such as a work's technologies, description or declared source files. Those graph citations are evidence for the single answer, not a list of every related entity or resource destination. A wiki passage or Wikipedia extract used instead carries its own source; optional model augmentation must preserve the local answer's authoritative citations.

The knowledge-state manifest covers this engine, the parser and reasoner, the answer/resource modules, the ontology and graph inputs. Validation rejects changed code or schema without a rebuild and checks generated graph and search contents read-only. cj:implementationDigest records the bytes of a component's declared source files in the generated wiki graph. These are freshness checks, not a proof that SPARQL support or this explanation is correct; behavior changes still require review.