/// <summary>Initializes a new instance of the <see cref="UrlMatchingResourceResolutionStrategy" /> class.</summary> /// <param name="ontology">Optional ontology provider.</param> /// <param name="mappingAssemblies">Optional mapping assemblies.</param> /// <param name="baseUris">Base uris.</param> /// <param name="webRequestFactory">Web request factory method.</param> public UrlMatchingResourceResolutionStrategy(IOntologyProvider ontology, IEnumerable <Assembly> mappingAssemblies, IEnumerable <Uri> baseUris, Func <Uri, WebRequest> webRequestFactory = null) { _namedGraphSelector = new BaseUriNamedGraphSelector(_baseUris = baseUris); _metaGraph.BaseUri = new Uri("urn:meta:graph"); _tripleStore.Add(_metaGraph); _entityContext = new Lazy <IEntityContext>(() => CreateEntityContext(ontology, mappingAssemblies)); _webRequestFactory = webRequestFactory ?? CreateRequest; _predicateNode = _metaGraph.CreateUriNode(Foaf.primaryTopic); }
private IList <EntityQuad> CreateOperationMock(Uri operationUri, Uri classUri) { IList <EntityQuad> quads = new List <EntityQuad>(); var graph = new Graph() { BaseUri = (Uri)BaseUrl }; _tripleStore.Add(graph); var triples = new[] { new Tuple <Uri, Uri, object>(operationUri, Rdf.type, new Uri(EntityConverter.Hydra + "Operation")), new Tuple <Uri, Uri, object>(operationUri, new Uri(EntityConverter.Hydra + "method"), Method), new Tuple <Uri, Uri, object>(operationUri, new Uri(EntityConverter.Hydra + "returns"), classUri), new Tuple <Uri, Uri, object>(classUri, Rdf.type, new Uri(EntityConverter.Hydra + "Class")) }; foreach (var triple in triples) { if (triple.Item3 is Uri) { graph.Assert(graph.CreateUriNode(triple.Item1), graph.CreateUriNode(triple.Item2), graph.CreateUriNode((Uri)triple.Item3)); } else { graph.Assert(graph.CreateUriNode(triple.Item1), graph.CreateUriNode(triple.Item2), graph.CreateLiteralNode(triple.Item3.ToString())); } var value = (triple.Item3 is Uri ? Node.ForUri((Uri)triple.Item3) : Node.ForLiteral(triple.Item3.ToString())); quads.Add(new EntityQuad(new EntityId(triple.Item1), Node.ForUri(triple.Item1), Node.ForUri(triple.Item2), value)); } return(quads); }
public static void LoadTestFile(this ITripleStore store, string fileName, Uri graphUri) { var graph = new Graph(); graph.BaseUri = graphUri; graph.LoadTestFile(fileName); store.Add(graph); }
public void TripleStoreIsEmpty02() { ITripleStore store = this.GetInstance(); store.Add(new Graph()); Assert.False(store.IsEmpty); }
public void TripleStoreHasGraph02() { ITripleStore store = this.GetInstance(); IGraph g = new Graph(); store.Add(g); Assert.True(store.HasGraph(null)); }
public void TripleStoreAdd01() { ITripleStore store = this.GetInstance(); Graph g = new Graph(); store.Add(g); Assert.False(store.IsEmpty); Assert.True(store.HasGraph(g.BaseUri)); }
public void TripleStoreHasGraph03() { ITripleStore store = this.GetInstance(); IGraph g = new Graph(); g.BaseUri = new Uri("http://nosuchdomain.com/graph"); store.Add(g); Assert.True(store.HasGraph(g.BaseUri)); }
public void TripleStoreAdd02() { ITripleStore store = this.GetInstance(); IGraph g = new Graph(); g.BaseUri = new Uri("http://example.org/graph"); store.Add(g); Assert.False(store.IsEmpty); Assert.True(store.HasGraph(g.BaseUri)); }
/// <summary>Loads data from string with optional automated graph generation.</summary> /// <param name="store">Target store to be loaded with data.</param> /// <param name="data">String with data.</param> /// <param name="parser">RDF reader.</param> /// <param name="metaGraphUri">When provided, store will have automatically created graphs for all resources that are mentioned in the meta graph provided.</param> public static void LoadFromString(this ITripleStore store, string data, IRdfReader parser, Uri metaGraphUri) { ITripleStore targetStore = (metaGraphUri != null ? new TripleStore() : store); IGraph graph = new Graph(); targetStore.Add(graph); graph.LoadFromString(data, parser); if (metaGraphUri != null) { store.ExpandGraphs((TripleStore)targetStore, metaGraphUri); } }
/// <summary> /// Handles Triples by asserting them into the appropriate Graph creating the Graph if necessary /// </summary> /// <param name="t">Triple</param> /// <returns></returns> protected override bool HandleTripleInternal(Triple t) { if (!_store.HasGraph(t.GraphUri)) { Graph g = new Graph(); g.BaseUri = t.GraphUri; _store.Add(g); } IGraph target = _store[t.GraphUri]; target.Assert(t.CopyTriple(target)); return(true); }
private static IGraph AddGraph(this ITripleStore store, Uri graphBaseUri) { IGraph result = new Graph() { BaseUri = graphBaseUri }; if (store.Add(result)) { return(result); } return(null); }
internal static IGraph FindOrCreate(this ITripleStore tripleStore, Uri uri) { var graph = tripleStore.Graphs.FirstOrDefault(item => AbsoluteUriComparer.Default.Equals(item.BaseUri, uri)); if (graph != null) { return(graph); } graph = new ThreadSafeGraph() { BaseUri = uri }; tripleStore.Add(graph); return(graph); }
public void Setup() { var metaGraphUri = ConfigurationSectionHandler.Default.Factories[DescriptionConfigurationSection.Default.DefaultStoreFactoryName].MetaGraphUri; _store = new TripleStore(); _store.Add(new Graph() { BaseUri = metaGraphUri }); _entityContext = new EntityContextFactory() .WithMetaGraphUri(metaGraphUri) .WithDefaultOntologies() .WithMappings(load => load.FromAssemblyOf <IProduct>()) .WithDotNetRDF(_store) .CreateContext(); _instance = _entityContext.Create <IProduct>(new EntityId("http://temp.uri/product/")); _instance.Name = "Test"; _entityContext.Commit(); }
private void IndexTriples(TypeDefinition typeDefinition) { if (typeDefinition.BaseType != null && typeDefinition.BaseType.FullName.Equals("System.Data.Objects.DataClasses.EntityObject")) { return; } if (typeDefinition.HasNestedTypes) { foreach (var nestedType in typeDefinition.NestedTypes) { IndexTriples(nestedType); } } foreach (var method in typeDefinition.Methods) { try { var triples = _instructionParser.ParseInstructions(method); foreach (var triple in triples) { _tripleStore.Add(triple); } } catch (ILParseException ex) { // the IL parsing is still a bit flaky _logOutput.LogAnalysis(ex.Message); _logOutput.LogAnalysis("CONTINUING!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); Trace.TraceError(ex.ToString()); } catch (Exception ex) { _logOutput.LogAnalysis(ex.Message); _logOutput.LogAnalysis("CONTINUING!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); Trace.TraceError(ex.ToString()); } } }
protected override EntityConverter CreateInstance() { _tripleStore = new TripleStore(); var metaGraph = new Graph() { BaseUri = ConfigurationSectionHandler.Default.Factories[DescriptionConfigurationSection.Default.DefaultStoreFactoryName].MetaGraphUri }; _tripleStore.Add(metaGraph); _context = new Mock <IEntityContext>(); _context.Setup(instance => instance.Load <IOperation>(It.IsAny <EntityId>())).Returns <EntityId>(id => CreateOperationMock(_tripleStore, id).Object); var entityContextProvider = new Mock <IEntityContextProvider>(MockBehavior.Strict); entityContextProvider.SetupGet(instance => instance.EntityContext).Returns(_context.Object); entityContextProvider.SetupGet(instance => instance.TripleStore).Returns(_tripleStore); var namedGraphSelector = new Mock <INamedGraphSelector>(MockBehavior.Strict); namedGraphSelector.Setup(instance => instance.SelectGraph(It.IsAny <EntityId>(), It.IsAny <IEntityMapping>(), It.IsAny <IPropertyMapping>())).Returns((Uri)BaseUrl); var namedGraphSelectorFactory = new Mock <INamedGraphSelectorFactory>(MockBehavior.Strict); namedGraphSelectorFactory.SetupGet(instance => instance.NamedGraphSelector).Returns(namedGraphSelector.Object); return(new EntityConverter(entityContextProvider.Object, namedGraphSelectorFactory.Object)); }
/// <summary> /// Adds a Graph to the store. /// </summary> /// <param name="g">Graph.</param> /// <param name="mergeIfExists">Whether to merge with an existing graph with the same URI.</param> /// <returns></returns> public virtual bool Add(IGraph g, bool mergeIfExists) { return(_store.Add(g, mergeIfExists)); }