/// <summary> /// Default ctor to build a typed literal with value and default "xsd:string" datatype /// </summary> public RDFTypedLiteral(String value) { this.Value = (value ?? String.Empty); this.Datatype = RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "string"); this.PatternMemberID = RDFModelUtilities.CreateHash(this.ToString()); if (!RDFModelUtilities.ValidateTypedLiteral(this)) { throw new RDFModelException("Cannot create RDFTypedLiteral because given \"value\" parameter is not well-formed or not compatible with the category of the datatype."); } }
/// <summary> /// Default ctor to build a typed literal with value and datatype /// </summary> public RDFTypedLiteral(String value, RDFDatatype datatype) { if (datatype != null) { this.Value = (value ?? String.Empty); this.Datatype = datatype; this.PatternMemberID = RDFModelUtilities.CreateHash(this.ToString()); if (!RDFModelUtilities.ValidateTypedLiteral(this)) { throw new RDFModelException("Cannot create RDFTypedLiteral because given \"value\" parameter is not well-formed or compatible with the category of the datatype."); } } }
/// <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."); } }
/// <summary> /// Tries to parse the given string in order to build the corresponding datatype /// </summary> internal static RDFDatatype GetDatatypeFromString(String datatypeString) { if (datatypeString != null && datatypeString.Trim() != String.Empty) { Uri datatypeUri = RDFModelUtilities.GetUriFromString(datatypeString); if (datatypeUri == null) { throw new RDFModelException("Cannot create RDFDatatype because given \"datatypeString\" (" + datatypeString + ") parameter cannot be converted to a valid Uri"); } String type = null; String ns = null; RDFDatatype dt = null; // e.g.: "http://www.w3.org/2001/XMLSchema#integer" if (datatypeUri.Fragment != String.Empty) { type = datatypeUri.Fragment.TrimStart(new Char[] { '#' }); //"integer" ns = datatypeUri.AbsoluteUri.TrimEnd(type.ToCharArray()); //"http://www.w3.org/2001/XMLSchema#" } // e.g.: "http://example.org/integer" or "ex:integer" else { type = datatypeUri.Segments[datatypeUri.Segments.Length - 1]; //"integer" ns = datatypeUri.AbsoluteUri.TrimEnd(type.ToCharArray()); //"http://example.org/" or "ex:" } //First try to search the register for prefix and datatype if (ns.EndsWith(":")) { ns = ns.TrimEnd(':'); dt = RDFDatatypeRegister.GetByPrefixAndDatatype(ns, type); } //If nothing found, try to search the register for namespace and datatype if(dt == null) { dt = RDFDatatypeRegister.GetByNamespaceAndDatatype(ns, type); //If nothing found, we must create and register a new datatype if (dt == null) { //First try to find a namespace to work with RDFNamespace nSpace = (RDFNamespaceRegister.GetByNamespace(ns) ?? RDFModelUtilities.GenerateNamespace(ns, true)); //If nothing found, we also have to create a new datatype dt = new RDFDatatype(nSpace.Prefix, nSpace.Namespace, type, RDFModelEnums.RDFDatatypeCategory.String); } } return dt; } throw new RDFModelException("Cannot create RDFDatatype because given \"datatypeString\" parameter is null or empty"); }