Exemple #1
0
        public static async Task <Content> RunAsync(Content content, IProgress <string> progress = null)
        {
            progress?.Report("[TextBot] - Getting Wikipedia page extract...");

            content.SourceContent = await WikipediaClient.GetWikipediaPageExtractAsync(content.WikipediaPageTitle).ConfigureAwait(false);

            progress?.Report("[TextBot] - Sanitazing extract...");

            content.SanitizedContent = content.SourceContent.Sanitize();

            progress?.Report("[TextBot] - Segmenting extract into sentences...");

            content.Sentences = content.SanitizedContent.BreakIntoSentences();

            if (progress != null)
            {
                await ReportChosenSentences(content, progress);
            }

            progress?.Report("[TextBot] - Getting key-phrases for the sentences...");

            //content.Sentences = await WatsonTextAnalyticsClient.ExtractKeyPhrasesAsync(content.Sentences.Take(content.NumberOfSentences).ToList());

            content.Sentences = await AzureTextAnalyticsClient.ExtractKeyPhrasesAsync(content.Sentences.Take(content.NumberOfSentences).ToList());

            progress?.Report("[TextBot] - Done.");

            return(content);
        }
        public async Task <IActionResult> GetByWord(string palavra)
        {
            WikipediaClient wClient = new WikipediaClient();

            var result = await wClient.GetWiki(palavra);

            return(Ok(result));
        }
Exemple #3
0
 public ArtistController(MusicBrainzClient musicBrainzClient,
                         WikiDataClient wikiDataClient,
                         WikipediaClient wikipediaClient,
                         CoverArtService coverArtService,
                         ILogger <ArtistController> logger)
 {
     _musicBrainzClient = musicBrainzClient;
     _wikiDataClient    = wikiDataClient;
     _wikipediaClient   = wikipediaClient;
     _coverArtService   = coverArtService;
     _logger            = logger;
 }
Exemple #4
0
        public async Task Wiki([Remainder] string text)
        {
            WikipediaClient client = new WikipediaClient();

            client.Limit = 1;

            QueryResult results = client.Search(text);

            var builder = new EmbedBuilder()
            {
                Color = new Color(114, 137, 218),
            };


            foreach (Search s in results.Search)
            {
                PageResult pages = client.GetPage(s.Title);

                string value = "\n";
                string name  = s.Title;

                foreach (Page page in pages.Pages)
                {
                    value = page.Extract;
                }

                if (value.Length > 1017 - s.Url.AbsoluteUri.Length)
                {
                    value  = value.Remove(1017 - s.Url.AbsoluteUri.Length);
                    value += "...\n\n";
                }
                else
                {
                    value += "\n\n";
                }

                value += s.Url.AbsoluteUri;

                builder.AddField(x => {
                    x.Name     = name;
                    x.IsInline = false;
                    x.Value    = value;
                });
            }

            await ReplyAsync("", false, builder.Build());
        }
        public async Task Wiki(string querry)
        {
            try
            {
                WikipediaClient wkclient = new WikipediaClient();

                string arg = querry;
                if (arg != null)
                {
                    string cont = await wkclient.Search(arg);

                    string clncont = Regex.Replace(cont, @"([^a-zA-Z0-9_]|^\s)", string.Empty);
                    string res     = String.Format("You asked for  :{0 }\n Answer: \n {1}", arg, cont);
                    //await e.Channel.SendMessage(String.Format("You asked for  :{0}\n",arg));
                    //await e.Channel.SendMessage(String.Format("Answer: \n {0}", cont));
                    string temp = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Temp");
                    if (Directory.Exists(temp) == true)
                    {
                        Directory.Delete(temp, true);
                    }
                    Directory.CreateDirectory(temp);
                    string path = Path.Combine(temp, arg + ".txt");
                    File.WriteAllText(path, cont);
                    Stream fil = File.OpenRead(path);
                    // var stat =await e.Channel.SendMessage(res);
                    if (cont.Length > 2000)
                    {
                        await Context.Channel.SendFileAsync(fil, path, String.Format("{0} You asked for  :{1} " +
                                                                                     "\n The answer exceeds the 2000 characters limit so it is saved on a plain text file"
                                                                                     , Context.User.Mention, arg));

                        File.Delete(path);
                    }
                    else
                    {
                        await ReplyAsync(res);
                    }
                }
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
            }

            // Console.WriteLine("Message State : {0} \n Message Text {1}", stat.State.ToString(), stat.Text);
        }
Exemple #6
0
        public void Register(ContainerBuilder builder)
        {
            builder
            .Register(c => new HttpClient())
            .SingleInstance();

            builder
            .AddCaching <WikipediaProvider>(TimeSpan.FromHours(2));

            builder
            .RegisterType <WikipediaSearchConverter>()
            .AsSelf();

            builder
            .Register(c => new JsonSerializer
            {
                Converters = { c.Resolve <WikipediaSearchConverter>() }
            });

            builder
            .Register(c => c
                      .Resolve <IConfigurationProvider>()
                      .GetConfiguration <WikipediaConfiguration>() ?? WikipediaConfiguration.Fallback)
            .AsSelf()
            .InstancePerDependency();

            builder
            .Register(c =>
            {
                var pluginConfig = c.Resolve <WikipediaConfiguration>();
                var clients      = new List <IWikipediaClient>();
                foreach (var baseUrl in pluginConfig.BaseUrls)
                {
                    var httpClient = new HttpClient
                    {
                        BaseAddress = new Uri(baseUrl)
                    };
                    var client = new WikipediaClient(httpClient, c.Resolve <JsonSerializer>());
                    clients.Add(client);
                }
                return(clients);
            })
            .As <IEnumerable <IWikipediaClient> >()
            .SingleInstance();
        }
Exemple #7
0
        public static async Task <string> AskAndReturnWikipediaPageTitleAsync(string searchTerm, int numberOfResults = 5)
        {
            WriteLine("");
            WriteLine($"Searching Wikipedia for '{searchTerm}'...");

            var pageTitles = await WikipediaClient.GetWikipediaPageTitlesAsync(searchTerm, numberOfResults).ConfigureAwait(false);

            if (pageTitles.Count == 0)
            {
                WriteLine("Your search term didn't return any result.");
                WriteLine("Press any key to exit...");
                ReadKey();
                Environment.Exit(0);
            }

            var optionChosen = WriteOptions(pageTitles, $"Choose an option for '{searchTerm}'.");

            return(optionChosen.value);
        }
Exemple #8
0
        private static async Task Main()
        {
            //Default language is English
            WikipediaClient client = new WikipediaClient();

            //Use HTTPS instead of HTTP
            client.UseTls = true;

            //We would like 5 results
            client.Limit = 5;

            //We would like to search inside the articles
            client.What = What.Text;

            const string searchText = "Microsoft C#";
            QueryResult  results    = await client.SearchAsync(searchText);

            Console.WriteLine("Searching for {0}:{1}", searchText, Environment.NewLine);
            Console.WriteLine("Found " + results.Search.Count + " English results:");

            foreach (Search s in results.Search)
            {
                Console.WriteLine(s.Title);
            }

            Console.WriteLine();
            Console.WriteLine();

            //We change the language to Spanish
            client.Language = Language.Spanish;

            results = client.Search("Microsoft C#");

            Console.WriteLine("Found " + results.Search.Count + " Spanish results:");

            foreach (Search s in results.Search)
            {
                Console.WriteLine(s.Title);
            }
        }
        public static QueryResult GetWikipediaDataAsync(string query)
        {
            var wikipedia = new WikipediaClient();

            return(wikipedia.Search(query));
        }