protected void CollectVariableNames(IVariableNode node, VariableScope scope)
        {
            VariableCollection variables = null;

            if (scope == VariableScope.Local)
            {
                variables = node.Root.Variables;
            }
            else if (scope == VariableScope.Global)
            {
                var gList   = Resources.LoadAll <DialogueSystemGlobals>("");
                var globals = (gList.Length > 0) ? gList[0] : null;
                if (globals != null)
                {
                    variables = globals.Variables;
                }
            }

            List <string> list = new List <string>();
            int           cnt  = 0;

            foreach (var g in variables.GetAll())
            {
                if (node.VariableName == g.Name)
                {
                    _selected = cnt;
                }
                list.Add(g.Name);
                cnt++;
            }
            _variables = list.ToArray();
        }
Beispiel #2
0
 /// <summary>
 /// Determines whether this Node is equal to a Variable Node (should always be false).
 /// </summary>
 /// <param name="other">Variable Node.</param>
 /// <returns></returns>
 public override bool Equals(IVariableNode other)
 {
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(false);
 }
Beispiel #3
0
        /// <summary>
        /// Creates a Node for the Context
        /// </summary>
        /// <param name="n">Node</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// In effect all this does is ensure that all Nodes end up in the same Graph which may occassionally not happen otherwise when Graph wrappers are involved
        /// </para>
        /// </remarks>
        public INode GetNode(INode n)
        {
            if (this._nodeMap == null)
            {
                this._nodeMap = new MultiDictionary <INode, INode>(new FastVirtualNodeComparer());
            }

            if (this._nodeMap.ContainsKey(n))
            {
                return(this._nodeMap[n]);
            }

            INode temp;

            switch (n.NodeType)
            {
            case NodeType.Blank:
                temp = this.GetBlankNode(((IBlankNode)n).InternalID);
                break;

            case NodeType.Variable:
                IVariableNode v = (IVariableNode)n;
                temp = this._factory.CreateVariableNode(v.VariableName);
                break;

            case NodeType.GraphLiteral:
                IGraphLiteralNode g = (IGraphLiteralNode)n;
                temp = this._factory.CreateGraphLiteralNode(g.SubGraph);
                break;

            case NodeType.Uri:
                IUriNode u = (IUriNode)n;
                temp = this._factory.CreateUriNode(u.Uri);
                break;

            case NodeType.Literal:
                ILiteralNode l = (ILiteralNode)n;
                if (l.DataType != null)
                {
                    temp = this._factory.CreateLiteralNode(l.Value, l.DataType);
                }
                else if (!l.Language.Equals(String.Empty))
                {
                    temp = this._factory.CreateLiteralNode(l.Value, l.Language);
                }
                else
                {
                    temp = this._factory.CreateLiteralNode(l.Value);
                }
                break;

            default:
                throw new RdfQueryException("Cannot construct unknown Node Types");
            }
            this._nodeMap.Add(n, temp);
            return(temp);
        }
Beispiel #4
0
 /// <summary>
 /// Returns an Integer indicating the Ordering of this Node compared to another Node.
 /// </summary>
 /// <param name="other">Node to test against.</param>
 /// <returns></returns>
 public override int CompareTo(IVariableNode other)
 {
     if (ReferenceEquals(this, other))
     {
         return(0);
     }
     // We are always greater than Nulls/Variable Nodes
     return(1);
 }
        /// <summary>
        /// Returns an Integer indicating the Ordering of this Node compared to another Node.
        /// </summary>
        /// <param name="other">Node to test against.</param>
        /// <returns></returns>
        public override int CompareTo(IVariableNode other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }

            // URI Nodes are greater than nulls and Variable Nodes
            return(1);
        }
