Skip to content

Add n10s.inference.isTypeRel UDF to check relationship type hierarchy (#271)#355

Open
jexp wants to merge 2 commits into
2026.01from
fix-271-isTypeRel
Open

Add n10s.inference.isTypeRel UDF to check relationship type hierarchy (#271)#355
jexp wants to merge 2 commits into
2026.01from
fix-271-isTypeRel

Conversation

@jexp

@jexp jexp commented May 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds n10s.inference.isTypeRel(rel, relTypeName, params) user function to MicroReasoners.java
  • The function is analogous to n10s.inference.hasLabel but operates on relationship types instead of node labels
  • Checks whether a relationship is explicitly or implicitly of the given type by traversing the RDFS property hierarchy (rdfs:subPropertyOf)

Function Signature

n10s.inference.isTypeRel(rel, relTypeName, {}) → Boolean

Parameters:

  • rel — the relationship to check
  • relTypeName — the target relationship type name to test against
  • params (optional) — override graph config settings inline: relLabel, subRelRel, relNameProp

Behaviour:

  1. Returns true immediately if the relationship's actual type equals relTypeName (exact match, no graph traversal needed)
  2. Otherwise queries the ontology graph for a subPropertyOf path from the actual type up to relTypeName
  3. Throws MicroReasonerException if neither a GraphConfig nor inline params are provided

Test Coverage

Three new tests added to MicroReasonersTest.java (19 inference tests pass total):

Test What it covers
testIsTypeRelNoOnto No GraphConfig → throws; exact match with inline params; no-match with inline params
testIsTypeRel Hierarchy traversal (ACTS_INWORKS_IN) with inline params
testIsTypeRelWithGraphConfig Same hierarchy traversal using a persisted GraphConfig

Docs

Added to inference.adoc: new === n10s.inference.isTypeRel section at the end of the "Hierarchies of Relationships" chapter. Includes a full movie-database example showing a WHERE clause filter that matches ACTED_IN and DIRECTED relationships as implicit WORKED_IN, and a note about the MicroReasonerException when neither a GraphConfig nor inline params are provided.

Updated reference.adoc: added n10s.inference.isTypeRel to the Inferencing functions table, renamed the parameters section to cover both getRels and isTypeRel, and added a note that relDir is getRels-only.

Closes #271

jexp added 2 commits May 9, 2026 03:28
New user function analogous to hasLabel but for relationship types:
checks whether a relationship is explicitly or implicitly of the given
type by traversing the RDFS property hierarchy (rdfs:subPropertyOf).

Closes #271
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