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


C# IGraph.GetTriplesWithPredicateObject方法代码示例

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


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

示例1: GetLists

        private static IDictionary<INode, List<INode>> GetLists(IGraph graph)
        {
            INode first = graph.CreateUriNode(new Uri(First));
            INode rest = graph.CreateUriNode(new Uri(Rest));
            INode nil = graph.CreateUriNode(new Uri(Nil));

            IDictionary<INode, List<INode>> lists = new Dictionary<INode, List<INode>>();
            IEnumerable<Triple> ends = graph.GetTriplesWithPredicateObject(rest, nil);
            foreach (Triple end in ends)
            {
                List<INode> list = new List<INode>();
                Triple iterator = graph.GetTriplesWithSubjectPredicate(end.Subject, first).First();
                INode head = iterator.Subject;
                while (true)
                {
                    list.Add(iterator.Object);
                    IEnumerable<Triple> restTriples = graph.GetTriplesWithPredicateObject(rest, iterator.Subject);
                    if (!restTriples.Any())
                    {
                        break;
                    }

                    iterator = graph.GetTriplesWithSubjectPredicate(restTriples.First().Subject, first).First();
                    head = iterator.Subject;
                }

                list.Reverse();
                lists.Add(head, list);
            }

            return lists;
        }
开发者ID:alien-mcl,项目名称:URSA,代码行数:32,代码来源:JsonLdWriter.cs

示例2: GetPackageRegistrationUri

 public static Uri GetPackageRegistrationUri(IGraph graph)
 {
     return ((IUriNode)graph.GetTriplesWithPredicateObject(
         graph.CreateUriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")),
         graph.CreateUriNode(new Uri("http://schema.nuget.org/schema#PackageRegistration")))
         .First().Subject).Uri;
 }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:7,代码来源:GraphSplitting.cs

示例3: MaterializeInference

        public static void MaterializeInference(IGraph graph)
        {
            //  hard code some type inference

            //  nuget:ApiAppPackage rdfs:subClassOf nuget:PackageDetails

            foreach (Triple triple in graph.GetTriplesWithPredicateObject(graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.ApiAppPackage)))
            {
                graph.Assert(triple.Subject, triple.Predicate, graph.CreateUriNode(Schema.DataTypes.PackageDetails));
            }

            //  nuget:PowerShellPackage rdfs:subClassOf nuget:PackageDetails

            foreach (Triple triple in graph.GetTriplesWithPredicateObject(graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.PowerShellPackage)))
            {
                graph.Assert(triple.Subject, triple.Predicate, graph.CreateUriNode(Schema.DataTypes.PackageDetails));
            }
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:18,代码来源:GraphHelpers.cs

示例4: GetResources

        public static IList<Uri> GetResources(IGraph graph)
        {
            IList<Uri> resources = new List<Uri>();

            INode rdfType = graph.CreateUriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));

            Uri[] types = new Uri[]
            {
                //new Uri("http://schema.nuget.org/schema#PackageRegistration"), 
                new Uri("http://schema.nuget.org/schema#PackageList")
            };

            foreach (Uri type in types)
            {
                foreach (Triple triple in graph.GetTriplesWithPredicateObject(rdfType, graph.CreateUriNode(type)))
                {
                    resources.Add(((IUriNode)triple.Subject).Uri);
                }
            }

            return resources;
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:22,代码来源:GraphSplitting.cs