Beispiel #6
0
        /// <summary>
        /// Copies a Node so it can be used in another Graph since by default Triples cannot contain Nodes from more than one Graph
        /// </summary>
        /// <param name="original">Node to Copy</param>
        /// <param name="target">Graph to Copy into</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// <strong>Warning:</strong> Copying Blank Nodes may lead to unforseen circumstances since no remapping of IDs between Graphs is done
        /// </para>
        /// </remarks>
        public static INode CopyNode(INode original, IGraph target)
        {
            //No need to copy if it's already in the relevant Graph
            if (ReferenceEquals(original.Graph, target))
            {
                return(original);
            }

            if (original.NodeType == NodeType.Uri)
            {
                IUriNode u  = (IUriNode)original;
                IUriNode u2 = new UriNode(target, u.Uri);

                return(u2);
            }
            else if (original.NodeType == NodeType.Literal)
            {
                ILiteralNode l = (ILiteralNode)original;
                ILiteralNode l2;
                if (l.Language.Equals(String.Empty))
                {
                    if (!(l.DataType == null))
                    {
                        l2 = new LiteralNode(target, l.Value, l.DataType);
                    }
                    else
                    {
                        l2 = new LiteralNode(target, l.Value);
                    }
                }
                else
                {
                    l2 = new LiteralNode(target, l.Value, l.Language);
                }

                return(l2);
            }
            else if (original.NodeType == NodeType.Blank)
            {
                IBlankNode b = (IBlankNode)original;
                IBlankNode b2;

                b2 = new BlankNode(target, b.InternalID);
                return(b2);
            }
            else if (original.NodeType == NodeType.Variable)
            {
                IVariableNode v = (IVariableNode)original;
                return(new VariableNode(target, v.VariableName));
            }
            else
            {
                throw new RdfException("Unable to Copy '" + original.GetType().ToString() + "' Nodes between Graphs");
            }
        }
Beispiel #7
0
        private Guid GetQuestionId(IVariableNode variableNodeId)
        {
            var question = m_domainItemLocator
                           .GetAll <IQuestionNode>()
                           .FirstOrDefault(x => x.QuestionName == variableNodeId.VariableName);

            if (question == null || !m_lookup.Exists(question.Id))
            {
                throw new ArgumentException($@"variable node '{variableNodeId.DisplayName}' variable not initialized");
            }

            return(question.Id);
        }
        /// <summary>
        /// Determines whether this Node is equal to a Variable Node
        /// </summary>
        /// <param name="other">Variable Node</param>
        /// <returns></returns>
        public override bool Equals(IVariableNode other)
        {
            if ((Object)other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(EqualityHelper.AreVariablesEqual(this, other));
        }
        /// <summary>
        /// Returns an Integer indicating the Ordering of this Node compared to another Node
        /// </summary>
        /// <param name="other">Node to test against</param>
        /// <returns></returns>
        public override int CompareTo(IVariableNode other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }

            if (other == null)
            {
                // Variables are considered greater than null
                return(1);
            }
            else
            {
                return(ComparisonHelper.CompareVariables(this, other));
            }
        }
        protected override void onGUI()
        {
            IVariableNode myTarget = (IVariableNode)target;

            EditorGUI.BeginChangeCheck();
            myTarget.ChangeScope((VariableScope)EditorGUILayout.EnumPopup("Scope", myTarget.Scope));
            if (EditorGUI.EndChangeCheck())
            {
                CollectVariableNames(myTarget, myTarget.Scope);
            }

            EditorGUI.BeginChangeCheck();
            _selected = EditorGUILayout.Popup("Variable", _selected, _variables);
            if (EditorGUI.EndChangeCheck())
            {
                myTarget.ChangeVariable(_variables[_selected]);
            }
        }
