コード例 #1
0
        //Creating store based on: http://dadev.cloudapp.net/Datos%20Abiertos/PDF/ReferenceGuide.pdf
        public static RDFMemoryStore CreateStore()
        {
            RDFMemoryStore rdfstore = new RDFMemoryStore();

            // "from wikipedia.com: mickey mouse is 85 years old"
            rdfstore.AddQuadruple(new RDFQuadruple(
                                      new RDFContext("http://www.wikipedia.com/"),
                                      new RDFResource("http://www.waltdisney.com/mickey_mouse"),
                                      new RDFResource("http://xmlns.com/foaf/0.1/age"),
                                      new RDFTypedLiteral("85", RDFModelEnums.RDFDatatypes.XSD_INT))
                                  );

            // "from waltdisney.com: mickey mouse is 85 years old"
            rdfstore.AddQuadruple(new RDFQuadruple(
                                      new RDFContext("http://www.waltdisney.com/"),
                                      new RDFResource("http://www.waltdisney.com/mickey_mouse"),
                                      new RDFResource("http://xmlns.com/foaf/0.1/age"),
                                      new RDFTypedLiteral("85", RDFModelEnums.RDFDatatypes.XSD_INT))
                                  );

            // "from wikipedia.com: donald duck has english-us name "donald duck""
            rdfstore.AddQuadruple(new RDFQuadruple(
                                      new RDFContext("http://www.wikipedia.com/"),
                                      new RDFResource("http://www.waltdisney.com/donald_duck"),
                                      new RDFResource("http://xmlns.com/foaf/0.1/name"),
                                      new RDFTypedLiteral("donald duck", RDFModelEnums.RDFDatatypes.XSD_STRING))
                                  );

            return(rdfstore);
        }
コード例 #2
0
        /// <summary>
        /// Gets a memory store corresponding to the query result
        /// </summary>
        public RDFMemoryStore ToRDFMemoryStore()
        {
            RDFMemoryStore   result = new RDFMemoryStore();
            RDFPatternMember ctx    = null;
            RDFPatternMember subj   = null;
            RDFPatternMember pred   = null;
            RDFPatternMember obj    = null;

            //Iterate the datatable rows and generate the corresponding triples to be added to the result memory store
            IEnumerator resultRows = this.DescribeResults.Rows.GetEnumerator();

            while (resultRows.MoveNext())
            {
                ctx = this.DescribeResults.Columns.Contains("?CONTEXT")
                        ? new RDFContext(RDFQueryUtilities.ParseRDFPatternMember(((DataRow)resultRows.Current)["?CONTEXT"].ToString()).ToString())
                        : new RDFContext(RDFNamespaceRegister.DefaultNamespace.NamespaceUri);
                subj = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)resultRows.Current)["?SUBJECT"].ToString());
                pred = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)resultRows.Current)["?PREDICATE"].ToString());
                obj  = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)resultRows.Current)["?OBJECT"].ToString());
                if (obj is RDFResource)
                {
                    result.AddQuadruple(new RDFQuadruple((RDFContext)ctx, (RDFResource)subj, (RDFResource)pred, (RDFResource)obj));
                }
                else
                {
                    result.AddQuadruple(new RDFQuadruple((RDFContext)ctx, (RDFResource)subj, (RDFResource)pred, (RDFLiteral)obj));
                }
            }

            return(result);
        }
コード例 #3
0
        public StoreManager()
        {
            Store = new RDFMemoryStore();

            String sqlServerConnString = "";

            SqlStore = new RDFSQLServerStore(sqlServerConnString);
        }
コード例 #4
0
        public static void RemoveStoreFromFederationTest()
        {
            RDFFederation  fed = StoreBuilder.CreateFederation();
            RDFMemoryStore mem = StoreBuilder.CreateStore();

            fed.RemoveStore(mem);
            Assert.DoesNotContain(mem, fed);
        }
コード例 #5
0
        /// <summary>
        /// Gets a query result corresponding to the given memory store
        /// </summary>
        public static RDFDescribeQueryResult FromRDFMemoryStore(RDFMemoryStore store)
        {
            RDFDescribeQueryResult result = new RDFDescribeQueryResult(string.Empty);

            if (store != null)
            {
                //Transform the memory store into a datatable and assign it to the query result
                result.DescribeResults = store.ToDataTable();
            }
            return(result);
        }
コード例 #6
0
        public static void ContainsQuadrupleTest()
        {
            RDFMemoryStore rdfms = StoreBuilder.CreateStore();

            RDFQuadruple contain = new RDFQuadruple(
                new RDFContext("http://www.waltdisney.com/"),
                new RDFResource("http://www.waltdisney.com/mickey_mouse"),
                new RDFResource("http://xmlns.com/foaf/0.1/age"),
                new RDFTypedLiteral("85", RDFModelEnums.RDFDatatypes.XSD_INT));

            Assert.True(rdfms.ContainsQuadruple(contain));
        }
コード例 #7
0
        public static void MergingGraphIntoStoreTest()
        {
            var mem   = new RDFMemoryStore();
            var graph = GraphBuilder.WaltDisneyGraphBuild();

            mem.MergeGraph(graph);

            /*
             * A memorystore és a gráf első elemének vizsgálatával
             * megállapítjuk, hogy sikeres volt-e a merge, mivel üres memorystore-ba mergeltünk
             */
            Assert.True(mem.First().Predicate.Equals(graph.First().Predicate));
        }
コード例 #8
0
        public static void MergingGraphIntoStoreTest_AvoidsDuplicateInsertions()
        {
            var store1 = new RDFMemoryStore();
            var graph1 = GraphBuilder.WaltDisneyGraphBuild();
            var graph2 = GraphBuilder.WaltDisneyGraphBuild();

            var store2 = new RDFMemoryStore();

            store1.MergeGraph(graph1);
            store1.MergeGraph(graph2);

            store2.MergeGraph(graph1);

            var result = store1.DifferenceWith(store2);

            Assert.Empty(result);
        }
コード例 #9
0
        public static void CreateSimpleStoreTest()
        {
            RDFMemoryStore rdfms = StoreBuilder.CreateStore();

            Assert.Equal(3, rdfms.QuadruplesCount);
        }
コード例 #10
0
ファイル: RDFNQuads.cs プロジェクト: mdesalvo/RDFSharp
        /// <summary>
        /// Deserializes the given N-Quads stream to a memory store. 
        /// </summary>
        internal static RDFMemoryStore Deserialize(Stream inputStream) {
            Int64 nquadIndex = 0;
            try {

                #region deserialize
                using (StreamReader sr    = new StreamReader(inputStream, Encoding.ASCII)) {
                    RDFMemoryStore result = new RDFMemoryStore();
                    String  nquad         = String.Empty;
                    String[] tokens       = new String[4];
                    RDFResource S         = null;
                    RDFResource P         = null;
                    RDFResource O         = null;
                    RDFLiteral  L         = null;
                    RDFContext  C         = new RDFContext();
                    while((nquad          = sr.ReadLine()) != null) {
                        nquadIndex++;

                        #region sanitize  & tokenize
                        //Cleanup previous data
                        S                 = null;
                        tokens[0]         = String.Empty;
                        P                 = null;
                        tokens[1]         = String.Empty;
                        O                 = null;
                        L                 = null;
                        tokens[2]         = String.Empty;
                        C                 = new RDFContext();
                        tokens[3]         = String.Empty;

                        //Preliminary sanitizations: clean trailing space-like chars
                        nquad             = nquad.Trim(new Char[] { ' ', '\t', '\r', '\n' });

                        //Skip empty or comment lines
                        if (nquad        == String.Empty || nquad.StartsWith("#")) {
                            continue;
                        }

                        //Tokenizes the sanitized quad 
                        tokens            = TokenizeNQuad(nquad);
                        #endregion

                        #region subj
                        String subj       = tokens[0].TrimStart(new Char[] { '<' })
                                                     .TrimEnd(new   Char[] { '>' })
                                                     .Replace("_:", "bnode:");
                        S                 = new RDFResource(RDFModelUtilities.ASCII_To_Unicode(subj));
                        #endregion

                        #region pred
                        String pred       = tokens[1].TrimStart(new Char[] { '<' })
                                                     .TrimEnd(new   Char[] { '>' });
                        P                 = new RDFResource(RDFModelUtilities.ASCII_To_Unicode(pred));
                        #endregion

                        #region object
                        if (tokens[2].StartsWith("<")      ||
                            tokens[2].StartsWith("bnode:") ||
                            tokens[2].StartsWith("_:")) {
                            String obj    = tokens[2].TrimStart(new Char[] { '<' })
                                                     .TrimEnd(new Char[] { '>' })
                                                     .Replace("_:", "bnode:")
                                                     .Trim(new Char[] { ' ', '\n', '\t', '\r' });
                            O             = new RDFResource(RDFModelUtilities.ASCII_To_Unicode(obj));
                        }
                        #endregion

                        #region literal
                        else {

                            #region sanitize
                            tokens[2]     = RDFNTriples.regexSqt.Replace(tokens[2], String.Empty);
                            tokens[2]     = RDFNTriples.regexEqt.Replace(tokens[2], String.Empty);
                            tokens[2]     = tokens[2].Replace("\\\\", "\\")
                                                     .Replace("\\\"", "\"")
                                                     .Replace("\\n", "\n")
                                                     .Replace("\\t", "\t")
                                                     .Replace("\\r", "\r");
                            tokens[2]     = RDFModelUtilities.ASCII_To_Unicode(tokens[2]);
                            #endregion

                            #region plain literal
                            if (!tokens[2].Contains("^^") ||
                                 tokens[2].EndsWith("^^") ||
                                 tokens[2].Substring(tokens[2].LastIndexOf("^^", StringComparison.Ordinal) + 2, 1) != "<") {
                                if (RDFNTriples.regexLPL.Match(tokens[2]).Success) {
                                    tokens[2]        = tokens[2].Replace("\"@", "@");
                                    String pLitValue = tokens[2].Substring(0, tokens[2].LastIndexOf("@", StringComparison.Ordinal));
                                    String pLitLang  = tokens[2].Substring(tokens[2].LastIndexOf("@", StringComparison.Ordinal) + 1);
                                    L     = new RDFPlainLiteral(HttpUtility.HtmlDecode(pLitValue), pLitLang);
                                }
                                else {
                                    L     = new RDFPlainLiteral(HttpUtility.HtmlDecode(tokens[2]));
                                }
                            }
                            #endregion

                            #region typed literal
                            else {
                                tokens[2]                    = tokens[2].Replace("\"^^", "^^");
                                String tLitValue             = tokens[2].Substring(0, tokens[2].LastIndexOf("^^", StringComparison.Ordinal));
                                String tLitDatatype          = tokens[2].Substring(tokens[2].LastIndexOf("^^", StringComparison.Ordinal) + 2)
                                                                        .TrimStart(new Char[] { '<' })
                                                                        .TrimEnd(new   Char[] { '>' });
                                RDFModelEnums.RDFDatatypes dt = RDFModelUtilities.GetDatatypeFromString(tLitDatatype);
                                L                            = new RDFTypedLiteral(HttpUtility.HtmlDecode(tLitValue), dt);
                            }
                            #endregion

                        }
                        #endregion

                        #region context
                        if (!String.IsNullOrEmpty(tokens[3])) {
                             String ctx     = tokens[3].TrimStart(new Char[] { '<' })
                                                       .TrimEnd(new   Char[] { '>' });

                             Uri ctxUri     = null;
                             if (Uri.TryCreate(ctx, UriKind.Absolute, out ctxUri)) {
                                 C          = new RDFContext(RDFModelUtilities.ASCII_To_Unicode(ctxUri.ToString()));
                             }
                             else {
                                 throw new RDFModelException("found context '" + ctx +"' which is not a well-formed absolute Uri");
                             }
                        }
                        #endregion

                        #region addquadruple
                        if (O != null) {
                            result.AddQuadruple(new RDFQuadruple(C, S, P, O));
                        }
                        else {
                            result.AddQuadruple(new RDFQuadruple(C, S, P, L));
                        }
                        #endregion

                    }
                    return result;
                }
                #endregion

            }
            catch(Exception ex) {
                throw new RDFModelException("Cannot deserialize N-Quads (line " + nquadIndex + ") because: " + ex.Message, ex);
            }
        }
