コード例 #1
0
        private async Task <IndexerResult> QueryIndexer(
            IIndexer indexer
            , Query query
            , CancellationToken token
            )
        {
            var indexerResult = new IndexerResult {
                Indexer = indexer.Tag
            };

            try
            {
                var result = await indexer.Query(query, token);

                indexerResult.Torrents = result?.Where(t => t != null)
                                         ?? new Torrent[0];
            }
            catch (TaskCanceledException exception)
            {
                _logger.LogError(
                    $"{indexer} timed out during query."
                    , exception
                    );
            }
            catch (Exception exception)
            {
                _logger.LogError(
                    $"{indexer} threw an exception during execution."
                    , exception
                    );
            }

            return(indexerResult);
        }
コード例 #2
0
ファイル: Scouter.cs プロジェクト: cralexns/Traktor
 public Magnet(IndexerResult result, int score)
 {
     this.Title        = result.Title;
     this.IsFullSeason = result.IsFullSeason;
     this.Link         = new Uri(result.Magnet);
     this.Score        = score;
 }
コード例 #3
0
 // running in UI thread
 private void OnIndexingFinished(object sender, IndexerResult result)
 {
     lock (this)
     {
         this.NumOfIndexingThreads--;
     }
 }
コード例 #4
0
        public IEnumerable <string> GetResult(IndexerFile file)
        {
            IndexerResult indexerResult = new IndexerResult();

            _configuration.Splitter.SetResultPhase(true);

            if (!_textExtractors.ContainsKey(file.Extension))
            {
                string message = "No extractor is defined for file extension: " + file.Extension + ".";
                throw new Exception(message);
            }

            ITextExtractor textExtractor = _textExtractors[file.Extension];
            string         fileText      = File.ReadAllText(file.Path);

            foreach (string identifier in textExtractor.Extract(fileText, _configuration.ExtractType))
            {
                try
                {
                    IdentifierSplitResult identifierSplitResult = new IdentifierSplitResult(identifier, file);
                    identifierSplitResult.Add(_configuration.Splitter.Split(identifier));
                    indexerResult.AddSplitResult(identifierSplitResult);
                }
                catch (Exception)
                {
                    continue;
                }
            }

            return(indexerResult.GetSplitResultList().SelectMany(x => x.Splits).Select(Filter).Where(x => !string.IsNullOrEmpty(x)));
        }
コード例 #5
0
ファイル: Scouter.cs プロジェクト: cralexns/Traktor
                public int CalculateScore(IndexerResult result)
                {
                    foreach (var def in this.Definition)
                    {
                        if (IsMatch(def, result))
                        {
                            return(this.Weight);
                        }
                    }

                    return(0);
                }
コード例 #6
0
        /// <summary>
        /// Populates result after indexer completes
        /// </summary>
        private void BackgroundWorker_WorkCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            ProgressValue        = 0;
            IsIndexingInProgress = false;
            HasIndexingResult    = true;
            NotifyPropertyChanged(() => HasIndexingResult);
            UpdateCanStartIndexing();

            if (e.Error != null)
            {
                Status = e.Error.Message;
                return;
            }

            if (e.Cancelled)
            {
                Status = "Process Cancelled.";
                return;
            }

            IndexerResult result = (IndexerResult)e.Result;

            if (result == null)
            {
                Status = "Process did not return any result.";
                return;
            }

            IdentifierCount        = result.GetSplitResultList().Count;
            DictionaryWordsCount   = result.GetDictionaryWordList().Count;
            TokensCount            = result.GetTokenList().Count;
            UnidentifiedWordsCount = result.GetUnidentifiedList().Count;

            DictionaryWords   = string.Join(Environment.NewLine, result.GetDictionaryWordList().Keys.OrderBy(x => x).ThenBy(x => x.Length));
            Tokens            = string.Join(Environment.NewLine, result.GetTokenList().Keys.OrderBy(x => x).ThenBy(x => x.Length));
            UnidentifiedWords = string.Join(Environment.NewLine, result.GetUnidentifiedList().Keys.OrderBy(x => x.Length).ThenBy(x => x));
            CorrectedWords    = string.Join(Environment.NewLine, result.GetCorrectionDictionary().OrderBy(x => x.Key).Select(x => x.Key + ": " + x.Value.Word));
            StemmedWords      = string.Join(Environment.NewLine, result.GetStemmedDictionary().OrderBy(x => x.Key).Select(x => x.Key + ": " + x.Value.Word));

            NotifyPropertyChanged(() => IdentifierCount);
            NotifyPropertyChanged(() => DictionaryWordsCount);
            NotifyPropertyChanged(() => TokensCount);
            NotifyPropertyChanged(() => UnidentifiedWordsCount);
            NotifyPropertyChanged(() => DictionaryWords);
            NotifyPropertyChanged(() => UnidentifiedWords);
            NotifyPropertyChanged(() => Tokens);
            NotifyPropertyChanged(() => StemmedWords);
            NotifyPropertyChanged(() => CorrectedWords);

            _result = result;
            Status  = "";
        }