Beispiel #11
0
    /// <summary>
    /// Copies a Node so it can be used in another Graph since by default Triples cannot contain Nodes from more than one Graph
    /// </summary>
    /// <param name="original">Node to Copy</param>
    /// <param name="target">Graph to Copy into</param>
    /// <returns></returns>
    /// <remarks>
    /// <para>
    /// <strong>Warning:</strong> Copying Blank Nodes may lead to unforseen circumstances since no remapping of IDs between Graphs is done
    /// </para>
    /// </remarks>
    public static INode CopyNode(INode original, IGraph target) {
      // No need to copy if it's already in the relevant Graph
      if (ReferenceEquals(original.Graph, target)) return original;

      // if a node can copy itself then let it do it
      var selfcopyable_original = original as Storage.Virtualisation.ICanCopy;
      if (selfcopyable_original != null) return selfcopyable_original.CopyNode(target);

      // if it doesn't, copy it's values:

      if (original.NodeType == NodeType.Uri) {
        IUriNode u = (IUriNode)original;
        IUriNode u2 = new UriNode(target, u.Uri);

        return u2;
      } else if (original.NodeType == NodeType.Literal) {
        ILiteralNode l = (ILiteralNode)original;
        ILiteralNode l2;
        if (l.Language.Equals(String.Empty)) {
          if (!(l.DataType == null)) {
            l2 = new LiteralNode(target, l.Value, l.DataType);
          } else {
            l2 = new LiteralNode(target, l.Value);
          }
        } else {
          l2 = new LiteralNode(target, l.Value, l.Language);
        }

        return l2;
      } else if (original.NodeType == NodeType.Blank) {
        IBlankNode b = (IBlankNode)original;
        IBlankNode b2;

        b2 = new BlankNode(target, b.InternalID);
        return b2;
      } else if (original.NodeType == NodeType.Variable) {
        IVariableNode v = (IVariableNode)original;
        return new VariableNode(target, v.VariableName);
      } else {
        throw new RdfException("Unable to Copy '" + original.GetType().ToString() + "' Nodes between Graphs");
      }
    }
        /// <summary>
        /// Determines whether two Variable Nodes are equal.
        /// </summary>
        /// <param name="a">First Variable Node.</param>
        /// <param name="b">Second Variable Node.</param>
        /// <returns></returns>
        public static bool AreVariablesEqual(IVariableNode a, IVariableNode b)
        {
            if (ReferenceEquals(a, b))
            {
                return(true);
            }
            if (a == null)
            {
                if (b == null)
                {
                    return(true);
                }
                return(false);
            }
            else if (b == null)
            {
                return(false);
            }

            return(a.VariableName.Equals(b.VariableName, StringComparison.Ordinal));
        }
        /// <summary>
        /// Compares two Variable Nodes.
        /// </summary>
        /// <param name="a">First Variable Node.</param>
        /// <param name="b">Second Variable Node.</param>
        /// <returns></returns>
        public static int CompareVariables(IVariableNode a, IVariableNode b)
        {
            if (ReferenceEquals(a, b))
            {
                return(0);
            }
            if (a == null)
            {
                if (b == null)
                {
                    return(0);
                }
                return(-1);
            }
            else if (b == null)
            {
                return(1);
            }

            return(String.Compare(a.VariableName, b.VariableName, StringComparison.Ordinal));
        }
Beispiel #14
0
        public void NodeCompareToMixedNodes2()
        {
            Graph         g = new Graph();
            IBlankNode    b = g.CreateBlankNode();
            ILiteralNode  l = g.CreateLiteralNode("literal", "en");
            IUriNode      u = g.CreateUriNode(new Uri("http://example.org"));
            IVariableNode v = g.CreateVariableNode("var");

            int c = b.CompareTo(l);

            Assert.Equal(c * -1, l.CompareTo(b));
            c = b.CompareTo(u);
            Assert.Equal(c * -1, u.CompareTo(b));
            c = b.CompareTo(v);
            Assert.Equal(c * -1, v.CompareTo(b));

            c = l.CompareTo(b);
            Assert.Equal(c * -1, b.CompareTo(l));
            c = l.CompareTo(u);
            Assert.Equal(c * -1, u.CompareTo(l));
            c = l.CompareTo(v);
            Assert.Equal(c * -1, v.CompareTo(l));

            c = u.CompareTo(b);
            Assert.Equal(c * -1, b.CompareTo(u));
            c = u.CompareTo(l);
            Assert.Equal(c * -1, l.CompareTo(u));
            c = u.CompareTo(v);
            Assert.Equal(c * -1, v.CompareTo(u));

            c = v.CompareTo(b);
            Assert.Equal(c * -1, b.CompareTo(v));
            c = v.CompareTo(l);
            Assert.Equal(c * -1, l.CompareTo(v));
            c = v.CompareTo(u);
            Assert.Equal(c * -1, u.CompareTo(v));
        }
