Re: Graph-based Selectors

Semantic Web Interest Group,

Update: Please find below, in the postscript, a significantly revised copy of the document about a new language for graph-based selection inspired by CSS and SPARQL.

It is a fun project, a work in progress, and hopefully is of some interest to you. I welcome your feedback, comments, questions, and ideas!

I am presently considering notational options for expressing reification and RDF-star/SPARQL-star features in selectors.

The freshest version of the document is available here: https://github.com/AdamSobieski/Foundation/blob/main/Notes/Graph-based%20Selectors.md .


Best regards,
Adam Sobieski
http://www.phoster.com

P.S.:

Introduction<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#introduction>

A new language inspired by CSS and SPARQL is described for selecting graphs, nodes, and edges for purposes of styling.

Use Cases<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#use-cases>

Use cases for this language include:

  1.  Visually styling displayed graphs, nodes, and edges.
  2.  Adding properties and values to graphs, nodes, and edges, e.g., to finite-state machines and their states and transitions.

Path Syntax<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#path-syntax>

Let us consider paths of alternating nodes and edges. For examples:

node(...) > edge(...) > node(...) { property: value; }

edge(...) > node(...) > edge(...) { property: value; }

The contents in the parentheses, above, are to be drawn from a subset of the CSS selector syntax as the following example intends to clarify:

node([attr="value"]) > edge(*) > node(.has-selection) { color: blue; }

Datasets with Multiple Graphs<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#datasets-with-multiple-graphs>

Datasets may contain multiple graphs. The following examples show how selection can be expressed for these scenarios. The descendent combinator, a blank space, is used between selected graphs and their descendent nodes or edges.

graph(...) node(...) > edge(...) > node(...) { property: value; }

graph(...) edge(...) > node(...) > edge(...) { property: value; }

The following example makes concrete the parenthesized CSS-based selectors:

