Exemplo n.º 1
0
        public void Setup()
        {
            _typesMapping     = new TestPropertyMapping(typeof(ITypedEntity), typeof(IEnumerable <EntityId>), "Types", Rdf.type);
            _factory          = new Mock <IEntityContextFactory>();
            _ontologyProvider = new TestOntologyProvider();
            _mappings         = new Mock <IMappingsRepository>();
            _entityStore      = new Mock <IEntityStore>();
            _entityStore.Setup(es => es.GetObjectsForPredicate(It.IsAny <EntityId>(), Rdf.type, It.IsAny <Uri>()))
            .Returns(new Node[0]);
            _mappings.Setup(m => m.MappingFor <ITypedEntity>())
            .Returns(new EntityMapping(typeof(ITypedEntity), new ClassMapping[0], new[] { _typesMapping }, new PropertyMapping[0]));
            _mappings.Setup(m => m.MappingFor(typeof(ITypedEntity)))
            .Returns(new EntityMapping(typeof(ITypedEntity), new ClassMapping[0], new[] { _typesMapping }, new PropertyMapping[0]));
            _store           = new Mock <IEntitySource>();
            _baseUriSelector = new Mock <IBaseUriSelectionPolicy>(MockBehavior.Strict);
            _factory.Setup(f => f.Ontologies).Returns(_ontologyProvider);
            var catalog = new TestTransformerCatalog();

            _changesTracker = new Mock <IDatasetChangesTracker>(MockBehavior.Strict);
            _entityContext  = new EntityContext(
                _factory.Object,
                _mappings.Object,
                _entityStore.Object,
                _store.Object,
                _baseUriSelector.Object,
                new TestCache(),
                new DefaultBlankNodeIdGenerator(),
                catalog,
                new InternalProxyCaster((entity, mapping) => new EntityProxy(entity, mapping, catalog, new TestGraphSelector(), null), _mappings.Object, new TestGraphSelector(), _entityStore.Object),
                _changesTracker.Object,
                null);
        }
        /// <summary>Includes a given <see cref="IOntologyProvider" /> in context that will be created.</summary>
        /// <param name="ontologyProvider">Target ontology provider.</param>
        /// <returns>This <see cref="EntityContextFactory" /> </returns>
        public EntityContextFactory WithOntology(IOntologyProvider ontologyProvider)
        {
            // todo: get rid of Guid by refatoring how ontolgies are added
            _container.RegisterInstance(ontologyProvider, Guid.NewGuid().ToString());

            return(this);
        }
Exemplo n.º 3
0
 /// <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);
 }
Exemplo n.º 4
0
        private static async void Initialize()
        {
            var jsonLdReader = new JsonLdReader();

            using (var streamReader = new StreamReader(typeof(HydraClientFactory).Assembly.GetManifestResourceStream(HydraVocabularyResourceName)))
            {
                _ontologyProvider = new StaticOntologyProvider((await jsonLdReader.Read(streamReader)).First().Statements);
                Sync.Set();
            }
        }
        // TODO: Consider a mechanism of ignoring missing ontology providers. Use case: partial publications, i.e. updated assembly with new mappings, but not published prefix mapping.
        private static Uri GetTermUri(IOntologyProvider ontologyProvider, string namespacePrefix, string termName)
        {
            var resolvedUri = ontologyProvider.ResolveUri(namespacePrefix, termName);

            if (resolvedUri == null)
            {
                var message = string.Format("Cannot resolve QName {0}:{1}", namespacePrefix, termName);
                LogTo.Fatal(message);
                throw new MappingException(message);
            }

            return resolvedUri;
        }
        // TODO: Consider a mechanism of ignoring missing ontology providers. Use case: partial publications, i.e. updated assembly with new mappings, but not published prefix mapping.
        private static Uri GetTermUri(IOntologyProvider ontologyProvider, string namespacePrefix, string termName, ILogger log)
        {
            var resolvedUri = ontologyProvider.ResolveUri(namespacePrefix, termName);

            if (resolvedUri == null)
            {
                var message = string.Format("Cannot resolve QName {0}:{1}", namespacePrefix, termName);
                log.Fatal(message);
                throw new MappingException(message);
            }

            return(resolvedUri);
        }
Exemplo n.º 7
0
 internal StatementGatheringProcessingState(
     ISerializableEntitySource entitySource,
     IOntologyProvider ontologyProvider,
     IDictionary <Iri, ISet <Statement> > statements,
     IDictionary <Iri, int> statementsStatistics,
     ISet <Iri> forbiddenHypermedia,
     Func <Statement, bool> statementsFilter)
 {
     _entitySource                    = entitySource;
     _ontologyProvider                = ontologyProvider;
     _statements                      = statements;
     _statementsStatistics            = statementsStatistics;
     _forbiddenHypermedia             = forbiddenHypermedia;
     _statementsFilter                = statementsFilter;
     _entitySource.StatementAsserted += OnStatementAsserted;
 }