Beispiel #15
0
        public void NodeCompareToMixedNodes2()
        {
            Graph         g = new Graph();
            IBlankNode    b = g.CreateBlankNode();
            ILiteralNode  l = g.CreateLiteralNode("literal", "en");
            IUriNode      u = g.CreateUriNode(new Uri("http://example.org"));
            IVariableNode v = g.CreateVariableNode("var");

            int c = b.CompareTo(l);

            Assert.AreEqual(c * -1, l.CompareTo(b), "Expected l compareTo b to be inverse of b compareTo l");
            c = b.CompareTo(u);
            Assert.AreEqual(c * -1, u.CompareTo(b), "Expected l compareTo u to be inverse of u compareTo l");
            c = b.CompareTo(v);
            Assert.AreEqual(c * -1, v.CompareTo(b), "Expected l compareTo v to be inverse of v compareTo l");

            c = l.CompareTo(b);
            Assert.AreEqual(c * -1, b.CompareTo(l), "Expected b compareTo l to be inverse of l compareTo b");
            c = l.CompareTo(u);
            Assert.AreEqual(c * -1, u.CompareTo(l), "Expected u compareTo l to be inverse of l compareTo u");
            c = l.CompareTo(v);
            Assert.AreEqual(c * -1, v.CompareTo(l), "Expected v compareTo l to be inverse of l compareTo v");

            c = u.CompareTo(b);
            Assert.AreEqual(c * -1, b.CompareTo(u), "Expected b compareTo u to be inverse of u compareTo b");
            c = u.CompareTo(l);
            Assert.AreEqual(c * -1, l.CompareTo(u), "Expected l compareTo u to be inverse of u compareTo l");
            c = u.CompareTo(v);
            Assert.AreEqual(c * -1, v.CompareTo(u), "Expected v compareTo u to be inverse of u compareTo v");

            c = v.CompareTo(b);
            Assert.AreEqual(c * -1, b.CompareTo(v), "Expected b compareTo v to be inverse of v compareTo b");
            c = v.CompareTo(l);
            Assert.AreEqual(c * -1, l.CompareTo(v), "Expected l compareTo v to be inverse of v compareTo l");
            c = v.CompareTo(u);
            Assert.AreEqual(c * -1, u.CompareTo(v), "Expected u compareTo v to be inverse of v compareTo u");
        }
Beispiel #16
0
 public int CompareTo(IVariableNode other)
 {
     return(_source.CompareTo(other));
 }
Beispiel #17
0
 /// <summary>
 /// Compares this Node to another Variable Node
 /// </summary>
 /// <param name="other">Other Variable Node</param>
 /// <returns></returns>
 /// <remarks>
 /// Unless Virtual Equality (equality based on the Virtual RDF Provider and Virtual ID) can be determined or the Nodes are of different types then the Nodes value will have to be materialised in order to perform comparison.
 /// </remarks>
 public virtual int CompareTo(IVariableNode other)
 {
     return(this.CompareTo((INode)other));
 }
