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

Need tooling/workflow to create ShEx JSON files from ShExR (i.e. Turtle) encoding of same #38

Open
danbri opened this issue Apr 1, 2022 · 2 comments
Assignees

Comments

@danbri
Copy link
Contributor

danbri commented Apr 1, 2022

At Google we're looking into publishing .ttl but the JS tools here need ShEx in JSON(-LD) form.

I believe everything is in the shexjs codebase as exposed at http://shex.io/webapps/shex.js/doc/shex-simple.html somewhere, @ericprud is considering API possibilities.

@danbri
Copy link
Contributor Author

danbri commented Apr 1, 2022

See also:

@danbri
Copy link
Contributor Author

danbri commented Apr 1, 2022

In the shex validator (not schemarama, to be clear, but the tinyurl in prev. entry in this issue), ... remove the querymap section, make sure there's still something to validate, and when you validate there will be shexj at the bottom of the page:

https://gist.github.com/danbri/1ae3afdad3f7a82177376eafc113d6eb

@ericprud adds that behind the scenes the flow is more like:

ShExR and ShexJ -> ShExC, ShExC -> ShExJ

In raw form we get this:

{
  "type": "Schema",
  "shapes": [
    {
      "type": "ShapeAnd",
      "id": "http://shex.io/webapps/shex.js/doc/S1",
      "shapeExprs": [
        {
          "type": "Shape",
          "expression": {
            "type": "TripleConstraint",
            "predicate": "http://schema.org/url",
            "min": 1,
            "max": -1,
            "semActs": [
              {
                "type": "SemAct",
                "name": "https://google.com/search/validation/validurl",
                "code": "console.log('some url checking code here')"
              }
            ]
          }
        },
        {
          "type": "Shape",
          "expression": {
            "type": "TripleConstraint",
            "predicate": "http://schema.org/datePublished",
            "min": 0,
            "max": 1,
            "semActs": [
              {
                "type": "SemAct",
                "name": "https://google.com/search/validation/validdate-time",
                "code": "console.log('some datetime checking code here')"
              }
            ]
          }
        },
        {
          "type": "Shape",
          "expression": {
            "type": "TripleConstraint",
            "predicate": "http://schema.org/claimReviewed"
          }
        },
        {
          "type": "Shape",
          "expression": {
            "type": "TripleConstraint",
            "predicate": "http://schema.org/itemReviewed",
            "valueExpr": {
              "type": "ShapeAnd",
              "shapeExprs": [
                {
                  "type": "Shape",
                  "expression": {
                    "type": "TripleConstraint",
                    "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                    "valueExpr": {
                      "type": "NodeConstraint",
                      "values": [
                        "http://schema.org/CreativeWork"
                      ]
                    }
                  }
                },
                {
                  "type": "ShapeOr",
                  "shapeExprs": [
                    {
                      "type": "ShapeNot",
                      "shapeExpr": {
                        "type": "Shape",
                        "expression": {
                          "type": "TripleConstraint",
                          "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                          "valueExpr": {
                            "type": "NodeConstraint",
                            "values": [
                              "http://schema.org/CreativeWork"
                            ]
                          }
                        }
                      }
                    },
                    {
                      "type": "ShapeAnd",
                      "shapeExprs": [
                        {
                          "type": "Shape",
                          "expression": {
                            "type": "TripleConstraint",
                            "predicate": "http://schema.org/author",
                            "valueExpr": {
                              "type": "ShapeAnd",
                              "shapeExprs": [
                                {
                                  "type": "ShapeOr",
                                  "shapeExprs": [
                                    {
                                      "type": "Shape",
                                      "expression": {
                                        "type": "TripleConstraint",
                                        "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                                        "valueExpr": {
                                          "type": "NodeConstraint",
                                          "values": [
                                            "http://schema.org/Organization"
                                          ]
                                        }
                                      }
                                    },
                                    {
                                      "type": "Shape",
                                      "expression": {
                                        "type": "TripleConstraint",
                                        "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                                        "valueExpr": {
                                          "type": "NodeConstraint",
                                          "values": [
                                            "http://schema.org/Person"
                                          ]
                                        }
                                      }
                                    }
                                  ]
                                },
                                {
                                  "type": "ShapeOr",
                                  "shapeExprs": [
                                    {
                                      "type": "ShapeNot",
                                      "shapeExpr": {
                                        "type": "ShapeOr",
                                        "shapeExprs": [
                                          {
                                            "type": "Shape",
                                            "expression": {
                                              "type": "TripleConstraint",
                                              "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                                              "valueExpr": {
                                                "type": "NodeConstraint",
                                                "values": [
                                                  "http://schema.org/Organization"
                                                ]
                                              }
                                            }
                                          },
                                          {
                                            "type": "Shape",
                                            "expression": {
                                              "type": "TripleConstraint",
                                              "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                                              "valueExpr": {
                                                "type": "NodeConstraint",
                                                "values": [
                                                  "http://schema.org/Person"
                                                ]
                                              }
                                            }
                                          }
                                        ]
                                      }
                                    },
                                    {
                                      "type": "Shape",
                                      "expression": {
                                        "type": "TripleConstraint",
                                        "predicate": "http://schema.org/name",
                                        "min": 0,
                                        "max": 1
                                      }
                                    }
                                  ]
                                }
                              ]
                            },
                            "min": 0,
                            "max": 1
                          }
                        },
                        {
                          "type": "Shape",
                          "expression": {
                            "type": "TripleConstraint",
                            "predicate": "http://schema.org/datePublished",
                            "min": 0,
                            "max": 1,
                            "semActs": [
                              {
                                "type": "SemAct",
                                "name": "https://google.com/search/validation/validdate-time",
                                "code": "console.log('some datetime checking code here')"
                              }
                            ]
                          }
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            "min": 0,
            "max": 1
          }
        },
        {
          "type": "Shape",
          "expression": {
            "type": "TripleConstraint",
            "predicate": "http://schema.org/author",
            "valueExpr": {
              "type": "ShapeAnd",
              "shapeExprs": [
                {
                  "type": "ShapeOr",
                  "shapeExprs": [
                    {
                      "type": "Shape",
                      "expression": {
                        "type": "TripleConstraint",
                        "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                        "valueExpr": {
                          "type": "NodeConstraint",
                          "values": [
                            "http://schema.org/Organization"
                          ]
                        }
                      }
                    },
                    {
                      "type": "Shape",
                      "expression": {
                        "type": "TripleConstraint",
                        "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                        "valueExpr": {
                          "type": "NodeConstraint",
                          "values": [
                            "http://schema.org/Person"
                          ]
                        }
                      }
                    }
                  ]
                },
                {
                  "type": "ShapeOr",
                  "shapeExprs": [
                    {
                      "type": "ShapeNot",
                      "shapeExpr": {
                        "type": "ShapeOr",
                        "shapeExprs": [
                          {
                            "type": "Shape",
                            "expression": {
                              "type": "TripleConstraint",
                              "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                              "valueExpr": {
                                "type": "NodeConstraint",
                                "values": [
                                  "http://schema.org/Organization"
                                ]
                              }
                            }
                          },
                          {
                            "type": "Shape",
                            "expression": {
                              "type": "TripleConstraint",
                              "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                              "valueExpr": {
                                "type": "NodeConstraint",
                                "values": [
                                  "http://schema.org/Person"
                                ]
                              }
                            }
                          }
                        ]
                      }
                    },
                    {
                      "type": "ShapeAnd",
                      "shapeExprs": [
                        {
                          "type": "ShapeOr",
                          "shapeExprs": [
                            {
                              "type": "Shape",
                              "expression": {
                                "type": "TripleConstraint",
                                "predicate": "http://schema.org/name"
                              }
                            },
                            {
                              "type": "Shape",
                              "expression": {
                                "type": "TripleConstraint",
                                "predicate": "http://schema.org/url"
                              }
                            }
                          ]
                        },
                        {
                          "type": "Shape",
                          "expression": {
                            "type": "TripleConstraint",
                            "predicate": "http://schema.org/url",
                            "min": 0,
                            "max": -1,
                            "semActs": [
                              {
                                "type": "SemAct",
                                "name": "https://google.com/search/validation/validurl",
                                "code": "console.log('some url checking code here')"
                              }
                            ]
                          }
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            "min": 0,
            "max": 1
          }
        },
        {
          "type": "Shape",
          "expression": {
            "type": "TripleConstraint",
            "predicate": "http://schema.org/reviewRating",
            "valueExpr": {
              "type": "ShapeAnd",
              "shapeExprs": [
                {
                  "type": "Shape",
                  "expression": {
                    "type": "TripleConstraint",
                    "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                    "valueExpr": {
                      "type": "NodeConstraint",
                      "values": [
                        "http://schema.org/Rating"
                      ]
                    }
                  }
                },
                {
                  "type": "ShapeOr",
                  "shapeExprs": [
                    {
                      "type": "ShapeNot",
                      "shapeExpr": {
                        "type": "Shape",
                        "expression": {
                          "type": "TripleConstraint",
                          "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                          "valueExpr": {
                            "type": "NodeConstraint",
                            "values": [
                              "http://schema.org/Rating"
                            ]
                          }
                        }
                      }
                    },
                    {
                      "type": "ShapeAnd",
                      "shapeExprs": [
                        {
                          "type": "Shape",
                          "expression": {
                            "type": "TripleConstraint",
                            "predicate": "http://schema.org/alternateName"
                          }
                        },
                        {
                          "type": "ShapeAnd",
                          "shapeExprs": [
                            {
                              "type": "ShapeOr",
                              "shapeExprs": [
                                {
                                  "type": "ShapeNot",
                                  "shapeExpr": {
                                    "type": "Shape",
                                    "expression": {
                                      "type": "TripleConstraint",
                                      "predicate": "http://schema.org/name"
                                    }
                                  }
                                },
                                {
                                  "type": "Shape",
                                  "expression": {
                                    "type": "TripleConstraint",
                                    "predicate": "http://schema.org/alternateName",
                                    "min": 0,
                                    "max": 1
                                  }
                                }
                              ]
                            },
                            {
                              "type": "ShapeOr",
                              "shapeExprs": [
                                {
                                  "type": "ShapeNot",
                                  "shapeExpr": {
                                    "type": "ShapeNot",
                                    "shapeExpr": {
                                      "type": "Shape",
                                      "expression": {
                                        "type": "TripleConstraint",
                                        "predicate": "http://schema.org/name"
                                      }
                                    }
                                  }
                                },
                                {
                                  "type": "Shape",
                                  "expression": {
                                    "type": "TripleConstraint",
                                    "predicate": "http://schema.org/alternateName",
                                    "min": 1,
                                    "max": -1
                                  }
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "type": "ShapeNot",
                          "shapeExpr": {
                            "type": "ShapeAnd",
                            "shapeExprs": [
                              {
                                "type": "Shape",
                                "expression": {
                                  "type": "TripleConstraint",
                                  "predicate": "http://schema.org/alternateName"
                                }
                              },
                              {
                                "type": "Shape",
                                "expression": {
                                  "type": "TripleConstraint",
                                  "predicate": "http://schema.org/name"
                                }
                              }
                            ]
                          }
                        },
                        {
                          "type": "ShapeOr",
                          "shapeExprs": [
                            {
                              "type": "ShapeNot",
                              "shapeExpr": {
                                "type": "ShapeAnd",
                                "shapeExprs": [
                                  {
                                    "type": "ShapeOr",
                                    "shapeExprs": [
                                      {
                                        "type": "Shape",
                                        "expression": {
                                          "type": "TripleConstraint",
                                          "predicate": "http://schema.org/ratingValue"
                                        }
                                      },
                                      {
                                        "type": "Shape",
                                        "expression": {
                                          "type": "TripleConstraint",
                                          "predicate": "http://schema.org/bestRating"
                                        }
                                      },
                                      {
                                        "type": "Shape",
                                        "expression": {
                                          "type": "TripleConstraint",
                                          "predicate": "http://schema.org/worstRating"
                                        }
                                      }
                                    ]
                                  },
                                  {
                                    "type": "ShapeNot",
                                    "shapeExpr": {
                                      "type": "ShapeAnd",
                                      "shapeExprs": [
                                        {
                                          "type": "Shape",
                                          "expression": {
                                            "type": "TripleConstraint",
                                            "predicate": "http://schema.org/ratingValue",
                                            "valueExpr": {
                                              "type": "NodeConstraint",
                                              "pattern": "-1"
                                            }
                                          }
                                        },
                                        {
                                          "type": "Shape",
                                          "expression": {
                                            "type": "TripleConstraint",
                                            "predicate": "http://schema.org/bestRating",
                                            "valueExpr": {
                                              "type": "NodeConstraint",
                                              "pattern": "-1"
                                            }
                                          }
                                        },
                                        {
                                          "type": "Shape",
                                          "expression": {
                                            "type": "TripleConstraint",
                                            "predicate": "http://schema.org/worstRating",
                                            "valueExpr": {
                                              "type": "NodeConstraint",
                                              "pattern": "-1"
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  }
                                ]
                              }
                            },
                            {
                              "type": "ShapeAnd",
                              "shapeExprs": [
                                {
                                  "type": "Shape",
                                  "expression": {
                                    "type": "TripleConstraint",
                                    "predicate": "http://schema.org/ratingValue",
                                    "valueExpr": {
                                      "type": "ShapeOr",
                                      "shapeExprs": [
                                        {
                                          "type": "NodeConstraint",
                                          "pattern": "([0-9]+[\\.,]?[0-9]*)/([0-9]+[\\.,]?[0-9]*)"
                                        },
                                        {
                                          "type": "NodeConstraint",
                                          "pattern": "([0-9]+[\\.,]?[0-9]*)%"
                                        },
                                        {
                                          "type": "NodeConstraint",
                                          "pattern": "([0-9]+[\\.,]?[0-9]*)"
                                        }
                                      ]
                                    },
                                    "min": 1,
                                    "max": -1
                                  }
                                },
                                {
                                  "type": "ShapeOr",
                                  "shapeExprs": [
                                    {
                                      "type": "ShapeNot",
                                      "shapeExpr": {
                                        "type": "Shape",
                                        "expression": {
                                          "type": "TripleConstraint",
                                          "predicate": "http://schema.org/ratingValue",
                                          "valueExpr": {
                                            "type": "NodeConstraint",
                                            "pattern": "([0-9]+[\\.,]?[0-9]*)"
                                          },
                                          "min": 1,
                                          "max": -1
                                        }
                                      }
                                    },
                                    {
                                      "type": "Shape",
                                      "semActs": [
                                        {
                                          "type": "SemAct",
                                          "name": "https://google.com/search/validation/validrating"
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            "min": 1,
            "max": -1
          }
        }
      ]
    }
  ],
  "@context": "http://www.w3.org/ns/shex.jsonld"
}

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