Exemple #1
0
        /// <summary>
        /// SPO-flavor ctor
        /// </summary>
        public RDFTriple(RDFResource subj, RDFResource pred, RDFResource obj)
        {
            //TripleFlavor
            this.TripleFlavor = RDFModelEnums.RDFTripleFlavors.SPO;

            //Subject
            this.Subject = (subj ?? new RDFResource());

            //Predicate
            if (pred != null)
            {
                if (pred.IsBlank)
                {
                    throw new RDFModelException("Cannot create RDFTriple because \"pred\" parameter is a blank resource");
                }
                this.Predicate = pred;
            }
            else
            {
                throw new RDFModelException("Cannot create RDFTriple because \"pred\" parameter is null");
            }

            //Object
            this.Object = (obj ?? new RDFResource());

            //TripleID
            this.TripleID = RDFModelUtilities.CreateHash(this.ToString());

            //ReificationSubject
            this.ReificationSubject = new RDFResource(string.Concat("bnode:", this.TripleID.ToString()));
        }
 /// <summary>
 /// Uri-based ctor to build a context from the given Uri
 /// </summary>
 public RDFContext(Uri ctxUri)
 {
     if (ctxUri != null)
     {
         Uri tempUri = RDFModelUtilities.GetUriFromString(ctxUri.ToString());
         if (tempUri != null)
         {
             if (!tempUri.ToString().ToUpperInvariant().StartsWith("BNODE:"))
             {
                 this.Context         = tempUri;
                 this.PatternMemberID = RDFModelUtilities.CreateHash(this.ToString());
             }
             else
             {
                 throw new RDFStoreException("Cannot create RDFContext because given \"ctxUri\" parameter represents a blank node Uri.");
             }
         }
         else
         {
             throw new RDFStoreException("Cannot create RDFContext because given \"ctxUri\" parameter does not represent a valid Uri.");
         }
     }
     else
     {
         throw new RDFStoreException("Cannot create RDFContext because given \"ctxUri\" parameter is null.");
     }
 }
Exemple #3
0
        /// <summary>
        /// SPL-flavor ctor
        /// </summary>
        public RDFTriple(RDFResource subj, RDFResource pred, RDFLiteral lit)
        {
            //TripleFlavor
            this.TripleFlavor = RDFModelEnums.RDFTripleFlavor.SPL;

            //Subject
            this.Subject = (subj ?? new RDFResource());

            //Predicate
            if (pred != null)
            {
                if (pred.IsBlank)
                {
                    throw new RDFModelException("Cannot create RDFTriple because \"pred\" parameter is a blank resource");
                }
                this.Predicate = pred;
            }
            else
            {
                throw new RDFModelException("Cannot create RDFTriple because \"pred\" parameter is null");
            }

            //Object
            this.Object = (lit ?? new RDFPlainLiteral(String.Empty));

            //TripleID
            this.TripleID = RDFModelUtilities.CreateHash(this.ToString());

            //ReificationSubject
            this.ReificationSubject = new RDFResource("bnode:" + this.TripleID);
        }
Exemple #4
0
        /// <summary>
        /// SPL-flavor ctor
        /// </summary>
        public RDFTriple(RDFResource subj, RDFResource pred, RDFLiteral lit)
        {
            //TripleFlavor
            this.TripleFlavor = RDFModelEnums.RDFTripleFlavors.SPL;

            //Subject
            this.Subject = subj ?? new RDFResource();

            //Predicate
            if (pred != null)
            {
                if (pred.IsBlank)
                {
                    throw new RDFModelException("Cannot create RDFTriple because \"pred\" parameter is a blank resource");
                }
                this.Predicate = pred;
            }
            else
            {
                throw new RDFModelException("Cannot create RDFTriple because \"pred\" parameter is null");
            }

            //Object
            this.Object = lit ?? new RDFPlainLiteral(string.Empty);

            //LazyTripleID
            this.LazyTripleID = new Lazy <long>(() => RDFModelUtilities.CreateHash(this.ToString()));

            //LazyReificationSubject
            this.LazyReificationSubject = new Lazy <RDFResource>(() => new RDFResource(string.Concat("bnode:", this.TripleID.ToString())));
        }
