Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The shape topology to Mermaid #29

Closed
pietercolpaert opened this issue Apr 23, 2024 · 7 comments
Closed

The shape topology to Mermaid #29

pietercolpaert opened this issue Apr 23, 2024 · 7 comments
Assignees

Comments

@pietercolpaert
Copy link
Member

pietercolpaert commented Apr 23, 2024

It would be useful to be able to export the shape topology as a mermaid description.

I.e., the shape topology

Shape {
   atLeastOneLists: [ Shape {
       requiredPaths: ["gsp:geo asWKT|asGML", "^foaf:member"],
       optionalPaths: ["foaf:knows"]
   },
   Shape {
    //...
   }]
} 

Could be translated to this in mermaid:

flowchart TD
    S(( ))-->X{ }
    X-->S1(( ))
    X-->S2(( ))
    S1-->|gsp:geo|S3[ ]-->|"asWKT | asGML"|S4[ ]
    S5[ ]-->|^foaf:member|S1
    S1-.->|foaf:knows|S6[ ]

Visualizing into:

flowchart TD
    S(( ))-->X{ }
    X-->S1(( ))
    X-->S2(( ))
    S1-->|gsp:geo|S3[ ]-->|"asWKT | asGML"|S4[ ]
    S5[ ]-->|^foaf:member|S1
    S1-.->|foaf:knows|S6[ ]
Loading
@pheyvaer
Copy link
Collaborator

@pietercolpaert Can you explain how it fits in the extractor? What is the function description and input parameters?

@pietercolpaert
Copy link
Member Author

pietercolpaert commented Apr 30, 2024

import {CBDShapeExtractor} from "extract-cbd-shape";

This will create the shape topology already. the shapesGraphStore is an rdf-stores RDFStore containing all quads of the shape

let extractor = new CBDShapeExtractor(shapesGraphStore);

This now has something of type ShapesGraph in it, in which I’d like to add a toMermaid function that takes the term of the nodeshape as a parameter

extractor.shapesGraph.toMermaid(df.namedNode('nodeshapeIRI'));

@pheyvaer
Copy link
Collaborator

pheyvaer commented May 2, 2024

@pietercolpaert How would you convert something like this shape to Mermaid?

ex:Shape a sh:NodeShape ;
    sh:property [
        sh:path ex:subject ;
        sh:minCount 1 ;
        sh:node [
            sh:property [
                sh:path rdfs:label ;
                sh:minCount 1
            ]
        ]
    ] .

When it's converted to a Shape topology it has both requiredPaths and nodeLinks, and both mention ex:subject:

{
  "requiredPaths": [
    {
      "predicate": {
        "termType": "NamedNode",
        "value": "http://example.org/subject"
      }
    }
  ],
  "nodeLinks": [
    {
      "pathPattern": {
        "predicate": {
          "termType": "NamedNode",
          "value": "http://example.org/subject"
        }
      },
      "link": {
        "termType": "BlankNode",
        "value": "n3-39"
      }
    }
  ],
  "atLeastOneLists": [],
  "optionalPaths": [],
  "closed": false
}

pheyvaer added a commit that referenced this issue May 2, 2024
@pheyvaer pheyvaer self-assigned this May 2, 2024
@pietercolpaert
Copy link
Member Author

pietercolpaert commented May 2, 2024

A nodelink path is also going to be repeated in either the optional or in the required path indeed. So I’d say if a path is already processed as part of a nodelink, let’s ignore it in the optional/required, unless we will also visualize required vs. optional in a different way, i.e. by using a dashed line instead of a full line?

I.e., for optional node links, this then would become:

flowchart TD
    S(( ))---X{OR}
    X---S1(( ))
    X---S2(( ))
    S1-->|gsp:geo|S3[ ]-->|"asWKT | asGML"|S4[ ]
    S5(( ))-.->|^foaf:member|S1
    S1-->|foaf:knows|S6[ ]
    S5-->|rdfs:label|S7[ ]

Imagine the foaf:member’s subject is an organization, that if given, must have an rdfs:label, we can show it as follows:

flowchart TD
    S(( ))---X{OR}
    X---S1(( ))
    X---S2(( ))
    S1-->|gsp:geo|S3[ ]-->|"asWKT | asGML"|S4[ ]
    S5(( ))-.->|^foaf:member|S1
    S1-->|foaf:knows|S6[ ]
    S5-->|rdfs:label|S7[ ]
Loading

@pheyvaer
Copy link
Collaborator

pheyvaer commented May 2, 2024

Ok! I included that.

Another question: how do we deal with double inverse paths?

ex:DoubleInversePathShape a sh:NodeShape ;
    sh:closed true;
    sh:property [
        sh:path ([sh:inversePath [sh:inversePath ex:p1 ] ]) ;
        sh:minCount 1
    ] .

Do we just invert the first inverse path and leave the second as is (which is what happens now) or do we keep inverting them until we can't anymore?

P.S. I don't fully understand why someone would use a double inverse path in the first place 😄

@pietercolpaert
Copy link
Member Author

I believe we should turn it around again indeed: double inverse becomes forward

@pheyvaer
Copy link
Collaborator

pheyvaer commented May 6, 2024

Closed by #30

@pheyvaer pheyvaer closed this as completed May 6, 2024
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

No branches or pull requests

2 participants