graph(#id-123) node([attr="value"]) > edge(*) > node(.has-selection) { color: blue; }

The following example shows how one would express a selection from a named graph:

@namespace rdf url(http://www.w3.org/1999/02/22-rdf-syntax-ns#)

graph([rdf|about="http://example.org/stuff/1.0/graph"]) node([attr="value"]) > edge(*) > node(.has-selection)
{
  color: blue;
}

Selection<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#selection>

Let us expand the path syntax by utilizing a question-mark to indicate which component to select.

?node([attr="value"]) > edge(*) > node(.has-selection) { color: blue; }
node([attr="value"]) > ?edge(*) > node(.has-selection) { color: blue; }
node([attr="value"]) > edge(*) > ?node(.has-selection) { color: blue; }

Logical Operations<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#logical-operations>

Logical operators, not(), and(), and or(), can be utilized.

node([attr="value"]) > edge(*) > or(node(.txt-sel) > ?edge(.rt-clk), node(.img-sel) > ?edge(.rt-clk)) > node(.context-menu)
{
  color: blue;
}

Repetition<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#repetition>

repeat(min, max, pattern) can be a shorthand notation for describing a disjunction between a path repeated a number of times.

node([attr="value"]) > repeat(0, 9, edge(.key-press) > node(*)) > edge(.key-press) > ?node(*)
{
  color: blue;
}

Binding<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#binding>

The :as(--variable-name) syntax can be used to bind graphs, nodes, and edges to named variable instances.

The Semantic Web<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#the-semantic-web>
RDF/XML<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#rdfxml>

Towards providing the expressiveness to select and style both nodes and edges from RDF graphs, the following example select and styles from RDF/XML markup.

<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:ex="http://example.org/stuff/1.0/">
  <ex:editor>
    <rdf:Description>
      <ex:homePage>
        <rdf:Description rdf:about="http://purl.org/net/dajobe/" />
      </ex:homePage>
      <ex:fullName>Dave Beckett</ex:fullName>
    </rdf:Description>
  </ex:editor>
  <dc:title>RDF 1.1 XML Syntax</dc:title>
</rdf:Description>

Using the syntax under discussion, one could select one or more nodes and style them:

@namespace rdf url(http://www.w3.org/1999/02/22-rdf-syntax-ns#)
@namespace ex  url(http://example.org/stuff/1.0/)

node([rdf|about="http://www.w3.org/TR/rdf-syntax-grammar"]) > edge(ex|editor) > node(*) > edge(ex|fullName) > ?node(*)
{
   color: blue;
}

Here is a mapping from that selector to a SPARQL query:

PREFIX ex: <http://example.org/stuff/1.0/>
SELECT ?y
WHERE
{
  <http://www.w3.org/TR/rdf-syntax-grammar> ex:editor ?x .
  ?x ex:fullName ?y .
}

SPARQL<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#sparql>

Here is a SPARQL query which will be mapped to a selector in the new syntax.

PREFIX ex: <http://example.org/stuff/1.0/>
SELECT ?y
WHERE
{
  ?x ex:p1 123 .
  ?x ex:p2 456 .
  ?x ex:p3 ?y .
}

@namespace rdf url(http://www.w3.org/1999/02/22-rdf-syntax-ns#)
@namespace ex  url(http://example.org/stuff/1.0/)

and(
  node(*):as(--x) > edge(ex|p1) > node([rdf|value=123]),
  node(*):as(--x) > edge(ex|p2) > node([rdf|value=456]),
  node(*):as(--x) > edge(ex|p3) > ?node(*)
)
{
  color: blue;
}

Here is a more complex SPARQL query which involves multiple graphs:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?person
WHERE {
    ?person foaf:name ?name .
    GRAPH ?g1 { ?person a foaf:Person }
    GRAPH ?g2 { ?person a foaf:Person }
    GRAPH ?g3 { ?person a foaf:Person }
    FILTER(?g1 != ?g2 && ?g1 != ?g3 && ?g2 != ?g3) .
}

This could be expressed utilizing the new selector syntax:

@namespace rdf url(http://www.w3.org/1999/02/22-rdf-syntax-ns#)
@namespace foaf url(http://xmlns.com/foaf/0.1/)

and(
  graph(*):as(--g1) ?node(*):as(--person) > edge(rdf|type) > node(foaf|Person),
  graph(*):as(--g2) ?node(*):as(--person) > edge(rdf|type) > node(foaf|Person),
  graph(*):as(--g3) ?node(*):as(--person) > edge(rdf|type) > node(foaf|Person)
):filter(--g1 != --g2):filter(--g1 != --g3):filter(--g2 != --g3)
{
  color: blue;
}

Or, more succinctly:

@namespace rdf url(http://www.w3.org/1999/02/22-rdf-syntax-ns#)
@namespace foaf url(http://xmlns.com/foaf/0.1/)

and(
  graph(*):as(--g1) ?node(foaf|Person):as(--person),
  graph(*):as(--g2) ?node(foaf|Person):as(--person),
  graph(*):as(--g3) ?node(foaf|Person):as(--person)
):filter(--g1 != --g2):filter(--g1 != --g3):filter(--g2 != --g3)
{
  color: blue;
}

Selected Previous Works<https://github.com/AdamSobieski/Foundation/edit/main/Notes/Graph-based%20Selectors.md#selected-previous-works>

  *   CSS Selectors<https://www.w3.org/TR/selectors-4/>
  *   Fresnel Selector Language for RDF<https://www.w3.org/2005/04/fresnel-info/fsl/>
  *   Graph Stylesheets<https://www.w3.org/2001/11/IsaViz/gss/gssmanual.html>
  *   RDF/XML<https://www.w3.org/TR/rdf12-xml/>
  *   RDF-star<https://w3c.github.io/rdf-star/cg-spec/editors_draft.html>
  *   SPARQL<https://www.w3.org/TR/sparql12-query/>
  *   SPARQL-star<https://w3c.github.io/rdf-star/cg-spec/editors_draft.html>

Received on Tuesday, 24 October 2023 05:04:09 UTC