Exemple #5
0
        /// <summary>
        /// Default ctor for CSPO pattern
        /// </summary>
        public RDFPattern(RDFPatternMember context, RDFPatternMember subject, RDFPatternMember predicate, RDFPatternMember objLit) : this(subject, predicate, objLit)
        {
            //Context
            if (context != null)
            {
                if (context is RDFContext || context is RDFVariable)
                {
                    this.Context = context;
                    if (context is RDFVariable)
                    {
                        if (!this.Variables.Exists(v => v.Equals(context)))
                        {
                            this.Variables.Add((RDFVariable)context);
                        }
                    }
                }
                else
                {
                    throw new RDFQueryException("Cannot create RDFPattern because given \"context\" parameter (" + context + ") is neither a context or a variable");
                }
            }
            else
            {
                throw new RDFQueryException("Cannot create RDFPattern because given \"context\" parameter is null");
            }

            //PatternID
            this.PatternID = RDFModelUtilities.CreateHash(this.ToString());
        }
        /// <summary>
        /// SPO-flavor ctor
        /// </summary>
        public RDFQuadruple(RDFContext context, RDFResource subj, RDFResource pred, RDFResource obj)
        {
            //TripleFlavor
            this.TripleFlavor = RDFModelEnums.RDFTripleFlavors.SPO;

            //Context
            this.Context = context ?? new RDFContext();

            //Subject
            this.Subject = subj ?? new RDFResource();

            //Predicate
            if (pred != null)
            {
                if (pred.IsBlank)
                {
                    throw new RDFStoreException("Cannot create RDFQuadruple because given \"pred\" parameter is a blank resource");
                }
                this.Predicate = pred;
            }
            else
            {
                throw new RDFStoreException("Cannot create RDFQuadruple because given \"pred\" parameter is null");
            }

            //Object
            this.Object = obj ?? new RDFResource();

            //LazyQuadrupleID
            this.LazyQuadrupleID = new Lazy <long>(() => RDFModelUtilities.CreateHash(this.ToString()));

            //LazyReificationSubject
            this.LazyReificationSubject = new Lazy <RDFResource>(() => new RDFResource(string.Concat("bnode:", this.QuadrupleID.ToString())));
        }
 /// <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.");
     }
 }
Exemple #8
0
 /// <summary>
 /// Uri-based ctor to build a namespace with prefix and uri
 /// </summary>
 public RDFNamespace(String prefix, Uri nSpace)
 {
     if (prefix != null && Regex.IsMatch(prefix, @"^[a-zA-Z0-9_]+$"))
     {
         if (prefix.ToUpperInvariant() != "BNODE" && prefix.ToUpperInvariant() != "XMLNS")
         {
             if (nSpace != null &&
                 !nSpace.ToString().ToUpperInvariant().StartsWith("BNODE:") &&
                 !nSpace.ToString().ToUpperInvariant().StartsWith("XMLNS:"))
             {
                 this.Prefix      = prefix;
                 this.Namespace   = RDFModelUtilities.GetUriFromString(nSpace.ToString());
                 this.NamespaceID = RDFModelUtilities.CreateHash(this.ToString());
             }
             else
             {
                 throw new RDFModelException("Cannot create RDFNamespace because \"nSpace\" parameter is null or cannot start with \"bnode\" or \"xmlns\" prefixes, because they are reserved.");
             }
         }
         else
         {
             throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter cannot be \"bnode\"or \"xmlns\", because they are reserved.");
         }
     }
     else
     {
         throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter is null or not alphanumeric.");
     }
 }
 /// <summary>
 /// Default-ctor to build a taxonomy entry with the given subject, predicate and object resources
 /// </summary>
 internal RDFOntologyTaxonomyEntry(RDFOntologyResource taxonomySubject,
                                   RDFOntologyResource taxonomyPredicate,
                                   RDFOntologyResource taxonomyObject)
 {
     if (taxonomySubject != null)
     {
         if (taxonomyPredicate != null)
         {
             if (taxonomyObject != null)
             {
                 this.TaxonomySubject   = taxonomySubject;
                 this.TaxonomyPredicate = taxonomyPredicate;
                 this.TaxonomyObject    = taxonomyObject;
                 this.InferenceType     = RDFSemanticsEnums.RDFOntologyInferenceType.None;
                 this.TaxonomyEntryID   = RDFModelUtilities.CreateHash(this.ToString());
             }
             else
             {
                 throw new RDFSemanticsException("Cannot create RDFOntologyTaxonomyEntry because given \"taxonomyObject\" parameter is null.");
             }
         }
         else
         {
             throw new RDFSemanticsException("Cannot create RDFOntologyTaxonomyEntry because given \"taxonomyPredicate\" parameter is null.");
         }
     }
     else
     {
         throw new RDFSemanticsException("Cannot create RDFOntologyTaxonomyEntry because given \"taxonomySubject\" parameter is null.");
     }
 }
