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

[Feature request] Extracting shapes from triples #48

Open
pietercolpaert opened this issue Jan 15, 2021 · 7 comments
Open

[Feature request] Extracting shapes from triples #48

pietercolpaert opened this issue Jan 15, 2021 · 7 comments

Comments

@pietercolpaert
Copy link

pietercolpaert commented Jan 15, 2021

I’m looking for a library that can help me to extract triples adhering to a SHACL shapes from an array of triples.

Could look like this:

const data = await loadDataset('my-data.ttl')
const shapeData = await loadDataset('personShape.ttl')
const objectIterator = extractObjects(data, shapeData, "ex:PersonShape1")
for await (const object of objectIterator) {
    console.log(object); // contains an occurence of array of triples according to this specific shape.
}

Use case issue: TREEcg/event-stream-client#2

@bergos
Copy link

bergos commented Jan 16, 2021

I think there are two different ways to approach this:

a) A separate method for the SHACLValidator. I would propose to use a more "graph style" vocabulary. Maybe coverage, cause the result would be the coverage of all triples when traversing the graph according to all SHACL nodes.

b) Add a coverage property to the ValidationResult. The validate method of the SHACLValidator returns a ValidationReport. The report contains multiple ValidationResult in the results property. That would even allow us to distinguish between different results for the same shape. I'm not sure if there are any drawbacks. But if there are drawbacks, a second argument for options could be added to the validate method to enable this feature.

I would prefer option b.

@martinmaillard you know the library the best. What's your opinion on that topic?

@tpluscode
Copy link
Collaborator

tpluscode commented Jan 17, 2021

From the perspective of SHACL I think the key step is determining the Focus Nodes which conform shapes. Once you know that it is simple to extract the subgraph by walking the Property Shapes.

For starters, I would propose adding only the first step to the library. In my mind that would be a TermMap<Term, Term[]> of shapes and conforming nodes (or the other way round, don't know which makes most sense).

type FocusNode = Term
type Shape = Term

interface ValidationResult {
  // for every conforming FocusNode return the matched Shapes
  conformingFocusNodes: TermMap<FocusNode, Shape[]>
}

@pietercolpaert
Copy link
Author

I like the ideas. Some thoughts:

  • I don’t think this task actually requires validation though: I may want to be forgiving and also get invalid objects.
  • Indeed, when you know the Focus Node the task becomes easier. When dealing with a collection for which all members adhere to a shape, you do know these focus nodes, which is what we do in the use case at Determining which triples need to be emitted per event-based object TREEcg/event-stream-client#2
  • For this task, probably open shapes don’t require any SHACL shape processing, right? We should only process closed shapes to limit the triples added to the resulting triple group.

@martinmaillard
Copy link
Contributor

This seems like a very useful feature: I actually implemented something somewhat similar in a project. But I wonder if it really belongs in this library.

@ktk
Copy link
Member

ktk commented Jan 19, 2021

To give some more context, this issue started on Twitter and @bergos proposed to do an issue here. But I also was asking myself if the library is the right place to do it.
As in we should reflect that before it becomes a "stable" feature in here. Maybe putting it somewhere separate is a good idea.

@tpluscode
Copy link
Collaborator

I'm re-reading the comments. Is it actually something different from what I proposed above?

@pietercolpaert
Copy link
Author

Don’t think so! I’m just a bit puzzled about who should do what now!

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

5 participants