o-development / ldo-cli

A command line interface for linked data objects
Other
3 stars 0 forks source link

Question: Reference shape from different file #3

Open mrkvon opened 1 year ago

mrkvon commented 1 year ago

With ldo-cli, in shex file, can we reference a shape defined in other shex file?

Something along the lines of

# solidProfile.shex

# Trying at least something...
IMPORT <publicTypeIndex.shex>

PREFIX ex: <https://example.com/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX solid: <http://www.w3.org/ns/solid/terms#>

ex:SolidProfile {
  solid:publicTypeIndex @ex:PublicTypeIndex * ; # <=== This is causing problems
  rdfs:seeAlso @ex:SolidProfile * # <==== This works fine
  # ... and more ...
}
# publicTypeIndex.shex

PREFIX ex: <https://example.com/>

ex:PublicTypeIndex {
  # ...
}

With such setting, the solidProfile.typings.ts didn't get generated, but failed with error like

(node:224922) UnhandledPromiseRejectionWarning: SyntaxError: ';' expected. (54:63)
  52 |      * A registry of all types used on the user's Pod (for public access)
  53 |      */
> 54 |     "http://www.w3.org/ns/solid/terms#publicTypeIndex"?: https://example.com/PublicTypeIndex[];
     |                                                               ^
  55 |     seeAlso?: (SolidProfile)[];
  56 | }
  57 |

Am i missing something, or is this currently not possible?

Motivation

I'm trying to figure out a good way to query Solid data across multiple documents, and i'd like to use LDO because of its awesome shape-based type safety.

One idea i want to try: fetch all relevant documents[^1], create rdf dataset from them, and then use LDO on the dataset, to access the results easily. For this, multiple related shapes would need to get chained together, so we could do

[^1]: At the end, this may be a bit more complicated. We could fetch new relevant documents as we follow our nose through the rdf graph according to query (whatever that may look like)

solidProfile.publicTypeIndex
  .flatMap(
    publicTypeIndex => publicTypeIndex.references.map(typeRegistration => typeRegistration.instance)
  )

// etc...

Of course we could put all the shapes into a single file. But that would be a bit hard to maintain or reuse...

jaxoncreed commented 1 year ago

@mrkvon Yes, this feature is not currently implemented. There are a few workarounds. You could copy the external shape into your .shex file, or you could manually define your types and JSON-LD context.

mrkvon commented 1 year ago

@jaxoncreed

Let me just clarify: we already copied external shapes to the project folder. We're trying to reference a shape from other file in the same folder of the project (not external shapes from e.g. shaperepo). Is that also not supported currently?

In any case, to resolve this we've copied all shapes into a single file (WIP), and it works. The downside is the shapes may be harder to maintain and reuse, as i already wrote.