Exemplo n.º 1
0
        /// <summary>
        /// Runs the content parsing part of the summarizing algorithm
        /// </summary>
        /// <param name="contentProvider"></param>
        /// <param name="contentParser"></param>
        /// <returns></returns>
        public ParsedDocument ParseContent(IContentProvider contentProvider, IContentParser contentParser)
        {
            if (contentProvider == null)
            {
                throw new ArgumentNullException("contentProvider");
            }
            if (contentParser == null)
            {
                throw new ArgumentNullException("contentParser");
            }

            var resultingParsedDocument = new ParsedDocument();

            resultingParsedDocument.Sentences = contentParser.SplitContentIntoSentences(contentProvider.Content);
            if (resultingParsedDocument.Sentences == null)
            {
                throw new InvalidOperationException(string.Format("{0}.SplitContentIntoSentences must not return null", contentProvider.GetType().FullName));
            }
            foreach (var workingSentence in resultingParsedDocument.Sentences)
            {
                workingSentence.TextUnits = contentParser.SplitSentenceIntoTextUnits(workingSentence.OriginalSentence);
                if (workingSentence.TextUnits == null)
                {
                    throw new InvalidOperationException(string.Format("{0}.SplitSentenceIntoTextUnits must not return null", contentProvider.GetType().FullName));
                }
            }
            return(resultingParsedDocument);
        }
Exemplo n.º 2
0
 public void before_each_test_setup()
 {
     TargetContentProvider = Substitute.For <IContentProvider>();
     TargetContentProvider.Content.Returns(Content);
     TargetContentParser = Substitute.For <IContentParser>();
     TargetContentParser.SplitContentIntoSentences(Arg.Any <string>()).Returns(
         new List <Sentence>
     {
         new Sentence {
             OriginalSentence = Sentence1
         },
         new Sentence {
             OriginalSentence = Sentence2
         }
     }
         );
     TargetContentParser.SplitSentenceIntoTextUnits(Arg.Any <string>()).Returns(
         new List <TextUnit>
     {
         new TextUnit {
             RawValue = Content
         }
     }
         );
 }
