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

outE (out edges) and inE (in edges) methods #62

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

Conversation

cristianvasquez
Copy link

Hi,

I was trying to 'follow my nose' and explore properties and objects using clownface, but it was difficult for me to explore 'properties' (for example, to get the label of a property)

I added the outE (out edges) and inE (in edges) methods to experiment. I find them useful.

This is the inspiration: https://github.com/mpollmeier/gremlin-scala/blob/master/gremlin-scala/src/test/scala/gremlin/scala/ArrowSyntaxSpec.scala

I made this pull request to discuss the addition of these two functions

@cristianvasquez
Copy link
Author

Motivation:

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

const ns = {
  ex: rdf.namespace('http://example.org/'),
}
const dataset = rdf.dataset()
dataset.addAll([
  rdf.quad(ns.ex.bob, ns.ex.exoticProperty, rdf.literal('Bob')),
  rdf.quad(ns.ex.exoticProperty, ns.ex.label, rdf.literal('First name')),
])

const bob = clownface({ dataset: dataset })
   .namedNode(ns.ex.bob)

// What's the label of exoticProperty?
console.log(bob.outE(ns.ex.exoticProperty).out(ns.ex.label).value)

// outputs 'First name'

@tpluscode
Copy link
Contributor

I support this effort, albeit I have not looked closely yet. That said, the motivation does not give it justice. What you describe can simply be done as

-bob.outE(ns.ex.exoticProperty).out(ns.ex.label).value
+bob.node(ns.ex.exoticProperty).out(ns.ex.label).value

What is missing, and came up a bunch of times, is to discover properties of bob

// will return pointer to ex:exoticProperty
const properties = bob.outE()

@cristianvasquez
Copy link
Author

As it is, we can also use it to discover the properties of bob

I agree that that is the best use case.

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

const ns = {
  ex: rdf.namespace('http://example.org/'),
}
const dataset = rdf.dataset()
dataset.addAll([
  rdf.quad(ns.ex.bob, ns.ex.exoticProperty, rdf.literal('Bob')),
  rdf.quad(ns.ex.exoticProperty, ns.ex.label, rdf.literal('First name')),
  rdf.quad(ns.ex.bob, ns.ex.age, rdf.literal(99)),
])

const bob = clownface({ dataset: dataset })
   .namedNode(ns.ex.bob)

console.log(bob.outE().values)
// Outputs
// [ 'http://example.org/exoticProperty', 'http://example.org/age' ]

@bergos
Copy link
Contributor

bergos commented Jan 19, 2022

In the RDF world, the term edge is not used that much. predicate and property are more common, where predicate is used in the context of triples and property in a higher level context. property is therefore the better choice for clownface. prop has already become a synonym for property for software developers. That would be in balance of having a short method name, but still one with a speaking name.

-> E should be replaced with prop

@cristianvasquez
Copy link
Author

@bergos, the property is renamed.
Now that you mention it, I'm a bit unsure about prop instead of predicate (or pred), because in general, the API is using 'predicate'

@bergos
Copy link
Contributor

bergos commented Jan 19, 2022

The predicate is used only for indexed argument variables. It's somehow in the docs but not really part of the interface. For sure, I didn't spend much time thinking about the naming. But you are right, that's a conflict. We should align the internal variables to the public interface, but let's do that in a separate PR to keep this one small.

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.

None yet

3 participants