Beispiel #18
0
 /// <summary>
 /// Checks this Node for equality against another Variable Node
 /// </summary>
 /// <param name="other">Other Variable Node</param>
 /// <returns></returns>
 /// <remarks>
 /// Unless Virtual Equality (equality based on the Virtual RDF Provider and Virtual ID) can be determined or the Nodes are of different types then the Nodes value will have to be materialised in order to perform the equality check.
 /// </remarks>
 public virtual bool Equals(IVariableNode other)
 {
     return(this.TypedEquality(other));
 }
Beispiel #19
0
 /// <summary>
 /// Nodes must implement a CompareTo method to allow them to be Sorted.
 /// </summary>
 /// <param name="other">Node to compare self to.</param>
 /// <returns></returns>
 /// <remarks>
 /// Implementations should use the SPARQL Term Sort Order for ordering nodes (as opposed to value sort order).  Standard implementations of Node type specific comparisons can be found in <see cref="ComparisonHelper">ComparisonHelper</see>.
 /// </remarks>
 public abstract int CompareTo(IVariableNode other);
Beispiel #20
0
 /// <summary>
 /// Nodes must implement an Equals method so we can do type specific equality.
 /// </summary>
 /// <param name="other">Node to check for equality.</param>
 /// <returns></returns>
 /// <remarks>
 /// Nodes implementations are also required to implement an override of the non-generic Equals method.  Standard implementations of some equality comparisons can be found in <see cref="EqualityHelper">EqualityHelper</see>.
 /// </remarks>
 public abstract bool Equals(IVariableNode other);
Beispiel #21
0
 /// <summary>
 /// Nodes must implement an Equals method so we can do type specific equality
 /// </summary>
 /// <param name="other">Node to check for equality</param>
 /// <returns></returns>
 /// <remarks>
 /// Nodes implementations are also required to implement an override of the non-generic Equals method.  Standard implementations of some equality comparisons can be found in <see cref="EqualityHelper">EqualityHelper</see>
 /// </remarks>
 public abstract bool Equals(IVariableNode other);
Beispiel #22
0
 /// <summary>
 /// Nodes must implement a CompareTo method to allow them to be Sorted
 /// </summary>
 /// <param name="other">Node to compare self to</param>
 /// <returns></returns>
 /// <remarks>
 /// Implementations should use the SPARQL Term Sort Order for ordering nodes (as opposed to value sort order).  Standard implementations of Node type specific comparisons can be found in <see cref="ComparisonHelper">ComparisonHelper</see>
 /// </remarks>
 public abstract int CompareTo(IVariableNode other);
