Skip to content

isIri() and isBlank() on a node (root subject and relation value) - #418

Merged
flyon merged 2 commits into
mainfrom
feat/subject-term-type
Nov 9, 2026
Merged

flyon merged 2 commits into
mainfrom
feat/subject-term-type

Conversation

@flyon

@flyon flyon commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Depends on #417. This branch is based on fix/page-by-subject, so that a paged select applies the filter inside the per-subject page. Merge #417 first. This PR's own change is the second commit.

What changed

A query had no way to test whether the root subject is an IRI or a blank node. isIri and isBlank existed only on literal values (.where((p) => p.isIri()) threw "is accessed in a query, but it does not have a @linkedProperty decorator"). So a read of named subjects only, e.g. classes without the anonymous owl:unionOf class expressions, had to filter after the read, which breaks paging.

QueryShape (the root subject and every relation value) now has isIri() and isBlank(). They sit next to its existing str() and isDefined(), are named after the README's expression table, and lower to SPARQL isIRI / isBlank:

Person.select((p) => p.name).where((p) => p.isIri())              // named subjects only
Person.select((p) => p.name).minus((p) => p.isBlank())            // leave out blank nodes
Person.select((p) => p.name).where((p) => p.bestFriend.isBlank()) // a relation's value

Both names are added to RESERVED_QUERY_DSL_NAMES. The README documents them under MINUS and in the expression section. Changeset: minor (new DSL surface).

Generated SPARQL for Person.select((p) => p.name).from([g]).minus((p) => p.isBlank()).orderBy((p) => p.name).limit(7):

SELECT DISTINCT ?a0 ?a0_name WHERE {
  { SELECT ?a0 (MIN(?a0_name) AS ?page_order_0) WHERE {
      GRAPH <g> {
        ?a0 rdf:type <Person> . OPTIONAL { ?a0 <name> ?a0_name . }
        MINUS { ?a0 rdf:type <Person> . FILTER(isBlank(?a0)) } }
    } GROUP BY ?a0 ORDER BY DESC(BOUND(?page_order_0)) ASC(?page_order_0) ASC(?a0) LIMIT 7 }
  GRAPH <g> { ?a0 rdf:type <Person> . OPTIONAL { ?a0 <name> ?a0_name . }
              MINUS { ?a0 rdf:type <Person> . FILTER(isBlank(?a0)) } } }
ORDER BY DESC(BOUND(?page_order_0)) ASC(?page_order_0) ASC(?a0) DESC(BOUND(?a0_name)) ASC(?a0_name)

With .where((p) => p.isIri()) the page holds FILTER(isIRI(?a0)) before its LIMIT.

Tests

  • New src/tests/subject-term-type.test.ts. Four lowering tests cover root where isIri/isBlank, the filter inside the page before LIMIT, and a relation. Five live Fuseki tests use two IRI and two blank-node subjects, with where, minus, pages with limit/offset, and a relation whose value is a blank node. Written first: Tests: 9 failed, 9 total.
  • New factories whereRootIsIri and minusRootIsBlank in query-fixtures, so the DSL-JSON round-trip covers them.
  • Full suite with a live Fuseki (FUSEKI_BASE_URL=http://localhost:3962 FUSEKI_ADMIN_PASSWORD=admin npm test, after npx linked build):
[fuseki] live tests: 503 total — 501 passed, 0 failed, 2 skipped
Test Suites: 4 skipped, 174 passed, 174 of 178 total
Tests:       122 skipped, 3380 passed, 3502 total

tsc -p tsconfig-tests.json passed with exit 0.

Follow-ups

  • isLiteral() on a node is not added: a subject or a relation's value is never a literal.

flyon added 2 commits November 9, 2026 20:13
…I on every page

A row LIMIT counted a subject twice when the data held two values of a
maxCount-1 path (a label in two languages), so a page held fewer subjects
than asked. Paged selects now use the sub-SELECT of subjects whenever a row
carries any value besides its subject; a select of subjects only keeps its
plain LIMIT. An offset without an orderBy pages in subject order.
.where((p) => p.isIri()) keeps the named subjects, .minus((p) => p.isBlank())
leaves out the blank nodes. On a paged select the filter applies inside the
page of subjects, before its LIMIT.
@flyon
flyon merged commit d145c66 into main Nov 9, 2026
2 checks passed
@flyon
flyon deleted the feat/subject-term-type branch November 9, 2026 21:19
@linked-fw-release linked-fw-release Bot mentioned this pull request Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant