예제 #1
0
        private IEntityContext CreateEntityContext(IOntologyProvider ontologyProvider, IEnumerable <Assembly> mappingAssemblies)
        {
            var factory = new EntityContextFactory()
                          .WithMappings(builder => BuildMappingAssemblies(builder, mappingAssemblies))
                          .WithDefaultOntologies()
                          .WithMetaGraphUri(_metaGraph.BaseUri)
                          .WithNamedGraphSelector(_namedGraphSelector)
                          .WithDotNetRDF(_tripleStore);

            if (ontologyProvider != null)
            {
                factory = factory.WithOntology(ontologyProvider);
            }

            return(factory.CreateContext());
        }
예제 #2
0
    static void Main()
    {
        ITripleStore store = new TripleStore();

        store.LoadFromFile("input.trig");
        var factory = new EntityContextFactory();

        // it is also possible to add fluent/attribute mappings separately
        factory.WithMappings(mb => mb.FromAssemblyOf <IPerson>());

        // this is necessary to tell where entities' data is stored in named graphs
        // see the input.trig file to find out how it does that
        factory.WithMetaGraphUri(new Uri("http://romanticweb.net/samples"));

        // this API bound to change in the future so that custom
        // namespaces can be added easily
        factory.WithOntology(new DefaultOntologiesProvider(BuiltInOntologies.DCTerms |
                                                           BuiltInOntologies.FOAF));

        factory.WithDotNetRDF(store);

        var context = factory.CreateContext();

        foreach (var person in context.AsQueryable <IPerson>().Where(p => p.Name != "Karol"))
        {
            var pubId = "http://romanticweb.net/samples/publication/" + Guid.NewGuid();
            var pub   = context.Create <IPublication>(pubId);
            pub.Title = string.Format("Publication about RDF by {0} {1}",
                                      person.Name, person.LastName);
            pub.DatePublished = DateTime.Now;

            person.Publications.Add(pub);
        }

        context.Commit();

        store.SaveToFile("output.trig", new TriGWriter());
    }