RDFVariable represents a named "hole" in a pattern, to be filled with values during queries.
Inheritance: RDFPatternMember
コード例 #1
0
 /// <summary>
 /// Default-ctor to build a filter on the given variable for the given language
 /// </summary>
 public RDFLangMatchesFilter(RDFVariable variable, string language)
 {
     if (variable != null)
     {
         if (language != null)
         {
             if (language == string.Empty || language == "*" || RDFPlainLiteral.LangTag.Match(language).Success)
             {
                 this.Variable = variable;
                 this.Language = language.ToUpperInvariant();
             }
             else
             {
                 throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter (" + language + ") does not represent a valid language.");
             }
         }
         else
         {
             throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter is null.");
         }
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #2
0
 /// <summary>
 /// Default-ctor to build a filter on the given variable for the given language
 /// </summary>
 public RDFLangMatchesFilter(RDFVariable variable, String language)
 {
     if (variable != null)
     {
         if (language != null)
         {
             if (language == String.Empty || language == "*" || Regex.IsMatch(language, "^[a-zA-Z]+([\\-][a-zA-Z0-9]+)*$"))
             {
                 this.Variable = variable;
                 this.Language = language.ToUpperInvariant();
                 this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
             }
             else
             {
                 throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter (" + language + ") does not represent a valid language.");
             }
         }
         else
         {
             throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter is null.");
         }
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #3
0
        /// <summary>
        /// Adds the given column of bindings to the SPARQL values
        /// </summary>
        public RDFValues AddColumn(RDFVariable variable, List <RDFPatternMember> bindings)
        {
            if (variable != null)
            {
                //Initialize bindings of the given variable
                if (!this.Bindings.ContainsKey(variable.ToString()))
                {
                    this.Bindings.Add(variable.ToString(), new List <RDFPatternMember>());
                }

                //Populate bindings of the given variable
                //(null indicates the special UNDEF binding)
                if (bindings?.Any() ?? false)
                {
                    bindings.ForEach(b => this.Bindings[variable.ToString()].Add((b is RDFResource || b is RDFLiteral) ? b : null));
                }
                else
                {
                    this.Bindings[variable.ToString()].Add(null);
                }

                //Mark the SPARQL values as evaluable
                this.IsEvaluable = true;
            }
            return(this);
        }
コード例 #4
0
 /// <summary>
 /// Default-ctor to build a filter on the given variable for the given language
 /// </summary>
 public RDFLangMatchesFilter(RDFVariable variable, string language)
 {
     if (variable != null)
     {
         if (language != null)
         {
             if (language == string.Empty || language == "*" || Regex.IsMatch(language, "^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$"))
             {
                 this.Variable = variable;
                 this.Language = language.ToUpperInvariant();
             }
             else
             {
                 throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter (" + language + ") does not represent a valid language.");
             }
         }
         else
         {
             throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter is null.");
         }
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #5
0
 /// <summary>
 /// Default-ctor to build a filter on the given variable
 /// </summary>
 public RDFIsNumericFilter(RDFVariable variable) {
     if (variable != null) {
         this.Variable = variable;
         this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
     }
     else {
         throw new RDFQueryException("Cannot create RDFIsNumericFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #6
0
 /// <summary>
 /// Default-ctor to build an OrderBy modifier of the given flavor on the given variable 
 /// </summary>
 public RDFOrderByModifier(RDFVariable variable, RDFQueryEnums.RDFOrderByFlavors orderbyFlavor) {
     if (variable != null) {
         this.OrderByFlavor = orderbyFlavor;
         this.Variable      = variable;
         this.ModifierID    = RDFModelUtilities.CreateHash(this.ToString());   
     }
     else {
         throw new RDFQueryException("Cannot create RDFOrderByModifier because given \"variable\" parameter is null.");
     }
 }
コード例 #7
0
ファイル: RDFBoundFilter.cs プロジェクト: dgerding/RDFSharp
 /// <summary>
 /// Default-ctor to build a filter on the given variable
 /// </summary>
 public RDFBoundFilter(RDFVariable variable)
 {
     if (variable != null)
     {
         this.Variable = variable;
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFBoundFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #8
0
 /// <summary>
 /// Adds the given variable to the results of the query
 /// </summary>
 public RDFSelectQuery AddProjectionVariable(RDFVariable projectionVariable)
 {
     if (projectionVariable != null)
     {
         if (!this.ProjectionVars.Any(pv => pv.Key.ToString().Equals(projectionVariable.ToString(), StringComparison.OrdinalIgnoreCase)))
         {
             this.ProjectionVars.Add(projectionVariable, this.ProjectionVars.Count);
         }
     }
     return(this);
 }
コード例 #9
0
 /// <summary>
 /// Default-ctor to build a GROUP_CONCAT aggregator on the given variable, with the given projection name and given separator
 /// </summary>
 public RDFGroupConcatAggregator(RDFVariable aggrVariable, RDFVariable projVariable, string separator) : base(aggrVariable, projVariable)
 {
     if (string.IsNullOrEmpty(separator))
     {
         this.Separator = " ";
     }
     else
     {
         this.Separator = separator;
     }
 }
コード例 #10
0
 /// <summary>
 /// Default-ctor to build an OrderBy modifier of the given flavor on the given variable
 /// </summary>
 public RDFOrderByModifier(RDFVariable variable, RDFQueryEnums.RDFOrderByFlavors orderbyFlavor)
 {
     if (variable != null)
     {
         this.OrderByFlavor = orderbyFlavor;
         this.Variable      = variable;
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFOrderByModifier because given \"variable\" parameter is null.");
     }
 }
コード例 #11
0
 /// <summary>
 /// Default-ctor to build a filter on the given variable for the given datatype
 /// </summary>
 public RDFDatatypeFilter(RDFVariable variable, RDFModelEnums.RDFDatatypes datatype)
 {
     if (variable != null)
     {
         this.Variable = variable;
         this.Datatype = datatype;
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFDatatypeFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #12
0
ファイル: RDFIsBlankFilter.cs プロジェクト: Mozes96/IBH
 /// <summary>
 /// Default-ctor to build a filter on the given variable
 /// </summary>
 public RDFIsBlankFilter(RDFVariable variable)
 {
     if (variable != null)
     {
         this.Variable = variable;
         this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFIsBlankFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #13
0
ファイル: RDFOrderByModifier.cs プロジェクト: Mozes96/IBH
 /// <summary>
 /// Default-ctor to build an OrderBy modifier of the given flavor on the given variable
 /// </summary>
 public RDFOrderByModifier(RDFVariable variable, RDFQueryEnums.RDFOrderByFlavors orderbyFlavor)
 {
     if (variable != null)
     {
         this.OrderByFlavor = orderbyFlavor;
         this.Variable      = variable;
         this.ModifierID    = RDFModelUtilities.CreateHash(this.ToString());
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFOrderByModifier because given \"variable\" parameter is null.");
     }
 }
コード例 #14
0
 /// <summary>
 /// Default-ctor to build a filter on the given variable for the given datatype 
 /// </summary>
 public RDFDatatypeFilter(RDFVariable variable, RDFDatatype datatype) {
     if (variable != null) {
         if (datatype != null) {
             this.Variable = variable;
             this.Datatype = datatype;
             this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
         }
         else {
             throw new RDFQueryException("Cannot create RDFDatatypeFilter because \"datatype\" parameter is null.");
         }
     }
     else {
         throw new RDFQueryException("Cannot create RDFDatatypeFilter because \"variable\" parameter is null.");
     }
 }
コード例 #15
0
 /// <summary>
 /// Default-ctor to build a filter on the given variable for the given regular expression 
 /// </summary>
 public RDFRegexFilter(RDFVariable variable, Regex regex) {
     if (variable != null) {
         if(regex != null) {
             this.Variable = variable;
             this.RegEx    = regex;
             this.FilterID = RDFModelUtilities.CreateHash(this.ToString());   
         }
         else {
             throw new RDFQueryException("Cannot create RDFRegexFilter because \"regex\" parameter is null.");
         }
     }
     else {
         throw new RDFQueryException("Cannot create RDFRegexFilter because \"variable\" parameter is null.");
     }
 }
コード例 #16
0
 /// <summary>
 /// Default-ctor to build an equality filter between the given variable and the given RDF term 
 /// </summary>
 public RDFSameTermFilter(RDFVariable variable, RDFPatternMember rdfTerm) {
     if (variable != null) {
         if (rdfTerm != null) {
             this.Variable = variable;
             this.RDFTerm  = rdfTerm;
             this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
         }
         else {
             throw new RDFQueryException("Cannot create RDFSameTermFilter because \"rdfTerm\" parameter is null.");
         }
     }
     else {
         throw new RDFQueryException("Cannot create RDFSameTermFilter because \"variable\" parameter is null.");
     }
 }
コード例 #17
0
 /// <summary>
 /// Adds the given variable to the describe terms of the query
 /// </summary>
 public RDFDescribeQuery AddDescribeTerm(RDFVariable describeVar)
 {
     if (describeVar != null)
     {
         if (!this.DescribeTerms.Any(dt => dt.Equals(describeVar)))
         {
             this.DescribeTerms.Add(describeVar);
             //Variable
             if (!this.Variables.Any(v => v.Equals(describeVar)))
             {
                 this.Variables.Add(describeVar);
             }
         }
     }
     return(this);
 }
コード例 #18
0
 /// <summary>
 /// Default-ctor to build a filter on the given variable for the given regular expression
 /// </summary>
 public RDFRegexFilter(RDFVariable variable, Regex regex)
 {
     if (variable != null)
     {
         if (regex != null)
         {
             this.Variable = variable;
             this.RegEx    = regex;
         }
         else
         {
             throw new RDFQueryException("Cannot create RDFRegexFilter because given \"regex\" parameter is null.");
         }
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFRegexFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #19
0
 /// <summary>
 /// Default-ctor to build an equality filter between the given variable and the given RDF term
 /// </summary>
 public RDFSameTermFilter(RDFVariable variable, RDFPatternMember rdfTerm)
 {
     if (variable != null)
     {
         if (rdfTerm != null)
         {
             this.Variable = variable;
             this.RDFTerm  = rdfTerm;
         }
         else
         {
             throw new RDFQueryException("Cannot create RDFSameTermFilter because given \"rdfTerm\" parameter is null.");
         }
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFSameTermFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #20
0
ファイル: RDFRegexFilter.cs プロジェクト: Mozes96/IBH
 /// <summary>
 /// Default-ctor to build a filter on the given variable for the given regular expression
 /// </summary>
 public RDFRegexFilter(RDFVariable variable, Regex regex)
 {
     if (variable != null)
     {
         if (regex != null)
         {
             this.Variable = variable;
             this.RegEx    = regex;
             this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
         }
         else
         {
             throw new RDFQueryException("Cannot create RDFRegexFilter because given \"regex\" parameter is null.");
         }
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFRegexFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #21
0
 /// <summary>
 /// Default-ctor to build an aggregator on the given variable and with the given projection name
 /// </summary>
 internal RDFAggregator(RDFVariable aggregatorVariable, RDFVariable projectionVariable)
 {
     if (aggregatorVariable != null)
     {
         if (projectionVariable != null)
         {
             this.AggregatorVariable = aggregatorVariable;
             this.ProjectionVariable = projectionVariable;
             this.AggregatorContext  = new RDFAggregatorContext();
         }
         else
         {
             throw new RDFQueryException("Cannot create RDFAggregator because given \"projectionVariable\" parameter is null.");
         }
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFAggregator because given \"aggregatorVariable\" parameter is null.");
     }
 }
コード例 #22
0
 /// <summary>
 /// Default-ctor to build an equality filter between the given variable and the given RDF term
 /// </summary>
 public RDFSameTermFilter(RDFVariable variable, RDFPatternMember rdfTerm)
 {
     if (variable != null)
     {
         if (rdfTerm != null)
         {
             this.Variable = variable;
             this.RDFTerm  = rdfTerm;
             this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
         }
         else
         {
             throw new RDFQueryException("Cannot create RDFSameTermFilter because given \"rdfTerm\" parameter is null.");
         }
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFSameTermFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #23
0
 /// <summary>
 /// Default-ctor to build a filter on the given variable for the given language 
 /// </summary>
 public RDFLangMatchesFilter(RDFVariable variable, String language) {
     if (variable != null) {
         if (language != null) {
             if (language == String.Empty || language == "*" || Regex.IsMatch(language, "^[a-zA-Z]+([\\-][a-zA-Z0-9]+)*$")) {
                     this.Variable = variable;
                     this.Language = language.ToUpperInvariant();
                     this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
             }
             else {
                 throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter (" + language + ") does not represent a valid language.");
             }
         }
         else {
             throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter is null.");
         }
     }
     else {
         throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"variable\" parameter is null.");
     }
 }
コード例 #24
0
ファイル: RdfViewer.aspx.cs プロジェクト: smoore4moma/tms-rdf
        protected void GetRDF()
        {
            try
            {

                // First we set some core RDF resources
                // agent refers to artist(s)
                RDFResource type = RDFVocabulary.RDF.TYPE;
                RDFResource name = RDFVocabulary.FOAF.NAME;
                RDFResource agent = RDFVocabulary.FOAF.AGENT;

                // TGN is a Getty vocabulary for locations
                // TGN added to RDFSharp vocabularies manually.  TGN ID is stored in TMSThes (or equivalent in TMS 2014+)
                RDFResource tgn = new RDFResource(RDFVocabulary.TGN.BASE_URI);

                // The predicates below are often part of ULAN (which we don't have)
                // unsure if using bio events this way is acceptable...

                RDFResource livedIn = new RDFResource("http://purl.org/vocab/bio/0.1/event/livedIn");
                RDFResource activeIn = new RDFResource("http://purl.org/vocab/bio/0.1/event/activeIn");
                RDFResource educatedIn = new RDFResource("http://purl.org/vocab/bio/0.1/event/educatedIn");
                RDFResource bornIn = new RDFResource("http://purl.org/vocab/bio/0.1/event/bornIn");
                RDFResource diedIn = new RDFResource("http://purl.org/vocab/bio/0.1/event/diedIn");

                RDFResource anUri = new RDFResource("http://example.org/uris#anUri");

                // Create variables
                RDFVariable x = new RDFVariable("x", true);
                RDFVariable y = new RDFVariable("y", true);
                RDFVariable n = new RDFVariable("n", true);
                RDFVariable h = new RDFVariable("h", true);
                RDFVariable p = new RDFVariable("p", true);

                string m_select = DropDownList1.Text;
                string m_filter = TextBox1.Text;

                RDFResource m_sparql_resource = livedIn;

                if (m_select == "livedIn")
                {
                    m_sparql_resource = livedIn;
                }
                if (m_select == "activeIn")
                {
                    m_sparql_resource = activeIn;
                }
                if (m_select == "educatedIn")
                {
                    m_sparql_resource = educatedIn;
                }
                if (m_select == "bornIn")
                {
                    m_sparql_resource = bornIn;
                }
                if (m_select == "diedIn")
                {
                    m_sparql_resource = diedIn;
                }

                // Create Sparql Select query
                RDFSelectQuery q1 = new RDFSelectQuery()
                .AddPatternGroup(new RDFPatternGroup("TmsPatternGroup")
                .AddPattern(new RDFPattern(y, m_sparql_resource, x))
                .AddPattern(new RDFPattern(x, type, tgn))
                .AddPattern(new RDFPattern(y, name, h).Optional())
                .AddPattern(new RDFPattern(x, name, n).Optional())
                .AddFilter(new RDFRegexFilter(n, new Regex(m_filter, RegexOptions.IgnoreCase))))
                .AddModifier(new RDFDistinctModifier());

                // Apply query
                string m_conn = ConfigurationManager.ConnectionStrings["RDFConnectionString"].ConnectionString;
                RDFSQLServerStore rdf_mssql = new RDFSQLServerStore(m_conn);
                RDFSelectQueryResult res = q1.ApplyToStore(rdf_mssql);

                Label1.Text = "RESULTS: " + res.SelectResultsCount + "\n\n" + q1;
                GridView1.DataSource = res.SelectResults;
                GridView1.DataBind();

            }
            catch (Exception ex)
            {
                string m_debug = ex.Message;
            }
        }
コード例 #25
0
 /// <summary>
 /// Default-ctor to build a MIN aggregator on the given variable, with the given projection name and given flavor
 /// </summary>
 public RDFMinAggregator(RDFVariable aggrVariable, RDFVariable projVariable, RDFQueryEnums.RDFMinMaxAggregatorFlavors aggregatorFlavor) : base(aggrVariable, projVariable)
 {
     this.AggregatorFlavor = aggregatorFlavor;
 }
コード例 #26
0
 /// <summary>
 /// Default-ctor to build a PARTITION aggregator on the given variable and with the given projection name
 /// </summary>
 internal RDFPartitionAggregator(RDFVariable aggrVariable, RDFVariable projVariable) : base(aggrVariable, projVariable)
 {
 }
コード例 #27
0
ファイル: RDFSumAggregator.cs プロジェクト: dgerding/RDFSharp
 /// <summary>
 /// Default-ctor to build a SUM aggregator on the given variable and with the given projection name
 /// </summary>
 public RDFSumAggregator(RDFVariable aggrVariable, RDFVariable projVariable) : base(aggrVariable, projVariable)
 {
 }
コード例 #28
0
        /// <summary>
        /// Compacts the reified quadruples by removing their 4 standard statements 
        /// </summary>
        public override void UnreifyQuadruples()
        {
            //Create SPARQL SELECT query for detecting reified quadruples
            var T = new RDFVariable("T");
            var C = new RDFVariable("C");
            var S = new RDFVariable("S");
            var P = new RDFVariable("P");
            var O = new RDFVariable("O");
            var Q = new RDFSelectQuery()
                            .AddPatternGroup(new RDFPatternGroup("UnreifyQuadruples")
                                .AddPattern(new RDFPattern(C, T, RDFVocabulary.RDF.TYPE, RDFVocabulary.RDF.STATEMENT))
                                .AddPattern(new RDFPattern(C, T, RDFVocabulary.RDF.SUBJECT, S))
                                .AddPattern(new RDFPattern(C, T, RDFVocabulary.RDF.PREDICATE, P))
                                .AddPattern(new RDFPattern(C, T, RDFVocabulary.RDF.OBJECT, O))
                                .AddFilter(new RDFIsUriFilter(C))
                                .AddFilter(new RDFIsUriFilter(T))
                                .AddFilter(new RDFIsUriFilter(S))
                                .AddFilter(new RDFIsUriFilter(P))
                            );

            //Apply it to the store
            var R = Q.ApplyToStore(this);

            //Iterate results
            var reifiedQuadruples = R.SelectResults.Rows.GetEnumerator();
            while (reifiedQuadruples.MoveNext()) {

                //Get reification data (T, C, S, P, O)
                var tRepresent = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)reifiedQuadruples.Current)["?T"].ToString());
                var tContext   = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)reifiedQuadruples.Current)["?C"].ToString());
                var tSubject   = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)reifiedQuadruples.Current)["?S"].ToString());
                var tPredicate = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)reifiedQuadruples.Current)["?P"].ToString());
                var tObject    = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)reifiedQuadruples.Current)["?O"].ToString());

                //Cleanup store from detected reifications
                if (tObject is RDFResource) {
                    this.AddQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tSubject, (RDFResource)tPredicate, (RDFResource)tObject));
                    this.RemoveQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tRepresent, RDFVocabulary.RDF.TYPE, RDFVocabulary.RDF.STATEMENT));
                    this.RemoveQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tRepresent, RDFVocabulary.RDF.SUBJECT, (RDFResource)tSubject));
                    this.RemoveQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tRepresent, RDFVocabulary.RDF.PREDICATE, (RDFResource)tPredicate));
                    this.RemoveQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tRepresent, RDFVocabulary.RDF.OBJECT, (RDFResource)tObject));
                }
                else {
                    this.AddQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tSubject, (RDFResource)tPredicate, (RDFLiteral)tObject));
                    this.RemoveQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tRepresent, RDFVocabulary.RDF.TYPE, RDFVocabulary.RDF.STATEMENT));
                    this.RemoveQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tRepresent, RDFVocabulary.RDF.SUBJECT, (RDFResource)tSubject));
                    this.RemoveQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tRepresent, RDFVocabulary.RDF.PREDICATE, (RDFResource)tPredicate));
                    this.RemoveQuadruple(new RDFQuadruple(new RDFContext(((RDFResource)tContext).URI), (RDFResource)tRepresent, RDFVocabulary.RDF.OBJECT, (RDFLiteral)tObject));
                }

            }
        }
