clownface
clownface copied to clipboard
outE (out edges) and inE (in edges) methods
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
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'
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()
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' ]
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
@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'
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.