예제 #1
0
        /// <summary>Uses a specific serializer.</summary>
        /// <remarks>Uses a specific serializer.</remarks>
        /// <exception cref="JsonLD.Core.JsonLdError"></exception>
        public static JToken FromRDF(JToken input, JsonLdOptions options, IRDFParser parser
                                     )
        {
            RDFDataset dataset = parser.Parse(input);
            // convert from RDF
            JToken rval = new JsonLdApi(options).FromRDF(dataset);

            // re-process using the generated context if outputForm is set
            if (options.outputForm != null)
            {
                if ("expanded".Equals(options.outputForm))
                {
                    return(rval);
                }
                else
                {
                    if ("compacted".Equals(options.outputForm))
                    {
                        return(Compact(rval, dataset.GetContext(), options));
                    }
                    else
                    {
                        if ("flattened".Equals(options.outputForm))
                        {
                            return(Flatten(rval, dataset.GetContext(), options));
                        }
                        else
                        {
                            throw new JsonLdError(JsonLdError.Error.UnknownError);
                        }
                    }
                }
            }
            return(rval);
        }
예제 #2
0
        /// <summary>Converts an RDF dataset to JSON-LD.</summary>
        /// <remarks>Converts an RDF dataset to JSON-LD.</remarks>
        /// <param name="dataset">
        /// a serialized string of RDF in a format specified by the format
        /// option or an RDF dataset to convert.
        /// </param>
        /// <?></?>
        /// <param name="callback">(err, output) called once the operation completes.</param>
        /// <exception cref="JsonLDNet.Core.JsonLdError"></exception>
        public static JToken FromRDF(JToken dataset, JsonLdOptions options)
        {
            // handle non specified serializer case
            IRDFParser parser = null;

            if (options.format == null && dataset.Type == JTokenType.String)
            {
                // attempt to parse the input as nquads
                options.format = "application/nquads";
            }
            if (rdfParsers.ContainsKey(options.format))
            {
                parser = rdfParsers[options.format];
            }
            else
            {
                throw new JsonLdError(JsonLdError.Error.UnknownFormat, options.format);
            }
            // convert from RDF
            return(FromRDF(dataset, options, parser));
        }
예제 #3
0
 /// <exception cref="JsonLD.Core.JsonLdError"></exception>
 public static JToken FromRDF(JToken input, IRDFParser parser)
 {
     return(FromRDF(input, new JsonLdOptions(string.Empty), parser));
 }
예제 #4
0
 public static void RegisterRDFParser(string format, IRDFParser parser)
 {
     rdfParsers[format] = parser;
 }