Exemplo n.º 8
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());
        }
Exemplo n.º 9
0
 internal ProcessingState(
     IEntityContext context,
     IOntologyProvider ontologyProvider,
     Iri rootResource,
     LinksPolicy linksPolicy,
     string originatingMediaType)
 {
     _ontologyProvider     = ontologyProvider;
     _statements           = new Dictionary <Iri, ISet <Statement> >();
     _statementsStatistics = new Dictionary <Iri, int>();
     Context            = context;
     ForbiddenHypermeda = new HashSet <Iri>();
     AllHypermedia      = new HashSet <Iri>();
     BaseUrl            = rootResource;
     Root                 = rootResource.ToRoot();
     LinksPolicy          = linksPolicy;
     OriginatingMediaType = originatingMediaType;
 }
 public void Setup()
 {
     _typesMapping = new TestPropertyMapping(typeof(ITypedEntity), typeof(IEnumerable<EntityId>), "Types", Vocabularies.Rdf.type);
     _factory = new Mock<IEntityContextFactory>();
     _ontologyProvider = new TestOntologyProvider();
     _mappings = new Mock<IMappingsRepository>();
     _entityStore = new Mock<IEntityStore>();
     _entityStore.Setup(es => es.GetObjectsForPredicate(It.IsAny<EntityId>(), Rdf.type, It.IsAny<Uri>()))
                 .Returns(new Node[0]);
     _mappings.Setup(m => m.MappingFor<ITypedEntity>()).Returns(new EntityMapping(typeof(ITypedEntity), new ClassMapping[0], new[] { _typesMapping }));
     _mappings.Setup(m => m.MappingFor(typeof(ITypedEntity))).Returns(new EntityMapping(typeof(ITypedEntity), new ClassMapping[0], new[] { _typesMapping }));
     _store = new Mock<IEntitySource>();
     _baseUriSelector = new Mock<IBaseUriSelectionPolicy>(MockBehavior.Strict);
     var mappingContext = new MappingContext(_ontologyProvider);
     _entityContext = new EntityContext(
         _factory.Object,
         _mappings.Object,
         mappingContext,
         _entityStore.Object,
         _store.Object,
         _baseUriSelector.Object,
         new TestGraphSelector(),
         new TestCache());
 }
 /// <summary>Creates a default ontology provider with given built in ontologies initialized.</summary>
 /// <param name="ontologyProvider">Ontology provider to be wrapped by this instance.</param>
 public DefaultOntologiesProvider(IOntologyProvider ontologyProvider) :
     this(ontologyProvider, BuiltInOntologies.RDF | BuiltInOntologies.RDFS | BuiltInOntologies.OWL | BuiltInOntologies.SKOS | BuiltInOntologies.DC | BuiltInOntologies.DCTerms | BuiltInOntologies.DCAM | BuiltInOntologies.DCMIType | BuiltInOntologies.FOAF | BuiltInOntologies.Schema | BuiltInOntologies.SIOC | BuiltInOntologies.GEO | BuiltInOntologies.LDP | BuiltInOntologies.CNT | BuiltInOntologies.SPIN | BuiltInOntologies.SP)
 {
 }
        /// <summary>Includes a given <see cref="IOntologyProvider" /> in context that will be created.</summary>
        /// <param name="ontologyProvider">Target ontology provider.</param>
        /// <returns>This <see cref="EntityContextFactory" /> </returns>
        public EntityContextFactory WithOntology(IOntologyProvider ontologyProvider)
        {
            EnsureOntologyProvider();
            if (!_actualOntologyProvider.OntologyProviders.Contains(ontologyProvider))
            {
                _actualOntologyProvider.OntologyProviders.Add(ontologyProvider);
            }

            return this;
        }
Exemplo n.º 13
0
 /// <summary>Initializes a new instance of the <see cref="N3HypermediaProcessor" /> class.</summary>
 /// <param name="ontologyProvider">Ontology provider.</param>
 /// <param name="httpCall">HTTP call facility.</param>
 public N3HypermediaProcessor(IOntologyProvider ontologyProvider, HttpCallFacility httpCall)
     : base(ontologyProvider, httpCall)
 {
 }
 /// <summary>Initializes a new instance of the <see cref="HypermediaProcessorBase" /> class.</summary>
 /// <param name="ontologyProvider">Ontology provider.</param>
 /// <param name="httpCall">HTTP call facility.</param>
 protected HypermediaProcessorBase(IOntologyProvider ontologyProvider, HttpCallFacility httpCall)
 {
     _ontologyProvider = ontologyProvider ?? throw new ArgumentNullException(nameof(ontologyProvider));
     HttpCall          = httpCall ?? throw new ArgumentNullException(nameof(httpCall));
 }