コード例 #7
0
ファイル: Scouter.cs プロジェクト: xtfrost/Traktor
                private bool IsMatch(string def, IndexerResult result)
                {
                    switch (this.Category)
                    {
                    case ParameterCategory.Resolution:
                        return(Compare(result.VideoQuality, GetEnum <IndexerResult.VideoQualityLevel>(def)));

                    case ParameterCategory.Audio:
                    case ParameterCategory.Source:
                    case ParameterCategory.Tag:
                        var req = GetEnum <IndexerResult.QualityTrait>(def);
                        if (this.Comparison == ParameterComparison.NotEqual)
                        {
                            return(result.Traits.All(x => Compare(x, req)));
                        }
                        else
                        {
                            return(result.Traits.Any(x => Compare(x, req)));
                        }
                        //foreach (var trait in result.Traits)
                        //{
                        //    if (Compare(trait, req))
                        //        return true;
                        //}
                        return(false);

                    case ParameterCategory.Group:
                        return(Compare(result.Group, def as string));

                    case ParameterCategory.SizeMb:
                        return(Compare(result.SizeBytes, ((def.ToLong() ?? 0) * 1024 * 1024)));

                    case ParameterCategory.FreeText:
                        return(result.Title.Contains(def as string));

                    case ParameterCategory.Peers:
                        if (def.EndsWith("S"))
                        {
                            return(Compare(result.Seeds, def.Substring(0, def.Length - 1).ToInt() ?? 0));
                        }
                        if (def.EndsWith("L"))
                        {
                            return(Compare(result.Peers, def.Substring(0, def.Length - 1).ToInt() ?? 0));
                        }
                        return(Compare(result.Seeds + result.Peers, def.ToInt() ?? 0));
                    }
                    return(false);
                }
コード例 #8
0
        /// <summary>
        /// Get Result
        /// </summary>
        /// <returns>Indexer Result</returns>
        private IndexerResult GetResult()
        {
            IndexerResult indexerResult = new IndexerResult();

            _configuration.Splitter.SetResultPhase(true);

            // extract
            int totalFileCount   = _configuration.FilesToScan.Count;
            int currentFileCount = 0;

            foreach (IndexerFile file in _configuration.FilesToScan)
            {
                try
                {
                    _configuration.NotificationHandler.UpdateStatus(NotificationType.ReadingFileForIdentifiers, currentFileCount, totalFileCount, "Extracting file identifier: " + file.Name);

                    if (!_textExtractors.ContainsKey(file.Extension))
                    {
                        string message = "No extractor is defined for file extension: " + file.Extension + ".  Do you want to skip this file?";
                        if (_configuration.NotificationHandler.GetYesNoAnswer(QuestionType.NoTextExtratorDefined, message))
                        {
                            continue;
                        }
                    }

                    ITextExtractor textExtractor = _textExtractors[file.Extension];
                    string         fileText      = File.ReadAllText(file.Path);
                    foreach (string identifier in textExtractor.Extract(fileText, _configuration.ExtractType))
                    {
                        _configuration.NotificationHandler.UpdateStatus(NotificationType.Splitting, currentFileCount, totalFileCount, "Splitting token: " + identifier + " in file: " + file.Name);
                        IdentifierSplitResult identifierSplitResult = new IdentifierSplitResult(identifier, file);
                        identifierSplitResult.Add(_configuration.Splitter.Split(identifier));
                        indexerResult.AddSplitResult(identifierSplitResult);
                    }
                }
                catch (Exception e)
                {
                    string additionalMessage = "Error reading file. " + Environment.NewLine + "File: " + file.Name +
                                               Environment.NewLine + "Message: " + e.Message + Environment.NewLine +
                                               "Do you want to skip this file?";
                    if (!_configuration.NotificationHandler.GetYesNoAnswer(QuestionType.ErrorReadingFile, additionalMessage))
                    {
                        throw;
                    }
                }
                finally
                {
                    currentFileCount++;
                }
            }

            // Since while adding result we do not have merged token, misspelled and stemmed word info, filter them and add to respective list
            indexerResult.UpdateFromMergeToken(_tokenDictionary);
            indexerResult.UpdateFromMisspelled(_tokenDictionary);
            indexerResult.UpdateFromStemmed(_tokenDictionary);

            // Filter 3: Stem every identified. If the word is identified replace the word with stemmed word
            if (_configuration.Stemmer != null)
            {
                List <string> dictionaryWordList     = indexerResult.GetDictionaryWordList().Keys.ToList();
                int           totalIdentifiedCount   = dictionaryWordList.Count;
                int           currentIdentifiedCount = 0;
                foreach (string identified in dictionaryWordList)
                {
                    currentIdentifiedCount++;
                    _configuration.NotificationHandler.UpdateStatus(NotificationType.Stemming, currentIdentifiedCount, totalIdentifiedCount, "Stemming: " + identified);
                    string stemmedText = _configuration.Stemmer.GetStemmedText(identified);
                    if (stemmedText != null && stemmedText != identified && _configuration.Dictionary.IsWord(stemmedText))
                    {
                        indexerResult.AddStemmedWordAndReplaceIdentified(identified, stemmedText);
                    }
                }
            }

            // Filter result
            indexerResult.RemoveFilterWordAndTokenResult(_configuration.Dictionary);

            _configuration.NotificationHandler.UpdateStatus(NotificationType.IndexingCompleted, 1, 1, "Indexing Completed");
            return(indexerResult);
        }