Exemplo n.º 3
0
 public DockerGraphFactory(
     [NotNull] IContentParser contentParser,
     [NotNull] IPathService pathService)
 {
     _contentParser = contentParser ?? throw new ArgumentNullException(nameof(contentParser));
     _pathService   = pathService ?? throw new ArgumentNullException(nameof(pathService));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Runs the content parsing part of the summarizing algorithm
        /// </summary>
        /// <param name="contentProvider"></param>
        /// <param name="contentParser"></param>
        /// <returns></returns>
        public ParsedDocument ParseContent(IContentProvider contentProvider, IContentParser contentParser)
        {
            if (contentProvider == null)
            {
                throw new ArgumentNullException(nameof(contentProvider));
            }
            if (contentParser == null)
            {
                throw new ArgumentNullException(nameof(contentParser));
            }

            var resultingParsedDocument = new ParsedDocument
            {
                Sentences = contentParser
                            .SplitContentIntoSentences(contentProvider.Content)
                            .Where(sentence => !string.IsNullOrWhiteSpace(sentence.OriginalSentence))
                            .ToList()
            };

            foreach (Sentence workingSentence in resultingParsedDocument.Sentences)
            {
                workingSentence.TextUnits = contentParser
                                            .SplitSentenceIntoTextUnits(workingSentence.OriginalSentence)
                                            .Where(word => !string.IsNullOrWhiteSpace(word.RawValue))
                                            .ToList();
            }

            return(resultingParsedDocument);
        }
        /// <summary>
        /// Runs the content parsing part of the summarizing algorithm
        /// </summary>
        /// <param name="contentProvider"></param>
        /// <param name="contentParser"></param>
        /// <returns></returns>
        public ParsedDocument ParseContent(IContentProvider contentProvider, IContentParser contentParser)
        {
            if (contentProvider == null)
            {
                throw new ArgumentNullException(nameof(contentProvider));
            }
            if (contentParser == null)
            {
                throw new ArgumentNullException(nameof(contentParser));
            }

            var resultingParsedDocument = new ParsedDocument
            {
                Sentences = contentParser.SplitContentIntoSentences(contentProvider.Content)
            };
            if (resultingParsedDocument.Sentences == null)
            {
                throw new InvalidOperationException(
                    $"{contentProvider.GetType().FullName}.SplitContentIntoSentences must not return null");
            }
            foreach (var workingSentence in resultingParsedDocument.Sentences)
            {
                workingSentence.TextUnits = contentParser.SplitSentenceIntoTextUnits(workingSentence.OriginalSentence);
                if (workingSentence.TextUnits == null)
                {
                    throw new InvalidOperationException(
                        $"{contentProvider.GetType().FullName}.SplitSentenceIntoTextUnits must not return null");
                }
            }
            return resultingParsedDocument;
        }
        /// <summary>
        /// Runs the content parsing part of the summarizing algorithm
        /// </summary>
        /// <param name="contentProvider"></param>
        /// <param name="contentParser"></param>
        /// <returns></returns>
        public ParsedDocument ParseContent(IContentProvider contentProvider, IContentParser contentParser)
        {
            if (contentProvider == null)
            {
                throw new ArgumentNullException(nameof(contentProvider));
            }
            if (contentParser == null)
            {
                throw new ArgumentNullException(nameof(contentParser));
            }

            ParsedDocument resultingParsedDocument = new ParsedDocument
            {
                Sentences = contentParser.SplitContentIntoSentences(contentProvider.Content)
            };

            if (resultingParsedDocument.Sentences == null)
            {
                throw new InvalidOperationException($"{contentProvider.GetType().FullName}.SplitContentIntoSentences must not return null");
            }
            foreach (Sentence workingSentence in resultingParsedDocument.Sentences)
            {
                workingSentence.TextUnits = contentParser.SplitSentenceIntoTextUnits(workingSentence.OriginalSentence);
                if (workingSentence.TextUnits == null)
                {
                    throw new InvalidOperationException($"{contentProvider.GetType().FullName}.SplitSentenceIntoTextUnits must not return null");
                }
            }
            return(resultingParsedDocument);
        }
Exemplo n.º 7
0
 public BoundRequestController(
     Context context,
     TRequestController requestController,
     IContentParser contentParser)
 {
     _requestController = requestController;
     _context           = context;
     _contentParser     = contentParser;
 }
 public SdnItemsProcessingService(ISdnRepository sdnRepository,
                                  IContentDownloader contentDownloader,
                                  IContentParser contentParser,
                                  ILogger logger)
 {
     _sdnRepository     = sdnRepository;
     _contentDownloader = contentDownloader;
     _contentParser     = contentParser;
     _logger            = logger;
 }
Exemplo n.º 9
0
        public async Task HandleAsync(WorkerOperation operation)
        {
            IContentParser <IEnumerable <TDto> > parser = this.contentParser.FirstOrDefault(p => p.ContentType == operation.ContentType);

            if (parser == null)
            {
                //TODO handler null parser
            }

            TDto[] dtos = parser.Parse(operation.Content).ToArray();

            var failureReasons = new List <string>();

            for (int i = 0; i < dtos.Length; i++)
            {
                TDto dto = dtos[i];

                if (!IsValid(dto, out string reason))
                {
                    failureReasons.Add($"Validation error processing row {i + 1}. {reason}.");
                    continue;
                }

                try
                {
                    var enrichers = new List <Task>();

                    foreach (IEnricher <TDto> enricher in this.enrichers)
                    {
                        enrichers.Add(enricher.EnrichAsync(dto));
                    }

                    await Task.WhenAll(enrichers);
                }
                catch (Exception ex)
                {
                    this.logger.LogError(ex, $"Failed to process row {i + 1} while running enricher.",
                                         new { operation.Id, operation.JobId, operation.ContentType, operation.Entity }, dto);

                    failureReasons.Add($"Failed to process row {i + 1}.");
                }

                await this.repository.CreateAsync(CreateDomainEntity(dto, operation.Body));
            }

            if (failureReasons.Count > 0)
            {
                await this.workerOperationStatusRepository.CreateAsync(operation, failureReasons);
            }
        }
Exemplo n.º 10
0
        public ContentParseUnitTest()
        {
            // configure services injection.
            var serviceProvider = new ServiceCollection()
                                  .AddLogging()
                                  .AddSingleton <IContentParser, ContentParser>()
                                  .BuildServiceProvider();

            _fakeContents = new Faker();
            _logger       = serviceProvider
                            .GetService <ILoggerFactory>()
                            .CreateLogger(typeof(ContentParseUnitTest));
            // get required service
            _contentParserService = serviceProvider.GetService <IContentParser>();
        }
Exemplo n.º 11
0
        public FileSystemOutputHandler(
            CommandLineOptions commandLineOptions,
            IFileSystem fileSystem,
            IContext <Post, Tag, Page> context,
            ITemplateHandler templateHandler,
            IContentParser contentParser,
            IOptions <SiteConfig> siteConfig,
            ISourceHandler sourceHandler,
            ISlugHelper slugHelper)
        {
            (this.commandLineOptions, this.fileSystem, this.context, this.templateHandler,
             this.contentParser, this.siteConfig, this.sourceHandler, this.slugHelper) =
                (commandLineOptions, fileSystem, context, templateHandler, contentParser, siteConfig.Value, sourceHandler, slugHelper);

            this.site = new { config = this.siteConfig, tags = this.context.Tags.OrderBy(t => t.Name), pages = this.context.Pages };
        }
Exemplo n.º 12
0
 public MSMQQueue(IContentParser parser, IConfigurationSource cfg, ILogger logger)
     : base(parser, cfg, logger)
 {
 }
Exemplo n.º 13
0
 public HomeController(ILogger <HomeController> logger, IContentParser contentParser)
 {
     _logger        = logger;
     _contentParser = contentParser;
 }
 public void throws_if_null_arguments_are_passed(IContentProvider contentProvider,
     IContentParser contentParser)
 {
     Assert.Throws<ArgumentNullException>(() => Target.ParseContent(contentProvider, contentParser));
 }
Exemplo n.º 15
0
 public void throws_if_null_arguments_are_passed(IContentProvider contentProvider, IContentParser contentParser)
 {
     Assert.That(() => Target.ParseContent(contentProvider, contentParser), Throws.TypeOf <ArgumentNullException>());
 }
Exemplo n.º 16
0
 public void throws_if_null_arguments_are_passed(IContentProvider contentProvider, IContentParser contentParser)
 {
     Target.ParseContent(contentProvider, contentParser);
 }
Exemplo n.º 17
0
 public MSMQQueue(IContentParser parser, IConfigurationSource cfg, ILogger logger)
     : base(parser, cfg, logger)
 {
 }
Exemplo n.º 18
0
 public HttpMessageSource(IContentParser parser, IConfigurationSource cfg, ILogger logger)
     : base(parser, cfg, logger)
 {
     Messages = new ConcurrentQueue<IMessage>();
 }
Exemplo n.º 19
0
 public FileConverter(IFileReader fileReader, IContentParser contentParser)
 {
     _fileReader    = fileReader;
     _contentParser = contentParser;
 }
Exemplo n.º 20
0
 protected BaseMessageSource(IContentParser parser, IConfigurationSource cfg, ILogger logger)
 {
     Parser        = parser;
     Configuration = cfg;
     Logger        = logger;
 }
 public void throws_if_null_arguments_are_passed(IContentProvider contentProvider, IContentParser contentParser)
 {
     Target.ParseContent(contentProvider, contentParser);
 }
Exemplo n.º 22
0
 public HttpMessageSource(IContentParser parser, IConfigurationSource cfg, ILogger logger) : base(parser, cfg, logger)
 {
     Messages = new ConcurrentQueue <IMessage>();
 }
Exemplo n.º 23
0
 public ProcessingWorker(IPostRepository repository, IContentParser <Post> contentParser)
 {
     _repository    = repository;
     _contentParser = contentParser;
 }
Exemplo n.º 24
0
 public BaseParser(IContentParser parser)
 {
     _contextParser = parser;
 }
Exemplo n.º 25
0
 public WebsiteScraper(IContentParser contentParser)
 {
     _contentParser = contentParser;
 }