Exemplo n.º 1
0
        public Task <IEnumerable <KeyValuePair <Iri, IEnumerable <Statement> > > > Read(StreamReader streamReader)
        {
            if (streamReader == null)
            {
                throw new ArgumentNullException(nameof(streamReader));
            }

            var defaultGraph = new TypePrioritizingStatementCollection();
            var graphMap     = new Dictionary <Iri, IEnumerable <Statement> >();
            var dataset      = (RDFDataset)JsonLdProcessor.ToRDF(JSONUtils.FromReader(streamReader));

            foreach (var graphName in dataset.GraphNames())
            {
                var graphIri = (graphName == "@default" ? null : (graphName.StartsWith("_:") ? new Iri() : new Iri(graphName)));
                IEnumerable <Statement> statements;
                if (graphIri == null)
                {
                    statements = defaultGraph;
                }
                else if (!graphMap.TryGetValue(graphIri, out statements))
                {
                    graphMap[graphIri] = statements = new TypePrioritizingStatementCollection();
                }

                var statementsCollection = (ICollection <Statement>)statements;
                foreach (var quad in dataset.GetQuads(graphName))
                {
                    statementsCollection.Add(quad.AsStatement());
                }
            }

            return(Task.FromResult(new[] { new KeyValuePair <Iri, IEnumerable <Statement> >(null, defaultGraph) }.Concat(graphMap)));
        }