コード例 #11
0
        /// <summary>
        /// Gets a memory store containing quadruples satisfying the given pattern
        /// </summary>
        internal override RDFMemoryStore SelectQuadruples(RDFContext  ctx,
                                                          RDFResource subj,
                                                          RDFResource pred,
                                                          RDFResource obj,
                                                          RDFLiteral  lit) {
            RDFMemoryStore result    = new RDFMemoryStore();
            MySqlCommand command     = null;

            //Intersect the filters
            if (ctx                 != null) {
                if (subj            != null) {
                    if (pred        != null) {
                        if (obj     != null) {
                            //C->S->P->O
                            command  = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND SubjectID = @SUBJID AND PredicateID = @PREDID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                            command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                            command.Parameters.Add(new MySqlParameter("CTXID",  MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                            command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //C->S->P->L
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND SubjectID = @SUBJID AND PredicateID = @PREDID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                                command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                                command.Parameters.Add(new MySqlParameter("CTXID",  MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //C->S->P->
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND SubjectID = @SUBJID AND PredicateID = @PREDID", this.Connection);
                                command.Parameters.Add(new MySqlParameter("CTXID",  MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            }
                        }
                    }
                    else {
                        if (obj     != null) {
                            //C->S->->O
                            command  = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND SubjectID = @SUBJID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                            command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                            command.Parameters.Add(new MySqlParameter("CTXID",  MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                            command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //C->S->->L
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND SubjectID = @SUBJID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                                command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                                command.Parameters.Add(new MySqlParameter("CTXID",  MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //C->S->->
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND SubjectID = @SUBJID", this.Connection);
                                command.Parameters.Add(new MySqlParameter("CTXID",  MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            }
                        }
                    }
                }
                else {
                    if (pred        != null) {
                        if (obj     != null) {
                            //C->->P->O
                            command  = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND PredicateID = @PREDID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                            command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                            command.Parameters.Add(new MySqlParameter("CTXID",  MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                            command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //C->->P->L
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND PredicateID = @PREDID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                                command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                                command.Parameters.Add(new MySqlParameter("CTXID",  MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //C->->P->
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND PredicateID = @PREDID", this.Connection);
                                command.Parameters.Add(new MySqlParameter("CTXID",  MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            }
                        }
                    }
                    else {
                        if (obj     != null) {
                            //C->->->O
                            command  = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                            command.Parameters.Add(new MySqlParameter("TFV",   MySqlDbType.Int32));
                            command.Parameters.Add(new MySqlParameter("CTXID", MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("OBJID", MySqlDbType.Int64));
                            command.Parameters["TFV"].Value   = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["CTXID"].Value = ctx.PatternMemberID;
                            command.Parameters["OBJID"].Value = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //C->->->L
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                                command.Parameters.Add(new MySqlParameter("TFV",   MySqlDbType.Int32));
                                command.Parameters.Add(new MySqlParameter("CTXID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("OBJID", MySqlDbType.Int64));
                                command.Parameters["TFV"].Value   = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["CTXID"].Value = ctx.PatternMemberID;
                                command.Parameters["OBJID"].Value = lit.PatternMemberID;
                            }
                            else {
                                //C->->->
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ContextID = @CTXID", this.Connection);
                                command.Parameters.Add(new MySqlParameter("CTXID", MySqlDbType.Int64));
                                command.Parameters["CTXID"].Value = ctx.PatternMemberID;
                            }
                        }
                    }
                }
            }
            else {
                if (subj            != null) {
                    if (pred        != null) {
                        if (obj     != null) {
                            //->S->P->O
                            command  = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE SubjectID = @SUBJID AND PredicateID = @PREDID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                            command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                            command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //->S->P->L
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE SubjectID = @SUBJID AND PredicateID = @PREDID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                                command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                                command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //->S->P->
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE SubjectID = @SUBJID AND PredicateID = @PREDID", this.Connection);
                                command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            }
                        }
                    }
                    else {
                        if (obj     != null) {
                            //->S->->O
                            command  = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE SubjectID = @SUBJID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                            command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                            command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //->S->->L
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE SubjectID = @SUBJID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                                command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                                command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //->S->->
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE SubjectID = @SUBJID", this.Connection);
                                command.Parameters.Add(new MySqlParameter("SUBJID", MySqlDbType.Int64));
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            }
                        }
                    }
                }
                else {
                    if (pred        != null) {
                        if (obj     != null) {
                            //->->P->O
                            command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE PredicateID = @PREDID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                            command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                            command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                            command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //->->P->L
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE PredicateID = @PREDID AND ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                                command.Parameters.Add(new MySqlParameter("TFV",    MySqlDbType.Int32));
                                command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                                command.Parameters.Add(new MySqlParameter("OBJID",  MySqlDbType.Int64));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //->->P->
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE PredicateID = @PREDID", this.Connection);
                                command.Parameters.Add(new MySqlParameter("PREDID", MySqlDbType.Int64));
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            }
                        }
                    }
                    else {
                        if (obj     != null) {
                            //->->->O
                            command  = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                            command.Parameters.Add(new MySqlParameter("TFV",   MySqlDbType.Int32));
                            command.Parameters.Add(new MySqlParameter("OBJID", MySqlDbType.Int64));
                            command.Parameters["TFV"].Value   = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["OBJID"].Value = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //->->->L
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples WHERE ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
                                command.Parameters.Add(new MySqlParameter("TFV",   MySqlDbType.Int32));
                                command.Parameters.Add(new MySqlParameter("OBJID", MySqlDbType.Int64));
                                command.Parameters["TFV"].Value   = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["OBJID"].Value = lit.PatternMemberID;
                            }
                            else {
                                //->->->
                                command = new MySqlCommand("SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples", this.Connection);
                            }
                        }
                    }
                }
            }

            //Prepare and execute command
            try {

                //Open connection
                this.Connection.Open();

                //Prepare command
                command.Prepare();
                command.CommandTimeout = 120;

                //Execute command
                using (var quadruples  = command.ExecuteReader()) {
                    if(quadruples.HasRows) {
                        while (quadruples.Read()) {
                            result.AddQuadruple(RDFStoreUtilities.ParseQuadruple(quadruples));
                        }
                    }
                }

                //Close connection
                this.Connection.Close();

            }
            catch (Exception ex) {

                //Close connection
                this.Connection.Close();

                //Propagate exception
                throw new RDFStoreException("Cannot read data from MySQL store because: " + ex.Message, ex);

            }

            return result;
        }
コード例 #12
0
        /// <summary>
        /// Gets a memory store containing quadruples satisfying the given pattern
        /// </summary>
        internal override RDFMemoryStore SelectQuadruples(RDFContext ctx,
                                                          RDFResource subj,
                                                          RDFResource pred,
                                                          RDFResource obj,
                                                          RDFLiteral lit) {
            RDFMemoryStore result    = new RDFMemoryStore();
            NpgsqlCommand command    = null;

            //Intersect the filters
            if (ctx                 != null) {
                if (subj            != null) {
                    if (pred        != null) {
                        if (obj     != null) {
                            //C->S->P->O
                            command  = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND subjectid = @SUBJID AND predicateid = @PREDID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                            command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                            command.Parameters.Add(new NpgsqlParameter("CTXID",  NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                            command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //C->S->P->L
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND subjectid = @SUBJID AND predicateid = @PREDID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                                command.Parameters.Add(new NpgsqlParameter("CTXID",  NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //C->S->P->
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND subjectid = @SUBJID AND predicateid = @PREDID", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("CTXID",  NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            }
                        }
                    }
                    else {
                        if (obj     != null) {
                            //C->S->->O
                            command  = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND subjectid = @SUBJID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                            command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                            command.Parameters.Add(new NpgsqlParameter("CTXID",  NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                            command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //C->S->->L
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND subjectid = @SUBJID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                                command.Parameters.Add(new NpgsqlParameter("CTXID",  NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //C->S->->
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND subjectid = @SUBJID", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("CTXID",  NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            }
                        }
                    }
                }
                else {
                    if (pred        != null) {
                        if (obj     != null) {
                            //C->->P->O
                            command  = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND predicateid = @PREDID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                            command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                            command.Parameters.Add(new NpgsqlParameter("CTXID",  NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                            command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //C->->P->L
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND predicateid = @PREDID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                                command.Parameters.Add(new NpgsqlParameter("CTXID",  NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //C->->P->
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND predicateid = @PREDID", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("CTXID",  NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                                command.Parameters["CTXID"].Value  = ctx.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            }
                        }
                    }
                    else {
                        if (obj     != null) {
                            //C->->->O
                            command  = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                            command.Parameters.Add(new NpgsqlParameter("TFV",   NpgsqlDbType.Integer));
                            command.Parameters.Add(new NpgsqlParameter("CTXID", NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("OBJID", NpgsqlDbType.Bigint));
                            command.Parameters["TFV"].Value   = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["CTXID"].Value = ctx.PatternMemberID;
                            command.Parameters["OBJID"].Value = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //C->->->L
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("TFV",   NpgsqlDbType.Integer));
                                command.Parameters.Add(new NpgsqlParameter("CTXID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("OBJID", NpgsqlDbType.Bigint));
                                command.Parameters["TFV"].Value   = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["CTXID"].Value = ctx.PatternMemberID;
                                command.Parameters["OBJID"].Value = lit.PatternMemberID;
                            }
                            else {
                                //C->->->
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE contextid = @CTXID", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("CTXID", NpgsqlDbType.Bigint));
                                command.Parameters["CTXID"].Value = ctx.PatternMemberID;
                            }
                        }
                    }
                }
            }
            else {
                if (subj            != null) {
                    if (pred        != null) {
                        if (obj     != null) {
                            //->S->P->O
                            command  = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE subjectid = @SUBJID AND predicateid = @PREDID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                            command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                            command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //->S->P->L
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE subjectid = @SUBJID AND predicateid = @PREDID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                                command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //->S->P->
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE subjectid = @SUBJID AND predicateid = @PREDID", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            }
                        }
                    }
                    else {
                        if (obj     != null) {
                            //->S->->O
                            command  = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE subjectid = @SUBJID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                            command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                            command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //->S->->L
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE subjectid = @SUBJID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                                command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //->S->->
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE subjectid = @SUBJID", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("SUBJID", NpgsqlDbType.Bigint));
                                command.Parameters["SUBJID"].Value = subj.PatternMemberID;
                            }
                        }
                    }
                }
                else {
                    if (pred        != null) {
                        if (obj     != null) {
                            //->->P->O
                            command  = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE predicateid = @PREDID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                            command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                            command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                            command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                            command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            command.Parameters["OBJID"].Value  = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //->->P->L
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE predicateid = @PREDID AND objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("TFV",    NpgsqlDbType.Integer));
                                command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                                command.Parameters.Add(new NpgsqlParameter("OBJID",  NpgsqlDbType.Bigint));
                                command.Parameters["TFV"].Value    = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                                command.Parameters["OBJID"].Value  = lit.PatternMemberID;
                            }
                            else {
                                //->->P->
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE predicateid = @PREDID", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("PREDID", NpgsqlDbType.Bigint));
                                command.Parameters["PREDID"].Value = pred.PatternMemberID;
                            }
                        }
                    }
                    else {
                        if (obj     != null) {
                            //->->->O
                            command  = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                            command.Parameters.Add(new NpgsqlParameter("TFV",   NpgsqlDbType.Integer));
                            command.Parameters.Add(new NpgsqlParameter("OBJID", NpgsqlDbType.Bigint));
                            command.Parameters["TFV"].Value   = RDFModelEnums.RDFTripleFlavors.SPO;
                            command.Parameters["OBJID"].Value = obj.PatternMemberID;
                        }
                        else {
                            if (lit != null) {
                                //->->->L
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\" WHERE objectid = @OBJID AND tripleflavor = @TFV", this.Connection);
                                command.Parameters.Add(new NpgsqlParameter("TFV",   NpgsqlDbType.Integer));
                                command.Parameters.Add(new NpgsqlParameter("OBJID", NpgsqlDbType.Bigint));
                                command.Parameters["TFV"].Value   = RDFModelEnums.RDFTripleFlavors.SPL;
                                command.Parameters["OBJID"].Value = lit.PatternMemberID;
                            }
                            else {
                                //->->->
                                command = new NpgsqlCommand("SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\"", this.Connection);
                            }
                        }
                    }
                }
            }

            //Prepare and execute command
            try {

                //Open connection
                this.Connection.Open();

                //Prepare command
                command.Prepare();

                //Execute command
                using (var quadruples  = command.ExecuteReader()) {
                    if(quadruples.HasRows) {
                        while (quadruples.Read()) {
                            result.AddQuadruple(RDFStoreUtilities.ParseQuadruple(quadruples));
                        }
                    }
                }

                //Close connection
                this.Connection.Close();

            }
            catch (Exception ex) {

                //Close connection
                this.Connection.Close();

                //Propagate exception
                throw new RDFStoreException("Cannot read data from PostgreSQL store because: " + ex.Message, ex);

            }

            return result;
        }
コード例 #13
0
 /// <summary>
 /// Gets a store containing all quadruples
 /// </summary>
 public override RDFStore SelectAllQuadruples() {
     RDFMemoryStore result                         = new RDFMemoryStore();
     try {
         //Open connection
         this.Connection.Open();
         //Execute command
         using (SQLiteDataReader fetchedQuadruples = this.Commands["SELECT"].ExecuteReader()) {
             if (fetchedQuadruples.HasRows) {
                 //Iterate fetched quadruples
                 while (fetchedQuadruples.Read()) {
                     //Add the fetched quadruple to the result
                     result.AddQuadruple(RDFStoreUtilities.ParseQuadruple(fetchedQuadruples));
                 }
             }
         }
         //Close connection
         this.Connection.Close();
     }
     catch (Exception ex) {
         //Close connection
         this.Connection.Close();
         //Propagate exception
         throw new RDFStoreException("Cannot read data from SQLite store because: " + ex.Message);
     }
     return result;
 }
コード例 #14
0
 /// <summary>
 /// Checks if the store contains the given quadruple
 /// </summary>
 public override Boolean ContainsQuadruple(RDFQuadruple quadruple) {
     RDFMemoryStore result = new RDFMemoryStore();
     if (quadruple        != null) {
         try {
             //Open connection
             this.Connection.Open();
             //Modify command
             this.Commands["SELECT"].CommandText              += " WHERE QuadrupleID = @QID";
             //Add parameters
             this.Commands["SELECT"].Parameters.Add(new MySqlParameter("QID", MySqlDbType.Int64));
             //Prepare command
             this.Commands["SELECT"].Prepare();
             //Valorize parameters
             this.Commands["SELECT"].Parameters["QID"].Value   = quadruple.QuadrupleID;
             //Execute command
             using (MySqlDataReader fetchedQuadruples          = this.Commands["SELECT"].ExecuteReader()) {
                 if (fetchedQuadruples.HasRows) {
                     //Iterate fetched quadruples
                     while (fetchedQuadruples.Read()) {
                         //Add the fetched quadruple to the result
                         result.AddQuadruple(RDFStoreUtilities.ParseQuadruple(fetchedQuadruples));
                     }
                 }
             }
             //Close connection
             this.Connection.Close();
             //Restore command
             this.Commands["SELECT"].CommandText               = "SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples";
             //Restore parameters
             this.Commands["SELECT"].Parameters.Clear();
         }
         catch (Exception ex) {
             //Close connection
             this.Connection.Close();
             //Restore command
             this.Commands["SELECT"].CommandText               = "SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples";
             //Restore parameters
             this.Commands["SELECT"].Parameters.Clear();
             //Propagate exception
             throw new RDFStoreException("Cannot read data from MySQL store because: " + ex.Message);
         }
     }
     return (result.QuadruplesCount > 0);
 }
コード例 #15
0
 /// <summary>
 /// Asynchronously gets a query result corresponding to the given memory store
 /// </summary>
 public static Task <RDFDescribeQueryResult> FromRDFMemoryStoreAsync(RDFMemoryStore store)
 => Task.Run(() => FromRDFMemoryStore(store));
コード例 #16
0
 /// <summary>
 /// Gets a memory store containing quadruples with the specified literal
 /// </summary>
 public override RDFStore SelectQuadruplesByLiteral(RDFLiteral objectLiteral) {
     RDFMemoryStore result = new RDFMemoryStore();
     if (objectLiteral != null) {
         try {
             //Open connection
             this.Connection.Open();
             //Modify command
             this.Commands["SELECT"].CommandText               += " WHERE tripleflavor = 2 AND objectid = @OBJID";
             //Add parameters
             this.Commands["SELECT"].Parameters.Add(new NpgsqlParameter("OBJID", NpgsqlDbType.Bigint));
             //Valorize parameters
             this.Commands["SELECT"].Parameters["OBJID"].Value  = objectLiteral.PatternMemberID;
             //Execute command
             using (NpgsqlDataReader fetchedQuadruples          = this.Commands["SELECT"].ExecuteReader()) {
                 if (fetchedQuadruples.HasRows) {
                     //Iterate fetched quadruples
                     while (fetchedQuadruples.Read()) {
                         //Add the fetched quadruple to the result
                         result.AddQuadruple(RDFStoreUtilities.ParseQuadruple(fetchedQuadruples));
                     }
                 }
             }
             //Close connection
             this.Connection.Close();
             //Restore command
             this.Commands["SELECT"].CommandText                = "SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\"";
             //Restore parameters
             this.Commands["SELECT"].Parameters.Clear();
         }
         catch (Exception ex) {
             //Close connection
             this.Connection.Close();
             //Restore command
             this.Commands["SELECT"].CommandText                = "SELECT tripleflavor, context, subject, predicate, object FROM public.\"quadruples\"";
             //Restore parameters
             this.Commands["SELECT"].Parameters.Clear();
             //Propagate exception
             throw new RDFStoreException("Cannot read data from PostgreSQL store because: " + ex.Message);
         }
     }
     return result;
 }
コード例 #17
0
 /// <summary>
 /// Gets a memory store containing quadruples with the specified predicate
 /// </summary>
 public override RDFStore SelectQuadruplesByPredicate(RDFResource predicateResource) {
     RDFMemoryStore result  = new RDFMemoryStore();
     if (predicateResource != null) {
         try {
             //Open connection
             this.Connection.Open();
             //Modify command
             this.Commands["SELECT"].CommandText               += " WHERE PredicateID = @PREDID";
             //Add parameters
             this.Commands["SELECT"].Parameters.Add(new FbParameter("PREDID", FbDbType.BigInt));
             //Prepare command
             this.Commands["SELECT"].Prepare();
             //Valorize parameters
             this.Commands["SELECT"].Parameters["PREDID"].Value = predicateResource.PatternMemberID;
             //Execute command
             using (FbDataReader fetchedQuadruples              = this.Commands["SELECT"].ExecuteReader()) {
                 if (fetchedQuadruples.HasRows) {
                     //Iterate fetched quadruples
                     while (fetchedQuadruples.Read()) {
                         //Add the fetched quadruple to the result
                         result.AddQuadruple(RDFStoreUtilities.ParseQuadruple(fetchedQuadruples));
                     }
                 }
             }
             //Close connection
             this.Connection.Close();
             //Restore command
             this.Commands["SELECT"].CommandText                = "SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples";
             //Restore parameters
             this.Commands["SELECT"].Parameters.Clear();
         }
         catch (Exception ex) {
             //Close connection
             this.Connection.Close();
             //Restore command
             this.Commands["SELECT"].CommandText                = "SELECT TripleFlavor, Context, Subject, Predicate, Object FROM Quadruples";
             //Restore parameters
             this.Commands["SELECT"].Parameters.Clear();
             //Propagate exception
             throw new RDFStoreException("Cannot read data from Firebird store because: " + ex.Message);
         }
     }
     return result;
 }
コード例 #18
0
        /// <summary>
        /// Describes the terms of the given query with data from the given result table
        /// </summary>
        internal static DataTable DescribeTerms(RDFDescribeQuery describeQuery, Object graphOrStore, DataTable resultTable)
        {
            //Create the structure of the result datatable
            DataTable result = new DataTable("DESCRIBE_RESULTS");

            result.Columns.Add("SUBJECT", Type.GetType("System.String"));
            result.Columns.Add("PREDICATE", Type.GetType("System.String"));
            result.Columns.Add("OBJECT", Type.GetType("System.String"));
            result.AcceptChanges();

            //Query IS empty, so does not have pattern groups to fetch data from
            //(we can only proceed by searching for resources in the describe terms)
            if (describeQuery.IsEmpty)
            {
                //Iterate the describe terms of the query which are resources (variables are omitted, since useless)
                foreach (RDFPatternMember dt in describeQuery.DescribeTerms.Where(dterm => dterm is RDFResource))
                {
                    //Search on GRAPH
                    if (graphOrStore is RDFGraph)
                    {
                        //Search as RESOURCE (S-P-O)
                        RDFGraph desc = ((RDFGraph)graphOrStore).SelectTriplesBySubject((RDFResource)dt)
                                        .UnionWith(((RDFGraph)graphOrStore).SelectTriplesByPredicate((RDFResource)dt))
                                        .UnionWith(((RDFGraph)graphOrStore).SelectTriplesByObject((RDFResource)dt));
                        result.Merge(desc.ToDataTable(), true, MissingSchemaAction.Add);
                    }

                    //Search on STORE
                    else
                    {
                        //Search as RESOURCE (S-P-O)
                        RDFMemoryStore desc = ((RDFMemoryStore)((RDFMemoryStore)((RDFMemoryStore)((RDFStore)graphOrStore).SelectQuadruplesBySubject((RDFResource)dt))
                                                                .UnionWith(((RDFStore)graphOrStore).SelectQuadruplesByPredicate((RDFResource)dt)))
                                               .UnionWith(((RDFStore)graphOrStore).SelectQuadruplesByObject((RDFResource)dt)));
                        result.Merge(desc.ToDataTable(), true, MissingSchemaAction.Add);
                    }
                }
            }

            //Query IS NOT empty, so does have pattern groups to fetch data from
            else
            {
                //In case of a "Star" query, all the variables must be considered describe terms
                if (describeQuery.IsStar)
                {
                    describeQuery.PatternGroups.ForEach(pg =>
                                                        pg.Variables.ForEach(v => describeQuery.AddDescribeTerm(v))
                                                        );
                }

                //Iterate the describe terms of the query
                foreach (RDFPatternMember dt in describeQuery.DescribeTerms)
                {
                    //The describe term is a variable
                    if (dt is RDFVariable)
                    {
                        //Process the variable
                        if (resultTable.Columns.Contains(dt.ToString()))
                        {
                            //Iterate the results datatable's rows to retrieve terms to be described
                            IEnumerator rowsEnum = resultTable.Rows.GetEnumerator();
                            while (rowsEnum.MoveNext())
                            {
                                //Row contains a value in position of the variable corresponding to the describe term
                                if (!((DataRow)rowsEnum.Current).IsNull(dt.ToString()))
                                {
                                    //Retrieve the term to be described
                                    RDFPatternMember term = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)rowsEnum.Current)[dt.ToString()].ToString());

                                    //Search on GRAPH
                                    if (graphOrStore is RDFGraph)
                                    {
                                        //Search as RESOURCE (S-P-O)
                                        if (term is RDFResource)
                                        {
                                            RDFGraph desc = ((RDFGraph)graphOrStore).SelectTriplesBySubject((RDFResource)term)
                                                            .UnionWith(((RDFGraph)graphOrStore).SelectTriplesByPredicate((RDFResource)term))
                                                            .UnionWith(((RDFGraph)graphOrStore).SelectTriplesByObject((RDFResource)term));
                                            result.Merge(desc.ToDataTable(), true, MissingSchemaAction.Add);
                                        }
                                        //Search as LITERAL (L)
                                        else
                                        {
                                            RDFGraph desc = ((RDFGraph)graphOrStore).SelectTriplesByLiteral((RDFLiteral)term);
                                            result.Merge(desc.ToDataTable(), true, MissingSchemaAction.Add);
                                        }
                                    }

                                    //Search on STORE
                                    else
                                    {
                                        //Search as RESOURCE (S-P-O)
                                        if (term is RDFResource)
                                        {
                                            RDFMemoryStore desc = ((RDFMemoryStore)((RDFMemoryStore)((RDFMemoryStore)((RDFStore)graphOrStore).SelectQuadruplesBySubject((RDFResource)term))
                                                                                    .UnionWith(((RDFStore)graphOrStore).SelectQuadruplesByPredicate((RDFResource)term)))
                                                                   .UnionWith(((RDFStore)graphOrStore).SelectQuadruplesByObject((RDFResource)term)));
                                            result.Merge(desc.ToDataTable(), true, MissingSchemaAction.Add);
                                        }
                                        //Search as LITERAL (L)
                                        else
                                        {
                                            RDFMemoryStore desc = ((RDFMemoryStore)((RDFStore)graphOrStore).SelectQuadruplesByLiteral((RDFLiteral)term));
                                            result.Merge(desc.ToDataTable(), true, MissingSchemaAction.Add);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //The describe term is a resource
                    else
                    {
                        //Search on GRAPH
                        if (graphOrStore is RDFGraph)
                        {
                            //Search as RESOURCE (S-P-O)
                            RDFGraph desc = ((RDFGraph)graphOrStore).SelectTriplesBySubject((RDFResource)dt)
                                            .UnionWith(((RDFGraph)graphOrStore).SelectTriplesByPredicate((RDFResource)dt))
                                            .UnionWith(((RDFGraph)graphOrStore).SelectTriplesByObject((RDFResource)dt));
                            result.Merge(desc.ToDataTable(), true, MissingSchemaAction.Add);
                        }

                        //Search on STORE
                        else
                        {
                            //Search as RESOURCE (S-P-O)
                            RDFMemoryStore desc = ((RDFMemoryStore)((RDFMemoryStore)((RDFMemoryStore)((RDFStore)graphOrStore).SelectQuadruplesBySubject((RDFResource)dt))
                                                                    .UnionWith(((RDFStore)graphOrStore).SelectQuadruplesByPredicate((RDFResource)dt)))
                                                   .UnionWith(((RDFStore)graphOrStore).SelectQuadruplesByObject((RDFResource)dt)));
                            result.Merge(desc.ToDataTable(), true, MissingSchemaAction.Add);
                        }
                    }
                }
            }

            return(result);
        }
コード例 #19
0
        /// <summary>
        /// Selects the quadruples corresponding to the given pattern from the given store
        /// </summary>
        internal static List<RDFQuadruple> SelectQuadruples(RDFMemoryStore store,
                                                            RDFContext  ctx,
                                                            RDFResource subj,
                                                            RDFResource pred,
                                                            RDFResource obj,
                                                            RDFLiteral  lit) {
            var matchCtx         = new List<RDFQuadruple>();
            var matchSubj        = new List<RDFQuadruple>();
            var matchPred        = new List<RDFQuadruple>();
            var matchObj         = new List<RDFQuadruple>();
            var matchLit         = new List<RDFQuadruple>();
            var matchResult      = new List<RDFQuadruple>();
            if (store           != null) {

                //Filter by Context
                if (ctx         != null) {
                    foreach (var q in store.StoreIndex.SelectIndexByContext(ctx).Keys) {
                        matchCtx.Add(store.Quadruples[q]);
                    }
                }

                //Filter by Subject
                if (subj        != null) {
                    foreach (var q in store.StoreIndex.SelectIndexBySubject(subj).Keys) {
                        matchSubj.Add(store.Quadruples[q]);
                    }
                }

                //Filter by Predicate
                if (pred        != null) {
                    foreach (var q in store.StoreIndex.SelectIndexByPredicate(pred).Keys) {
                        matchPred.Add(store.Quadruples[q]);
                    }
                }

                //Filter by Object
                if (obj         != null) {
                    foreach (var q in store.StoreIndex.SelectIndexByObject(obj).Keys) {
                        matchObj.Add(store.Quadruples[q]);
                    }
                }

                //Filter by Literal
                if (lit         != null) {
                    foreach (var q in store.StoreIndex.SelectIndexByLiteral(lit).Keys) {
                        matchLit.Add(store.Quadruples[q]);
                    }
                }

                //Intersect the filters
                if (ctx                        != null) {
                    if (subj                   != null) {
                        if (pred               != null) {
                            if (obj            != null) {
                                //C->S->P->O
                                matchResult     = matchCtx.Intersect(matchSubj)
                                                          .Intersect(matchPred)
                                                          .Intersect(matchObj)
                                                          .ToList<RDFQuadruple>();
                            }
                            else {
                                if (lit        != null) {
                                    //C->S->P->L
                                    matchResult = matchCtx.Intersect(matchSubj)
                                                          .Intersect(matchPred)
                                                          .Intersect(matchLit)
                                                          .ToList<RDFQuadruple>();
                                }
                                else {
                                    //C->S->P->
                                    matchResult = matchCtx.Intersect(matchSubj)
                                                          .Intersect(matchPred)
                                                          .ToList<RDFQuadruple>();
                                }
                            }
                        }
                        else {
                            if (obj            != null) {
                                //C->S->->O
                                matchResult     = matchCtx.Intersect(matchSubj)
                                                          .Intersect(matchObj)
                                                          .ToList<RDFQuadruple>();
                            }
                            else {
                                if (lit        != null) {
                                    //C->S->->L
                                    matchResult = matchCtx.Intersect(matchSubj)
                                                          .Intersect(matchLit)
                                                          .ToList<RDFQuadruple>();
                                }
                                else {
                                    //C->S->->
                                    matchResult = matchCtx.Intersect(matchSubj)
                                                          .ToList<RDFQuadruple>();
                                }
                            }
                        }
                    }
                    else {
                        if (pred               != null) {
                            if (obj            != null) {
                                //C->->P->O
                                matchResult     = matchCtx.Intersect(matchPred)
                                                          .Intersect(matchObj)
                                                          .ToList<RDFQuadruple>();
                            }
                            else {
                                if (lit        != null) {
                                    //C->->P->L
                                    matchResult = matchCtx.Intersect(matchPred)
                                                          .Intersect(matchLit)
                                                          .ToList<RDFQuadruple>();
                                }
                                else {
                                    //C->->P->
                                    matchResult = matchCtx.Intersect(matchPred)
                                                          .ToList<RDFQuadruple>();
                                }
                            }
                        }
                        else {
                            if (obj            != null) {
                                //C->->->O
                                matchResult     = matchCtx.Intersect(matchObj)
                                                          .ToList<RDFQuadruple>();
                            }
                            else {
                                if (lit        != null) {
                                    //C->->->L
                                    matchResult = matchCtx.Intersect(matchLit)
                                                          .ToList<RDFQuadruple>();
                                }
                                else {
                                    //C->->->
                                    matchResult = matchCtx;
                                }
                            }
                        }
                    }
                }
                else {
                    if (subj                   != null) {
                        if (pred               != null) {
                            if (obj            != null) {
                                //->S->P->O
                                matchResult     = matchSubj.Intersect(matchPred)
                                                           .Intersect(matchObj)
                                                           .ToList<RDFQuadruple>();
                            }
                            else {
                                if (lit        != null) {
                                    //->S->P->L
                                    matchResult = matchSubj.Intersect(matchPred)
                                                           .Intersect(matchLit)
                                                           .ToList<RDFQuadruple>();
                                }
                                else {
                                    //->S->P->
                                    matchResult = matchSubj.Intersect(matchPred)
                                                           .ToList<RDFQuadruple>();
                                }
                            }
                        }
                        else {
                            if (obj            != null) {
                                //->S->->O
                                matchResult     = matchSubj.Intersect(matchObj)
                                                           .ToList<RDFQuadruple>();
                            }
                            else {
                                if (lit        != null) {
                                    //->S->->L
                                    matchResult = matchSubj.Intersect(matchLit)
                                                           .ToList<RDFQuadruple>();
                                }
                                else {
                                    //->S->->
                                    matchResult = matchSubj;
                                }
                            }
                        }
                    }
                    else {
                        if (pred               != null) {
                            if (obj            != null) {
                                //->->P->O
                                matchResult     = matchPred.Intersect(matchObj)
                                                           .ToList<RDFQuadruple>();
                            }
                            else {
                                if (lit        != null) {
                                    //->->P->L
                                    matchResult = matchPred.Intersect(matchLit)
                                                           .ToList<RDFQuadruple>();
                                }
                                else {
                                    //->->P->
                                    matchResult = matchPred;
                                }
                            }
                        }
                        else {
                            if (obj            != null) {
                                //->->->O
                                matchResult     = matchObj;
                            }
                            else {
                                if (lit        != null) {
                                    //->->->L
                                    matchResult = matchLit;
                                }
                                else {
                                    //->->->
                                    matchResult = store.Quadruples.Values.ToList<RDFQuadruple>();
                                }
                            }
                        }
                    }
                }

            }
            return matchResult;
        }
コード例 #20
0
ファイル: RDFTriX.cs プロジェクト: mdesalvo/RDFSharp
        /// <summary>
        /// Deserializes the given TriX stream to a memory store. 
        /// </summary>
        internal static RDFMemoryStore Deserialize(Stream inputStream)
        {
            try {

                #region deserialize
                RDFMemoryStore result = new RDFMemoryStore();
                Dictionary<Int64, RDFGraph> graphs = new Dictionary<Int64, RDFGraph>();
                using(StreamReader streamReader    = new StreamReader(inputStream, Encoding.UTF8)) {
                    using(XmlTextReader trixReader = new XmlTextReader(streamReader)) {
                        trixReader.DtdProcessing   = DtdProcessing.Ignore;
                        trixReader.Normalization   = false;

                        #region document
                        XmlDocument trixDoc        = new XmlDocument();
                        trixDoc.Load(trixReader);
                        #endregion

                        #region graph
                        if (trixDoc.DocumentElement != null) {

                            #region graphs extraction
                            var graphEnum                   = trixDoc.DocumentElement.ChildNodes.GetEnumerator();
                            while (graphEnum               != null && graphEnum.MoveNext()) {
                                XmlNode  graph              = (XmlNode)graphEnum.Current;
                                if (!graph.Name.Equals("graph", StringComparison.Ordinal)) {
                                     throw new Exception(" a \"<graph>\" element was expected, instead of unrecognized \"<" + graph.Name + ">\".");
                                }
                                Uri   graphUri              = RDFNamespaceRegister.DefaultNamespace.NamespaceUri;
                                Int64 graphID               = RDFNamespaceRegister.DefaultNamespace.NamespaceID;
                                if (!graphs.ContainsKey(graphID)) {
                                     graphs.Add(graphID, new RDFGraph().SetContext(graphUri));
                                }

                                #region triple
                                var encodedUris             = 0;
                                var tripleEnum              = graph.ChildNodes.GetEnumerator();
                                while (tripleEnum          != null && tripleEnum.MoveNext()) {
                                    XmlNode triple          = (XmlNode)tripleEnum.Current;

                                    #region uri
                                    if (triple.Name.Equals("uri", StringComparison.Ordinal)) {
                                        encodedUris++;
                                        if (encodedUris > 1) {
                                            throw new Exception(" given file encodes a graph with more than one \"<uri>\" element.");
                                        }

                                        graphUri            = RDFModelUtilities.GetUriFromString(triple.ChildNodes[0].InnerText);
                                        graphID             = RDFModelUtilities.CreateHash(graphUri.ToString());
                                        if (!graphs.ContainsKey(graphID)) {
                                             graphs.Add(graphID, new RDFGraph().SetContext(graphUri));
                                        }
                                    }
                                    #endregion

                                    #region triple
                                    else if(triple.Name.Equals("triple", StringComparison.Ordinal) && triple.ChildNodes.Count == 3) {

                                        #region subj
                                        //Subject is a resource ("<uri>") or a blank node ("<id>")
                                        if (triple.ChildNodes[0].Name.Equals("uri", StringComparison.Ordinal) ||
                                            triple.ChildNodes[0].Name.Equals("id", StringComparison.Ordinal))  {
                                            //Sanitize eventual blank node value
                                            if (triple.ChildNodes[0].Name.Equals("id", StringComparison.Ordinal)) {
                                                if (!triple.ChildNodes[0].InnerText.StartsWith("bnode:")) {
                                                     triple.ChildNodes[0].InnerText = "bnode:" + triple.ChildNodes[0].InnerText.Replace("_:", String.Empty);
                                                }
                                            }
                                        }
                                        //Subject is not valid: exception must be raised
                                        else {
                                            throw new RDFModelException("subject (" + triple.ChildNodes[0].Name + ") of \"<triple>\" element is neither \"<uri>\" or \"<id>\".");
                                        }
                                        #endregion

                                        #region pred
                                        //Predicate is not valid: exception must be raised
                                        if (!triple.ChildNodes[1].Name.Equals("uri", StringComparison.Ordinal)) {
                                             throw new RDFModelException("predicate (" + triple.ChildNodes[1].Name + ") of \"<triple>\" element must be \"<uri>\".");
                                        }
                                        #endregion

                                        #region object
                                        //Object is a resource ("<uri>") or a blank node ("<id>")
                                        if (triple.ChildNodes[2].Name.Equals("uri", StringComparison.Ordinal) ||
                                            triple.ChildNodes[2].Name.Equals("id", StringComparison.Ordinal))  {
                                            //Sanitize eventual blank node value
                                            if (triple.ChildNodes[2].Name.Equals("id", StringComparison.Ordinal)) {
                                                if (!triple.ChildNodes[2].InnerText.StartsWith("bnode:")) {
                                                     triple.ChildNodes[2].InnerText = "bnode:" + triple.ChildNodes[2].InnerText.Replace("_:", String.Empty);
                                                }
                                            }
                                            graphs[graphID].AddTriple(new RDFTriple(new RDFResource(triple.ChildNodes[0].InnerText),
                                                                                    new RDFResource(triple.ChildNodes[1].InnerText),
                                                                                    new RDFResource(triple.ChildNodes[2].InnerText)));
                                        }
                                        #endregion

                                        #region literal

                                        #region plain literal
                                        else if(triple.ChildNodes[2].Name.Equals("plainLiteral")) {
                                            if (triple.ChildNodes[2].Attributes != null && triple.ChildNodes[2].Attributes.Count > 0) {
                                                XmlAttribute xmlLang = triple.ChildNodes[2].Attributes[RDFVocabulary.XML.PREFIX + ":lang"];
                                                if (xmlLang         != null) {

                                                    //Plain literal with language
                                                    graphs[graphID].AddTriple(new RDFTriple(new RDFResource(triple.ChildNodes[0].InnerText),
                                                                                            new RDFResource(triple.ChildNodes[1].InnerText),
                                                                                            new RDFPlainLiteral(RDFModelUtilities.ASCII_To_Unicode(HttpUtility.HtmlDecode(triple.ChildNodes[2].InnerText)), xmlLang.Value)));

                                                }
                                                else {

                                                    //Plain literal without language
                                                    graphs[graphID].AddTriple(new RDFTriple(new RDFResource(triple.ChildNodes[0].InnerText),
                                                                                            new RDFResource(triple.ChildNodes[1].InnerText),
                                                                                            new RDFPlainLiteral(RDFModelUtilities.ASCII_To_Unicode(HttpUtility.HtmlDecode(triple.ChildNodes[2].InnerText)))));

                                                }
                                            }
                                            else {

                                                //Plain literal without language
                                                graphs[graphID].AddTriple(new RDFTriple(new RDFResource(triple.ChildNodes[0].InnerText),
                                                                                        new RDFResource(triple.ChildNodes[1].InnerText),
                                                                                        new RDFPlainLiteral(RDFModelUtilities.ASCII_To_Unicode(HttpUtility.HtmlDecode(triple.ChildNodes[2].InnerText)))));

                                            }
                                        }
                                        #endregion

                                        #region typed literal
                                        else if(triple.ChildNodes[2].Name.Equals("typedLiteral", StringComparison.Ordinal)) {
                                            if (triple.ChildNodes[2].Attributes != null && triple.ChildNodes[2].Attributes.Count > 0) {
                                                XmlAttribute rdfDtype = triple.ChildNodes[2].Attributes["datatype"];
                                                if (rdfDtype         != null) {
                                                    graphs[graphID].AddTriple(new RDFTriple(new RDFResource(triple.ChildNodes[0].InnerText),
                                                                                            new RDFResource(triple.ChildNodes[1].InnerText),
                                                                                            new RDFTypedLiteral(RDFModelUtilities.ASCII_To_Unicode(HttpUtility.HtmlDecode(triple.ChildNodes[2].InnerText)), RDFModelUtilities.GetDatatypeFromString(rdfDtype.Value))));
                                                }
                                                else {
                                                    throw new Exception(" found typed literal without required \"datatype\" attribute.");
                                                }
                                            }
                                            else {
                                                throw new Exception(" found typed literal without required \"datatype\" attribute.");
                                            }
                                        }
                                        #endregion

                                        #endregion

                                        #region exception
                                        //Object is not valid: exception must be raised
                                        else {
                                            throw new RDFModelException("object (" + triple.ChildNodes[2].Name + ") of \"<triple>\" element is neither \"<uri>\" or \"<id>\" or \"<plainLiteral>\" or \"<typedLiteral>\".");
                                        }
                                        #endregion

                                    }
                                    #endregion

                                    #region exception
                                    else {
                                        throw new RDFModelException("found a TriX element (" + triple.Name + ") which is neither \"<uri>\" or \"<triple>\", or is a \"<triple>\" without the required 3 childs.");
                                    }
                                    #endregion

                                }
                                #endregion

                            }
                            #endregion

                            #region graphs merging
                            foreach(var graph in graphs) {
                                result.MergeGraph(graph.Value);
                            }
                            #endregion

                        }
                        #endregion

                    }
                }
                return result;
                #endregion

            }
            catch(Exception ex) {
                throw new RDFModelException("Cannot deserialize TriX because: " + ex.Message, ex);
            }
        }
コード例 #21
0
 /// <summary>
 /// Gets a memory store containing quadruples with the specified literal
 /// </summary>
 public override RDFStore SelectQuadruplesByLiteral(RDFLiteral objectLiteral) {
     RDFMemoryStore result = new RDFMemoryStore();
     if (objectLiteral    != null) {
         try {
             //Open connection
             this.Connection.Open();
             //Modify command
             this.Commands["SELECT"].CommandText              += " WHERE TripleFlavor = 2 AND ObjectID = @OBJID";
             //Add parameters
             this.Commands["SELECT"].Parameters.Add(new SQLiteParameter("OBJID", DbType.Int64));
             //Prepare command
             this.Commands["SELECT"].Prepare();
             //Valorize parameters
             this.Commands["SELECT"].Parameters["OBJID"].Value = objectLiteral.PatternMemberID;
             //Execute command
             using (SQLiteDataReader fetchedQuadruples         = this.Commands["SELECT"].ExecuteReader()) {
                 if (fetchedQuadruples.HasRows) {
                     //Iterate fetched quadruples
                     while (fetchedQuadruples.Read()) {
                         //Add the fetched quadruple to the result
                         result.AddQuadruple(RDFStoreUtilities.ParseQuadruple(fetchedQuadruples));
                     }
                 }
             }
             //Close connection
             this.Connection.Close();
             //Restore command
             this.Commands["SELECT"].CommandText               = "SELECT TripleFlavor, Context, Subject, Predicate, Object FROM main.Quadruples";
             //Restore parameters
             this.Commands["SELECT"].Parameters.Clear();
         }
         catch (Exception ex) {
             //Close connection
             this.Connection.Close();
             //Restore command
             this.Commands["SELECT"].CommandText               = "SELECT TripleFlavor, Context, Subject, Predicate, Object FROM main.Quadruples";
             //Restore parameters
             this.Commands["SELECT"].Parameters.Clear();
             //Propagate exception
             throw new RDFStoreException("Cannot read data from SQLite store because: " + ex.Message);
         }
     }
     return result;
 }
コード例 #22
0
        private void WorkingWithRdfModels()
        {
            // CREATE RESOURCE
            var donaldduck = new RDFResource("http://www.waltdisney.com/donald_duck");

            // CREATE BLANK RESOURCE
            var disney_group = new RDFResource();

            // CREATE PLAIN LITERAL
            // "Donald Duck"
            var donaldduck_name = new RDFPlainLiteral("Donald Duck");
            // CREATE PLAIN LITERAL WITH LANGUAGE TAG
            // "Donald Duck"@en-US
            var donaldduck_name_enusLiteral = new RDFPlainLiteral("Donald Duck", "en-US");
            // CREATE TYPED LITERAL
            // "85"^^xsd:integer
            var mickeymouse_age = new RDFTypedLiteral("85", RDFModelEnums.RDFDatatypes.XSD_INTEGER);


            // CREATE TRIPLES
            // "Mickey Mouse is 85 years old"
            RDFTriple mickeymouse_is85yr
                = new RDFTriple(
                      new RDFResource("http://www.waltdisney.com/mickey_mouse"),
                      new RDFResource("http://xmlns.com/foaf/0.1/age"),
                      new RDFTypedLiteral("85", RDFModelEnums.RDFDatatypes.XSD_INTEGER));

            // "Donald Duck has english (US) name "Donald Duck""
            RDFTriple donaldduck_name_enus = new RDFTriple(
                new RDFResource("http://www.waltdisney.com/donald_duck"),
                new RDFResource("http://xmlns.com/foaf/0.1/name"),
                new RDFPlainLiteral("Donald Duck", "en-US"));


            // CREATE EMPTY GRAPH
            var another_graph     = new RDFGraph();
            var waltdisney_filled = new RDFGraph();

            // CREATE GRAPH FROM A LIST OF TRIPLES
            var triples = new List <RDFTriple> {
                mickeymouse_is85yr, donaldduck_name_enus
            };
            var waltdisney = new RDFGraph(triples);

            // SET CONTEXT OF A GRAPH
            waltdisney.SetContext(new Uri("http://waltdisney.com/"));

            // GET A DATATABLE FROM A GRAPH
            var waltdisney_table = waltdisney.ToDataTable();
            // GET A GRAPH FROM A DATATABLE
            var waltdisney_newgraph = RDFGraph.FromDataTable(waltdisney_table);

            // ITERATE TRIPLES OF A GRAPH WITH FOREACH
            foreach (var t in waltdisney)
            {
                Console.WriteLine("Triple: " + t);
                Console.WriteLine(" Subject: " + t.Subject);
                Console.WriteLine(" Predicate: " + t.Predicate);
                Console.WriteLine(" Object: " + t.Object);
            }

            // ITERATE TRIPLES OF A GRAPH WITH ENUMERATOR
            var triplesEnum = waltdisney.TriplesEnumerator;

            while (triplesEnum.MoveNext())
            {
                Console.WriteLine("Triple: " + triplesEnum.Current);
                Console.WriteLine(" Subject: " + triplesEnum.Current.Subject);
                Console.WriteLine(" Predicate: " + triplesEnum.Current.Predicate);
                Console.WriteLine(" Object: " + triplesEnum.Current.Object);
            }

            // GET COUNT OF TRIPLES CONTAINED IN A GRAPH
            var triplesCount = waltdisney.TriplesCount;

            // MULTIPLE SELECTIONS
            var multiple_selections_graph =
                waltdisney.SelectTriplesBySubject(new RDFResource("http://www.waltdisney.com/donald_duck"))
                .SelectTriplesByPredicate(new RDFResource("http://xmlns.com/foaf/0.1/name"));

            // SET OPERATIONS
            var set_operations_graph = waltdisney.IntersectWith(waltdisney_filled).UnionWith(another_graph);



            /*
             * var ntriplesFormat = RDFModelEnums.RDFFormats.NTriples;
             * // READ N-TRIPLES FILE
             * var graph = RDFGraph.FromFile(ntriplesFormat, "C:\\file.nt");
             * // READ N-TRIPLES STREAM
             * var graph = RDFGraph.FromStream(ntriplesFormat, inStream);
             * // WRITE N-TRIPLES FILE
             * graph.ToFile(ntriplesFormat, "C:\\newfile.nt");
             * // WRITE N-TRIPLES STREAM
             * graph.ToStream(ntriplesFormat, outStream);
             */

            /*
             * var turtleFormat = RDFModelEnums.RDFFormats.Turtle;
             * // READ TURTLE FILE
             * var graph = RDFGraph.FromFile(turtleFormat, "C:\\file.ttl");
             * // READ TURTLE STREAM
             * var graph = RDFGraph.FromStream(turtleFormat, inStream);
             * // WRITE TURTLE FILE
             * graph.ToFile(turtleFormat, "C:\\newfile.ttl");
             * // WRITE TURTLE STREAM
             * graph.ToStream(turtleFormat, outStream);
             */

            /*
             * var xmlFormat = RDFModelEnums.RDFFormats.RdfXml;
             * // READ RDF/XML FILE
             * var graph = RDFGraph.FromFile(xmlFormat, "C:\\file.rdf");
             * // READ RDF/XML STREAM
             * var graph = RDFGraph.FromStream(xmlFormat, inStream);
             * // WRITE RDF/XML FILE
             * graph.ToFile(xmlFormat, "C:\\newfile.rdf");
             * // WRITE RDF/XML STREAM
             * graph.ToStream(xmlFormat, outStream);
             */

            // CREATE NAMESPACE
            var waltdisney_ns = new RDFNamespace("wd", "http://www.waltdisney.com/");

            // USE NAMESPACE IN RESOURCE CREATION
            var duckburg = new RDFResource(waltdisney_ns + "duckburg");
            var mouseton = new RDFResource(waltdisney_ns + "mouseton");


            RDFNamespaceRegister.AddNamespace(waltdisney_ns);

            // Retrieves a namespace by seeking presence of its prefix (null if not found). Supports prefix.cc
            var ns1 = RDFNamespaceRegister.GetByPrefix("dbpedia", false); //local search
            var ns2 = RDFNamespaceRegister.GetByPrefix("dbpedia", true);  //search prefix.cc service if no result

            // GET DEFAULT NAMESPACE
            var nSpace = RDFNamespaceRegister.DefaultNamespace;

            // SET DEFAULT NAMESPACE
            RDFNamespaceRegister.SetDefaultNamespace(waltdisney_ns); //new graphs will default to this context

            // ITERATE NAMESPACES OF REGISTER WITH FOREACH
            foreach (var ns in RDFNamespaceRegister.Instance)
            {
                Console.WriteLine("Prefix: " + ns.NamespacePrefix);
                Console.WriteLine("Namespace: " + ns.NamespaceUri);
            }

            // ITERATE NAMESPACES OF REGISTER WITH ENUMERATOR
            var nspacesEnum = RDFNamespaceRegister.NamespacesEnumerator;

            while (nspacesEnum.MoveNext())
            {
                Console.WriteLine("Prefix: " + nspacesEnum.Current.NamespacePrefix);
                Console.WriteLine("Namespace: " + nspacesEnum.Current.NamespaceUri);
            }


            // CREATE TRIPLES WITH VOCABULARY FACILITIES
            // "Goofy Goof is 82 years old"
            RDFTriple goofygoof_is82yr = new RDFTriple(
                new RDFResource(new Uri("http://www.waltdisney.com/goofy_goof").ToString()),
                RDFVocabulary.FOAF.AGE,
                new RDFPlainLiteral("82")
                );

            // "Donald Duck knows Goofy Goof"
            RDFTriple donaldduck_knows_goofygoof = new RDFTriple(
                new RDFResource(new Uri("http://www.waltdisney.com/donald_duck").ToString()),
                RDFVocabulary.FOAF.KNOWS,
                new RDFResource(new Uri("http://www.waltdisney.com/goofy_goof").ToString())
                );

            // CREATE TYPED LITERALS
            var myAge      = new RDFTypedLiteral("34", RDFModelEnums.RDFDatatypes.XSD_INT);
            var myDate     = new RDFTypedLiteral("2017-01-07", RDFModelEnums.RDFDatatypes.XSD_DATE);
            var myDateTime = new RDFTypedLiteral("2017-01-07T23:11:05", RDFModelEnums.RDFDatatypes.XSD_DATETIME);
            var myXml      = new RDFTypedLiteral("<book>title</book>", RDFModelEnums.RDFDatatypes.RDF_XMLLITERAL);
            var myLiteral  = new RDFTypedLiteral("generic literal", RDFModelEnums.RDFDatatypes.RDFS_LITERAL);

            /*
             * The given list of items may be incomplete.
             * A container is semantically opened to the possibility of having further elements
             *
             * Alt: unordered semantic, duplicates not allowed;
             * Bag: unordered semantic, duplicates allowed;
             * Seq: ordered semantic, duplicates allowed;
             */

            // CREATE CONTAINER AND ADD ITEMS
            RDFContainer beatles_cont = new RDFContainer(RDFModelEnums.RDFContainerTypes.Bag, RDFModelEnums.RDFItemTypes.Resource);

            beatles_cont.AddItem(new RDFResource("http://beatles.com/ringo_starr"));
            beatles_cont.AddItem(new RDFResource("http://beatles.com/john_lennon"));
            beatles_cont.AddItem(new RDFResource("http://beatles.com/paul_mc_cartney"));
            beatles_cont.AddItem(new RDFResource("http://beatles.com/george_harrison"));

            /*
             * The given list of items may not be incomplete.
             * A collection is semantically closed to the possibility of having further elements
             */

            // CREATE COLLECTION AND ADD ITEMS
            RDFCollection beatles_coll = new RDFCollection(RDFModelEnums.RDFItemTypes.Resource);

            beatles_coll.AddItem(new RDFResource("http://beatles.com/ringo_starr"));
            beatles_coll.AddItem(new RDFResource("http://beatles.com/john_lennon"));
            beatles_coll.AddItem(new RDFResource("http://beatles.com/paul_mc_cartney"));
            beatles_coll.AddItem(new RDFResource("http://beatles.com/george_harrison"));


            // ADD CONTAINER/COLLECTION TO GRAPH
            waltdisney.AddContainer(beatles_cont);
            waltdisney.AddCollection(beatles_coll);



            // REIFY TRIPLE AND MERGE IT INTO A GRAPH
            RDFGraph reifGraph = goofygoof_is82yr.ReifyTriple();

            waltdisney = waltdisney.UnionWith(reifGraph);

            // ASSERT SOMETHING ABOUT REIFIED TRIPLE
            waltdisney.AddTriple(new RDFTriple(
                                     new RDFResource("http://www.wikipedia.com/"),
                                     new RDFResource("http://example.org/verb_state"),
                                     goofygoof_is82yr.ReificationSubject
                                     ));


            var existingGraph = new RDFGraph();


            // REIFY CONTAINER
            existingGraph.AddContainer(beatles_cont);

            existingGraph.AddTriple(new RDFTriple(
                                        new RDFResource("http://www.thebeatles.com/"),
                                        RDFVocabulary.FOAF.GROUP,
                                        beatles_cont.ReificationSubject
                                        ));

            // REIFY COLLECTION
            existingGraph.AddCollection(beatles_coll);

            existingGraph.AddTriple(new RDFTriple(
                                        new RDFResource("http://www.thebeatles.com/"),
                                        RDFVocabulary.FOAF.GROUP,
                                        beatles_coll.ReificationSubject
                                        ));

            // WORKING WITH RDF STORES

            // CREATE CONTEXT FROM STRING
            var wdisney_ctx = new RDFContext("http://www.waltdisney.com/");
            // CREATE CONTEXT FROM URI
            var wdisney_ctx_uri = new RDFContext(new Uri("http://www.waltdisney.com/"));
            // CREATE DEFAULT CONTEXT (DEFAULT NAMESPACE)
            var wdisney_ctx_default = new RDFContext();

            // CREATE QUADRUPLES
            // "From Wikipedia.com: Mickey Mouse is 85 years old"
            RDFQuadruple wk_mickeymouse_is85yr = new RDFQuadruple(
                new RDFContext("http://www.wikipedia.com/"),
                new RDFResource("http://www.waltdisney.com/mickey_mouse"),
                RDFVocabulary.FOAF.AGE,
                new RDFTypedLiteral("85", RDFModelEnums.RDFDatatypes.XSD_INTEGER)
                );

            // "From WaltDisney.com: Mickey Mouse is 85 years old"
            RDFQuadruple wd_mickeymouse_is85yr = new RDFQuadruple(
                new RDFContext("http://www.waltdisney.com/"),
                new RDFResource("http://www.waltdisney.com/mickey_mouse"),
                RDFVocabulary.FOAF.AGE,
                new RDFTypedLiteral("85", RDFModelEnums.RDFDatatypes.XSD_INTEGER)
                );

            // "From Wikipedia.com: Donald Duck has english name "Donald Duck""
            RDFQuadruple wk_donald_duck_name_enus = new RDFQuadruple(
                new RDFContext("http://www.wikipedia.com/"),
                new RDFResource("http://www.waltdisney.com/donald_duck"),
                RDFVocabulary.FOAF.NAME,
                new RDFPlainLiteral("Donald Duck", "en")
                );

            // CREATE EMPTY MEMORY STORE
            var wdStore = new RDFMemoryStore();

            // CREATE MEMORY STORE FROM A LIST OF QUADRUPLES
            var quadruples = new List <RDFQuadruple> {
                wk_mickeymouse_is85yr, wk_mickeymouse_is85yr
            };
            var wdStoreFilled = new RDFMemoryStore();

            foreach (var q in quadruples)
            {
                wdStoreFilled.AddQuadruple(q);
            }

            // GET A DATATABLE FROM A MEMORY STORE (any kind of store can be exported to datatable)
            var wdStore_table = wdStoreFilled.ToDataTable();
            // GET A MEMORY STORE FROM A DATATABLE
            var wdStore_new = RDFMemoryStore.FromDataTable(wdStore_table);


            // ITERATE QUADRUPLES OF A MEMORY STORE WITH FOREACH
            foreach (var q in wdStore)
            {
                Console.WriteLine("Quadruple: " + q);
                Console.WriteLine(" Context: " + q.Context);
                Console.WriteLine(" Subject: " + q.Subject);
                Console.WriteLine(" Predicate: " + q.Predicate);
                Console.WriteLine(" Object: " + q.Object);
            }

            // ITERATE QUADRUPLES OF A MEMORY STORE WITH ENUMERATOR
            var quadruplesEnum = wdStore.QuadruplesEnumerator;

            while (quadruplesEnum.MoveNext())
            {
                Console.WriteLine("Quadruple: " + quadruplesEnum.Current);
                Console.WriteLine(" Context: " + quadruplesEnum.Current.Context);
                Console.WriteLine(" Subject: " + quadruplesEnum.Current.Subject);
                Console.WriteLine(" Predicate: " + quadruplesEnum.Current.Predicate);
                Console.WriteLine(" Object: " + quadruplesEnum.Current.Object);
            }

            var nquadsFormat = RDFStoreEnums.RDFFormats.NQuads;

            // READ N-QUADS FILE
            //var myStore = RDFMemoryStore.FromFile(nquadsFormat, "C:\\file.nq");
            // READ N-QUADS STREAM
            //var myStore = RDFMemoryStore.FromStream(nquadsFormat, inStream);
            // WRITE N-QUADS FILE
            wdStoreFilled.ToFile(nquadsFormat, @"C:\TEMP\newfile.nq");
            // WRITE N-QUADS STREAM
            //myStore.ToStream(nquadsFormat, outStream);


            var trixFormat = RDFStoreEnums.RDFFormats.TriX;

            // READ TRIX FILE
            //var memStore = RDFMemoryStore.FromFile(trixFormat, "C:\\file.trix");
            // READ TRIX STREAM
            //var memStore = RDFMemoryStore.FromStream(trixFormat, inStream);
            // WRITE TRIX FILE
            wdStoreFilled.ToFile(trixFormat, @"C:\TEMP\newfile.trix");
            // WRITE TRIX STREAM
            //myStore.ToStream(trixFormat, outStream);


            // CONNECT TO SQLSERVER STORE WITH CONNECTION STRING
            //var sqlServer = new RDFSQLServerStore(sqlServerConnectionString);


            // CREATE EMPTY FEDERATION
            var fed = new RDFFederation();

            /*
             * // CREATE FEDERATION FROM A LIST OF STORES
             * var stores = new List<RDFStore>{ waltDisneyStore, waltDisneyStoreFilled };
             * var fedFilled = new RDFFederation();
             * foreach(var store in stores)
             * {
             *  fedFilled.AddStore(store);
             * }
             */

            // ITERATE STORES OF A FEDERATION
            foreach (var s in fed)
            {
                Console.WriteLine("Store: " + s);
                Console.WriteLine(" Type: " + s.StoreType);
            }
        }