当前位置: 首页>>代码示例>>C#>>正文


C# IGraph.CreateBlankNode方法代码示例

本文整理汇总了C#中IGraph.CreateBlankNode方法的典型用法代码示例。如果您正苦于以下问题:C# IGraph.CreateBlankNode方法的具体用法?C# IGraph.CreateBlankNode怎么用?C# IGraph.CreateBlankNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGraph的用法示例。


在下文中一共展示了IGraph.CreateBlankNode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateTriple

        private Triple CreateTriple(IToken s, IToken p, IToken o, IGraph g)
        {
            INode subj, pred, obj;

            switch (s.TokenType)
            {
                case Token.BLANKNODEWITHID:
                    subj = g.CreateBlankNode(s.Value.Substring(2));
                    break;
                case Token.URI:
                    subj = g.CreateUriNode(new Uri(s.Value));
                    break;
                default:
                    throw Error("Unexpected Token '" + s.GetType().ToString() + "' encountered, expected a Blank Node/URI as the Subject of a Triple", s);
            }

            switch (p.TokenType)
            {
                case Token.URI:
                    pred = g.CreateUriNode(new Uri(p.Value));
                    break;
                default:
                    throw Error("Unexpected Token '" + p.GetType().ToString() + "' encountered, expected a URI as the Predicate of a Triple", p);
            }

            switch (o.TokenType)
            {
                case Token.BLANKNODEWITHID:
                    obj = g.CreateBlankNode(o.Value.Substring(2));
                    break;
                case Token.LITERAL:
                    obj = g.CreateLiteralNode(o.Value);
                    break;
                case Token.LITERALWITHDT:
                    String dtUri = ((LiteralWithDataTypeToken)o).DataType;
                    obj = g.CreateLiteralNode(o.Value, new Uri(dtUri.Substring(1, dtUri.Length - 2)));
                    break;
                case Token.LITERALWITHLANG:
                    obj = g.CreateLiteralNode(o.Value, ((LiteralWithLanguageSpecifierToken)o).Language);
                    break;
                case Token.URI:
                    obj = g.CreateUriNode(new Uri(o.Value));
                    break;
                default:
                        throw Error("Unexpected Token '" + o.GetType().ToString() + "' encountered, expected a Blank Node/Literal/URI as the Object of a Triple", o);
            }

            return new Triple(subj, pred, obj, g);
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:49,代码来源:StreamingNQuadsParser.cs

示例2: RewriteDescribeBNodes

        //OPT: Replace with usage of MapTriple instead?

        /// <summary>
        /// Helper method which rewrites Blank Node IDs for Describe Queries
        /// </summary>
        /// <param name="t">Triple</param>
        /// <param name="mapping">Mapping of IDs to new Blank Nodes</param>
        /// <param name="g">Graph of the Description</param>
        /// <returns></returns>
        protected Triple RewriteDescribeBNodes(Triple t, Dictionary<String, INode> mapping, IGraph g)
        {
            INode s, p, o;
            String id;

            if (t.Subject.NodeType == NodeType.Blank)
            {
                id = t.Subject.GetHashCode() + "-" + t.Graph.GetHashCode();
                if (mapping.ContainsKey(id))
                {
                    s = mapping[id];
                }
                else
                {
                    s = g.CreateBlankNode(id);
                    mapping.Add(id, s);
                }
            }
            else
            {
                s = Tools.CopyNode(t.Subject, g);
            }

            if (t.Predicate.NodeType == NodeType.Blank)
            {
                id = t.Predicate.GetHashCode() + "-" + t.Graph.GetHashCode();
                if (mapping.ContainsKey(id))
                {
                    p = mapping[id];
                }
                else
                {
                    p = g.CreateBlankNode(id);
                    mapping.Add(id, p);
                }
            }
            else
            {
                p = Tools.CopyNode(t.Predicate, g);
            }

            if (t.Object.NodeType == NodeType.Blank)
            {
                id = t.Object.GetHashCode() + "-" + t.Graph.GetHashCode();
                if (mapping.ContainsKey(id))
                {
                    o = mapping[id];
                }
                else
                {
                    o = g.CreateBlankNode(id);
                    mapping.Add(id, o);
                }
            }
            else
            {
                o = Tools.CopyNode(t.Object, g);
            }

            return new Triple(s, p, o);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:70,代码来源:BaseDescribeAlgorithm.cs

示例3: MapGenidToBlank

 private static INode MapGenidToBlank(INode node, IGraph g)
 {
     if (node is UriNode)
     {
         var u = node as UriNode;
         if (u.Uri.ToString().StartsWith(Constants.GeneratedUriPrefix))
         {
             return g.CreateBlankNode(u.Uri.ToString().Substring(Constants.GeneratedUriPrefix.Length));
         }
     }
     return node;
 }
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:12,代码来源:ManifestEvaluation.cs

示例4: LoadNode

        /// <summary>
        /// Loads a Node from the Database into the relevant Graph
        /// </summary>
        /// <param name="g">Graph to load into</param>
        /// <param name="nodeID">Database Node ID</param>
        public override INode LoadNode(IGraph g, string nodeID)
        {
            if (this._nodes.ContainsKey(nodeID))
            {
                //Known in our Map already
                INode temp;
                try
                {
                    Monitor.Enter(this._nodes);
                    temp = this._nodes[nodeID];
                }
                finally
                {
                    Monitor.Exit(this._nodes);
                }

                if (temp.Graph == g)
                {
                    //Graph matches so just return
                    return temp;
                }
                else
                {
                    //Need to copy into the Graph
                    return Tools.CopyNode(temp, g);
                }
            }
            else
            {
                //Retrieve from the Database
                String getID = "SELECT * FROM NODES WHERE nodeID=" + nodeID;
                DataTable data = this.ExecuteQuery(getID);

                if (data.Rows.Count == 0)
                {
                    this.Close(true, true);
                    throw new RdfStorageException("Unable to load a required Node Record from the Database, Node ID '" + nodeID + "' is missing");
                }
                else
                {
                    DataRow r = data.Rows[0];

                    int type;
                    String value;
                    INode n;
                    type = Int32.Parse(r["nodeType"].ToString());
                    value = r["nodeValue"].ToString().Normalize();

                    //Parse the Node Value based on the Node Type
                    switch ((NodeType)type)
                    {
                        case NodeType.Blank:
                            //Ignore the first two characters which will be _:
                            value = value.Substring(2);
                            n = g.CreateBlankNode(value);
                            break;
                        case NodeType.Literal:
                            //Extract Data Type or Language Specifier as appropriate
                            String lit, typeorlang;
                            if (value.Contains("^^"))
                            {
                                lit = value.Substring(0, value.LastIndexOf("^^"));
                                typeorlang = value.Substring(value.LastIndexOf("^^") + 2);
                                n = g.CreateLiteralNode(lit, new Uri(typeorlang));
                            }
                            else if (_validLangSpecifier.IsMatch(value))
                            {
                                lit = value.Substring(0, value.LastIndexOf("@"));
                                typeorlang = value.Substring(value.LastIndexOf("@") + 1);
                                n = g.CreateLiteralNode(lit, typeorlang);
                            }
                            else
                            {
                                n = g.CreateLiteralNode(value);
                            }

                            INode orig = n;

                            //Check the Hash Code
                            int expectedHash = Int32.Parse(r["nodeHash"].ToString());
                            if (expectedHash != n.GetHashCode())
                            {
                                //We've wrongly decoded the info?
                                ILiteralNode ln = (ILiteralNode)n;
                                if (!ln.Language.Equals(String.Empty))
                                {
                                    //Wrongly attached a Language Specifier?
                                    n = g.CreateLiteralNode(value);
                                    if (expectedHash != n.GetHashCode())
                                    {
                                        n = orig;
                                        //throw new RdfStorageException("Unable to decode a Stored Node into a Literal Node correctly");
                                    }
                                }
                                else if (ln.DataType != null)
//.........这里部分代码省略.........
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:101,代码来源:MicrosoftSqlStoreManager.cs

示例5: LoadNode

        /// <summary>
        /// Decodes an Object into an appropriate Node
        /// </summary>
        /// <param name="g">Graph to create the Node in</param>
        /// <param name="n">Object to convert</param>
        /// <returns></returns>
        private INode LoadNode(IGraph g, Object n)
        {
            INode temp;
            if (n is SqlExtendedString)
            {
                SqlExtendedString iri = (SqlExtendedString)n;
                if (iri.IriType == SqlExtendedStringType.BNODE)
                {
                    //Blank Node
                    temp = g.CreateBlankNode(n.ToString().Substring(9));

                }
                else if (iri.IriType != iri.StrType)
                {
                    //Literal
                    temp = g.CreateLiteralNode(n.ToString());
                }
                else if (iri.IriType == SqlExtendedStringType.IRI)
                {
                    //Uri
                    Uri u = new Uri(n.ToString(), UriKind.RelativeOrAbsolute);
                    if (!u.IsAbsoluteUri)
                    {
                        u = new Uri(Tools.ResolveUri(u, g.BaseUri));
                    }
                    temp = g.CreateUriNode(u);
                }
                else
                {
                    //Assume a Literal
                    temp = g.CreateLiteralNode(n.ToString());
                }
            }
            else if (n is SqlRdfBox)
            {
                SqlRdfBox lit = (SqlRdfBox)n;
                if (lit.StrLang != null)
                {
                    //Language Specified Literal
                    temp = g.CreateLiteralNode(n.ToString(), lit.StrLang);
                }
                else if (lit.StrType != null)
                {
                    //Data Typed Literal
                    temp = g.CreateLiteralNode(n.ToString(), new Uri(lit.StrType));
                }
                else
                {
                    //Literal
                    temp = g.CreateLiteralNode(n.ToString());
                }
            }
            else if (n is String)
            {
                String s = n.ToString();
                if (s.StartsWith("nodeID://"))
                {
                    //Blank Node
                    temp = g.CreateBlankNode(s.Substring(9));
                }
                else
                {
                    //Literal
                    temp = g.CreateLiteralNode(s);
                }
            }
            else if (n is Int32)
            {
                temp = ((Int32)n).ToLiteral(g);
            }
            else if (n is Int16)
            {
                temp = ((Int16)n).ToLiteral(g);
            }
            else if (n is Single)
            {
                temp = ((Single)n).ToLiteral(g);
            }
            else if (n is Double)
            {
                temp = ((Double)n).ToLiteral(g);
            }
            else if (n is Decimal)
            {
                temp = ((Decimal)n).ToLiteral(g);
            }
            else if (n is DateTime)
            {
                temp = ((DateTime)n).ToLiteral(g);
            }
            else if (n is TimeSpan)
            {
                temp = ((TimeSpan)n).ToLiteral(g);
            }
//.........这里部分代码省略.........
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:101,代码来源:VirtuosoManager.cs

示例6: Load

        public static void Load(IGraph output, JObject flattened)
        {
            JObject context = (JObject)flattened["@context"];

            IDictionary<string, string> types = new Dictionary<string, string>();

            foreach (JProperty term in context.Properties())
            {
                if (term.Value.Type == JTokenType.Object)
                {
                    types.Add(term.Name, (((JObject)term.Value)["@type"]).ToString());
                }
                else
                {
                    output.NamespaceMap.AddNamespace(term.Name, new Uri(term.Value.ToString()));
                }
            }

            JArray graph = (JArray)flattened["@graph"];

            foreach (JObject item in graph)
            {
                string id = item["@id"].ToString();

                INode s = id.StartsWith("_:")
                    ?
                    (INode)output.CreateBlankNode(id.Substring(2)) : (INode)output.CreateUriNode(new Uri(id));

                foreach (JProperty prop in ((JObject)item).Properties())
                {
                    if (prop.Name == "@id")
                    {
                        continue;
                    }

                    if (prop.Name == "@type")
                    {
                        INode p = output.CreateUriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));

                        if (prop.Value.Type == JTokenType.Array)
                        {
                            foreach (JToken type in (JArray)prop.Value)
                            {
                                INode o = output.CreateUriNode(type.ToString());
                                output.Assert(s, p, o);
                            }
                        }
                        else
                        {
                            INode o = output.CreateUriNode(prop.Value.ToString());
                            output.Assert(s, p, o);
                        }
                    }
                    else
                    {
                        INode p = output.CreateUriNode(prop.Name);

                        if (prop.Value.Type == JTokenType.Object)
                        {
                            string pid = ((JObject)prop.Value)["@id"].ToString();

                            INode o = pid.StartsWith("_:")
                                ?
                                (INode)output.CreateBlankNode(pid.Substring(2)) : (INode)output.CreateUriNode(new Uri(pid));

                            output.Assert(s, p, o);
                        }
                        else
                        {
                            string type = "string";
                            types.TryGetValue(prop.Name, out type);

                            INode o;
                            if (type == "@id")
                            {
                                string pv = prop.Value.ToString();

                                o = pv.StartsWith("http:") ? output.CreateUriNode(new Uri(pv)) : output.CreateUriNode(pv);
                            }
                            else
                            {
                                o = output.CreateLiteralNode(prop.Value.ToString());
                            }

                            output.Assert(s, p, o);
                        }
                    }
                }
            }
        }
开发者ID:johnataylor,项目名称:JLD,代码行数:90,代码来源:JsonLd2Graph.cs

示例7: thingOneOf

        public static void thingOneOf(IGraph graph, IUriNode[] listInds)
        {
            IBlankNode oneOfNode = graph.CreateBlankNode();
            IBlankNode chainA = graph.CreateBlankNode();
            IUriNode rdfType = graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
            IUriNode rdfFirst = graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfListFirst));
            IUriNode rdfRest = graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfListRest));
            IUriNode rdfNil = graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfListNil));
            IUriNode owlClass = graph.CreateUriNode(new Uri(NamespaceMapper.OWL + "Class"));
            IUriNode owlOneOf = graph.CreateUriNode(new Uri(NamespaceMapper.OWL + "oneOf"));
            IUriNode owlThing = graph.CreateUriNode(new Uri(NamespaceMapper.OWL + "Thing"));
            IUriNode owlEquivClass = graph.CreateUriNode(new Uri(NamespaceMapper.OWL + "equivalentClass"));

            graph.Assert(new Triple(oneOfNode, rdfType, owlClass));
            graph.Assert(new Triple(oneOfNode, owlOneOf, chainA));
            graph.Assert(new Triple(owlThing, owlEquivClass, oneOfNode));

            for (int i = 0; i < listInds.Length; i++)
            {
                graph.Assert(new Triple(chainA, rdfFirst, listInds[i]));
                IBlankNode chainB = graph.CreateBlankNode();

                if (i < listInds.Length - 1)
                {
                    graph.Assert(new Triple(chainA, rdfRest, chainB));
                    chainA = chainB;
                }
            }
            graph.Assert(new Triple(chainA, rdfRest, rdfNil));
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:30,代码来源:OwlOneOf.cs


注:本文中的IGraph.CreateBlankNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。