Exemple #10
0
        /// <summary>
        /// SPO-flavor ctor
        /// </summary>
        public RDFQuadruple(RDFContext context, RDFResource subj, RDFResource pred, RDFResource obj)
        {
            //TripleFlavor
            this.TripleFlavor = RDFModelEnums.RDFTripleFlavors.SPO;

            //Context
            this.Context = (context ?? new RDFContext());

            //Subject
            this.Subject = (subj ?? new RDFResource());

            //Predicate
            if (pred != null)
            {
                if (pred.IsBlank)
                {
                    throw new RDFStoreException("Cannot create RDFQuadruple because given \"pred\" parameter is a blank resource");
                }
                this.Predicate = pred;
            }
            else
            {
                throw new RDFStoreException("Cannot create RDFQuadruple because given \"pred\" parameter is null");
            }

            //Object
            this.Object = (obj ?? new RDFResource());

            //QuadrupleID
            this.QuadrupleID = RDFModelUtilities.CreateHash(this.ToString());
        }
Exemple #11
0
 /// <summary>
 /// Default-ctor to build a plain literal with language
 /// </summary>
 public RDFPlainLiteral(String value, String language) : this(value)  {
     if (language != null && Regex.IsMatch(language, "^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$"))
     {
         this.Language        = language.ToUpperInvariant();
         this.PatternMemberID = RDFModelUtilities.CreateHash(this.ToString());
     }
 }
Exemple #12
0
 /// <summary>
 /// Default-ctor to build an empty memory store
 /// </summary>
 public RDFMemoryStore()
 {
     this.StoreType  = "MEMORY";
     this.StoreGUID  = Guid.NewGuid().ToString();
     this.StoreIndex = new RDFStoreIndex();
     this.StoreID    = RDFModelUtilities.CreateHash(this.ToString());
     this.Quadruples = new Dictionary <long, RDFQuadruple>();
 }
Exemple #13
0
 /// <summary>
 /// Selects the target represented by the given string from this shape
 /// </summary>
 public RDFTarget SelectTarget(string targetName)
 {
     if (targetName != null)
     {
         long targetID = RDFModelUtilities.CreateHash(targetName);
         return(this.Targets.Find(t => t.PatternMemberID.Equals(targetID)));
     }
     return(null);
 }
Exemple #14
0
 /// <summary>
 /// Selects the constraint represented by the given string from this shape
 /// </summary>
 public RDFConstraint SelectConstraint(string constraintName)
 {
     if (constraintName != null)
     {
         long constraintID = RDFModelUtilities.CreateHash(constraintName);
         return(this.Constraints.Find(c => c.PatternMemberID.Equals(constraintID)));
     }
     return(null);
 }
        /// <summary>
        /// Builds a namespace with given prefix and Uri
        /// </summary>
        public RDFNamespace(string prefix, string uri)
        {
            //Validate prefix: must contain only letters/numbers and cannot be "bnode" or "xmlns"
            if (!string.IsNullOrWhiteSpace(prefix))
            {
                prefix = prefix.Trim();

                if (Prefix.Match(prefix).Success)
                {
                    if (prefix.ToUpperInvariant() == "BNODE" || prefix.ToUpperInvariant() == "XMLNS")
                    {
                        throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter cannot be \"bnode\" or \"xmlns\"");
                    }
                }
                else
                {
                    throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter contains unallowed characters");
                }
            }
            else
            {
                throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter is null or empty");
            }

            //Validate uri: must be an absolute Uri and cannot start with "bnode:" or "xmlns:"
            if (!string.IsNullOrWhiteSpace(uri))
            {
                uri = uri.Trim();

                Uri finalUri = RDFModelUtilities.GetUriFromString(uri);
                if (finalUri != null)
                {
                    if (!finalUri.ToString().ToUpperInvariant().StartsWith("BNODE:") &&
                        !finalUri.ToString().ToUpperInvariant().StartsWith("XMLNS:"))
                    {
                        this.NamespacePrefix = prefix;
                        this.NamespaceUri    = finalUri;
                        this.DereferenceUri  = finalUri;
                        this.NamespaceID     = RDFModelUtilities.CreateHash(this.ToString());
                    }
                    else
                    {
                        throw new RDFModelException("Cannot create RDFNamespace because \"uri\" parameter cannot start with \"bnode:\" or \"xmlns:\"");
                    }
                }
                else
                {
                    throw new RDFModelException("Cannot create RDFNamespace because \"uri\" parameter is not a valid Uri");
                }
            }
            else
            {
                throw new RDFModelException("Cannot create RDFNamespace because \"uri\" parameter is null or empty");
            }
        }
