public SparqlResponseProperty GetNodeValuesFromSparqlResult(SparqlResult sparqlResult, string value)
        {
            INode node;
            var   data = new SparqlResponseProperty();

            if (sparqlResult.TryGetValue(value, out node))
            {
                if (node != null)
                {
                    data.Type = node.NodeType.ToString().ToLower();
                    switch (node.NodeType)
                    {
                    case NodeType.Uri:
                        data.Value = ((IUriNode)node).Uri.AbsoluteUri;
                        break;

                    case NodeType.Blank:
                        data.Value = ((IBlankNode)node).InternalID;
                        break;

                    case NodeType.Literal:
                        //You may want to inspect the DataType and Language properties and generate
                        //a different string here
                        data.Value    = ((ILiteralNode)node).Value;
                        data.DataType = ((ILiteralNode)node).DataType?.OriginalString;
                        break;

                    default:
                        throw new RdfOutputException("Unexpected Node Type");
                    }
                }
            }
            return(data);
        }
コード例 #2
0
 public static T GetNode <T>(this SparqlResult result, string variable) where T : class
 {
     if (result.TryGetValue(variable, out INode subNode))
     {
         return(subNode as T);
     }
     return(default(T));
 }
コード例 #3
0
 public static T GetValue <T>(this SparqlResult result, string variable)
     where T : INode
 {
     if (result.TryGetValue(variable, out var node) && node is T tNode)
     {
         return(tNode);
     }
     throw new InvalidOperationException($"The result does not contain any values for '{variable}'.");
 }
コード例 #4
0
        public static bool TryGetValue <T>(this SparqlResult result, string variable, out T value)
            where T : INode
        {
            if (result.TryGetValue(variable, out var node) && node is T tNode)
            {
                value = tNode;
                return(true);
            }

            value = default(T);
            return(false);
        }
コード例 #5
0
        public static SparqlResponseProperty GetNodeValuesFromSparqlResult(this SparqlResult sparqlResult, string value)
        {
            INode node;
            var   data = new SparqlResponseProperty();

            if (sparqlResult.TryGetValue(value, out node))
            {
                if (node != null)
                {
                    data.Type = node.NodeType.ToString().ToLower();

                    switch (node.NodeType)
                    {
                    case NodeType.Uri:
                        data.Type  = Shacl.NodeKinds.IRI;
                        data.Value = ((IUriNode)node).Uri.AbsoluteUri;
                        break;

                    case NodeType.Blank:
                        data.Type  = Shacl.NodeKinds.BlankNode;
                        data.Value = ((IBlankNode)node).InternalID;
                        break;

                    case NodeType.Literal:
                        //You may want to inspect the DataType and Language properties and generate
                        //a different string here
                        data.Type     = Shacl.NodeKinds.Literal;
                        data.DataType = ((ILiteralNode)node).DataType?.OriginalString;
                        data.Value    = ((ILiteralNode)node).Value;
                        data.Language = ((ILiteralNode)node).Language;
                        break;

                    default:
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                        throw new RdfOutputException("Unexpected Node Type");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
                    }
                }
            }
            return(data);
        }
コード例 #6
0
        private static string GetResultValue(SparqlResult result, string variable)
        {
            string data;

            if (result.TryGetValue(variable, out var n))
            {
                switch (n.NodeType)
                {
                case NodeType.Uri:
                    data = ((IUriNode)n).Uri.AbsoluteUri;
                    break;

                case NodeType.Blank:
                    data = ((IBlankNode)n).InternalID;
                    break;

                case NodeType.Literal:
                    data = ((ILiteralNode)n).Value;
                    break;

                case NodeType.GraphLiteral:
                    data = n.ToString();
                    break;

                case NodeType.Variable:
                    data = n.ToString();
                    break;

                default:
                    throw new RdfOutputException("Unexpected Node Type");
                }
            }
            else
            {
                data = Empty;
            }

            return(data);
        }
コード例 #7
0
 private static string GetValue(string variable, SparqlResult result, WebClient webClient)
 {
     string _answer = string.Empty;
     INode _node;
     if (result.TryGetValue(variable, out _node))
     {
         switch (_node.NodeType)
         {
             case NodeType.Uri:
                 string _uri = ((IUriNode)_node).Uri.AbsoluteUri;
                 if (webClient == null)
                     _answer = _uri;
                 else
                     try
                     {
                         _answer = webClient.DownloadString(_uri);
                     }
                     catch (WebException)
                     {
                         _answer = string.Empty;
                     }
                 break;
             case NodeType.Blank:
                 _answer = ((IBlankNode)_node).ToString();
                 break;
             case NodeType.Literal:
                 _answer = ((ILiteralNode)_node).Value;
                 break;
             default:
                 throw new RdfOutputException("Unexpected Node Type");
         }
     }
     return _answer;
 }