Exemplo n.º 15
0
 public void Setup()
 {
     _ontology = new Mock <IOntologyProvider>().Object;
 }
 private Uri GetUri(IOntologyProvider p)
 {
     return new Uri("urn:parent:level3");
 }
 public void Setup()
 {
     _ontology = new Mock<IOntologyProvider>().Object;
 }
Exemplo n.º 18
0
 /// <summary>Default constructor with ontology provider and default graph selector passed.</summary>
 /// <param name="ontologyProvider">Ontology provider.</param>
 /// <param name="conventions"></param>
 public MappingContext(IOntologyProvider ontologyProvider, IEnumerable <IConvention> conventions)
 {
     _ontologyProvider = ontologyProvider;
     Conventions       = conventions;
 }
Exemplo n.º 19
0
 /// <summary>Default constructor with ontology provider and default graph selector passed.</summary>
 /// <param name="ontologyProvider">Ontology provider.</param>
 public MappingContext(IOntologyProvider ontologyProvider)
     : this(ontologyProvider, new IConvention[0])
 {
 }
 public GeneratedDictionaryMappingSource(MappingContext mappingContext, EmitHelper emitHelper, ILogger log)
 {
     _visitor          = new FluentMappingProviderBuilder(log);
     _emitHelper       = emitHelper;
     _ontologyProvider = mappingContext.OntologyProvider;
 }
Exemplo n.º 21
0
 /// <summary>Tries to resolve a prefix for given <see cref="Uri"/>.</summary>
 /// <param name="ontologies">Instance of the <see cref="IOntologyProvider"/>.</param>
 /// <param name="uri">Uri to be resolved.</param>
 /// <returns><see cref="String" /> beeing a prefix of the given <see cref="Uri"/> or <b>null</b>.</returns>
 public static string ResolveUri(this IOntologyProvider ontologies, Uri uri)
 {
     return(ontologies.Ontologies.Where(item => item.BaseUri.AbsoluteUri == uri.AbsoluteUri).Select(item => item.Prefix).FirstOrDefault());
 }
Exemplo n.º 22
0
 /// <summary>Tries to resolve a prefix for given Uri.</summary>
 /// <param name="ontologies">Instance of the <see cref="IOntologyProvider"/>.</param>
 /// <param name="uriString">Uri to be resolved.</param>
 /// <returns><see cref="String" /> beeing a prefix of the given Uri or <b>null</b>.</returns>
 public static string ResolveUri(this IOntologyProvider ontologies, string uriString)
 {
     return(ontologies.ResolveUri(new Uri(uriString)));
 }
 public GeneratedDictionaryMappingSource(IOntologyProvider ontologyProvider)
 {
     _ontologyProvider = ontologyProvider;
 }
 /// <summary>Creates a default ontology provider with given built in ontologies initialized.</summary>
 /// <param name="ontologyProvider">Ontology provider to be wrapped by this instance.</param>
 /// <param name="ontologies">Ontologies to be included int this instance.</param>
 public DefaultOntologiesProvider(IOntologyProvider ontologyProvider, BuiltInOntologies ontologies)
     : base()
 {
     _ontologies = ontologyProvider.Ontologies.ToList();
     _includedOntologies = new List<BuiltInOntologies>();
     Include(ontologies);
 }
Exemplo n.º 25
0
 /// <summary>Default constructor with ontology provider and default graph selector passed.</summary>
 /// <param name="ontologyProvider">Ontology provider.</param>
 /// <param name="conventions"></param>
 public MappingContext(IOntologyProvider ontologyProvider, IEnumerable<IConvention> conventions)
 {
     _ontologyProvider = ontologyProvider;
     Conventions = conventions;
 }
 private Uri GetUri(IOntologyProvider p)
 {
     return(new Uri("urn:parent:level3"));
 }
 public GeneratedListMappingSource(IOntologyProvider ontologyProvider)
 {
     _ontologyProvider = ontologyProvider;
 }
 private Uri GetUri(IOntologyProvider p)
 {
     return(new Uri("urn:override:parent3"));
 }
Exemplo n.º 29
0
 /// <summary>Default constructor with ontology provider and default graph selector passed.</summary>
 /// <param name="ontologyProvider">Ontology provider.</param>
 public MappingContext(IOntologyProvider ontologyProvider)
     : this(ontologyProvider, new IConvention[0])
 {
 }
 private Uri GetUri(IOntologyProvider p)
 {
     return new Uri("urn:override:parent3");
 }