Esempio n. 1
0
 /// <summary>
 /// Create a new instance of the <c>StardogStore</c> class.
 /// </summary>
 /// <param name="host">URL of the host to connect to.</param>
 /// <param name="username">Username to be used when connecting.</param>
 /// <param name="password">Password to be used when connecting.</param>
 /// <param name="storeId">Knowledge base / database identifier.</param>
 public StardogStore(string host, string username, string password, string storeId)
 {
     _connector  = new StardogConnector(host, storeId, username, password);
     _rdfHandler = new StardogRdfHandler();
 }
Esempio n. 2
0
        /// <summary>
        /// Loads a serialized graph from the given stream into the current store. See allowed <see cref="RdfSerializationFormat">formats</see>.
        /// </summary>
        /// <param name="stream">Stream containing a serialized graph</param>
        /// <param name="modelUri">Uri of the graph in this store</param>
        /// <param name="format">Allowed formats</param>
        /// <param name="update">Pass false if you want to overwrite the existing data. True if you want to add the new data to the existing.</param>
        /// <returns></returns>
        public override Uri Read(Stream stream, Uri modelUri, RdfSerializationFormat format, bool update)
        {
            if (!update)
            {
                // Clear the graph.
                RemoveModel(modelUri);
            }

            // Number of triples to write simultanously.
            const uint bulkSize = 100;

            // Collect the triples that have been read.
            List <Triple> triples = new List <Triple>();

            // A handler which will fill the triples up to the bulk size.
            StardogRdfHandler handler = new StardogRdfHandler()
            {
                OnReadTriple = (e, t) =>
                {
                    if (triples.Count < bulkSize)
                    {
                        triples.Add(t);
                    }
                    else
                    {
                        _connector.UpdateGraph(modelUri, triples, null);

                        triples.Clear();
                    }
                },
                OnReadEnded = (e, ok) =>
                {
                    if (triples.Count > 0)
                    {
                        _connector.UpdateGraph(modelUri, triples, null);
                    }
                }
            };

            using (var reader = new StreamReader(stream))
            {
                switch (format)
                {
                case RdfSerializationFormat.N3:
                    new Notation3Parser().Load(handler, reader);
                    break;

                case RdfSerializationFormat.NTriples:
                    new NTriplesParser().Load(handler, reader);
                    break;

                case RdfSerializationFormat.Trig:
                    new TriGParser().Load(handler, reader);
                    break;

#if !NET35
                case RdfSerializationFormat.NQuads:
                    new NQuadsParser().Load(handler, reader);
                    break;
#endif

                case RdfSerializationFormat.Turtle:
                    new TurtleParser().Load(handler, reader);
                    break;

                case RdfSerializationFormat.Json:
                    new RdfJsonParser().Load(handler, reader);
                    break;

#if !NET35
                case RdfSerializationFormat.JsonLd:
                    new JsonLdParser().Load(handler, reader);
                    break;
#endif

                case RdfSerializationFormat.RdfXml:
                    new RdfXmlParser().Load(handler, reader);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(format), format, null);
                }
            }

            return(modelUri);
        }