且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

编码挑战:检测不良语法

更新时间:2023-02-26 14:22:55

这是一个使用API​​服务的快速'n'脏解决方案。可悲的是,服务不如Grammarly ...

Here is a quick 'n' dirty solution using an API service. Sadly the service is not as good as Grammarly...
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Net;

namespace TextGearsApi
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Coding challenge: detect poor grammar");
            Console.WriteLine("=====================================\n");

            // Get you API key here: https://textgears.com
            var api = new TextGearsApi("[key_goes_here");

            for (;;)
            {
                Console.Write("Text to check: ");
                var text = Console.ReadLine();
                if (string.IsNullOrEmpty(text)) break;

                try
                {
                    var result = api.Check(text);
                    if (result?.Errors?.Count != 0)
                    {
                        Console.WriteLine("Recommendations:");
                        for (int i = 0; i < result.Errors.Count; i++)
                        {
                            var item = result.Errors[i];
                            Console.WriteLine(


{i + 1}: {item.Bad}>> {string.Join( ,item.Better。选择(x =>
" {i + 1}: {item.Bad} >> {string.Join(", ", item.Better.Select(x =>


\ { x} \))} );
}
Console.WriteLine();
}
其他
{
Console.WriteLine(
看起来没问题。\ n );
}
}
catch(exception ex)
{
Console.WriteLine(
"\"{x}\""))}"); } Console.WriteLine(); } else { Console.WriteLine("Looks okay.\n"); } } catch (Exception ex) { Console.WriteLine(