Coder Social home page Coder Social logo

Comments (12)

jlanza avatar jlanza commented on June 15, 2024

Could you provide an example on how to use the PrefixMap. I have a map but when serializing the url are not shriked. Should I do it manually?
The issue is that I want my data to be included with prefixes and then when printing or serializing choose wether it is extended or not. Or even create the appropiate options for it based on the map used.

I'm thinking on using json-ld.js in conjunction with your serializer.

from rdf-ext.

ktk avatar ktk commented on June 15, 2024

@jlanza can you provide some sample code of what you have?

from rdf-ext.

bergos avatar bergos commented on June 15, 2024

At the moment the N3 serializer is the only one that supports exporting the prefix map. Importing works with the N3 and JSON-LD parser.

The JSON-LD serializer exports triples in flat form. Because JSON-LD can be written in different forms, the jsonld.js should be used to convert the JSON to the target form.

Maybe we can add a method to convert a prefix map to a JSON-LD context to compact the JSON.

from rdf-ext.

jlanza avatar jlanza commented on June 15, 2024

For the moment I think I'm going to use the following function to create namespaces based on the prefixMap. This way the creation of the nodes is always going to be in long form:

var namespace = function(nsuri) {
  return function(ln) {
    return new rdf.createNamedNode(nsuri + (ln != null ? ln : ''));
  };
};

var RDF = namespace(prefixMap["rdf"]);
var type = RDF("type");

But if I have time I will fork the json-serializer in order to include the prefix map and extend any reference that is shortened (shrink). Do you think it is ok to use another element in options object like you do in N3 parser?

from rdf-ext.

bergos avatar bergos commented on June 15, 2024

To avoid code duplication and option handling for jsonld.js I think the way to go would be a method to write code like this:

serializer.serialize(graph).then(function (json) {
return jsonld.promises().compact(json, serializer.prefixToContext(graph))
})

That would allow to use the full power of jsonld.js without the need to handle all possible options and methods in the serializer.

from rdf-ext.

jlanza avatar jlanza commented on June 15, 2024

Yes... You're right. This is more or less what I was thinking. But does the Graph contains the prefixMap of the environment?
Besides the other issue is that for instance if I have my entities defined shrinked, then the serializer should take the prefixMap in order to extend them. What I mean is:

var node1 = rdf.createNamedNode("rdf:type");
var node2 = rdf.createNamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");

both node1 and node2 should be the same, considering the prefixMap the environment has implemented.

from rdf-ext.

ktk avatar ktk commented on June 15, 2024

From how I remember the spec this would not work as rdf:typeneeds to be resolved manually. I was always annoyed by that as IMHO one should be able to specify the prefixMap for the whole environment and then the graphs should know it and automatically resolve it where necessary.

from rdf-ext.

jlanza avatar jlanza commented on June 15, 2024

I have the same thoughts as you and that's what my question was about!!! ;) Not just for rdf:type but for any other. It would be great to have entities written in an easy way. This is why I took the approach of the namespace function above.

Besides concerning the serialization and the context retrieval from the prefixMap I have done the following.

var context = {};
for (var prefix in myprofile.prefixes) {
  if (typeof myprofile.prefixes[prefix] === 'function') {
    continue;
  }
  context[prefix] = myprofile.prefixes[prefix];
}

If you'd like I can include a function in PrefixMap and TermMap as .toJSON() so you get rid of the functions and then this object can be used to create context, etc.

from rdf-ext.

ktk avatar ktk commented on June 15, 2024

Examples of how it was ment to be can be found in RDF Interfaces spec.

My idea went one step further: I started creating a 1:1 mapping of prefixes I use based on RDFa initial contexts, see https://github.com/uduvudu/uv-context for more information. My idea was then to simply load that (for example as a node module) into my code so I could directly use the prefixes in all my code. But I never finished the module-work.

from rdf-ext.

jlanza avatar jlanza commented on June 15, 2024

Looks interesting... I'm forking and incluing the above code.. Then it's up to you to accept ;)

from rdf-ext.

ktk avatar ktk commented on June 15, 2024

@bergos @tpluscode is this issue still relevant here? From my understanding this would be something for RDF Environment.

from rdf-ext.

ktk avatar ktk commented on June 15, 2024

Prefix-maps are legacy feature and no longer supported in the current version. There is currently no replacement.

from rdf-ext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.