Exemplo n.º 1
0
        /// <summary>
        /// Determines whether a given String is a valid Plain Literal for the given Datatype.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="dt">Datatype.</param>
        /// <param name="syntax">Turtle Syntax.</param>
        /// <returns></returns>
        public static bool IsValidPlainLiteral(String value, Uri dt, TurtleSyntax syntax)
        {
            StringComparison comparison = (syntax == TurtleSyntax.Original ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);

            if ((value.Equals("true", comparison) || value.Equals("false", comparison)) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeBoolean))
            {
                return(true);
            }
            else if (_validDecimal.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDecimal))
            {
                return(true);
            }
            else if (_validInteger.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeInteger))
            {
                return(true);
            }
            else if (_validDouble.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDouble))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets whether the given value is a valid prefix in Turtle.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="syntax">Turtle Syntax.</param>
        /// <returns></returns>
        public static bool IsValidPrefix(String value, TurtleSyntax syntax)
        {
            // W3C Standard Turtle
            // PNAME_NS	::=	PN_PREFIX? ':'

            // Original Member Submission Turtle
            // qname	::=	prefixName? ':' name?

            // The productions are identical for our purposes
            if (value.Equals(String.Empty))
            {
                return(false);
            }
            if (!value.EndsWith(":"))
            {
                return(false);
            }
            if (value.Equals(":"))
            {
                return(true);
            }

            // IsPNPrefix() implements the appropriate productions for the different syntaxes
            return(IsPNPrefix(value.Substring(0, value.Length - 1), syntax));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Infers the Type of a Plain Literal.
        /// </summary>
        /// <param name="p">Plain Literal to infer the Type of.</param>
        /// <param name="syntax">Turtle Syntax.</param>
        /// <returns>A Uri  representing the XML Scheme Data Type for the Plain Literal.</returns>
        public static Uri InferPlainLiteralType(PlainLiteralToken p, TurtleSyntax syntax)
        {
            String           value      = p.Value;
            StringComparison comparison = (syntax == TurtleSyntax.Original ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);

            if (value.Equals("true", comparison) || value.Equals("false", comparison))
            {
                // Is a Boolean
                return(UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeBoolean));
            }
            else if (_validInteger.IsMatch(value))
            {
                // Is an Integer
                return(UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeInteger));
            }
            else if (_validDecimal.IsMatch(value))
            {
                // Is a Decimal
                return(UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeDecimal));
            }
            else if (_validDouble.IsMatch(value))
            {
                // Is a Double
                return(UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeDouble));
            }
            else
            {
                throw new RdfParseException("Unable to automatically Infer a Type for this PlainLiteralToken.  Plain Literals may only be Booleans, Integers, Decimals or Doubles");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines whether a given String is a valid QName.
        /// </summary>
        /// <param name="value">String to test.</param>
        /// <param name="syntax">Turtle Syntax.</param>
        /// <returns></returns>
        public static bool IsValidQName(String value, TurtleSyntax syntax)
        {
            if (!value.Contains(":"))
            {
                return(false);
            }
            String prefix = value.Substring(0, value.IndexOf(':') + 1);
            String lname  = prefix.Length < value.Length ? value.Substring(prefix.Length) : String.Empty;

            return(IsValidPrefix(prefix, syntax) && IsValidLocalName(lname, syntax));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determines whether a given String is a valid Plain Literal.
        /// </summary>
        /// <param name="value">String to test.</param>
        /// <param name="syntax">Turtle Syntax.</param>
        /// <returns></returns>
        public static bool IsValidPlainLiteral(String value, TurtleSyntax syntax)
        {
            StringComparison comparison = (syntax == TurtleSyntax.Original ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);

            if (value.Equals("true", comparison) || value.Equals("false", comparison))
            {
                return(true);
            }
            else
            {
                return(_validDecimal.IsMatch(value) || _validInteger.IsMatch(value) || _validDouble.IsMatch(value));
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new compressing Turtle writer using the given syntax level
 /// </summary>
 /// <param name="syntax">Syntax Level</param>
 public CompressingTurtleWriter(TurtleSyntax syntax)
 {
     this._syntax = syntax;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new Turtle Writer Context with custom settings
 /// </summary>
 /// <param name="g">Graph to write</param>
 /// <param name="output">TextWriter to write to</param>
 /// <param name="compressionLevel">Compression Level to use</param>
 /// <param name="prettyPrint">Pretty Print Mode</param>
 /// <param name="hiSpeed">High Speed Mode</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleWriterContext(IGraph g, TextWriter output, int compressionLevel, bool prettyPrint, bool hiSpeed, TurtleSyntax syntax)
     : base(g, output, compressionLevel, prettyPrint, hiSpeed)
 {
     this._formatter    = (syntax == TurtleSyntax.Original ? new TurtleFormatter(g) : new TurtleW3CFormatter(g));
     this._uriFormatter = (IUriFormatter)this._formatter;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a new Turtle Writer Context with default settings
 /// </summary>
 /// <param name="g">Graph to write</param>
 /// <param name="output">TextWriter to write to</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleWriterContext(IGraph g, TextWriter output, TurtleSyntax syntax)
     : this(g, output, Options.DefaultCompressionLevel, true, true, syntax)
 {
 }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a new Turtle Parser which uses the given Token Queue Mode.
 /// </summary>
 /// <param name="queueMode">Queue Mode for Turtle.</param>
 /// <param name="syntax">Turtle Syntax.</param>
 public TurtleParser(TokenQueueMode queueMode, TurtleSyntax syntax)
     : this(syntax)
 {
     _queueMode = queueMode;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates a new Turtle Parser Context with default settings
 /// </summary>
 /// <param name="handler">RDF Handler</param>
 /// <param name="tokeniser">Tokeniser to use</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleParserContext(IRdfHandler handler, ITokeniser tokeniser, TurtleSyntax syntax)
     : this(handler, tokeniser, syntax, TokenQueueMode.SynchronousBufferDuringParsing, false, false)
 {
 }
Exemplo n.º 11
0
 /// <summary>
 /// Creates a new Turtle Parser Context with custom settings
 /// </summary>
 /// <param name="g">Graph to parse into</param>
 /// <param name="tokeniser">Tokeniser to use</param>
 /// <param name="syntax">Turtle Syntax</param>
 /// <param name="traceParsing">Whether to trace parsing</param>
 /// <param name="traceTokeniser">Whether to trace tokenisation</param>
 public TurtleParserContext(IGraph g, ITokeniser tokeniser, TurtleSyntax syntax, bool traceParsing, bool traceTokeniser)
     : this(g, tokeniser, syntax, TokenQueueMode.SynchronousBufferDuringParsing, traceParsing, traceTokeniser)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Creates a new Turtle Parser Context with default settings
 /// </summary>
 /// <param name="g">Graph to parse into</param>
 /// <param name="tokeniser">Tokeniser to use</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleParserContext(IGraph g, ITokeniser tokeniser, TurtleSyntax syntax)
     : this(g, tokeniser, syntax, TokenQueueMode.SynchronousBufferDuringParsing, false, false)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// Creates a new Turtle Parser which uses the given Token Queue Mode
 /// </summary>
 /// <param name="queueMode">Queue Mode for Tokenising</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleParser(TokenQueueMode queueMode, TurtleSyntax syntax)
     : this(syntax)
 {
     this._queueMode = queueMode;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Creates a new Turtle Parser
 /// </summary>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleParser(TurtleSyntax syntax)
 {
     this._syntax = syntax;
 }
Exemplo n.º 15
0
        /// <summary>
        /// Determines whether a given String is a valid QName
        /// </summary>
        /// <param name="value">String to test</param>
        /// <param name="syntax">Turtle Syntax</param>
        /// <returns></returns>
        public static bool IsValidQName(String value, TurtleSyntax syntax)
        {
            if (value.Contains(':'))
            {
                String ns, localname;
                ns = value.Substring(0, value.IndexOf(':'));
                localname = value.Substring(value.IndexOf(':') + 1);

                //Namespace Validation
                if (!ns.Equals(String.Empty))
                {
                    //Allowed empty Namespace
                    if (ns.StartsWith("-") || ns.StartsWith("."))
                    {
                        //Can't start with a - or .
                        return false;
                    }
                    else
                    {
                        char[] nchars = ns.ToCharArray();
                        if (IsPNCharsBase(nchars[0]))
                        {
                            if (nchars.Length > 1)
                            {
                                for (int i = 1; i < nchars.Length; i++)
                                {
                                    //Check if valid Name Char
                                    //The . character is not allowed in original Turtle but is permitted in new Turtle
                                    if (!IsPNChars(nchars[i]) || (nchars[i] == '.' && syntax == TurtleSyntax.Original)) return false;
                                }
                                //If we reach here the Namespace is OK
                            }
                            else
                            {
                                //Only 1 Character which was valid so OK
                            }
                        }
                        else
                        {
                            //Doesn't start with a valid Name Start Char
                            return false;
                        }
                    }
                }

                //Local Name Validation
                if (!localname.Equals(String.Empty))
                {
                    //Allowed empty Local Name
                    char[] lchars = localname.ToCharArray();

                    if (IsPNCharsU(lchars[0]) || (Char.IsDigit(lchars[0]) && syntax == TurtleSyntax.W3C))
                    {
                        if (lchars.Length > 1)
                        {
                            for (int i = 1; i < lchars.Length; i++)
                            {
                                //Check if valid Name Char
                                //The . character is not allowed in original Turtle but is permitted in new Turtle
                                if (!IsPNChars(lchars[i]) || (lchars[i] == '.' && syntax == TurtleSyntax.Original)) return false;
                            }
                            //If we reach here the Local Name is OK
                        }
                        else
                        {
                            //Only 1 Character which was valid so OK
                        }
                    }
                    else
                    {
                        //Not a valid Name Start Char
                        return false;
                    }
                }

                //If we reach here then it's all valid
                return true;
            }
            else
            {
                //Must contain a colon
                return false;
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Determines whether a given String is a valid Plain Literal for the given Datatype
 /// </summary>
 /// <param name="value">Value</param>
 /// <param name="dt">Datatype</param>
 /// <param name="syntax">Turtle Syntax</param>
 /// <returns></returns>
 public static bool IsValidPlainLiteral(String value, Uri dt, TurtleSyntax syntax)
 {
     StringComparison comparison = (syntax == TurtleSyntax.Original ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);
     if ((value.Equals("true", comparison) || value.Equals("false", comparison)) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeBoolean))
     {
         return true;
     }
     else if (_validDecimal.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDecimal))
     {
         return true;
     }
     else if (_validInteger.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeInteger))
     {
         return true;
     }
     else if (_validDouble.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDouble))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Determines whether a given String is a valid Plain Literal
 /// </summary>
 /// <param name="value">String to test</param>
 /// <param name="syntax">Turtle Syntax</param>
 /// <returns></returns>
 public static bool IsValidPlainLiteral(String value, TurtleSyntax syntax)
 {
     StringComparison comparison = (syntax == TurtleSyntax.Original ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);
     if (value.Equals("true", comparison) || value.Equals("false", comparison))
     {
         return true;
     }
     else
     {
         return (_validDecimal.IsMatch(value) || _validInteger.IsMatch(value) || _validDouble.IsMatch(value));
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Infers the Type of a Plain Literal
        /// </summary>
        /// <param name="p">Plain Literal to infer the Type of</param>
        /// <param name="syntax">Turtle Syntax</param>
        /// <returns>A Uri  representing the XML Scheme Data Type for the Plain Literal</returns>
        public static Uri InferPlainLiteralType(PlainLiteralToken p, TurtleSyntax syntax)
        {
            String value = p.Value;
            StringComparison comparison = (syntax == TurtleSyntax.Original ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);

            if (value.Equals("true", comparison) || value.Equals("false", comparison))
            {
                //Is a Boolean
                return UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeBoolean);
            }
            else if (_validInteger.IsMatch(value))
            {
                //Is an Integer
                return UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeInteger);
            }
            else if (_validDecimal.IsMatch(value))
            {
                //Is a Decimal
                return UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeDecimal);
            }
            else if (_validDouble.IsMatch(value))
            {
                //Is a Double
                return UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeDouble);
            }
            else
            {
                throw new RdfParseException("Unable to automatically Infer a Type for this PlainLiteralToken.  Plain Literals may only be Booleans, Integers, Decimals or Doubles");
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// Creates a new Turtle Tokeniser
 /// </summary>
 /// <param name="input">The Input Stream to generate Tokens from</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleTokeniser(StreamReader input, TurtleSyntax syntax)
     : this(BlockingTextReader.Create(input), syntax)
 {
 }
Exemplo n.º 20
0
 /// <summary>
 /// Creates a new Turtle Tokeniser
 /// </summary>
 /// <param name="input">The Input Stream to generate Tokens from</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleTokeniser(BlockingTextReader input, TurtleSyntax syntax)
     : base(input)
 {
     this._in = input;
     this.Format = "Turtle";
     this._syntax = syntax;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Creates a new Turtle Parser Context with custom settings
 /// </summary>
 /// <param name="handler">RDF Handler</param>
 /// <param name="tokeniser">Tokeniser to use</param>
 /// <param name="syntax">Turtle Syntax</param>
 /// <param name="queueMode">Tokeniser Queue Mode</param>
 public TurtleParserContext(IRdfHandler handler, ITokeniser tokeniser, TurtleSyntax syntax, TokenQueueMode queueMode)
     : this(handler, tokeniser, syntax, queueMode, false, false)
 {
 }
Exemplo n.º 22
0
 /// <summary>
 /// Creates a new Turtle Writer Context with default settings
 /// </summary>
 /// <param name="g">Graph to write</param>
 /// <param name="output">TextWriter to write to</param>
 /// <param name="syntax">Turtle Syntax</param>
 public CompressingTurtleWriterContext(IGraph g, TextWriter output, TurtleSyntax syntax)
     : this(g, output, Options.DefaultCompressionLevel, true, true, syntax)
 {
 }
Exemplo n.º 23
0
 /// <summary>
 /// Creates a new Turtle Parser Context with custom settings
 /// </summary>
 /// <param name="g">Graph to parse into</param>
 /// <param name="tokeniser">Tokeniser to use</param>
 /// <param name="syntax">Turtle Syntax</param>
 /// <param name="queueMode">Tokeniser Queue Mode</param>
 public TurtleParserContext(IGraph g, ITokeniser tokeniser, TurtleSyntax syntax, TokenQueueMode queueMode)
     : this(g, tokeniser, syntax, queueMode, false, false)
 {
 }
Exemplo n.º 24
0
 /// <summary>
 /// Creates a new Turtle Writer Context with custom settings
 /// </summary>
 /// <param name="g">Graph to write</param>
 /// <param name="output">TextWriter to write to</param>
 /// <param name="compressionLevel">Compression Level to use</param>
 /// <param name="prettyPrint">Pretty Print Mode</param>
 /// <param name="hiSpeed">High Speed Mode</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleWriterContext(IGraph g, TextWriter output, int compressionLevel, bool prettyPrint, bool hiSpeed, TurtleSyntax syntax)
     : base(g, output, compressionLevel, prettyPrint, hiSpeed)
 {
     this._formatter = (syntax == TurtleSyntax.Original ? new TurtleFormatter(g) : new TurtleW3CFormatter(g));
     this._uriFormatter = (IUriFormatter)this._formatter;
 }
Exemplo n.º 25
0
 /// <summary>
 /// Creates a new Turtle Parser Context with custom settings
 /// </summary>
 /// <param name="g">Graph to parse into</param>
 /// <param name="tokeniser">Tokeniser to use</param>
 /// <param name="syntax">Turtle Syntax</param>
 /// <param name="queueMode">Tokeniser Queue Mode</param>
 /// <param name="traceParsing">Whether to trace parsing</param>
 /// <param name="traceTokeniser">Whether to trace tokenisation</param>
 public TurtleParserContext(IGraph g, ITokeniser tokeniser, TurtleSyntax syntax, TokenQueueMode queueMode, bool traceParsing, bool traceTokeniser)
     : base(g, tokeniser, queueMode, traceParsing, traceTokeniser)
 {
     this._syntax = syntax;
 }
Exemplo n.º 26
0
        /// <summary>
        /// Gets whether the given value is the valid prefix portion of a prefixed name in Turtle.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="syntax">Turtle Syntax.</param>
        /// <returns></returns>
        public static bool IsPNPrefix(String value, TurtleSyntax syntax)
        {
            char[] cs    = value.ToCharArray();
            int    start = 1;

            switch (syntax)
            {
            case TurtleSyntax.W3C:
                // PN_PREFIX	::=	PN_CHARS_BASE ((PN_CHARS | '.')* PN_CHARS)?

                if (cs.Length == 0)
                {
                    return(true);
                }

                // First character must be in PN_CHARS_BASE
                if (!IsPNCharsBase(cs[0]))
                {
                    // Handle surrogate pairs for UTF-32 characters
                    if (UnicodeSpecsHelper.IsHighSurrogate(cs[0]) && cs.Length > 1)
                    {
                        if (!IsPNCharsBase(cs[0], cs[1]))
                        {
                            return(false);
                        }
                        start++;
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (cs.Length == start)
                {
                    return(true);
                }

                // Intermediate characters must be a '.' or in PN_CHARS
                for (int i = start; i < cs.Length - 1; i++)
                {
                    if (cs[i] != '.' && !IsPNChars(cs[i]))
                    {
                        // Handle surrogate pairs for UTF-32 characters
                        if (UnicodeSpecsHelper.IsHighSurrogate(cs[i]) && i < cs.Length - 2)
                        {
                            if (!IsPNChars(cs[i], cs[i + 1]))
                            {
                                return(false);
                            }
                            i++;
                        }
                        else if (UnicodeSpecsHelper.IsHighSurrogate(cs[i]) && i == cs.Length - 2)
                        {
                            // This case handles the case where the final character is a UTF-32 character representing by a surrogate pair
                            return(IsPNChars(cs[i], cs[i + 1]));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }

                // Final character must be in PN_CHARS
                return(IsPNChars(cs[cs.Length - 1]));

            default:
                // prefixName	::=	( nameStartChar - '_' ) nameChar*

                if (cs.Length == 0)
                {
                    return(true);
                }

                // First character must be a name start char and not a _
                if (!IsNameStartChar(cs[0]) || cs[0] == '_')
                {
                    // Handle surrogate pairs for UTF-32
                    if (UnicodeSpecsHelper.IsHighSurrogate(cs[0]) && cs.Length > 1)
                    {
                        if (!IsNameStartChar(cs[0], cs[1]))
                        {
                            return(false);
                        }
                        start++;
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (cs.Length == start)
                {
                    return(true);
                }

                // Subsequent characters must be in nameChar
                for (int i = start; i < cs.Length; i++)
                {
                    if (!IsNameChar(cs[i]))
                    {
                        // Handle surrogate pairs for UTF-32
                        if (UnicodeSpecsHelper.IsHighSurrogate(cs[i]) && i < cs.Length - 1)
                        {
                            if (!IsNameChar(cs[i], cs[i + 1]))
                            {
                                return(false);
                            }
                            i++;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// Creates a new Turtle Parser.
 /// </summary>
 /// <param name="syntax">Turtle Syntax.</param>
 public TurtleParser(TurtleSyntax syntax)
 {
     _syntax = syntax;
 }
Exemplo n.º 28
0
        /// <summary>
        /// Gets whether the given value is the valid local name portion of a prefixed name in Turtle.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="syntax">Turtle Syntax.</param>
        /// <returns></returns>
        public static bool IsValidLocalName(String value, TurtleSyntax syntax)
        {
            char[] cs = value.ToCharArray();

            // Empty local names are valid
            if (cs.Length == 0)
            {
                return(true);
            }

            switch (syntax)
            {
            case TurtleSyntax.W3C:
                // PNAME_LN	::=	PNAME_NS PN_LOCAL
                // PNAME_NS	::=	PN_PREFIX? ':'

                // Local name is a syntax of namespace segments
                String[] portions = value.Split(':');

                // Each non-final portion conforms to the PNAME_NS production
                // This is a PN_PREFIX followed by a ':' so we can call IsPNPrefix() directly
                // However we have to be careful because the final portion can contain bare : which we already split on
                int p;
                for (p = 0; p < portions.Length - 1; p++)
                {
                    if (portions[p].Length == 0)
                    {
                        continue;
                    }

                    // If we see any of the escape sequence starters or a leading digit then this must be the start of the local name
                    if (portions[p].Contains("%") || portions[p].Contains("\\") || Char.IsDigit(portions[p][0]))
                    {
                        break;
                    }

                    // Otherwise must be a valid prefix
                    if (!IsPNPrefix(portions[p], syntax))
                    {
                        return(false);
                    }
                }

                String final = portions[portions.Length - 1];
                if (p < portions.Length - 1)
                {
                    final = String.Join(":", portions, p, portions.Length - p);
                }

                // Final portion may be empty which is valid because a portion may consist solely of a : which would result in this scenario
                if (final.Length == 0)
                {
                    return(true);
                }

                // Final portion conforms to PN_LOCAL
                return(IsPNLocal(final));

            default:
                // name	::=	nameStartChar nameChar*

                int start = 1;

                // Validate first character is a nameStartChar
                if (!IsNameStartChar(cs[0]))
                {
                    if (UnicodeSpecsHelper.IsHighSurrogate(cs[0]) && cs.Length > 1)
                    {
                        if (!IsNameStartChar(cs[0], cs[1]))
                        {
                            return(false);
                        }
                        start++;
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (cs.Length == start)
                {
                    return(true);
                }

                // Further characters must be nameChar
                for (int i = start; i < cs.Length; i++)
                {
                    if (!IsNameChar(cs[i]))
                    {
                        if (UnicodeSpecsHelper.IsHighSurrogate(cs[i]) && i < cs.Length - 1)
                        {
                            if (!IsNameChar(cs[i], cs[i + 1]))
                            {
                                return(false);
                            }
                            i++;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// Creates a new Turtle Writer Context with custom settings
 /// </summary>
 /// <param name="g">Graph to write</param>
 /// <param name="output">TextWriter to write to</param>
 /// <param name="compressionLevel">Compression Level to use</param>
 /// <param name="prettyPrint">Pretty Print Mode</param>
 /// <param name="hiSpeed">High Speed Mode</param>
 /// <param name="syntax">Turtle Syntax</param>
 public CompressingTurtleWriterContext(IGraph g, TextWriter output, int compressionLevel, bool prettyPrint, bool hiSpeed, TurtleSyntax syntax)
     : base(g, output, compressionLevel, prettyPrint, hiSpeed, syntax)
 {
 }
Exemplo n.º 30
0
 /// <summary>
 /// Creates a new Turtle Writer
 /// </summary>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleWriter(TurtleSyntax syntax)
 {
     this._syntax = syntax;
 }
Exemplo n.º 31
0
 /// <summary>
 /// Creates a new Turtle Writer Context with custom settings
 /// </summary>
 /// <param name="g">Graph to write</param>
 /// <param name="output">TextWriter to write to</param>
 /// <param name="prettyPrint">Pretty Print Mode</param>
 /// <param name="hiSpeed">High Speed Mode</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleWriterContext(IGraph g, TextWriter output, bool prettyPrint, bool hiSpeed, TurtleSyntax syntax)
     : this(g, output, Options.DefaultCompressionLevel, prettyPrint, hiSpeed, syntax)
 {
 }
Exemplo n.º 32
0
 /// <summary>
 /// Creates a new compressing Turtle writer using the given syntax level
 /// </summary>
 /// <param name="syntax">Syntax Level</param>
 public CompressingTurtleWriter(TurtleSyntax syntax)
 {
     this._syntax = syntax;
 }
Exemplo n.º 33
0
 /// <summary>
 /// Creates a new Compressing Turtle Writer which uses the given Compression Level and Syntax Level
 /// </summary>
 /// <param name="compressionLevel">Desired Compression Level</param>
 /// <param name="syntax">Syntax Level</param>
 /// <remarks>See Remarks for this classes <see cref="CompressingTurtleWriter.CompressionLevel">CompressionLevel</see> property to see what effect different compression levels have</remarks>
 public CompressingTurtleWriter(int compressionLevel, TurtleSyntax syntax)
     : this(compressionLevel)
 {
     this._syntax = syntax;
 }
Exemplo n.º 34
0
 /// <summary>
 /// Creates a new Turtle Writer Context with custom settings
 /// </summary>
 /// <param name="g">Graph to write</param>
 /// <param name="output">TextWriter to write to</param>
 /// <param name="prettyPrint">Pretty Print Mode</param>
 /// <param name="hiSpeed">High Speed Mode</param>
 /// <param name="syntax">Turtle Syntax</param>
 public TurtleWriterContext(IGraph g, TextWriter output, bool prettyPrint, bool hiSpeed, TurtleSyntax syntax)
     : this(g, output, Options.DefaultCompressionLevel, prettyPrint, hiSpeed, syntax)
 {
 }
Exemplo n.º 35
0
 /// <summary>
 /// Creates a new GZipped Turtle parser.
 /// </summary>
 /// <param name="syntax">Turtle Syntax.</param>
 public GZippedTurtleParser(TurtleSyntax syntax)
     : base(new TurtleParser(syntax))
 {
 }
Exemplo n.º 36
0
        /// <summary>
        /// Determines whether a given String is a valid QName
        /// </summary>
        /// <param name="value">String to test</param>
        /// <param name="syntax">Turtle Syntax</param>
        /// <returns></returns>
        public static bool IsValidQName(String value, TurtleSyntax syntax)
        {
            if (value.Contains(':'))
            {
                String ns, localname;
                ns        = value.Substring(0, value.IndexOf(':'));
                localname = value.Substring(value.IndexOf(':') + 1);

                //Namespace Validation
                if (!ns.Equals(String.Empty))
                {
                    //Allowed empty Namespace
                    if (ns.StartsWith("-") || ns.StartsWith("."))
                    {
                        //Can't start with a - or .
                        return(false);
                    }
                    else
                    {
                        char[] nchars = ns.ToCharArray();
                        if (IsPNCharsBase(nchars[0]))
                        {
                            if (nchars.Length > 1)
                            {
                                for (int i = 1; i < nchars.Length; i++)
                                {
                                    //Check if valid Name Char
                                    //The . character is not allowed in original Turtle but is permitted in new Turtle
                                    if (!IsPNChars(nchars[i]) || (nchars[i] == '.' && syntax == TurtleSyntax.Original))
                                    {
                                        return(false);
                                    }
                                }
                                //If we reach here the Namespace is OK
                            }
                            else
                            {
                                //Only 1 Character which was valid so OK
                            }
                        }
                        else
                        {
                            //Doesn't start with a valid Name Start Char
                            return(false);
                        }
                    }
                }

                //Local Name Validation
                if (!localname.Equals(String.Empty))
                {
                    //Allowed empty Local Name
                    char[] lchars = localname.ToCharArray();

                    if (IsPNCharsU(lchars[0]) || (Char.IsDigit(lchars[0]) && syntax == TurtleSyntax.W3C))
                    {
                        if (lchars.Length > 1)
                        {
                            for (int i = 1; i < lchars.Length; i++)
                            {
                                //Check if valid Name Char
                                //The . character is not allowed in original Turtle but is permitted in new Turtle
                                if (!IsPNChars(lchars[i]) || (lchars[i] == '.' && syntax == TurtleSyntax.Original))
                                {
                                    return(false);
                                }
                            }
                            //If we reach here the Local Name is OK
                        }
                        else
                        {
                            //Only 1 Character which was valid so OK
                        }
                    }
                    else
                    {
                        //Not a valid Name Start Char
                        return(false);
                    }
                }

                //If we reach here then it's all valid
                return(true);
            }
            else
            {
                //Must contain a colon
                return(false);
            }
        }
Exemplo n.º 37
0
 /// <summary>
 /// Creates a new Turtle Writer.
 /// </summary>
 /// <param name="syntax">Turtle Syntax.</param>
 public TurtleWriter(TurtleSyntax syntax)
 {
     _syntax = syntax;
 }
Exemplo n.º 38
0
 /// <summary>
 /// Creates a new Turtle Parser Context with custom settings.
 /// </summary>
 /// <param name="handler">RDF Handler.</param>
 /// <param name="tokeniser">Tokeniser to use.</param>
 /// <param name="syntax">Turtle Syntax.</param>
 /// <param name="queueMode">Tokeniser Queue Mode.</param>
 /// <param name="traceParsing">Whether to trace parsing.</param>
 /// <param name="traceTokeniser">Whether to trace tokenisation.</param>
 public TurtleParserContext(IRdfHandler handler, ITokeniser tokeniser, TurtleSyntax syntax, TokenQueueMode queueMode, bool traceParsing, bool traceTokeniser)
     : base(handler, tokeniser, queueMode, traceParsing, traceTokeniser)
 {
     _syntax = syntax;
 }
Exemplo n.º 39
0
 /// <summary>
 /// Creates a new Compressing Turtle Writer which uses the given Compression Level and Syntax Level
 /// </summary>
 /// <param name="compressionLevel">Desired Compression Level</param>
 /// <param name="syntax">Syntax Level</param>
 /// <remarks>See Remarks for this classes <see cref="CompressingTurtleWriter.CompressionLevel">CompressionLevel</see> property to see what effect different compression levels have</remarks>
 public CompressingTurtleWriter(int compressionLevel, TurtleSyntax syntax)
     : this(compressionLevel)
 {
     this._syntax = syntax;
 }
Exemplo n.º 40
0
 /// <summary>
 /// Creates a new Turtle Writer Context with custom settings
 /// </summary>
 /// <param name="g">Graph to write</param>
 /// <param name="output">TextWriter to write to</param>
 /// <param name="compressionLevel">Compression Level to use</param>
 /// <param name="prettyPrint">Pretty Print Mode</param>
 /// <param name="hiSpeed">High Speed Mode</param>
 /// <param name="syntax">Turtle Syntax</param>
 public CompressingTurtleWriterContext(IGraph g, TextWriter output, int compressionLevel, bool prettyPrint, bool hiSpeed, TurtleSyntax syntax)
     : base(g, output, compressionLevel, prettyPrint, hiSpeed, syntax)
 {
 }