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

feat: graph traversals #45

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

feat: graph traversals #45

wants to merge 7 commits into from

Conversation

tpluscode
Copy link
Contributor

@tpluscode tpluscode commented Jul 16, 2020

I propose this to allow moving pointer(s) between (named) graphs in a dataset

import cf from 'clownface'
import rdf from 'rdf-ext'

const pointer = cf({ dataset: rdf.dataset(), term: rdf.blankNode() })

const defaultGraphPointer = unionGraphPointer.fromGraph(pointer.defaultGraph)

const namedGraphPointer = defaultGraphPointer.fromGraph(rdf.namedNode())

const againUnionGraph = namedGraphPointer.fromGraph(null)

Now that I look at this, I'm a little concerned about literals and blank nodes. While the former would be harmless albeit strange, blank nodes should maybe be excluded from this feature?

@codecov-commenter
Copy link

codecov-commenter commented Jul 16, 2020

Codecov Report

Merging #45 into master will increase coverage by 0.38%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #45      +/-   ##
==========================================
+ Coverage   98.18%   98.57%   +0.38%     
==========================================
  Files           9        9              
  Lines         276      281       +5     
==========================================
+ Hits          271      277       +6     
+ Misses          5        4       -1     
Impacted Files Coverage Δ
lib/Clownface.js 99.15% <100.00%> (+0.03%) ⬆️
lib/Context.js 100.00% <0.00%> (+1.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1a4500...3b33b88. Read the comment docs.

@tpluscode tpluscode marked this pull request as ready for review July 16, 2020 14:24
@martinwebrant
Copy link

martinwebrant commented Dec 21, 2020

I struggle to use the implicit/explicit graphs in an easy way. Normally I do not care which graph something belongs to but there are cases like when I want to get a label of the type of a node - then I only want to get the exact type from the explicit graph.

For my use case it would be great to add the graph when matching things like:
myNamedNode.out(ns.rdf.type, ns.onto.explicit).out(ns.rdfs.label).value;
where ns.onto.explicit is the explicit graph.
Could also use the options if one does not want to add more arguments.
myNamedNode.out(ns.rdf.type, {graph: ns.onto.explicit}).out(ns.rdfs.label).value;

What do you think?

edit:
I found an ok solution for my problem. The sourcecode revealed that one can create two context's and if I create two datasets (one of explicit and one for implicit) and order the explicit first then I will get the type result from that first which is exactly what I want.
Looks like you are working on making the _context a bit more public which would suit me fine.
Not sure who helps out with the typescript definitions, but I can fix them up when you are done.

edit2:
Creating context does not help, after traversing you loose the context that did not match and subsequent queries will not get the complete result.

@tpluscode
Copy link
Contributor Author

Hello @martinwebrant. Sorry for late reply.

In code where I needed a specific graph, in the current version I would create a new pointer object like:

let pointer: GraphPointer
let graph: Term

const pointerAtGraph = cf({ dataset: pointer.dataset, term: pointer.term, graph })

I maintain the typings by the way

@martinwebrant
Copy link

const pointerAtGraph = cf({ dataset: pointer.dataset, term: pointer.term, graph })

Thanks, I'll do it like that for 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

Successfully merging this pull request may close these issues.

3 participants