示例5: Initialise

        protected virtual void Initialise(IGraph g)
        {
            //First ensure all the correct namespace prefixes are set
            g.NamespaceMap.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            g.NamespaceMap.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            g.NamespaceMap.AddNamespace("owl", new Uri(NamespaceMapper.OWL));
            g.NamespaceMap.AddNamespace("void", new Uri(VoIDNamespace));
            g.NamespaceMap.AddNamespace("foaf", new Uri(FoafNamespace));
            g.NamespaceMap.AddNamespace("dcterms", new Uri(DublinCoreTermsNamespace));

            //Find Datasets
            foreach (Triple t in g.GetTriplesWithPredicateObject(g.CreateUriNode("rdf:type"), g.CreateUriNode("void:Dataset")))
            {
                VoIDDataset dataset = new VoIDDataset(g, t.Subject);
                if (this._datasets.ContainsKey(t.Subject))
                {
                    throw new NotImplementedException("Merging VoID Datasets is not yet implemented");
                }
                else
                {
                    this._datasets.Add(t.Subject, dataset);
                }
            }

            //Find Linksets
            foreach (Triple t in g.GetTriplesWithPredicateObject(g.CreateUriNode("rdf:type"), g.CreateUriNode("void:Linkset")))
            {
                VoIDLinkset linkset = new VoIDLinkset(g, t.Subject);
                if (this._linksets.ContainsKey(t.Subject))
                {
                    throw new NotImplementedException("Merging VoID Linksets is not yet implemented");
                }
                else
                {
                    this._linksets.Add(t.Subject, linkset);
                }
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:38,代码来源:VoIDDescription.cs

示例6: Initialise

        protected override void Initialise(IGraph g)
        {
            if (g.BaseUri != null) this._node = g.CreateUriNode();

            //First ensure all the correct namespace prefixes are set to the correct URIs
            g.NamespaceMap.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            g.NamespaceMap.AddNamespace("void", new Uri(VoIDNamespace));
            g.NamespaceMap.AddNamespace("foaf", new Uri(FoafNamespace));
            g.NamespaceMap.AddNamespace("dcterms", new Uri(DublinCoreTermsNamespace));
            g.NamespaceMap.AddNamespace("aat", new Uri(AATNamespace));

            //First look for an Expansion Profile description
            Triple profileDescriptor = new Triple(g.CreateUriNode(), g.CreateUriNode("rdf:type"), g.CreateUriNode("aat:ExpansionProfile"));
            if (g.ContainsTriple(profileDescriptor))
            {
                //Does it specify a Max Expansion Depth?
                Triple maxDepthSpecifier = g.GetTriplesWithSubjectPredicate(g.CreateUriNode(), g.CreateUriNode("aat:maxExpansionDepth")).FirstOrDefault();
                if (maxDepthSpecifier != null)
                {
                    if (maxDepthSpecifier.Object.NodeType == NodeType.Literal)
                    {
                        ILiteralNode l = (ILiteralNode)maxDepthSpecifier.Object;
                        if (l.DataType != null && l.DataType.ToString().Equals(XmlSpecsHelper.XmlSchemaDataTypeInteger))
                        {
                            this._maxDepth = Int32.Parse(l.Value);
                        }
                    }
                }
            }

            //Find Datasets
            foreach (Triple t in g.GetTriplesWithPredicateObject(g.CreateUriNode("rdf:type"), g.CreateUriNode("void:Dataset")))
            {
                ExpansionDataset dataset = new ExpansionDataset(g, t.Subject);
                if (this._datasets.ContainsKey(t.Subject))
                {
                    throw new NotImplementedException("Merging Expansion Datasets is not yet implemented");
                }
                else
                {
                    this._datasets.Add(t.Subject, dataset);
                }
            }

            //Find Linksets
            foreach (Triple t in g.GetTriplesWithPredicateObject(g.CreateUriNode("rdf:type"), g.CreateUriNode("void:Linkset")))
            {
                ExpansionLinkset linkset = new ExpansionLinkset(g, t.Subject);
                if (this._linksets.ContainsKey(t.Subject))
                {
                    throw new NotImplementedException("Merging Expansion Linksets is not yet implemented");
                }
                else
                {
                    this._linksets.Add(t.Subject, linkset);
                }
            }

        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:59,代码来源:ExpansionProfile.cs

示例7: AutoDetectReadersAndWriters

        /// <summary>
        /// Given a Configuration Graph will detect Readers and Writers for RDF and SPARQL syntaxes and register them with <see cref="MimeTypesHelper">MimeTypesHelper</see>.  This will cause the library defaults to be overridden where appropriate.
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        public static void AutoDetectReadersAndWriters(IGraph g)
        {
            IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
            INode desiredType = CreateConfigurationNode(g, ClassRdfParser);
            INode formatMimeType = g.CreateUriNode(new Uri("http://www.w3.org/ns/formats/media_type"));
            INode formatExtension = g.CreateUriNode(new Uri("http://www.w3.org/ns/formats/preferred_suffix"));
            Object temp;
            String[] mimeTypes, extensions;

            //Load RDF Parsers
            foreach (INode objNode in g.GetTriplesWithPredicateObject(rdfType, desiredType).Select(t => t.Subject))
            {
                temp = LoadObject(g, objNode);
                if (temp is IRdfReader)
                {
                    //Get the formats to associate this with
                    mimeTypes = ConfigurationLoader.GetConfigurationArray(g, objNode, formatMimeType);
                    if (mimeTypes.Length == 0) throw new DotNetRdfConfigurationException("Auto-detection of Readers and Writers failed as the Parser specified by the Node '" + objNode.ToString() + "' is not associated with any MIME types");
                    extensions = ConfigurationLoader.GetConfigurationArray(g, objNode, formatExtension);

                    //Register
                    MimeTypesHelper.RegisterParser((IRdfReader)temp, mimeTypes, extensions);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Auto-detection of Readers and Writers failed as the Node '" + objNode.ToString() + "' was stated to be rdf:type of dnr:RdfParser but failed to load as an object which implements the required IRdfReader interface");
                }
            }

            //Load Dataset parsers
            desiredType = CreateConfigurationNode(g, ClassDatasetParser);
            foreach (INode objNode in g.GetTriplesWithPredicateObject(rdfType, desiredType).Select(t => t.Subject))
            {
                temp = LoadObject(g, objNode);
                if (temp is IStoreReader)
                {
                    //Get the formats to associate this with
                    mimeTypes = ConfigurationLoader.GetConfigurationArray(g, objNode, formatMimeType);
                    if (mimeTypes.Length == 0) throw new DotNetRdfConfigurationException("Auto-detection of Readers and Writers failed as the Parser specified by the Node '" + objNode.ToString() + "' is not associated with any MIME types");
                    extensions = ConfigurationLoader.GetConfigurationArray(g, objNode, formatExtension);

                    //Register
                    MimeTypesHelper.RegisterParser((IStoreReader)temp, mimeTypes, extensions);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Auto-detection of Readers and Writers failed as the Node '" + objNode.ToString() + "' was stated to be rdf:type of dnr:DatasetParser but failed to load as an object which implements the required IStoreReader interface");
                }
            }

            //Load SPARQL Result parsers
            desiredType = CreateConfigurationNode(g, ClassSparqlResultsParser);
            foreach (INode objNode in g.GetTriplesWithPredicateObject(rdfType, desiredType).Select(t => t.Subject))
            {
                temp = LoadObject(g, objNode);
                if (temp is ISparqlResultsReader)
                {
                    //Get the formats to associate this with
                    mimeTypes = ConfigurationLoader.GetConfigurationArray(g, objNode, formatMimeType);
                    if (mimeTypes.Length == 0) throw new DotNetRdfConfigurationException("Auto-detection of Readers and Writers failed as the Parser specified by the Node '" + objNode.ToString() + "' is not associated with any MIME types");
                    extensions = ConfigurationLoader.GetConfigurationArray(g, objNode, formatExtension);

                    //Register
                    MimeTypesHelper.RegisterParser((ISparqlResultsReader)temp, mimeTypes, extensions);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Auto-detection of Readers and Writers failed as the Node '" + objNode.ToString() + "' was stated to be rdf:type of dnr:SparqlResultsParser but failed to load as an object which implements the required ISparqlResultsReader interface");
                }
            }

            //Load RDF Writers
            desiredType = CreateConfigurationNode(g, ClassRdfWriter);
            foreach (INode objNode in g.GetTriplesWithPredicateObject(rdfType, desiredType).Select(t => t.Subject))
            {
                temp = LoadObject(g, objNode);
                if (temp is IRdfWriter)
                {
                    //Get the formats to associate this with
                    mimeTypes = ConfigurationLoader.GetConfigurationArray(g, objNode, formatMimeType);
                    if (mimeTypes.Length == 0) throw new DotNetRdfConfigurationException("Auto-detection of Readers and Writers failed as the Writer specified by the Node '" + objNode.ToString() + "' is not associated with any MIME types");
                    extensions = ConfigurationLoader.GetConfigurationArray(g, objNode, formatExtension);

                    //Register
                    MimeTypesHelper.RegisterWriter((IRdfWriter)temp, mimeTypes, extensions);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Auto-detection of Readers and Writers failed as the Node '" + objNode.ToString() + "' was stated to be rdf:type of dnr:RdfWriter but failed to load as an object which implements the required IRdfWriter interface");
                }
            }

            //Load Dataset Writers
            desiredType = CreateConfigurationNode(g, ClassDatasetWriter);
            foreach (INode objNode in g.GetTriplesWithPredicateObject(rdfType, desiredType).Select(t => t.Subject))
            {
//.........这里部分代码省略.........
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:101,代码来源:ConfigurationLoader.cs

示例8: AutoDetectObjectFactories

        /// <summary>
        /// Given a Configuration Graph will detect Object Factories defined in the Graph and add them to the list of available factories
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        public static void AutoDetectObjectFactories(IGraph g)
        {
            IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
            INode objLoader = CreateConfigurationNode(g, ClassObjectFactory);

            foreach (INode objNode in g.GetTriplesWithPredicateObject(rdfType, objLoader).Select(t => t.Subject))
            {
                Object temp = LoadObject(g, objNode);
                if (temp is IObjectFactory)
                {
                    AddObjectFactory((IObjectFactory)temp);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Auto-detection of Object Loaders failed as the Node '" + objNode.ToString() + "' was stated to be rdf:type of dnr:ObjectFactory but failed to load as an object which implements the IObjectFactory interface");
                }
            }
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:22,代码来源:ConfigurationLoader.cs

示例9: FindExpandableUris

        private void FindExpandableUris(UriToExpand u, IGraph g, ExpansionContext context)
        {
            if (u.Depth == context.Profile.MaxExpansionDepth) return;

            try
            {
                IUriNode current = g.CreateUriNode(u.Uri);

                //Find owl:sameAs and rdfs:seeAlso links
                foreach (Triple t in g.GetTriplesWithSubjectPredicate(current, context.SameAs))
                {
                    if (t.Object.NodeType == NodeType.Uri)
                    {
                        context.Uris.Enqueue(new UriToExpand(((IUriNode)t.Object).Uri, u.Depth + 1));
                        context.LinkGraph.Assert(t.CopyTriple(context.LinkGraph));
                    }
                }
                foreach (Triple t in g.GetTriplesWithPredicateObject(context.SameAs, current))
                {
                    if (t.Subject.NodeType == NodeType.Uri)
                    {
                        context.Uris.Enqueue(new UriToExpand(((IUriNode)t.Subject).Uri, u.Depth + 1));
                        context.LinkGraph.Assert(t.CopyTriple(context.LinkGraph));
                    }
                }
                foreach (Triple t in g.GetTriplesWithSubjectPredicate(current, context.SeeAlso))
                {
                    if (t.Object.NodeType == NodeType.Uri)
                    {
                        context.Uris.Enqueue(new UriToExpand(((IUriNode)t.Object).Uri, u.Depth + 1));
                        context.LinkGraph.Assert(t.CopyTriple(context.LinkGraph));
                    }
                }

                //Then apply Linksets
                foreach (ExpansionLinkset linkset in context.Profile.ExpansionLinksets)
                {
                    //Check if Linkset is ignored
                    if (linkset.Ignore) continue;

                    //Check if either Dataset is ignored
                    if (context.Profile.GetExpansionDataset(linkset.SubjectsTarget).Ignore) return;
                    if (context.Profile.GetExpansionDataset(linkset.ObjectsTarget).Ignore) return;

                    foreach (INode pred in linkset.Predicates)
                    {
                        //Find links from the current Graph Base URI
                        foreach (Triple t in g.GetTriplesWithSubjectPredicate(current, pred))
                        {
                            if (t.Object.NodeType == NodeType.Uri)
                            {
                                context.Uris.Enqueue(new UriToExpand(((IUriNode)t.Object).Uri, u.Depth + 1));
                                context.LinkGraph.Assert(t.CopyTriple(context.LinkGraph));
                            }
                            if (!linkset.IsDirected)
                            {
                                //If linkset is not directed then follow the link in the reverse direction
                                if (t.Subject.NodeType == NodeType.Uri)
                                {
                                    context.Uris.Enqueue(new UriToExpand(((IUriNode)t.Subject).Uri, u.Depth + 1));
                                    context.LinkGraph.Assert(t.CopyTriple(context.LinkGraph));
                                }
                            }
                        }

                        //Look for any links from other Graph URIs
                        foreach (IGraph graph in context.Store.Graphs)
                        {
                            INode curr = graph.CreateUriNode();
                            foreach (Triple t in g.GetTriplesWithSubjectPredicate(curr, pred))
                            {
                                if (t.Object.NodeType == NodeType.Uri)
                                {
                                    context.Uris.Enqueue(new UriToExpand(((IUriNode)t.Object).Uri, u.Depth + 1));
                                    context.LinkGraph.Assert(t.CopyTriple(context.LinkGraph));
                                }
                                if (!linkset.IsDirected)
                                {
                                    //If linkset is not directed then follow the link in the reverse direction
                                    if (t.Subject.NodeType == NodeType.Uri)
                                    {
                                        context.Uris.Enqueue(new UriToExpand(((IUriNode)t.Subject).Uri, u.Depth + 1));
                                        context.LinkGraph.Assert(t.CopyTriple(context.LinkGraph));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.DebugErrors("Error: Trying to find links to follow from Graph '" + g.BaseUri.ToString() + "' when an error occurred", ex);
            }
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:95,代码来源:ExpansionLoader.cs

示例10: FilterToEnumerable

        private IEnumerable<Triple> FilterToEnumerable(SelectFilter filter, IGraph g)
        {
            //Want to build an IEnumerable based on the Filter
            IEnumerable<Triple> ts = Enumerable.Empty<Triple>();
            INode s, p, o;
            int hash = (g.BaseUri == null) ? new Uri(GraphCollection.DefaultGraphUri).GetEnhancedHashCode() : g.BaseUri.GetEnhancedHashCode();

            if (filter.Subjects != null)
            {
                if (filter.Predicates != null)
                {
                    //Subject-Predicate filter
                    foreach (Entity subj in filter.Subjects)
                    {
                        s = SemWebConverter.FromSemWeb(subj, this.GetMapping(hash, g));
                        foreach (Entity pred in filter.Predicates)
                        {
                            p = SemWebConverter.FromSemWeb(pred, this.GetMapping(hash, g));
                            ts = ts.Concat(g.GetTriplesWithSubjectPredicate(s, p));
                        }
                    }
                }
                else if (filter.Objects != null)
                {
                    //Subject-Object filter
                    foreach (Entity subj in filter.Subjects)
                    {
                        s = SemWebConverter.FromSemWeb(subj, this.GetMapping(hash, g));
                        foreach (Resource obj in filter.Objects)
                        {
                            o = SemWebConverter.FromSemWeb(obj, this.GetMapping(hash, g));
                            ts = ts.Concat(g.GetTriplesWithSubjectObject(s, o));
                        }
                    }
                }
                else
                {
                    //Subjects filter
                    foreach (Entity subj in filter.Subjects)
                    {
                        s = SemWebConverter.FromSemWeb(subj, this.GetMapping(hash, g));
                        ts = ts.Concat(g.GetTriplesWithSubject(s));
                    }
                }
            }
            else if (filter.Predicates != null)
            {
                if (filter.Objects != null)
                {
                    //Predicate-Object Filter
                    foreach (Entity pred in filter.Predicates)
                    {
                        p = SemWebConverter.FromSemWeb(pred, this.GetMapping(hash, g));
                        foreach (Resource obj in filter.Objects)
                        {
                            o = SemWebConverter.FromSemWeb(obj, this.GetMapping(hash, g));
                            ts = ts.Concat(g.GetTriplesWithPredicateObject(p, o));
                        }
                    }
                }
                else
                {
                    //Predicate Filter
                    foreach (Entity pred in filter.Predicates)
                    {
                        p = SemWebConverter.FromSemWeb(pred, this.GetMapping(hash, g));
                        ts = ts.Concat(g.GetTriplesWithPredicate(p));
                    }
                }
            }
            else if (filter.Objects != null)
            {
                //Object Filter
                foreach (Resource obj in filter.Objects)
                {
                    o = SemWebConverter.FromSemWeb(obj, this.GetMapping(hash, g));
                    ts = ts.Concat(g.GetTriplesWithObject(o));
                }
            }
            else
            {
                //Everything is null so this is a Select All
                ts = g.Triples;
            }

            return ts;
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:87,代码来源:StoreSource.cs

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

示例12: WriteNavigationLinks

 private IEnumerable<PropertyInfo> WriteNavigationLinks(ODataWriter entryWriter, Uri entryLink, IGraph resultsGraph,
                                                 string entryResource, string entryType)
 {
     var subject = resultsGraph.CreateUriNode(UriFactory.Create(entryResource));
     var navigableProperties = new List<PropertyInfo>();
     foreach (var assocMap in _map.GetAssociationPropertyMappings(entryType))
     {
         var predicate = resultsGraph.CreateUriNode(UriFactory.Create(assocMap.Uri));
         List<Triple> matches = assocMap.IsInverse
                                    ? resultsGraph.GetTriplesWithPredicateObject(predicate, subject).ToList()
                                    : resultsGraph.GetTriplesWithSubjectPredicate(subject, predicate).ToList();
         if (matches.Any(t => t.Object is UriNode)) // Ignore literal and blank nodes as these cannot be entities
         {
             var navLink = new ODataNavigationLink
                 {
                     IsCollection = assocMap.IsCollection,
                     Name = assocMap.Name,
                     Url = new Uri(entryLink + "/" + assocMap.Name)
                 };
             entryWriter.WriteStart(navLink);
             entryWriter.WriteEnd();
             navigableProperties.Add(assocMap);
         }
     }
     return navigableProperties;
 }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:26,代码来源:ODataFeedGenerator.cs

示例13: CreateODataEntry

        private ODataEntry CreateODataEntry(IGraph resultsGraph, string entryResource, string entryType)
        {
            var idPrefix = _map.GetResourceUriPrefix(entryType);
            if (!entryResource.StartsWith(idPrefix))
            {
                // Now we have a problem
                throw new Exception("Cannot create entry feed for resource " + entryResource +
                                    ". Resource URI does not start with the expected prefix " + idPrefix);
            }
            var resourceId = entryResource.Substring(idPrefix.Length);
            var odataLink = _baseUri + _map.GetTypeSet(entryType) + "('" + resourceId + "')";
            var entry = new ODataEntry
                {
                    TypeName = entryType,
                    ReadLink = new Uri(odataLink),
                    Id = odataLink
                };
            var subject = resultsGraph.CreateUriNode(UriFactory.Create(entryResource));
            var properties = new List<ODataProperty>();

            var identifierPropertyMapping = _map.GetIdentifierPropertyMapping(entryType);
            if (identifierPropertyMapping != null)
            {
                properties.Add(new ODataProperty{Name=identifierPropertyMapping.Name, Value=resourceId});
            }

            foreach (var propertyMapping in _map.GetStructuralPropertyMappings(entryType))
            {
                var predicate = resultsGraph.CreateUriNode(UriFactory.Create(propertyMapping.Uri));
                var match = resultsGraph.GetTriplesWithSubjectPredicate(subject, predicate).FirstOrDefault();
                if (match != null)
                {
                    if (match.Object is LiteralNode)
                    {
                        var newProperty = new ODataProperty
                            {
                                Name = propertyMapping.Name,
                                Value = GetValue(match.Object, propertyMapping.PropertyType)
                            };
                        properties.Add(newProperty);
                    }
                    else if (match.Object is UriNode && propertyMapping.PropertyType.IsPrimitive())
                    {
                        var newProperty = new ODataProperty()
                            {
                                Name = propertyMapping.Name,
                                Value = GetValue(match.Object, propertyMapping.PropertyType)
                            };
                        properties.Add(newProperty);
                    }
                }
            }

            

            if (_writerSettings.Version == null ||  _writerSettings.Version >= ODataVersion.V3)
            {
                var associationLinks = new List<ODataAssociationLink>();
                foreach (var assocMap in _map.GetAssociationPropertyMappings(entryType))
                {
                    var predicate = resultsGraph.CreateUriNode(UriFactory.Create(assocMap.Uri));
                    bool hasMatch = false;
                    if (assocMap.IsInverse)
                    {
                        hasMatch = resultsGraph.GetTriplesWithPredicateObject(predicate, subject).Any();
                    }
                    else
                    {
                        hasMatch = resultsGraph.GetTriplesWithSubjectPredicate(subject, predicate).Any();
                    }
                    // TODO: May need to be more specific here to catch inverse/forward versions of the same
                    // RDF property being mapped to two different OData properties (e.g. broader and narrower on a category)
                    // This quick hack will work for now though:
                    //bool hasMatch = resultsGraph.GetTriplesWithPredicate(resultsGraph.CreateUriNode(UriFactory.Create(assocMap.Uri))).Any();
                    if (hasMatch)
                    {
                        associationLinks.Add(new ODataAssociationLink
                            {
                                Name = assocMap.Name,
                                Url = new Uri(odataLink + "/$links/" + assocMap.Name)
                            });
                    }
                }
                entry.AssociationLinks = associationLinks;
            }

            entry.Properties = properties;
            return entry;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:89,代码来源:ODataFeedGenerator.cs

示例14: LoadCatalogItems

        static async Task LoadCatalogItems(IStorage storage, IGraph graph, CancellationToken cancellationToken)
        {
            Trace.TraceInformation("RegistrationPersistence.LoadCatalogItems");

            IList<Uri> itemUris = new List<Uri>();

            IEnumerable<Triple> pages = graph.GetTriplesWithPredicateObject(graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.CatalogPage));

            foreach (Triple page in pages)
            {
                IEnumerable<Triple> items = graph.GetTriplesWithSubjectPredicate(page.Subject, graph.CreateUriNode(Schema.Predicates.CatalogItem));

                foreach (Triple item in items)
                {
                    itemUris.Add(((IUriNode)item.Object).Uri);
                }
            }

            IList<Task<IGraph>> tasks = new List<Task<IGraph>>();

            foreach (Uri itemUri in itemUris)
            {
                tasks.Add(LoadCatalogItem(storage, itemUri, cancellationToken));
            }

            await Task.WhenAll(tasks.ToArray());

            //TODO: if we have details at the package level and not inlined on a page we will merge them in here
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:29,代码来源:RegistrationPersistence.cs

示例15: SetIdVersionFromGraph

        private void SetIdVersionFromGraph(IGraph graph)
        {
            var resource = graph.GetTriplesWithPredicateObject(
                graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(GetItemType())).First();

            var id = graph.GetTriplesWithSubjectPredicate(
                resource.Subject, graph.CreateUriNode(Schema.Predicates.Id)).FirstOrDefault();
            if (id != null)
            {
                _id = ((ILiteralNode)id.Object).Value;
            }

            var version = graph.GetTriplesWithSubjectPredicate(
                resource.Subject, graph.CreateUriNode(Schema.Predicates.Version)).FirstOrDefault();
            if (version != null)
            {
                _version = ((ILiteralNode)version.Object).Value;
            }
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:19,代码来源:DeleteCatalogItem.cs


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