Exemple #16
0
 /// <summary>
 /// Selects the literal represented by the given string from the data
 /// </summary>
 public RDFOntologyLiteral SelectLiteral(String literal)
 {
     if (literal != null)
     {
         Int64 literalID = RDFModelUtilities.CreateHash(literal);
         if (this.Literals.ContainsKey(literalID))
         {
             return(this.Literals[literalID]);
         }
     }
     return(null);
 }
Exemple #17
0
 /// <summary>
 /// Selects the fact represented by the given string from the data
 /// </summary>
 public RDFOntologyFact SelectFact(String fact)
 {
     if (fact != null)
     {
         Int64 factID = RDFModelUtilities.CreateHash(fact);
         if (this.Facts.ContainsKey(factID))
         {
             return(this.Facts[factID]);
         }
     }
     return(null);
 }
Exemple #18
0
        /// <summary>
        /// Builds a namespace with given prefix and Uri
        /// </summary>
        public RDFNamespace(String prefix, String uri)
        {
            //Validate prefix: must contain only letters/numbers and cannot be "bnode" or "xmlns"
            if (prefix != null && prefix.Trim() != String.Empty)
            {
                prefix = prefix.Trim();

                if (Regex.IsMatch(prefix, @"^[a-zA-Z0-9_]+$"))
                {
                    if (prefix.ToUpperInvariant() == "BNODE" || prefix.ToUpperInvariant() == "XMLNS")
                    {
                        throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter cannot be \"bnode\" or \"xmlns\"");
                    }
                }
                else
                {
                    throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter contains unallowed characters");
                }
            }
            else
            {
                throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter is null or empty");
            }

            //Validate uri: must be an absolute Uri and cannot start with "bnode:" or "xmlns:"
            if (uri != null && uri.Trim() != String.Empty)
            {
                uri = uri.Trim();

                Uri _uri = RDFModelUtilities.GetUriFromString(uri);
                if (_uri != null)
                {
                    if (!_uri.ToString().ToUpperInvariant().StartsWith("BNODE:") && !_uri.ToString().ToUpperInvariant().StartsWith("XMLNS:"))
                    {
                        this.NamespacePrefix = prefix;
                        this.NamespaceUri    = _uri;
                        this.NamespaceID     = RDFModelUtilities.CreateHash(this.ToString());
                    }
                    else
                    {
                        throw new RDFModelException("Cannot create RDFNamespace because \"uri\" parameter cannot start with \"bnode:\" or \"xmlns:\"");
                    }
                }
                else
                {
                    throw new RDFModelException("Cannot create RDFNamespace because \"uri\" parameter is not a valid Uri");
                }
            }
            else
            {
                throw new RDFModelException("Cannot create RDFNamespace because \"uri\" parameter is null or empty");
            }
        }
Exemple #19
0
 /// <summary>
 /// Adds the given filter to the pattern group
 /// </summary>
 public RDFPatternGroup AddFilter(RDFFilter filter)
 {
     if (filter != null)
     {
         if (!this.Filters.Exists(f => f.Equals(filter)))
         {
             this.Filters.Add(filter);
             this.PatternGroupID = RDFModelUtilities.CreateHash(this.ToString());
         }
     }
     return(this);
 }