コード例 #29
0
        /// <summary>
        /// Adds the given variable to the describe terms of the query
        /// </summary>
        public RDFDescribeQuery AddDescribeTerm(RDFVariable describeVar) {
            if (describeVar != null) {
                if (!this.DescribeTerms.Exists(dt => dt.Equals(describeVar))) {
                    this.DescribeTerms.Add(describeVar);

                    //Variable
                    if (!this.Variables.Exists(v => v.Equals(describeVar))) {
                        this.Variables.Add(describeVar);
                    }

                }
            }
            return this;
        }
コード例 #30
0
ファイル: RDFPropertyPath.cs プロジェクト: roy61056/RDFSharp
        /// <summary>
        /// Gets the list of patterns corresponding to the path
        /// </summary>
        internal List <RDFPattern> GetPatternList()
        {
            List <RDFPattern> patterns = new List <RDFPattern>();

            #region Single Property
            if (this.Steps.Count == 1)
            {
                //InversePath (swap start/end)
                if (this.Steps[0].IsInverseStep)
                {
                    patterns.Add(new RDFPattern(this.End, this.Steps[0].StepProperty, this.Start));
                }

                //Path
                else
                {
                    patterns.Add(new RDFPattern(this.Start, this.Steps[0].StepProperty, this.End));
                }
            }
            #endregion

            #region Multiple Properties
            else
            {
                RDFPatternMember currStart = this.Start;
                RDFPatternMember currEnd   = new RDFVariable("__PP0");
                for (int i = 0; i < this.Steps.Count; i++)
                {
                    #region Alternative
                    if (this.Steps[i].StepFlavor == RDFQueryEnums.RDFPropertyPathStepFlavors.Alternative)
                    {
                        //Translate to union (item is not the last alternative)
                        if (i < this.Steps.Count - 1 && this.Steps[i + 1].StepFlavor == RDFQueryEnums.RDFPropertyPathStepFlavors.Alternative)
                        {
                            //Adjust start/end
                            if (!this.Steps.Any(p => p.StepFlavor == RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence && p.StepOrdinal > i))
                            {
                                currEnd = this.End;
                            }

                            //InversePath (swap start/end)
                            if (this.Steps[i].IsInverseStep)
                            {
                                patterns.Add(new RDFPattern(currEnd, this.Steps[i].StepProperty, currStart).UnionWithNext());
                            }

                            //Path
                            else
                            {
                                patterns.Add(new RDFPattern(currStart, this.Steps[i].StepProperty, currEnd).UnionWithNext());
                            }
                        }

                        //Translate to pattern (item is the last alternative)
                        else
                        {
                            //InversePath (swap start/end)
                            if (this.Steps[i].IsInverseStep)
                            {
                                patterns.Add(new RDFPattern(currEnd, this.Steps[i].StepProperty, currStart));
                            }

                            //Path
                            else
                            {
                                patterns.Add(new RDFPattern(currStart, this.Steps[i].StepProperty, currEnd));
                            }

                            //Adjust start/end
                            if (i < this.Steps.Count - 1)
                            {
                                currStart = currEnd;
                                if (i == this.Steps.Count - 2 || !this.Steps.Any(p => p.StepFlavor == RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence && p.StepOrdinal > i))
                                {
                                    currEnd = this.End;
                                }
                                else
                                {
                                    currEnd = new RDFVariable("__PP" + (i + 1));
                                }
                            }
                        }
                    }
                    #endregion

                    #region Sequence
                    else
                    {
                        //InversePath (swap start/end)
                        if (this.Steps[i].IsInverseStep)
                        {
                            patterns.Add(new RDFPattern(currEnd, this.Steps[i].StepProperty, currStart));
                        }

                        //Path
                        else
                        {
                            patterns.Add(new RDFPattern(currStart, this.Steps[i].StepProperty, currEnd));
                        }

                        //Adjust start/end
                        if (i < this.Steps.Count - 1)
                        {
                            currStart = currEnd;
                            if (i == this.Steps.Count - 2)
                            {
                                currEnd = this.End;
                            }
                            else
                            {
                                currEnd = new RDFVariable("__PP" + (i + 1));
                            }
                        }
                    }
                    #endregion
                }
            }
            #endregion

            return(patterns);
        }
コード例 #31
0
ファイル: RDFSelectQuery.cs プロジェクト: mdesalvo/RDFSharp
 /// <summary>
 /// Adds the given variable to the results of the query
 /// </summary>
 public RDFSelectQuery AddProjectionVariable(RDFVariable projectionVariable)
 {
     if (projectionVariable != null) {
         if (!this.ProjectionVars.Any(pv => pv.Key.ToString().Equals(projectionVariable.ToString(), StringComparison.OrdinalIgnoreCase))) {
              this.ProjectionVars.Add(projectionVariable, this.ProjectionVars.Count);
         }
     }
     return this;
 }