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


C# IGraph.CreateLiteralNode方法代码示例

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


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

示例1: Replace

        private void Replace(IGraph graph, IUriNode parent, Uri predicate, string jsonField)
        {
            JToken token = null;
            if (_galleryPage.TryGetValue(jsonField, out token))
            {
                JArray array = token as JArray;
                JValue val = token as JValue;

                if (array != null || val != null)
                {
                    var pred = graph.CreateUriNode(predicate);

                    var old = graph.GetTriplesWithSubjectPredicate(parent, pred).ToArray();

                    // remove the old values
                    foreach (var triple in old)
                    {
                        graph.Retract(triple);
                    }

                    if (array != null)
                    {
                        foreach (var child in array)
                        {
                            graph.Assert(parent, pred, graph.CreateLiteralNode(child.ToString()));
                        }
                    }
                    else
                    {
                        graph.Assert(parent, pred, graph.CreateLiteralNode(val.ToString()));
                    }
                }
            }
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:34,代码来源:GalleryGraphAddon.cs

示例2: ApplyToGraph

        /// <summary>
        /// Add data from nuget.packed.json
        /// </summary>
        public override void ApplyToGraph(IGraph graph, IUriNode mainNode)
        {
            Uri mainUri = mainNode.Uri;
            IUriNode typeNode = graph.CreateUriNode(Schema.Predicates.Type);

            // supported frameworks
            if (SupportedFrameworks != null)
            {
                foreach (string framework in SupportedFrameworks)
                {
                    graph.Assert(new Triple(mainNode, graph.CreateUriNode(Schema.Predicates.SupportedFramework), graph.CreateLiteralNode(framework)));
                }
            }

            // assets
            //if (AssetGroups != null)
            //{
            //    int groupId = 0;
            //    foreach (var group in AssetGroups)
            //    {
            //        // group type and id
            //        var groupNode = GetSubNode(graph, mainUri, "assetGroup", "" + groupId);
            //        graph.Assert(groupNode, typeNode, graph.CreateUriNode(PackageAssetGroupType));
            //        graph.Assert(mainNode, graph.CreateUriNode(AssetGroupPredicate), groupNode);
            //        groupId++;

            //        int propId = 0;

            //        // group properties
            //        foreach (var prop in group.Properties)
            //        {
            //            var propNode = GetSubNode(graph, groupNode, "property", "" + propId);
            //            propId++;
            //            graph.Assert(propNode, typeNode, graph.CreateUriNode(PackageAssetGroupPropertyType));
            //            graph.Assert(groupNode, graph.CreateUriNode(AssetGroupPropertyPredicate), propNode);
            //            graph.Assert(propNode, graph.CreateUriNode(AssetKeyPredicate), graph.CreateLiteralNode(prop.Key));
            //            graph.Assert(propNode, graph.CreateUriNode(AssetValuePredicate), graph.CreateLiteralNode(prop.Value));
            //        }

            //        int assetId = 0;

            //        // group items
            //        foreach (var item in group.Items)
            //        {
            //            var itemNode = GetSubNode(graph, groupNode, "asset", "" + assetId);
            //            assetId++;
            //            graph.Assert(itemNode, typeNode, graph.CreateUriNode(PackageAssetType));
            //            graph.Assert(groupNode, graph.CreateUriNode(AssetPredicate), itemNode);

            //            graph.Assert(itemNode, graph.CreateUriNode(AssetTypePredicate), graph.CreateLiteralNode(item.ArtifactType));
            //            graph.Assert(itemNode, graph.CreateUriNode(AssetPathPredicate), graph.CreateLiteralNode(item.Path));
            //        }
            //    }
            //}
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:58,代码来源:PackedData.cs

示例3: ApplyToGraph

 public override void ApplyToGraph(IGraph graph, IUriNode parent)
 {
     graph.Assert(parent, graph.CreateUriNode(new Uri(CantonConstants.CantonSchema + "origin")), graph.CreateLiteralNode(_origin));
     graph.Assert(parent, graph.CreateUriNode(new Uri(CantonConstants.CantonSchema + "commitId")), graph.CreateLiteralNode("" + _commitId));
 }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:5,代码来源:OriginGraphAddon.cs

示例4: ResolveAppSetting

        /// <summary>
        /// Attempts to resolve special &lt;appsettings&gt; URIs into actual values
        /// </summary>
        /// <param name="g"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// These special URIs have the form &lt;appsetting:Key&gt; where <strong>Key</strong> is the key for an appSetting in your applications configuration file.  When used these URIs are resolved at load time into the actual values from your configuration file.  This allows you to avoid spreading configuration data over multiple files since you can specify things like connection settings in the Application Config file and then simply reference them in the dotNetRDF configuration file.
        /// </para>
        /// <para>
        /// <strong>Warning: </strong> This feature is not supported in the Silverlight build 
        /// </para>
        /// </remarks>
        public static INode ResolveAppSetting(IGraph g, INode n)
        {
#if SILVERLIGHT
            return n;
#else
            if (n == null) return null;
            if (n.NodeType != NodeType.Uri) return n;

            String uri = ((IUriNode)n).Uri.ToString();
            if (!uri.StartsWith("appsetting:")) return n;

            String key = uri.Substring(uri.IndexOf(':') + 1);
            if (SysConfig.ConfigurationManager.AppSettings[key] == null)
            {
                return null;
            }
            else
            {
                return g.CreateLiteralNode(SysConfig.ConfigurationManager.AppSettings[key]);
            }
#endif
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:36,代码来源:ConfigurationLoader.cs

示例5: CreateEntryFromGraphWithVariable

 internal void CreateEntryFromGraphWithVariable(IGraph resultsGraph, string variableName, string entityType)
 {
     if (resultsGraph.IsEmpty) return;
     // Determine the resource that was bound to the specified SPARQL variable
     var resource = resultsGraph.GetTriplesWithPredicateObject(
         resultsGraph.CreateUriNode(new Uri("http://brightstardb.com/odata-sparql/variable-binding")),
         resultsGraph.CreateLiteralNode(variableName))
                 .Select(t => t.Subject)
                 .Cast<IUriNode>()
                 .Select(u => u.Uri)
                 .FirstOrDefault();
     if (resource == null) return;
     CreateEntryFromGraph(resultsGraph, resource.ToString(), entityType);
 }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:14,代码来源:ODataFeedGenerator.cs

示例6: AddCustomContent

 protected override void AddCustomContent(INode resource, IGraph graph)
 {
     if (_commitUserData != null)
     {
         string baseAddress = ((IUriNode)resource).Uri.ToString();
         INode commitUserData = graph.CreateUriNode(new Uri(baseAddress + "#commitUserData"));
         graph.Assert(resource, graph.CreateUriNode(Schema.Predicates.CatalogCommitUserData), commitUserData);
         foreach (KeyValuePair<string, string> item in _commitUserData)
         {
             graph.Assert(
                 commitUserData, 
                 graph.CreateUriNode(Schema.Predicates.CatalogPropertyPrefix + item.Key), 
                 graph.CreateLiteralNode(item.Value));
         }
     }
 }
开发者ID:jetzhao04,项目名称:NuGet.Services.Metadata,代码行数:16,代码来源:CatalogRoot.cs

示例7: 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

示例8: GetTripleText

        private void GetTripleText(OwlInstanceSupertype oc, PropertyInfo info, IGraph g, StringBuilder sb)
        {
            if (info.GetValue(oc, null) != null)
            {
                if (info.GetOwlResource() == null) return;

                sb.Append(this.FormatAsUri(oc.InstanceUri));
                sb.Append(' ');
                sb.Append(this.FormatAsUri(info.GetOwlResourceUri()));
                sb.Append(' ');
                String dtUri = info.GetDatatypeUri();
                if (dtUri == null)
                {
                    sb.Append(this.Format(g.CreateLiteralNode(info.GetValue(oc, null).ToString())));
                }
                else
                {
                    sb.Append(this.Format(g.CreateLiteralNode(info.GetValue(oc, null).ToString(), new Uri(dtUri))));
                }
                sb.AppendLine(" .");
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:22,代码来源:LinqUpdateProcessor.cs

示例9: 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

示例10: ToLiteralNode

        public static ILiteralNode ToLiteralNode(this string str, IGraph g, string language = null, Uri dataType = null)
        {
            if (dataType != null)
            {
                /// disabled - query filtering works without datetype specified
                //return g.CreateLiteralNode(str, dataType);
            }
            else if (!string.IsNullOrEmpty(language))
            {
                return g.CreateLiteralNode(str, language);
            }

            return g.CreateLiteralNode(str);
        }
开发者ID:jaka-logar,项目名称:RtvSloScraping,代码行数:14,代码来源:StringExtensions.cs

示例11: 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

示例12: 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


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