Beispiel #23
0
        /// <summary>
        /// Determines whether two Variable Nodes are equal
        /// </summary>
        /// <param name="a">First Variable Node</param>
        /// <param name="b">Second Variable Node</param>
        /// <returns></returns>
        public static bool AreVariablesEqual(IVariableNode a, IVariableNode b)
        {
            if (ReferenceEquals(a, b)) return true;
            if (a == null)
            {
                if (b == null) return true;
                return false;
            }
            else if (b == null)
            {
                return false;
            }

            return a.VariableName.Equals(b.VariableName, StringComparison.Ordinal);
        }
 /// <summary>
 /// Formats a Variable Node in SPARQL Syntax
 /// </summary>
 /// <param name="v">Variable Node</param>
 /// <param name="segment">Triple Segment</param>
 /// <returns></returns>
 protected override string FormatVariableNode(IVariableNode v, TripleSegment? segment)
 {
     return v.ToString();
 }
        /// <summary>
        /// Takes a <see cref="INode">INode</see> and converts it to a <see cref="IValuedNode">IValuedNode</see> if it is not already an instance that implements the interface.
        /// </summary>
        /// <param name="n">Node.</param>
        /// <returns>Valued Node.</returns>
        public static IValuedNode AsValuedNode(this INode n)
        {
            if (n == null)
            {
                return(null);
            }
            if (n is IValuedNode)
            {
                return((IValuedNode)n);
            }

            switch (n.NodeType)
            {
            case NodeType.Blank:
                IBlankNode b = (IBlankNode)n;
                return(new BlankNode(n.Graph, b.InternalID));

            case NodeType.GraphLiteral:
                IGraphLiteralNode glit = (IGraphLiteralNode)n;
                return(new GraphLiteralNode(n.Graph, glit.SubGraph));

            case NodeType.Literal:
                ILiteralNode lit = (ILiteralNode)n;
                // Decide what kind of valued node to produce based on node datatype
                if (lit.DataType != null)
                {
                    String dt = lit.DataType.AbsoluteUri;
                    switch (dt)
                    {
                    case XmlSpecsHelper.XmlSchemaDataTypeBoolean:
                        bool bVal;
                        if (Boolean.TryParse(lit.Value, out bVal))
                        {
                            return(new BooleanNode(n.Graph, bVal));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeByte:
                        // xsd:byte actually maps to SignedByte in .Net
                        sbyte sbVal;
                        if (sbyte.TryParse(lit.Value, out sbVal))
                        {
                            return(new SignedByteNode(n.Graph, sbVal, lit.Value));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeDate:
                        DateTime date;
                        if (DateTime.TryParse(lit.Value, null, DateTimeStyles.AdjustToUniversal, out date))
                        {
                            return(new DateNode(n.Graph, date, lit.Value));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeDateTime:
                        DateTime dateTime;
                        if (DateTime.TryParse(lit.Value, null, DateTimeStyles.AdjustToUniversal, out dateTime))
                        {
                            return(new DateTimeNode(n.Graph, dateTime, lit.Value));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeDayTimeDuration:
                    case XmlSpecsHelper.XmlSchemaDataTypeDuration:
                        TimeSpan timeSpan;
                        try
                        {
                            timeSpan = XmlConvert.ToTimeSpan(lit.Value);
                            return(new TimeSpanNode(n.Graph, timeSpan, lit.Value, lit.DataType));
                        }
                        catch
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeDecimal:
                        Decimal dec;
                        if (Decimal.TryParse(lit.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out dec))
                        {
                            return(new DecimalNode(n.Graph, dec, lit.Value));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeDouble:
                        Double dbl;
                        if (Double.TryParse(lit.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out dbl))
                        {
                            return(new DoubleNode(n.Graph, dbl, lit.Value));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeFloat:
                        Single flt;
                        if (Single.TryParse(lit.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out flt))
                        {
                            return(new FloatNode(n.Graph, flt, lit.Value));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeInt:
                    case XmlSpecsHelper.XmlSchemaDataTypeInteger:
                    case XmlSpecsHelper.XmlSchemaDataTypeLong:
                    case XmlSpecsHelper.XmlSchemaDataTypeShort:
                        long lng;
                        if (Int64.TryParse(lit.Value, out lng))
                        {
                            return(new LongNode(n.Graph, lng, lit.Value, lit.DataType));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeNegativeInteger:
                    case XmlSpecsHelper.XmlSchemaDataTypeNonPositiveInteger:
                        // Must be below zero
                        long neglng;
                        if (Int64.TryParse(lit.Value, out neglng) && neglng < 0)
                        {
                            return(new LongNode(n.Graph, neglng, lit.Value, lit.DataType));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeNonNegativeInteger:
                    case XmlSpecsHelper.XmlSchemaDataTypePositiveInteger:
                        // Must be above zero
                        long poslng;
                        if (Int64.TryParse(lit.Value, out poslng) && poslng >= 0)
                        {
                            return(new LongNode(n.Graph, poslng, lit.Value, lit.DataType));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeUnsignedByte:
                        // xsd:unsignedByte actually maps to Byte in .Net
                        byte byVal;
                        if (byte.TryParse(lit.Value, out byVal))
                        {
                            return(new ByteNode(n.Graph, byVal, lit.Value));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    case XmlSpecsHelper.XmlSchemaDataTypeUnsignedInt:
                    case XmlSpecsHelper.XmlSchemaDataTypeUnsignedLong:
                    case XmlSpecsHelper.XmlSchemaDataTypeUnsignedShort:
                        // Must be unsigned
                        ulong ulng;
                        if (UInt64.TryParse(lit.Value, out ulng))
                        {
                            return(new UnsignedLongNode(n.Graph, ulng, lit.Value, lit.DataType));
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }

                    default:
                        if (SparqlSpecsHelper.IntegerDataTypes.Contains(dt))
                        {
                            long l;
                            if (Int64.TryParse(lit.Value, out l))
                            {
                                return(new LongNode(n.Graph, l, lit.Value, lit.DataType));
                            }
                            else
                            {
                                return(new StringNode(n.Graph, lit.Value, lit.DataType));
                            }
                        }
                        else
                        {
                            return(new StringNode(n.Graph, lit.Value, lit.DataType));
                        }
                    }
                }
                else if (!lit.Language.Equals(String.Empty))
                {
                    return(new StringNode(n.Graph, lit.Value, lit.Language));
                }
                else
                {
                    return(new StringNode(n.Graph, lit.Value));
                }

            case NodeType.Uri:
                IUriNode u = (IUriNode)n;
                return(new UriNode(n.Graph, u.Uri));

            case NodeType.Variable:
                IVariableNode v = (IVariableNode)n;
                return(new VariableNode(n.Graph, v.VariableName));

            default:
                throw new RdfQueryException("Cannot create a valued node for an unknown node type");
            }
        }
Beispiel #26
0
        /// <summary>
        /// Compares two Variable Nodes
        /// </summary>
        /// <param name="a">First Variable Node</param>
        /// <param name="b">Second Variable Node</param>
        /// <returns></returns>
        public static int CompareVariables(IVariableNode a, IVariableNode b)
        {
            if (ReferenceEquals(a, b)) return 0;
            if (a == null)
            {
                if (b == null) return 0;
                return -1;
            }
            else if (b == null)
            {
                return 1;
            }

            return String.Compare(a.VariableName, b.VariableName, StringComparison.Ordinal);
        }
Beispiel #27
0
 /// <summary>
 /// Formats a Variable Node as a String for the given Format.
 /// </summary>
 /// <param name="v">Variable Name.</param>
 /// <param name="segment">Triple Segment.</param>
 /// <returns></returns>
 protected virtual String FormatVariableNode(IVariableNode v, TripleSegment?segment)
 {
     throw new RdfOutputException(WriterErrorMessages.VariableNodesUnserializable(_format));
 }
Beispiel #28
0
 /// <summary>
 /// Creates a new Virtual Variable Node
 /// </summary>
 /// <param name="g">Graph the Node belongs to</param>
 /// <param name="id">Virtual ID</param>
 /// <param name="provider">Virtual RDF Provider</param>
 /// <param name="value">Materialised Value</param>
 public SimpleVirtualVariableNode(IGraph g, int id, IVirtualRdfProvider <int, int> provider, IVariableNode value)
     : base(g, id, provider, value)
 {
 }
Beispiel #29
0
 /// <summary>
 /// Formats a Variable Node as a String for the given Format
 /// </summary>
 /// <param name="v">Variable Name</param>
 /// <param name="segment">Triple Segment</param>
 /// <returns></returns>
 protected virtual String FormatVariableNode(IVariableNode v, TripleSegment? segment)
 {
     throw new RdfOutputException(WriterErrorMessages.VariableNodesUnserializable(this._format));
 }
Beispiel #30
0
 /// <summary>
 /// Formats a Variable Node in SPARQL Syntax
 /// </summary>
 /// <param name="v">Variable Node</param>
 /// <param name="segment">Triple Segment</param>
 /// <returns></returns>
 protected override string FormatVariableNode(IVariableNode v, TripleSegment?segment)
 {
     return(v.ToString());
 }
Beispiel #31
0
 public bool Equals(IVariableNode other)
 {
     return(_source.Equals(other));
 }