rdfjs / data-model-spec

RDF/JS: Data model specification – A specification of a low level interface definition representing RDF data independent of a serialized format in a JavaScript environment.
http://rdf.js.org/data-model-spec/
72 stars 12 forks source link

Add DataFactory method to create from existing term #137

Closed RubenVerborgh closed 5 years ago

RubenVerborgh commented 5 years ago

We want to consider adding a method to DataFactory that takes a Term-shaped object (from any library) as input, and outputs a Term (from the library of the DataFactory) that equals it.

This can be used to convert a Term from one RDF/JS implementation to another.

rubensworks commented 5 years ago

For consistency, we may also want add a similar method for converting Quad objects.

elf-pavlik commented 5 years ago

I could make PR for DataFactory#clone()

(Term or Quad) clone((Term or Quad) other)

I think in this case we don't allow undefined or null

rubensworks commented 5 years ago

@elf-pavlik I would propose creating separate methods for cloning terms and quads (cloneTerm, cloneQuad). Implementations may otherwise become too complicated for determining the argument type.

RubenVerborgh commented 5 years ago

fromTerm/fromQuad?

bergos commented 5 years ago

👎 for .clone(), as this could be interpreted as a clone function of the factory itself. It doesn't make sense now, but maybe in the future we have an additional spec (Prefix + CURIE support which turns the DataFactory into an environment) were having multiple instance of the DataFactory makes more sense.

I favor fromTerm and fromQuad a little bit over cloneTerm and cloneQuad. from* indicates much stronger that new instances by the DataFactory are created and not that somehow the constructor of the given Term/Quad is used.

elf-pavlik commented 5 years ago

fromTerm & fromQuad SGTM, if no one else makes PR today/tomorrow I'll submit one on Wednesday

elf-pavlik commented 5 years ago

PR #158

awwright commented 5 years ago

Sorry I just noticed this, but I'm curious... Why not pass a plain object to the Term or Quad functions directly?

elf-pavlik commented 5 years ago

As I replied on https://gitter.im/rdfjs/public?at=5cb48398c55bd14d35ebcf88 single factory object makes it much easier to pass it around. Spec only defines methods on the factory and doesn't define any constructors for specific terms.