Exemple #20
0
 /// <summary>
 /// Default-ctor to build a named SPARQL variable
 /// </summary>
 public RDFVariable(String variableName)
 {
     if (variableName != null && variableName.Trim() != String.Empty)
     {
         this.VariableName    = "?" + variableName.Trim().ToUpperInvariant();
         this.PatternMemberID = RDFModelUtilities.CreateHash(this.ToString());
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFVariable because given \"variableName\" parameter is null or empty.");
     }
 }
 /// <summary>
 /// Selects the label represented by the given string from the scheme
 /// </summary>
 public RDFSKOSLabel SelectLabel(String label)
 {
     if (label != null)
     {
         Int64 labelID = RDFModelUtilities.CreateHash(label);
         if (this.Labels.ContainsKey(labelID))
         {
             return(this.Labels[labelID]);
         }
     }
     return(null);
 }
 /// <summary>
 /// Selects the ordered collection represented by the given string from the scheme
 /// </summary>
 public RDFSKOSOrderedCollection SelectOrderedCollection(String orderedCollection)
 {
     if (orderedCollection != null)
     {
         Int64 orderedCollectionID = RDFModelUtilities.CreateHash(orderedCollection);
         if (this.OrderedCollections.ContainsKey(orderedCollectionID))
         {
             return(this.OrderedCollections[orderedCollectionID]);
         }
     }
     return(null);
 }
Exemple #23
0
 /// <summary>
 /// Default-ctor to build an Offset modifier on a query
 /// </summary>
 public RDFOffsetModifier(Int32 offset)
 {
     if (offset >= 0)
     {
         this.Offset     = offset;
         this.ModifierID = RDFModelUtilities.CreateHash(this.ToString());
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFOffsetModifier because given \"offset\" parameter (" + offset + ") is negative.");
     }
 }
Exemple #24
0
 /// <summary>
 /// Default-ctor to build a Limit modifier on a query
 /// </summary>
 public RDFLimitModifier(Int32 limit)
 {
     if (limit >= 0)
     {
         this.Limit      = limit;
         this.ModifierID = RDFModelUtilities.CreateHash(this.ToString());
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFLimitModifier because given \"limit\" parameter (" + limit + ") is negative.");
     }
 }
Exemple #25
0
 /// <summary>
 /// Selects the shape represented by the given string from this shapes graph
 /// </summary>
 public RDFShape SelectShape(String shapeName)
 {
     if (shapeName != null)
     {
         Int64 shapeID = RDFModelUtilities.CreateHash(shapeName);
         if (this.Shapes.ContainsKey(shapeID))
         {
             return(this.Shapes[shapeID]);
         }
     }
     return(null);
 }
Exemple #26
0
 /// <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.");
     }
 }
Exemple #27
0
 /// <summary>
 /// Default-ctor to build a negation filter on the given filter
 /// </summary>
 public RDFBooleanNotFilter(RDFFilter filter)
 {
     if (filter != null)
     {
         this.Filter   = filter;
         this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFBooleanNotFilter because given \"filter\" parameter is null.");
     }
 }
Exemple #28
0
 /// <summary>
 /// Selects the concept represented by the given string from the scheme
 /// </summary>
 public RDFSKOSConcept SelectConcept(string concept)
 {
     if (concept != null)
     {
         long conceptID = RDFModelUtilities.CreateHash(concept);
         if (this.Concepts.ContainsKey(conceptID))
         {
             return(this.Concepts[conceptID]);
         }
     }
     return(null);
 }
Exemple #29
0
 /// <summary>
 /// Selects the collection represented by the given string from the scheme
 /// </summary>
 public RDFSKOSCollection SelectCollection(string collection)
 {
     if (collection != null)
     {
         long collectionID = RDFModelUtilities.CreateHash(collection);
         if (this.Collections.ContainsKey(collectionID))
         {
             return(this.Collections[collectionID]);
         }
     }
     return(null);
 }
Exemple #30
0
 /// <summary>
 /// Default-ctor to build an empty named pattern group
 /// </summary>
 public RDFPatternGroup(String patternGroupName)
 {
     if (patternGroupName != null && patternGroupName.Trim() != String.Empty)
     {
         this.PatternGroupName = patternGroupName.Trim().ToUpperInvariant();
         this.IsOptional       = false;
         this.JoinAsUnion      = false;
         this.Patterns         = new List <RDFPattern>();
         this.Filters          = new List <RDFFilter>();
         this.Variables        = new List <RDFVariable>();
         this.PatternGroupID   = RDFModelUtilities.CreateHash(this.ToString());
     }
 }